Committing a bundle explicitly in very rare cases
Committing a bundle sends all changes for entity instances in this group of entities to the database. A successful commit can perform any combination of adding, changing, or removing entity instances from the database. In typical code, do not explicitly commit a bundle.
For data changes, typically one of the following is true:
- The application has a default bundle management life cycle and commits the bundle at the appropriate time, for example, in rule set execution or typical PCF edit screens. There is no reason to explicitly commit this bundle.
- In some cases, you must
create an entirely new bundle. Do not explicitly commit the bundle. The
runWithNewBundleAPI commits the bundle automatically when your code completes.
For web service implementations that need
to change data, use the runWithNewBundle
API method. The runWithNewBundle
API method commits the bundle for you when your code completes.
If you are sure that committing the bundle is appropriate, use the method bundle.commit(). If the attempt fails, Gosu throws an exception. The entire commit process fails. The database remains unchanged.
Get the current bundle by calling the getCurrent static method on the
Transaction class:
uses gw.transaction.Transaction
var bundle = Transaction.getCurrent()
bundle.commit()
If you have an entity instance reference, use the
entity.bundle property to get its bundle.
Committing a bundle commits everything in the bundle, not just the instance
from which you got the bundle reference. For example:
var bundle = myPolicy.bundle
bundle.commit() // Commit all entities in the bundle
See also
