Interface BatchableEntityProvider<T>
- All Superinterfaces:
EntityProvider<T>,MutableEntityProvider<T>,Serializable
- All Known Implementing Classes:
BatchableLocalEntityProvider,CachingBatchableEntityProvider,CachingBatchableLocalEntityProvider
MutableEntityProvider that can execute several
update operations (that is, adding new entities, and updating and removing
existing entities) inside a single transaction. This feature is used by
JPAContainer when write-through/auto-commit is turned off.
If the entites handled by this provider contain complex associations, special care should be taken to enforce data integrity. The following example scenarios might give unexpected results if not dealt with properly:
Example 1
- Add Entity1
- Add Entity2
- Update Entity1 to reference Entity2
- Run batch
Example 2
- Add Entity1
- Add Entity2
- Update Entity1 to reference Entity2
- Remove Entity2
- Run batch
- Since:
- 1.0
- Author:
- Petter Holmström (Vaadin Ltd)
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceCallback interface used by thebatchUpdate(BatchableEntityProvider.BatchUpdateCallback)method. -
Method Summary
Modifier and TypeMethodDescriptionvoidExecutes a batch update using the specified callback parameter.Methods inherited from interface com.vaadin.featurepack.data.jpacontainer.EntityProvider
containsEntity, getAllEntityIdentifiers, getEntity, getEntityCount, getEntityIdentifierAt, getEntityManager, getEntityManagerProvider, getFirstEntityIdentifier, getIdentifier, getLastEntityIdentifier, getLazyLoadingDelegate, getNextEntityIdentifier, getPreviousEntityIdentifier, getQueryModifierDelegate, isEntitiesDetached, refresh, refreshEntity, setEntitiesDetached, setEntityManager, setEntityManagerProvider, setLazyLoadingDelegate, setQueryModifierDelegateMethods inherited from interface com.vaadin.featurepack.data.jpacontainer.MutableEntityProvider
addEntity, removeEntity, updateEntity, updateEntityProperty
-
Method Details
-
batchUpdate
void batchUpdate(BatchableEntityProvider.BatchUpdateCallback<T> callback) throws UnsupportedOperationException Executes a batch update using the specified callback parameter. The batch update should be run inside a single transaction. The implementation may either handle the transaction itself, or rely on external transaction handling provided by a container such as Spring or EJB. If the batch update fails, the entire transaction should be rolled back and an exception thrown. Otherwise, it should be committed.Clients should instantiate
BatchableEntityProvider.BatchUpdateCallback, implement theBatchableEntityProvider.BatchUpdateCallback.batchUpdate(MutableEntityProvider)method and execute the updates as if they were using an ordinaryMutableEntityProvider. The following example saves a list of transient entities:provider.batchUpdate(new BatchUpdateCallback
() { public void batchUpdate(MutableEntityProvider batchEnabledEntityProvider) { for (Entity e : myListOfEntitiesToAdd) { batchEnabledEntityProvider.addEntity(e); } } }); - Parameters:
callback- the callback that will be used to run the batch update.- Throws:
UnsupportedOperationException- if this entity provider does not support batch updates.
-