Package org.primefaces.model
Class JpaLazyDataModel<T>
java.lang.Object
javax.faces.model.DataModel<E>
javax.faces.model.ListDataModel<T>
org.primefaces.model.LazyDataModel<T>
org.primefaces.model.JpaLazyDataModel<T>
- Type Parameters:
T- The model class.
- All Implemented Interfaces:
Serializable,Iterable<T>,SelectableDataModel<T>
Basic
LazyDataModel implementation with JPA and Criteria API.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected SerializableSupplier<javax.persistence.EntityManager>protected String -
Constructor Summary
ConstructorsConstructorDescriptionFor serialization onlyJpaLazyDataModel(Class<T> entityClass, SerializableSupplier<javax.persistence.EntityManager> entityManager) Constructs a JpaLazyDataModel for usage without enabled selection.JpaLazyDataModel(Class<T> entityClass, SerializableSupplier<javax.persistence.EntityManager> entityManager, String rowKeyField) Constructs a JpaLazyDataModel with selection support.JpaLazyDataModel(Class<T> entityClass, SerializableSupplier<javax.persistence.EntityManager> entityManager, javax.faces.convert.Converter converter) Constructs a JpaLazyDataModel with selection support, with an already existingConverter. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidapplyFilters(javax.persistence.criteria.CriteriaBuilder cb, javax.persistence.criteria.CriteriaQuery<?> cq, javax.persistence.criteria.Root<T> root, Map<String, FilterMeta> filterBy) protected voidapplyGlobalFilters(Map<String, FilterMeta> filterBy, javax.persistence.criteria.CriteriaBuilder cb, javax.persistence.criteria.CriteriaQuery<?> cq, javax.persistence.criteria.Root<T> root, List<javax.persistence.criteria.Predicate> predicates) protected voidapplySort(javax.persistence.criteria.CriteriaBuilder cb, javax.persistence.criteria.CriteriaQuery<T> cq, javax.persistence.criteria.Root<T> root, Map<String, SortMeta> sortBy) protected ObjectconvertToType(Object value, Class valueType) intcount(Map<String, FilterMeta> filterBy) Counts the all available data for the given filters.protected javax.persistence.criteria.PredicatecreatePredicate(FilterMeta filter, Field filterField, javax.persistence.criteria.Root<T> root, javax.persistence.criteria.CriteriaBuilder cb, javax.persistence.criteria.Expression fieldExpression, Object filterValue) getRowData(String rowKey) protected MethodLoads the data for the given parameters.protected javax.persistence.criteria.ExpressionresolveFieldExpression(javax.persistence.criteria.CriteriaBuilder cb, javax.persistence.criteria.CriteriaQuery<?> cq, javax.persistence.criteria.Root<T> root, String fieldName) Methods inherited from class org.primefaces.model.LazyDataModel
getConverter, getMessage, getPageSize, getRowCount, getRowData, getRowData, getRowIndex, getWrappedData, isRowAvailable, iterator, iterator, recalculateFirst, setConverter, setPageSize, setRowCount, setRowIndex, setWrappedDataMethods inherited from class javax.faces.model.DataModel
addDataModelListener, getDataModelListeners, removeDataModelListenerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
entityClass
-
entityManager
-
rowKeyField
-
-
Constructor Details
-
JpaLazyDataModel
public JpaLazyDataModel()For serialization only -
JpaLazyDataModel
public JpaLazyDataModel(Class<T> entityClass, SerializableSupplier<javax.persistence.EntityManager> entityManager) Constructs a JpaLazyDataModel for usage without enabled selection.- Parameters:
entityClass- The entity classentityManager- TheEntityManager
-
JpaLazyDataModel
public JpaLazyDataModel(Class<T> entityClass, SerializableSupplier<javax.persistence.EntityManager> entityManager, String rowKeyField) Constructs a JpaLazyDataModel with selection support.- Parameters:
entityClass- The entity classentityManager- TheEntityManagerrowKeyField- The name of the rowKey property (e.g. "id")
-
JpaLazyDataModel
public JpaLazyDataModel(Class<T> entityClass, SerializableSupplier<javax.persistence.EntityManager> entityManager, javax.faces.convert.Converter converter) Constructs a JpaLazyDataModel with selection support, with an already existingConverter.- Parameters:
entityClass- The entity classentityManager- TheEntityManagerconverter- The converter, which will be used for converting the entity to a rowKey and vice versa
-
-
Method Details
-
count
Description copied from class:LazyDataModelCounts the all available data for the given filters. In case of SQL, this would execute a "SELECT COUNT ... WHERE ...". In case you dont use SQL and receive bothrowCountanddatawithin a single call, this method should just return0. You must callLazyDataModel.recalculateFirst(int, int, int)andLazyDataModel.setRowCount(int)in yourLazyDataModel.load(int, int, java.util.Map, java.util.Map)method.- Specified by:
countin classLazyDataModel<T>- Parameters:
filterBy- a map with all filter information (only relevant for DataTable, not for eg DataView)- Returns:
- the data count
-
load
public List<T> load(int first, int pageSize, Map<String, SortMeta> sortBy, Map<String, FilterMeta> filterBy) Description copied from class:LazyDataModelLoads the data for the given parameters.- Specified by:
loadin classLazyDataModel<T>- Parameters:
first- the first entrypageSize- the page sizesortBy- a map with all sort information (only relevant for DataTable, not for eg DataView)filterBy- a map with all filter information (only relevant for DataTable, not for eg DataView)- Returns:
- the data
-
applyFilters
protected void applyFilters(javax.persistence.criteria.CriteriaBuilder cb, javax.persistence.criteria.CriteriaQuery<?> cq, javax.persistence.criteria.Root<T> root, Map<String, FilterMeta> filterBy) -
applyGlobalFilters
protected void applyGlobalFilters(Map<String, FilterMeta> filterBy, javax.persistence.criteria.CriteriaBuilder cb, javax.persistence.criteria.CriteriaQuery<?> cq, javax.persistence.criteria.Root<T> root, List<javax.persistence.criteria.Predicate> predicates) -
createPredicate
protected javax.persistence.criteria.Predicate createPredicate(FilterMeta filter, Field filterField, javax.persistence.criteria.Root<T> root, javax.persistence.criteria.CriteriaBuilder cb, javax.persistence.criteria.Expression fieldExpression, Object filterValue) -
applySort
-
resolveFieldExpression
-
getRowData
- Specified by:
getRowDatain interfaceSelectableDataModel<T>- Overrides:
getRowDatain classLazyDataModel<T>
-
getRowKey
- Specified by:
getRowKeyin interfaceSelectableDataModel<T>- Overrides:
getRowKeyin classLazyDataModel<T>
-
convertToType
-
getRowKeyGetter
-