com.vaadin.addon.jpacontainer
Interface MutableEntityProvider<T>

All Superinterfaces:
EntityProvider<T>, Serializable
All Known Subinterfaces:
BatchableEntityProvider<T>
All Known Implementing Classes:
BatchableLocalEntityProvider, CachingBatchableEntityProvider, CachingBatchableLocalEntityProvider, CachingMutableEntityProvider, CachingMutableLocalEntityProvider, MutableEntityProvider, MutableLocalEntityProvider

public interface MutableEntityProvider<T>
extends EntityProvider<T>

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
 T addEntity(T entity)
          Adds entity to the persistence storage.
 void removeEntity(Object entityId)
          Removes the entity identified by entityId.
 T updateEntity(T entity)
          Saves the changes made to entity to the persistence storage.
 void updateEntityProperty(Object entityId, String propertyName, Object propertyValue)
          Updates a single property value of a specific entity.
 
Methods inherited from interface com.vaadin.addon.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 Detail

addEntity

T addEntity(T entity)
            throws RuntimeException
Adds entity to 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 of EntityProvider.isEntitiesDetached(), this may or may not be the same instance as entity. Therefore, if EntityProvider.isEntitiesDetached() is true, clients should always assume that entity != 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

T updateEntity(T entity)
               throws RuntimeException
Saves the changes made to entity to 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 of EntityProvider.isEntitiesDetached(), this may or may not be the same instance as entity. Therefore, if EntityProvider.isEntitiesDetached() is true, clients should always assume that entity != 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 - if propertyName is not a valid property name.
RuntimeException - if an error occurs while saving the change to the persistence storage.

removeEntity

void removeEntity(Object entityId)
                  throws RuntimeException
Removes the entity identified by entityId. 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.


Copyright © 2013 Vaadin Ltd. All rights reserved.