Interface MutableEntityProvider<T>
- All Superinterfaces:
EntityProvider<T>,Serializable
- All Known Subinterfaces:
BatchableEntityProvider<T>
- All Known Implementing Classes:
BatchableLocalEntityProvider,CachingBatchableEntityProvider,CachingBatchableLocalEntityProvider,CachingMutableEntityProvider,CachingMutableLocalEntityProvider,MutableEntityProvider,MutableLocalEntityProvider
Entity provider that also supports adding, updating and removing entities.
Implementations should pay special attention to the usage of the
EntityProvider.isEntitiesDetached() property.
All the methods defined in this interface should run in their own transactions. The implementation may either handle the transactions itself, or rely on declarative transaction handling as provided by e.g. Spring or EJB. If a method completes successfully, its transaction should be committed. If an error occurs while accessing the persistence storage, the transaction should be rolled back and a runtime exception should be thrown.
- Since:
- 1.0
- Author:
- Petter Holmström (Vaadin Ltd)
-
Method Summary
Modifier and TypeMethodDescriptionAddsentityto the persistence storage.voidremoveEntity(Object entityId) Removes the entity identified byentityId.updateEntity(T entity) Saves the changes made toentityto the persistence storage.voidupdateEntityProperty(Object entityId, String propertyName, Object propertyValue) Updates a single property value of a specific entity.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, setQueryModifierDelegate
-
Method Details
-
addEntity
Addsentityto the persistence storage. This method returns the same entity after adding to make it possible for the client to access the entity identifier. Note, however, that depending on the implementation of the entity provider and the state ofEntityProvider.isEntitiesDetached(), this may or may not be the same instance asentity. Therefore, ifEntityProvider.isEntitiesDetached()is true, clients should always assume thatentity != returnedEntity.- Parameters:
entity- the entity to add (must not be null).- Returns:
- the added entity.
- Throws:
RuntimeException- if an error occurs while adding the entity to the persistence storage.
-
updateEntity
Saves the changes made toentityto the persistence storage. This method returns the same entity after saving the changes. Note, however, that depending on the implementation of the entity provider and the state ofEntityProvider.isEntitiesDetached(), this may or may not be the same instance asentity. Therefore, ifEntityProvider.isEntitiesDetached()is true, clients should always assume thatentity != returnedEntity.- Parameters:
entity- the entity to update (must not be null).- Returns:
- the updated entity.
- Throws:
RuntimeException- if an error occurs while saving the changes to the persistence storage.
-
updateEntityProperty
void updateEntityProperty(Object entityId, String propertyName, Object propertyValue) throws IllegalArgumentException, RuntimeException Updates a single property value of a specific entity. If the entity is not found, nothing happens.- Parameters:
entityId- the identifier of the entity (must not be null).propertyName- the name of the property to update (must not be null).propertyValue- the new property value.- Throws:
IllegalArgumentException- ifpropertyNameis not a valid property name.RuntimeException- if an error occurs while saving the change to the persistence storage.
-
removeEntity
Removes the entity identified byentityId. If no entity is found, nothing happens.- Parameters:
entityId- the identifier of the entity to remove.- Throws:
RuntimeException- if an error occurs while removing the entity from the persistence storage.
-