|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.vaadin.addon.jpacontainer.provider.LocalEntityProvider<T>
com.vaadin.addon.jpacontainer.provider.MutableLocalEntityProvider<T>
com.vaadin.addon.jpacontainer.provider.CachingMutableLocalEntityProvider<T>
public class CachingMutableLocalEntityProvider<T>
En extended version of MutableLocalEntityProvider that also
implements the CachingEntityProvider interface.
This provider can be used in applications in the same manner as
MutableLocalEntityProvider, with a few exceptions. By default, the
cache is turned off which means that this provider effectively works as a
MutableLocalEntityProvider. The cache can be turned on using
setCacheEnabled(boolean).
If you are going to edit the entities returned by the container, you should
check the setCloneCachedEntities(boolean) before continuing.
| Constructor Summary | |
|---|---|
CachingMutableLocalEntityProvider(Class<T> entityClass)
Creates a new CachingLocalEntityProvider. |
|
CachingMutableLocalEntityProvider(Class<T> entityClass,
javax.persistence.EntityManager entityManager)
Creates a new CachingMutableLocalEntityProvider. |
|
| Method Summary | |
|---|---|
T |
addEntity(T entity)
Adds entity to the persistence storage. |
boolean |
containsEntity(EntityContainer<T> container,
Object entityId,
com.vaadin.data.Container.Filter filter)
Checks if the persistence storage contains an entity identified by entityId that is also matched by filter. |
void |
flush()
Flushes the cache, forcing all entities to be loaded from the persistence storage upon next request. |
List<Object> |
getAllEntityIdentifiers(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
Gets the identifiers of all items that match filter. |
T |
getEntity(EntityContainer<T> container,
Object entityId)
Loads the entity identified by entityId from the persistence
storage. |
int |
getEntityCacheMaxSize()
Gets the maximum number of entity instances to store in the cache. |
int |
getEntityCount(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter)
Gets the number of entities that are matched by filter. |
Object |
getEntityIdentifierAt(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy,
int index)
Gets the identifier of the entity at position index in the
result set determined from filter and sortBy. |
Object |
getFirstEntityIdentifier(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
Gets the identifier of the first item in the list of entities determined by filter and sortBy. |
Object |
getLastEntityIdentifier(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
Gets the identifier of the last item in the list of entities determined by filter and sortBy. |
Object |
getNextEntityIdentifier(EntityContainer<T> container,
Object entityId,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
Gets the identifier of the item next to the item identified by entityId in the list of entities determined by
filter and sortBy. |
Object |
getPreviousEntityIdentifier(EntityContainer<T> container,
Object entityId,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
Gets the identifier of the item previous to the item identified by entityId in the list of entities determined by
filter and sortBy. |
boolean |
isCacheEnabled()
Returns whether the entity provider currently has the internal cache enabled. |
boolean |
isCloneCachedEntities()
Returns whether entities found in the cache should be cloned before they are returned or not. |
boolean |
isEntitiesDetached()
If this method returns true, all entities returned from this entity provider are explicitly detached from the persistence context before returned, regardless of whether the persistence context is extended or transaction-scoped. |
void |
refresh()
Clears all caches and refreshes any loaded that cannot be discarded entities. |
T |
refreshEntity(T entity)
Refreshes an entity from DB. |
void |
removeEntity(Object entityId)
Removes the entity identified by entityId. |
void |
setCacheEnabled(boolean cacheInUse)
Turns the cache on or off. |
void |
setCloneCachedEntities(boolean clone)
Changes the value of the CachingEntityProvider.isCloneCachedEntities() flag. |
void |
setEntityCacheMaxSize(int maxSize)
Sets the maximum number of entity instances to store in the cache. |
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. |
boolean |
usesCache()
Returns whether the entity provider is currently using the internal cache, which will be the case if both the caching is enabled ( CachingEntityProvider.setCacheEnabled(boolean) and there is no filter modifiying
QueryModifierDelegate in use. |
| Methods inherited from class com.vaadin.addon.jpacontainer.provider.MutableLocalEntityProvider |
|---|
addListener, fireEntityProviderChangeEvent, isFireEntityProviderChangeEvent, isTransactionsHandledByProvider, removeListener, runInTransaction, setFireEntityProviderChangeEvents, setTransactionsHandledByProvider |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface com.vaadin.addon.jpacontainer.CachingEntityProvider |
|---|
setEntitiesDetached |
| Methods inherited from interface com.vaadin.addon.jpacontainer.EntityProvider |
|---|
getEntityManager, getEntityManagerProvider, getIdentifier, getLazyLoadingDelegate, getQueryModifierDelegate, setEntityManager, setEntityManagerProvider, setLazyLoadingDelegate, setQueryModifierDelegate |
| Constructor Detail |
|---|
public CachingMutableLocalEntityProvider(Class<T> entityClass,
javax.persistence.EntityManager entityManager)
CachingMutableLocalEntityProvider.
entityClass - the entity class (must not be null).entityManager - the entity manager to use (must not be null).public CachingMutableLocalEntityProvider(Class<T> entityClass)
CachingLocalEntityProvider. The entity manager
must be set using
LocalEntityProvider.setEntityManager(javax.persistence.EntityManager).
entityClass - the entity class (must not be null).| Method Detail |
|---|
public void flush()
CachingEntityProvider
flush in interface CachingEntityProvider<T>public int getEntityCacheMaxSize()
CachingEntityProvider
getEntityCacheMaxSize in interface CachingEntityProvider<T>public boolean isCacheEnabled()
CachingEntityProviderQueryModifierDelegate is in use and it modifies
the filters through the
QueryModifierDelegate.filtersWillBeAdded(javax.persistence.criteria.CriteriaBuilder, javax.persistence.criteria.CriteriaQuery, java.util.List)
method, caching will NOT be enabled.
isCacheEnabled in interface CachingEntityProvider<T>public void setCacheEnabled(boolean cacheInUse)
CachingEntityProviderQueryModifierDelegate is in use and it modifies
the filters through the
QueryModifierDelegate.filtersWillBeAdded(javax.persistence.criteria.CriteriaBuilder, javax.persistence.criteria.CriteriaQuery, java.util.List)
method, caching will NOT be enabled.
setCacheEnabled in interface CachingEntityProvider<T>cacheInUse - true to turn the cache on, false to turn it off.public boolean usesCache()
CachingEntityProviderCachingEntityProvider.setCacheEnabled(boolean) and there is no filter modifiying
QueryModifierDelegate in use.
usesCache in interface CachingEntityProvider<T>public void setEntityCacheMaxSize(int maxSize)
CachingEntityProvider
setEntityCacheMaxSize in interface CachingEntityProvider<T>maxSize - the new maximum size, or -1 for unlimited size.
public boolean containsEntity(EntityContainer<T> container,
Object entityId,
com.vaadin.data.Container.Filter filter)
EntityProviderentityId that is also matched by filter.
containsEntity in interface EntityProvider<T>containsEntity in class LocalEntityProvider<T>entityId - the entity identifier (must not be null).filter - the filter that the entity should match (may be null).
public List<Object> getAllEntityIdentifiers(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
EntityProviderfilter. This
method only exists to speed up
Container.getItemIds(), which in turn is used by
AbstractSelect and its subclasses (e.g. ComboBox).
Using this method is not recommended, as it does not use lazy loading.
getAllEntityIdentifiers in interface EntityProvider<T>getAllEntityIdentifiers in class LocalEntityProvider<T>filter - the filter that should be used to filter the entities (may be
null).sortBy - the properties to sort by, if any (may be null).
public T getEntity(EntityContainer<T> container,
Object entityId)
EntityProviderentityId from the persistence
storage.
getEntity in interface EntityProvider<T>getEntity in class LocalEntityProvider<T>entityId - the entity identifier (must not be null).
public boolean isEntitiesDetached()
EntityProviderIf this method returns false, the entities returned may be managed or detached, depending on the scope of the persistence context.
The default value is implementation specific.
isEntitiesDetached in interface CachingEntityProvider<T>isEntitiesDetached in interface EntityProvider<T>isEntitiesDetached in class LocalEntityProvider<T>EntityProvider.setEntitiesDetached(boolean)public boolean isCloneCachedEntities()
CachingEntityProvider#getEntity(java.lang.Object) with the same entity ID and without
flushing the cache in between may return the same entity instance. This
could be a problem if the instance is modified, as the cache would then
contain the locally modified entity instance and not the one that was
fetched from the persistence storage.
If the entity instances are serialized and deserialized before they reach the container, or the container is read-only, entities need not be cloned.
It is undefined what happens if this flag is true and the entities are not cloneable.
The default value of this flag is implementation dependent.
isCloneCachedEntities in interface CachingEntityProvider<T>CachingEntityProvider.setCloneCachedEntities(boolean)
public void setCloneCachedEntities(boolean clone)
throws UnsupportedOperationException
CachingEntityProviderCachingEntityProvider.isCloneCachedEntities() flag.
setCloneCachedEntities in interface CachingEntityProvider<T>clone - true to clone cached entities before returning them, false to
return them directly.
UnsupportedOperationException - if the implementation does not support changing the state of
this flag.
public int getEntityCount(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter)
EntityProviderfilter. If
no filter has been specified, the total number of entities is returned.
getEntityCount in interface EntityProvider<T>getEntityCount in class LocalEntityProvider<T>filter - the filter that should be used to filter the entities (may be
null).
public Object getEntityIdentifierAt(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy,
int index)
EntityProviderindex in the
result set determined from filter and sortBy.
getEntityIdentifierAt in interface EntityProvider<T>getEntityIdentifierAt in class LocalEntityProvider<T>filter - the filter that should be used to filter the entities (may be
null).sortBy - the properties to sort by, if any (may be null).index - the index of the entity to fetch.
public Object getFirstEntityIdentifier(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
EntityProviderfilter and sortBy.
getFirstEntityIdentifier in interface EntityProvider<T>getFirstEntityIdentifier in class LocalEntityProvider<T>filter - the filter that should be used to filter the entities (may be
null).sortBy - the properties to sort by, if any (may be null).
filter.
public Object getLastEntityIdentifier(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
EntityProviderfilter and sortBy.
getLastEntityIdentifier in interface EntityProvider<T>getLastEntityIdentifier in class LocalEntityProvider<T>filter - the filter that should be used to filter the entities (may be
null).sortBy - the properties to sort by, if any (may be null).
filter.
public Object getNextEntityIdentifier(EntityContainer<T> container,
Object entityId,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
EntityProviderentityId in the list of entities determined by
filter and sortBy.
getNextEntityIdentifier in interface EntityProvider<T>getNextEntityIdentifier in class LocalEntityProvider<T>filter - the filter that should be used to filter the entities (may be
null).sortBy - the properties to sort by, if any (may be null).
filter or entityId is
the last item.
public Object getPreviousEntityIdentifier(EntityContainer<T> container,
Object entityId,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
EntityProviderentityId in the list of entities determined by
filter and sortBy.
getPreviousEntityIdentifier in interface EntityProvider<T>getPreviousEntityIdentifier in class LocalEntityProvider<T>filter - the filter that should be used to filter the entities (may be
null).sortBy - the properties to sort by, if any (may be null).
filter or entityId is
the first item.public T addEntity(T entity)
MutableEntityProviderentity 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.
addEntity in interface MutableEntityProvider<T>addEntity in class MutableLocalEntityProvider<T>entity - the entity to add (must not be null).
public void removeEntity(Object entityId)
MutableEntityProviderentityId. If no entity is
found, nothing happens.
removeEntity in interface MutableEntityProvider<T>removeEntity in class MutableLocalEntityProvider<T>entityId - the identifier of the entity to remove.public T updateEntity(T entity)
MutableEntityProviderentity 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.
updateEntity in interface MutableEntityProvider<T>updateEntity in class MutableLocalEntityProvider<T>entity - the entity to update (must not be null).
public void updateEntityProperty(Object entityId,
String propertyName,
Object propertyValue)
throws IllegalArgumentException
MutableEntityProvider
updateEntityProperty in interface MutableEntityProvider<T>updateEntityProperty in class MutableLocalEntityProvider<T>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.
IllegalArgumentException - if propertyName is not a valid property name.public void refresh()
EntityProvider
refresh in interface EntityProvider<T>refresh in class LocalEntityProvider<T>public T refreshEntity(T entity)
EntityProvider
refreshEntity in interface EntityProvider<T>refreshEntity in class LocalEntityProvider<T>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||