Overview of bundles
To manage database transactions, Guidewire applications group entity instances in groups called bundles. A bundle is a collection of in-memory entity instances that represent rows in the database. The application transmits and saves all entity instances in the bundle to the database in one transaction. A bundle includes changed entities, new entities, and entities to delete from the database. Gosu represents a bundle with the class gw.transaction.Bundle.
Guidewire refers to the process of sending the entities to the database as committing the bundle to the database. If a bundle commit attempt completely succeeds, all database changes happen in a single database transaction. If the commit attempt fails in any way, the entire update fails and Gosu throws an exception.
A bundle is not thread-safe. Be aware of any concurrency issues when accessing entity instances in a bundle or committing those instances to the database. If multiple users can access the entity instances in a bundle simultaneously, you must use external synchronization to ensure reading and writing correct data, such as for property values.
The two basic types of bundles are read-only bundles and writable bundles. A database query places the results of the query are in a temporary read-only bundle. To change any data, you must copy the contents of a read-only bundle to a writable bundle.
Not all writable bundles eventually commit to the database. For example:
- A user might start to make data changes in the user interface but abandon the task.
- A user might start to make data changes in the user interface, try to save them, but errors prevent completion. Eventually, the user might cancel the action before fixing and completing the action.
- A batch process might attempt a database change, but errors prevent completing the action.
- A web service call might attempt a database change, but errors prevent completing the action.
If any code destroys a bundle that has uncommitted changes, no entity data in the database changes.
setFieldValue
as part of a specific approved use.See also
- Making an entity instance writable by adding to a bundle
- Adding entity instances to bundles
- Getting the bundle of an existing entity instance
- Getting an entity instance from a public ID or a key
- Creating new entity instances in specific bundles
- Committing a bundle explicitly in very rare cases
- Determining what data changed in a bundle
- Concurrency and thread safety
Accessing the current bundle
In most programming contexts, the application has already prepared a current bundle, for example, in all rule execution contexts, and typical PCF user interface code. When there is a current bundle, get the current bundle using the code:
gw.transaction.Transaction.getCurrent()In batch processes and WS-I web service implementations there is no current bundle. You need to create a new bundle for your data changes.
Warning about transaction class confusion
PolicyCenter
provides more than one Transaction
type in Gosu. This topic is about the class in the gw.transaction package, gw.transaction.Transaction. Do
not confuse the gw.transaction.Transaction
class with the Transaction
entity type or type list.
If you use the gw.transaction.Transaction API,
you can use a Gosu uses
statement such as the following:
uses gw.transaction.Transaction