|
||||||||||
| 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.CachingLocalEntityProvider<T>
public class CachingLocalEntityProvider<T>
En extended version of LocalEntityProvider that also implements the
CachingEntityProvider interface.
This provider can be used in applications in the same manner as
LocalEntityProvider, with a few exceptions. By default the cache is
on. The cache can be turned off using setCacheEnabled(boolean), in
which case the provider effectively works as a LocalEntityProvider.
If you are going to edit the entities returned by the container, you should
check the setCloneCachedEntities(boolean) before continuing.
| Constructor Summary | |
|---|---|
CachingLocalEntityProvider(Class<T> entityClass)
Creates a new CachingLocalEntityProvider. |
|
CachingLocalEntityProvider(Class<T> entityClass,
javax.persistence.EntityManager entityManager)
Creates a new CachingLocalEntityProvider. |
|
| Method Summary | |
|---|---|
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 |
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. |
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 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 CachingLocalEntityProvider(Class<T> entityClass)
CachingLocalEntityProvider. The entity manager
must be set using
LocalEntityProvider.setEntityManager(javax.persistence.EntityManager).
entityClass - the entity class (must not be null).
public CachingLocalEntityProvider(Class<T> entityClass,
javax.persistence.EntityManager entityManager)
CachingLocalEntityProvider.
entityClass - the entity class (must not be null).entityManager - the entity manager to use (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 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 | |||||||||