|
||||||||||
| 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>
public class LocalEntityProvider<T>
A read-only entity provider that works with a local EntityManager.
Most important features and limitations:
isEntitiesDetached())
CachingLocalEntityProvider should be used instead. However, this
entity provider consumes less memory than the caching provider.
| Constructor Summary | |
|---|---|
LocalEntityProvider(Class<T> entityClass)
Creates a new LocalEntityProvider. |
|
LocalEntityProvider(Class<T> entityClass,
javax.persistence.EntityManager entityManager)
Creates a new LocalEntityProvider. |
|
LocalEntityProvider(Class<T> entityClass,
EntityManagerProvider entityManagerProvider)
Creates a new LocalEntityProvider with the specified
EntityManagerProvider. |
|
| Method Summary | |
|---|---|
protected List<SortBy> |
addPrimaryKeyToSortList(List<SortBy> original)
Creates a copy of original and adds an entry for the primary
key to the end of the list. |
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. |
protected javax.persistence.TypedQuery<Object> |
createFilteredQuery(EntityContainer<T> container,
List<String> fieldsToSelect,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy,
boolean swapSortOrder)
Creates a filtered, optionally sorted, query. |
protected javax.persistence.TypedQuery<Object> |
createSiblingQuery(EntityContainer<T> container,
Object entityId,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy,
boolean backwards)
This method creates a query that can be used to fetch the siblings of a specific entity. |
protected javax.persistence.TypedQuery<Object> |
createUnsortedFilteredQuery(EntityContainer<T> container,
List<String> fieldsToSelect,
com.vaadin.data.Container.Filter filter)
Creates a filtered query that does not do any sorting. |
protected T |
detachEntity(T entity)
Detaches entity from the entity manager. |
protected boolean |
doContainsEntity(EntityContainer<T> container,
Object entityId,
com.vaadin.data.Container.Filter filter)
|
protected List<Object> |
doGetAllEntityIdentifiers(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
|
protected T |
doGetEntity(Object entityId)
|
protected int |
doGetEntityCount(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter)
|
protected Object |
doGetEntityIdentifierAt(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy,
int index)
|
protected javax.persistence.EntityManager |
doGetEntityManager()
Gets the entity manager. |
protected Object |
doGetFirstEntityIdentifier(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
|
protected Object |
doGetLastEntityIdentifier(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
|
protected Object |
doGetNextEntityIdentifier(EntityContainer<T> container,
Object entityId,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
|
protected Object |
doGetPreviousEntityIdentifier(EntityContainer<T> container,
Object entityId,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
|
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. |
protected EntityClassMetadata<T> |
getEntityClassMetadata()
Gets the metadata for the entity class. |
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. |
javax.persistence.EntityManager |
getEntityManager()
Gets the entity manager. |
EntityManagerProvider |
getEntityManagerProvider()
Gets the EntityManagerProvider that is used to find the current
entity manager unless one is specified using
setEntityManager(javax.persistence.EntityManager). |
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 |
getIdentifier(T entity)
Returns identifier for given entity |
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. |
LazyLoadingDelegate |
getLazyLoadingDelegate()
|
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. |
QueryModifierDelegate |
getQueryModifierDelegate()
|
protected Object |
getSibling(EntityContainer<T> container,
Object entityId,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy,
boolean backwards)
If backwards is false, this method will return the
identifier of the entity next to the entity identified by
entityId. |
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. |
protected Object |
readResolve()
|
void |
refresh()
Clears all caches and refreshes any loaded that cannot be discarded entities. |
T |
refreshEntity(T entity)
Refreshes an entity from DB. |
void |
setEntitiesDetached(boolean detached)
Specifies whether the entities returned by the entity provider should be explicitly detached or not. |
void |
setEntityManager(javax.persistence.EntityManager entityManager)
Sets the entity manager. |
void |
setEntityManagerProvider(EntityManagerProvider entityManagerProvider)
Sets the EntityManagerProvider that is used to find the current
entity manager unless set using
setEntityManager(javax.persistence.EntityManager) |
void |
setLazyLoadingDelegate(LazyLoadingDelegate delegate)
Set the delegate used for lazy loading. |
void |
setQueryModifierDelegate(QueryModifierDelegate delegate)
Sets the QueryModifierDelegate, which is called in the different
stages that the EntityProvider builds a criteria query. |
protected javax.persistence.criteria.Order |
translateSortBy(SortBy sortBy,
boolean swapSortOrder,
javax.persistence.criteria.CriteriaBuilder cb,
javax.persistence.criteria.Root<T> root)
Translates SortBy instances, which possibly contain nested properties (e.g. |
protected Object |
writeReplace()
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public LocalEntityProvider(Class<T> entityClass,
javax.persistence.EntityManager entityManager)
LocalEntityProvider.
entityClass - the entity class (must not be null).entityManager - the entity manager to use (must not be null).public LocalEntityProvider(Class<T> entityClass)
LocalEntityProvider. The entity manager or an
entity manager provider must be set using
setEntityManager(javax.persistence.EntityManager) or
setEntityManagerProvider(com.vaadin.addon.jpacontainer.EntityManagerProvider)
respectively.
entityClass - the entity class (must not be null).
public LocalEntityProvider(Class<T> entityClass,
EntityManagerProvider entityManagerProvider)
LocalEntityProvider with the specified
EntityManagerProvider.
entityClass - entityManagerProvider - | Method Detail |
|---|
protected Object writeReplace()
throws ObjectStreamException
ObjectStreamException
protected Object readResolve()
throws ObjectStreamException
ObjectStreamExceptionpublic void setEntityManagerProvider(EntityManagerProvider entityManagerProvider)
EntityManagerProvider that is used to find the current
entity manager unless set using
setEntityManager(javax.persistence.EntityManager)
setEntityManagerProvider in interface EntityProvider<T>entityManagerProvider - The entity manager provider to set.public EntityManagerProvider getEntityManagerProvider()
EntityManagerProvider that is used to find the current
entity manager unless one is specified using
setEntityManager(javax.persistence.EntityManager).
getEntityManagerProvider in interface EntityProvider<T>public void setEntityManager(javax.persistence.EntityManager entityManager)
setEntityManager in interface EntityProvider<T>entityManager - the entity manager to set.protected EntityClassMetadata<T> getEntityClassMetadata()
public javax.persistence.EntityManager getEntityManager()
getEntityManager in interface EntityProvider<T>
protected javax.persistence.EntityManager doGetEntityManager()
throws IllegalStateException
IllegalStateException - if no entity manager is set.protected List<SortBy> addPrimaryKeyToSortList(List<SortBy> original)
original and adds an entry for the primary
key to the end of the list.
original - the original list of sorting instructions (must not be null,
but may be empty).
protected javax.persistence.criteria.Order translateSortBy(SortBy sortBy,
boolean swapSortOrder,
javax.persistence.criteria.CriteriaBuilder cb,
javax.persistence.criteria.Root<T> root)
sortBy - the SortBy instance to translateswapSortOrder - swaps the specified sort order if true.cb - the CriteriaBuilder to useroot - the CriteriaQuery Root to be used.
protected javax.persistence.TypedQuery<Object> createUnsortedFilteredQuery(EntityContainer<T> container,
List<String> fieldsToSelect,
com.vaadin.data.Container.Filter filter)
fieldsToSelect - the fields to select (must not be null).filter - the filter to apply, or null if no filters should be applied.
createFilteredQuery(com.vaadin.addon.jpacontainer.EntityContainer,
java.util.List, com.vaadin.data.Container.Filter, java.util.List,
boolean)
protected javax.persistence.TypedQuery<Object> createFilteredQuery(EntityContainer<T> container,
List<String> fieldsToSelect,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy,
boolean swapSortOrder)
fieldsToSelect - the fields to select (must not be null).filter - the filter to apply, or null if no filters should be applied.sortBy - the fields to sort by (must include at least one field), or
null if the result should not be sorted at all.swapSortOrder - true to swap the sort order, false to use the sort order
specified in sortBy. Only applies if
sortBy is not null.
protected boolean doContainsEntity(EntityContainer<T> container,
Object entityId,
com.vaadin.data.Container.Filter filter)
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>entityId - the entity identifier (must not be null).filter - the filter that the entity should match (may be null).
protected T doGetEntity(Object entityId)
public T getEntity(EntityContainer<T> container,
Object entityId)
EntityProviderentityId from the persistence
storage.
getEntity in interface EntityProvider<T>entityId - the entity identifier (must not be null).
protected Object doGetEntityIdentifierAt(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy,
int index)
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>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.
protected int doGetEntityCount(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter)
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>filter - the filter that should be used to filter the entities (may be
null).
protected Object doGetFirstEntityIdentifier(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
public Object getFirstEntityIdentifier(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
EntityProviderfilter and sortBy.
getFirstEntityIdentifier in interface EntityProvider<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.
protected Object doGetLastEntityIdentifier(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
public Object getLastEntityIdentifier(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
EntityProviderfilter and sortBy.
getLastEntityIdentifier in interface EntityProvider<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.
protected Object getSibling(EntityContainer<T> container,
Object entityId,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy,
boolean backwards)
backwards is false, this method will return the
identifier of the entity next to the entity identified by
entityId. If true, this method will return the identifier of
the entity previous to the entity identified by entityId.
filter and sortBy is used to define and limit
the list of entities to be used for determining the sibling.
entityId - the identifier of the entity whose sibling to retrieve (must
not be null).filter - an optional filter to limit the entities (may be null).sortBy - the order in which the list should be sorted (must not be
null).backwards - true to fetch the previous sibling, false to fetch the next
sibling.
protected javax.persistence.TypedQuery<Object> createSiblingQuery(EntityContainer<T> container,
Object entityId,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy,
boolean backwards)
backwards is false, the query will begin
with the entity next to the entity identified by entityId.
If backwards is false, the query will begin with the entity
prior to the entity identified by entityId.
entityId - the identifier of the entity whose sibling to retrieve (must
not be null).filter - an optional filter to limit the entities (may be null).sortBy - the order in which the list should be sorted (must not be
null).backwards - true to fetch the previous sibling, false to fetch the next
sibling.
protected Object doGetNextEntityIdentifier(EntityContainer<T> container,
Object entityId,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
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>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.
protected Object doGetPreviousEntityIdentifier(EntityContainer<T> container,
Object entityId,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
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>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.protected T detachEntity(T entity)
entity from the entity manager. If
entity is null, then null is returned. If
isEntitiesDetached() is false, entity is returned
directly.
entity - the entity to detach.
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 EntityProvider<T>EntityProvider.setEntitiesDetached(boolean)
public void setEntitiesDetached(boolean detached)
throws UnsupportedOperationException
EntityProviderEntityProvider.isEntitiesDetached() for a more
detailed description of the consequences.
setEntitiesDetached in interface EntityProvider<T>detached - true to request explicitly detached entities, false otherwise.
UnsupportedOperationException - if the implementation does not allow the user to change the
way entities are returned.
protected List<Object> doGetAllEntityIdentifiers(EntityContainer<T> container,
com.vaadin.data.Container.Filter filter,
List<SortBy> sortBy)
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>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 void setQueryModifierDelegate(QueryModifierDelegate delegate)
EntityProviderQueryModifierDelegate, which is called in the different
stages that the EntityProvider builds a criteria query.
setQueryModifierDelegate in interface EntityProvider<T>delegate - the delegate.public QueryModifierDelegate getQueryModifierDelegate()
getQueryModifierDelegate in interface EntityProvider<T>QueryModifierDelegate.public Object getIdentifier(T entity)
EntityProvider
getIdentifier in interface EntityProvider<T>public T refreshEntity(T entity)
EntityProvider
refreshEntity in interface EntityProvider<T>public void setLazyLoadingDelegate(LazyLoadingDelegate delegate)
EntityProvider
setLazyLoadingDelegate in interface EntityProvider<T>delegate - the LazyLoadingDelegate to use.public LazyLoadingDelegate getLazyLoadingDelegate()
getLazyLoadingDelegate in interface EntityProvider<T>LazyLoadingDelegate in use or null if none
registered.public void refresh()
EntityProvider
refresh in interface EntityProvider<T>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||