Class MutableLocalEntityProvider<T>
java.lang.Object
com.vaadin.featurepack.data.jpacontainer.provider.LocalEntityProvider<T>
com.vaadin.featurepack.data.jpacontainer.provider.MutableLocalEntityProvider<T>
- All Implemented Interfaces:
EntityProvider<T>,EntityProviderChangeNotifier<T>,MutableEntityProvider<T>,Serializable
- Direct Known Subclasses:
BatchableLocalEntityProvider,CachingMutableLocalEntityProvider,MutableEntityProvider
public class MutableLocalEntityProvider<T>
extends LocalEntityProvider<T>
implements MutableEntityProvider<T>, EntityProviderChangeNotifier<T>
Extended version of
LocalEntityProvider that provides editing
support. Transactions can either be handled internally by the provider, or by
an external container such as Spring or EJB (see the JPAContainer manual for
examples of how to do this). By default, transactions are handled internally
by invoking the transaction methods of the EntityManager.
This entity provider fires EntityProviderChangeEvents every time an
entity is added, updated or deleted.
- Since:
- 1.0
- Author:
- Petter Holmström (Vaadin Ltd)
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionMutableLocalEntityProvider(Class<T> entityClass) Creates a newMutableLocalEntityProvider.MutableLocalEntityProvider(Class<T> entityClass, jakarta.persistence.EntityManager entityManager) Creates a newMutableLocalEntityProvider. -
Method Summary
Modifier and TypeMethodDescriptionAddsentityto the persistence storage.voidaddListener(EntityProviderChangeListener<T> listener) Registerslistenerto be notified ofEntityProviderChangeEvents.protected voidSendseventto all registered listeners ifisFireEntityProviderChangeEvent()is true.protected booleanReturns whetherEntityProviderChangeEvents should be fired by this entity provider.booleanReturns whether the entity provider is handling transactions internally (the default) or relies on external transaction handling.voidremoveEntity(Object entityId) Removes the entity identified byentityId.voidremoveListener(EntityProviderChangeListener<T> listener) Removes the previously registered listener.protected voidrunInTransaction(Runnable operation) IfisTransactionsHandledByProvider()is true,operationwill be executed inside a transaction that is commited after the operation is completed.protected voidsetFireEntityProviderChangeEvents(boolean fireEvents) Sets whetherEntityProviderChangeEvents should be fired by this entity provider.voidsetTransactionsHandledByProvider(boolean transactionsHandled) Specifies whether the entity provider should handle transactions itself or whether they should be handled outside (e.g. if declarative transactions are used).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 class com.vaadin.featurepack.data.jpacontainer.provider.LocalEntityProvider
addPrimaryKeyToSortList, containsEntity, createFilteredQuery, createSiblingQuery, createUnsortedFilteredQuery, detachEntity, doContainsEntity, doGetAllEntityIdentifiers, doGetEntity, doGetEntityCount, doGetEntityIdentifierAt, doGetEntityManager, doGetFirstEntityIdentifier, doGetLastEntityIdentifier, doGetNextEntityIdentifier, doGetPreviousEntityIdentifier, getAllEntityIdentifiers, getEntity, getEntityClassMetadata, getEntityCount, getEntityIdentifierAt, getEntityManager, getEntityManagerProvider, getFirstEntityIdentifier, getIdentifier, getLastEntityIdentifier, getLazyLoadingDelegate, getNextEntityIdentifier, getPreviousEntityIdentifier, getQueryModifierDelegate, getSibling, isEntitiesDetached, readResolve, refresh, refreshEntity, setEntitiesDetached, setEntityManager, setEntityManagerProvider, setLazyLoadingDelegate, setQueryModifierDelegate, translateSortBy, writeReplaceMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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
-
Constructor Details
-
MutableLocalEntityProvider
Creates a newMutableLocalEntityProvider. The entity manager must be set usingLocalEntityProvider.setEntityManager(javax.persistence.EntityManager).- Parameters:
entityClass- the entity class (must not be null).
-
MutableLocalEntityProvider
public MutableLocalEntityProvider(Class<T> entityClass, jakarta.persistence.EntityManager entityManager) Creates a newMutableLocalEntityProvider.- Parameters:
entityClass- the entity class (must not be null).entityManager- the entity manager to use (must not be null).
-
-
Method Details
-
setTransactionsHandledByProvider
public void setTransactionsHandledByProvider(boolean transactionsHandled) Specifies whether the entity provider should handle transactions itself or whether they should be handled outside (e.g. if declarative transactions are used).- Parameters:
transactionsHandled- true to handle the transactions internally, false to rely on external transaction handling.
-
isTransactionsHandledByProvider
public boolean isTransactionsHandledByProvider()Returns whether the entity provider is handling transactions internally (the default) or relies on external transaction handling.- Returns:
- true if transactions are handled internally, false if not.
-
runInTransaction
IfisTransactionsHandledByProvider()is true,operationwill be executed inside a transaction that is commited after the operation is completed. Otherwise,operationwill just be executed.- Parameters:
operation- the operation to run (must not be null).
-
addEntity
Description copied from interface:MutableEntityProviderAddsentityto 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.- Specified by:
addEntityin interfaceMutableEntityProvider<T>- Parameters:
entity- the entity to add (must not be null).- Returns:
- the added entity.
-
removeEntity
Description copied from interface:MutableEntityProviderRemoves the entity identified byentityId. If no entity is found, nothing happens.- Specified by:
removeEntityin interfaceMutableEntityProvider<T>- Parameters:
entityId- the identifier of the entity to remove.
-
updateEntity
Description copied from interface:MutableEntityProviderSaves 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.- Specified by:
updateEntityin interfaceMutableEntityProvider<T>- Parameters:
entity- the entity to update (must not be null).- Returns:
- the updated entity.
-
updateEntityProperty
public void updateEntityProperty(Object entityId, String propertyName, Object propertyValue) throws IllegalArgumentException Description copied from interface:MutableEntityProviderUpdates a single property value of a specific entity. If the entity is not found, nothing happens.- Specified by:
updateEntityPropertyin interfaceMutableEntityProvider<T>- 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.
-
addListener
Description copied from interface:EntityProviderChangeNotifierRegisterslistenerto be notified ofEntityProviderChangeEvents.- Specified by:
addListenerin interfaceEntityProviderChangeNotifier<T>- Parameters:
listener- the listener to register (must not be null).
-
removeListener
Description copied from interface:EntityProviderChangeNotifierRemoves the previously registered listener.- Specified by:
removeListenerin interfaceEntityProviderChangeNotifier<T>- Parameters:
listener- the listener to remove (must not be null).
-
setFireEntityProviderChangeEvents
protected void setFireEntityProviderChangeEvents(boolean fireEvents) Sets whetherEntityProviderChangeEvents should be fired by this entity provider. -
isFireEntityProviderChangeEvent
protected boolean isFireEntityProviderChangeEvent()Returns whetherEntityProviderChangeEvents should be fired by this entity provider. -
fireEntityProviderChangeEvent
Sendseventto all registered listeners ifisFireEntityProviderChangeEvent()is true.- Parameters:
event- the event to send (must not be null).
-