Class BaseEntityService<I extends Comparable<I> & Serializable,​E extends BaseEntity<I>>

    • Constructor Detail

      • BaseEntityService

        public BaseEntityService()
        The constructor initializes the type mapping. The I and E will be resolved to a concrete Class<?>.
    • Method Detail

      • getProvider

        public Provider getProvider()
        Returns the JPA provider being used. This is immutable (you can't override the method to change the internally used value).
        Returns:
        The JPA provider being used.
      • getDatabase

        public Database getDatabase()
        Returns the SQL database being used. This is immutable (you can't override the method to change the internally used value).
        Returns:
        The SQL database being used.
      • getIdentifierType

        protected Class<I> getIdentifierType()
        Returns the actual type of the generic ID type I. This is immutable (you can't override the method to change the internally used value).
        Returns:
        The actual type of the generic ID type I.
      • getEntityType

        protected Class<E> getEntityType()
        Returns the actual type of the generic base entity type E. This is immutable (you can't override the method to change the internally used value).
        Returns:
        The actual type of the generic base entity type E.
      • isGeneratedId

        protected boolean isGeneratedId()
        Returns whether the ID is generated. This is immutable (you can't override the method to change the internally used value).
        Returns:
        Whether the ID is generated.
      • getEntityManager

        protected EntityManager getEntityManager()
        Returns the entity manager being used. When you have only one persistence unit, then you don't need to override this. When you have multiple persistence units, then you need to extend the BaseEntityService like below wherein you supply the persistence unit specific entity manager and then let all your service classes extend from it instead.
         public abstract class YourBaseEntityService<E extends BaseEntity<Long>> extends BaseEntityService<Long, E> {
        
             @PersistenceContext(unitName = "yourPersistenceUnitName")
             private EntityManager entityManager;
        
             @Override
             public EntityManager getEntityManager() {
                 return entityManager;
             }
        
         }
         
        Returns:
        The entity manager being used.
      • getMetamodel

        protected EntityType<E> getMetamodel()
        Returns the metamodel of current base entity.
        Returns:
        The metamodel of current base entity.
      • getMetamodel

        public <I extends Comparable<I> & Serializable,​E extends BaseEntity<I>> EntityType<E> getMetamodel​(E entity)
        Returns the metamodel of given base entity.
        Type Parameters:
        I - The generic ID type of the given base entity.
        E - The generic base entity type of the given base entity.
        Parameters:
        entity - Base entity to obtain metamodel for.
        Returns:
        The metamodel of given base entity.
      • createNamedTypedQuery

        protected TypedQuery<E> createNamedTypedQuery​(String name)
        Create an instance of TypedQuery for executing a Java Persistence Query Language statement identified by the given name, usually to perform a SELECT e.
        Parameters:
        name - The name of the Java Persistence Query Language statement defined in metadata, which can be either a NamedQuery or a <persistence-unit><mapping-file>.
        Returns:
        An instance of TypedQuery for executing a Java Persistence Query Language statement identified by the given name, usually to perform a SELECT e.
      • createNamedQuery

        protected Query createNamedQuery​(String name)
        Create an instance of Query for executing a Java Persistence Query Language statement identified by the given name, usually to perform an INSERT, UPDATE or DELETE.
        Parameters:
        name - The name of the Java Persistence Query Language statement defined in metadata, which can be either a NamedQuery or a <persistence-unit><mapping-file>.
        Returns:
        An instance of Query for executing a Java Persistence Query Language statement identified by the given name, usually to perform an INSERT, UPDATE or DELETE.
      • createTypedQuery

        protected <T> TypedQuery<T> createTypedQuery​(String jpql,
                                                     Class<T> resultType)
        Create an instance of TypedQuery for executing the given Java Persistence Query Language statement which returns the specified T, usually to perform a SELECT t.
        Type Parameters:
        T - The generic result type.
        Parameters:
        jpql - The Java Persistence Query Language statement.
        resultType - The result type.
        Returns:
        An instance of TypedQuery for executing the given Java Persistence Query Language statement which returns the specified T, usually to perform a SELECT t.
      • createTypedQuery

        protected TypedQuery<E> createTypedQuery​(String jpql)
        Create an instance of TypedQuery for executing the given Java Persistence Query Language statement which returns a E, usually to perform a SELECT e.
        Parameters:
        jpql - The Java Persistence Query Language statement.
        Returns:
        An instance of TypedQuery for executing the given Java Persistence Query Language statement which returns a E, usually to perform a SELECT e.
      • createLongQuery

        protected TypedQuery<Long> createLongQuery​(String jpql)
        Create an instance of TypedQuery for executing the given Java Persistence Query Language statement which returns a Long, usually a SELECT e.id or SELECT COUNT(e).
        Parameters:
        jpql - The Java Persistence Query Language statement.
        Returns:
        An instance of TypedQuery for executing the given Java Persistence Query Language statement which returns a Long, usually a SELECT e.id or SELECT COUNT(e).
      • createQuery

        protected Query createQuery​(String jpql)
        Create an instance of Query for executing the given Java Persistence Query Language statement, usually to perform an INSERT, UPDATE or DELETE.
        Parameters:
        jpql - The Java Persistence Query Language statement.
        Returns:
        An instance of Query for executing the given Java Persistence Query Language statement, usually to perform an INSERT, UPDATE or DELETE.
      • find

        protected Optional<E> find​(String jpql,
                                   Object... parameters)
        Find entity by the given query and positional parameters, if any.

        Usage example:

         Optional<Foo> foo = find("SELECT f FROM Foo f WHERE f.bar = ?1 AND f.baz = ?2", bar, baz);
         

        Short jpql is also supported:

         Optional<Foo> foo = find("WHERE bar = ?1 AND baz = ?2", bar, baz);
         
        Parameters:
        jpql - The Java Persistence Query Language statement.
        parameters - The positional query parameters, if any.
        Returns:
        Found entity matching the given query and positional parameters, if any.
        Throws:
        NonUniqueResultException - When more than one entity is found matching the given query and positional parameters.
      • find

        protected Optional<E> find​(String jpql,
                                   Consumer<Map<String,​Object>> parameters)
        Find entity by the given query and mapped parameters, if any.

        Usage example:

         Optional<Foo> foo = find("SELECT f FROM Foo f WHERE f.bar = :bar AND f.baz = :baz", params -> {
             params.put("bar", bar);
             params.put("baz", baz);
         });
         

        Short jpql is also supported:

         Optional<Foo> foo = find("WHERE bar = :bar AND baz = :baz", params -> {
             params.put("bar", bar);
             params.put("baz", baz);
         });
         
        Parameters:
        jpql - The Java Persistence Query Language statement.
        parameters - To put the mapped query parameters in.
        Returns:
        Found entity matching the given query and mapped parameters, if any.
        Throws:
        NonUniqueResultException - When more than one entity is found matching the given query and mapped parameters.
      • findFirst

        protected Optional<E> findFirst​(String jpql,
                                        Object... parameters)
        Find first entity by the given query and positional parameters, if any. The difference with find(String, Object...) is that it doesn't throw NonUniqueResultException when there are multiple matches.

        Usage example:

         Optional<Foo> foo = findFirst("SELECT f FROM Foo f WHERE f.bar = ?1 AND f.baz = ?2", bar, baz);
         

        Short jpql is also supported:

         Optional<Foo> foo = findFirst("WHERE bar = ?1 AND baz = ?2", bar, baz);
         
        Parameters:
        jpql - The Java Persistence Query Language statement.
        parameters - The positional query parameters, if any.
        Returns:
        Found entity matching the given query and positional parameters, if any.
      • findFirst

        protected Optional<E> findFirst​(String jpql,
                                        Consumer<Map<String,​Object>> parameters)
        Find first entity by the given query and mapped parameters, if any. The difference with find(String, Consumer) is that it doesn't throw NonUniqueResultException when there are multiple matches.

        Usage example:

         Optional<Foo> foo = findFirst("SELECT f FROM Foo f WHERE f.bar = :bar AND f.baz = :baz", params -> {
             params.put("bar", bar);
             params.put("baz", baz);
         });
         

        Short jpql is also supported:

         Optional<Foo> foo = findFirst("WHERE bar = :bar AND baz = :baz", params -> {
             params.put("bar", bar);
             params.put("baz", baz);
         });
         
        Parameters:
        jpql - The Java Persistence Query Language statement.
        parameters - To put the mapped query parameters in.
        Returns:
        Found entity matching the given query and mapped parameters, if any.
      • findById

        public Optional<E> findById​(I id)
        Find entity by the given ID. This does not include soft deleted one.
        Parameters:
        id - Entity ID to find entity for.
        Returns:
        Found entity, if any.
      • findById

        protected Optional<E> findById​(I id,
                                       boolean includeSoftDeleted)
        Find entity by the given ID and set whether it may return a soft deleted one.
        Parameters:
        id - Entity ID to find entity for.
        includeSoftDeleted - Whether to include soft deleted ones in the search.
        Returns:
        Found entity, if any.
      • findSoftDeletedById

        public Optional<E> findSoftDeletedById​(I id)
        Find soft deleted entity by the given ID.
        Parameters:
        id - Entity ID to find soft deleted entity for.
        Returns:
        Found soft deleted entity, if any.
        Throws:
        NonSoftDeletableEntityException - When entity doesn't have SoftDeletable annotation set on any of its fields.
      • getById

        public E getById​(I id)
        Get entity by the given ID. This does not include soft deleted one.
        Parameters:
        id - Entity ID to get entity by.
        Returns:
        Found entity, or null if there is none.
      • getById

        protected E getById​(I id,
                            boolean includeSoftDeleted)
        Get entity by the given ID and set whether it may return a soft deleted one.
        Parameters:
        id - Entity ID to get entity by.
        includeSoftDeleted - Whether to include soft deleted ones in the search.
        Returns:
        Found entity, or null if there is none.
      • getByIdWithLoadGraph

        public E getByIdWithLoadGraph​(I id,
                                      String entityGraphName)
        Get entity by the given ID and entity graph name.
        Parameters:
        id - Entity ID to get entity by.
        entityGraphName - Entity graph name.
        Returns:
        Found entity, or null if there is none.
      • getSoftDeletedById

        public E getSoftDeletedById​(I id)
        Get soft deleted entity by the given ID.
        Parameters:
        id - Entity ID to get soft deleted entity by.
        Returns:
        Found soft deleted entity, or null if there is none.
        Throws:
        NonSoftDeletableEntityException - When entity doesn't have SoftDeletable annotation set on any of its fields.
      • getByIds

        public List<E> getByIds​(Iterable<I> ids)
        Get entities by the given IDs. The default ordering is by ID, descending. This does not include soft deleted ones.
        Parameters:
        ids - Entity IDs to get entities by.
        Returns:
        Found entities, or an empty set if there is none.
      • getByIds

        protected List<E> getByIds​(Iterable<I> ids,
                                   boolean includeSoftDeleted)
        Get entities by the given IDs and set whether it may include soft deleted ones. The default ordering is by ID, descending.
        Parameters:
        ids - Entity IDs to get entities by.
        includeSoftDeleted - Whether to include soft deleted ones in the search.
        Returns:
        Found entities, optionally including soft deleted ones, or an empty set if there is none.
        Throws:
        NonSoftDeletableEntityException - When entity doesn't have SoftDeletable annotation set on any of its fields.
      • exists

        protected boolean exists​(E entity)
        Check whether given entity exists. This method supports proxied entities.
        Parameters:
        entity - Entity to check.
        Returns:
        Whether entity with given entity exists.
      • list

        public List<E> list()
        List all entities. The default ordering is by ID, descending. This does not include soft deleted entities.
        Returns:
        List of all entities.
      • list

        protected List<E> list​(boolean includeSoftDeleted)
        List all entities and set whether it may include soft deleted ones. The default ordering is by ID, descending.
        Parameters:
        includeSoftDeleted - Whether to include soft deleted ones in the search.
        Returns:
        List of all entities, optionally including soft deleted ones.
        Throws:
        NonSoftDeletableEntityException - When entity doesn't have SoftDeletable annotation set on any of its fields.
      • listSoftDeleted

        public List<E> listSoftDeleted()
        List all entities that have been soft deleted. The default ordering is by ID, descending.
        Returns:
        List of all soft deleted entities.
        Throws:
        NonSoftDeletableEntityException - When entity doesn't have SoftDeletable annotation set on any of its fields.
      • list

        protected List<E> list​(String jpql,
                               Object... parameters)
        List entities matching the given query and positional parameters, if any.

        Usage example:

         List<Foo> foos = list("SELECT f FROM Foo f WHERE f.bar = ?1 AND f.baz = ?2", bar, baz);
         

        Short jpql is also supported:

         List<Foo> foos = list("WHERE bar = ?1 AND baz = ?2", bar, baz);
         
        Parameters:
        jpql - The Java Persistence Query Language statement.
        parameters - The positional query parameters, if any.
        Returns:
        List of entities matching the given query and positional parameters, if any.
      • list

        protected List<E> list​(String jpql,
                               Consumer<Map<String,​Object>> parameters)
        List entities matching the given query and mapped parameters, if any.

        Usage example:

         List<Foo> foos = list("SELECT f FROM Foo f WHERE f.bar = :bar AND f.baz = :baz", params -> {
             params.put("bar", bar);
             params.put("baz", baz);
         });
         

        Short jpql is also supported:

         List<Foo> foos = list("WHERE bar = :bar AND baz = :baz", params -> {
             params.put("bar", bar);
             params.put("baz", baz);
         });
         
        Parameters:
        jpql - The Java Persistence Query Language statement.
        parameters - To put the mapped query parameters in.
        Returns:
        List of entities matching the given query and mapped parameters, if any.
      • persist

        public I persist​(E entity)
        Persist given entity and immediately perform a flush. Any bean validation constraint violation will be logged separately.
        Parameters:
        entity - Entity to persist.
        Returns:
        Entity ID.
        Throws:
        IllegalEntityStateException - When entity is already persisted or its ID is not generated.
      • update

        public E update​(E entity)
        Update given entity. If jakarta.persistence.validation.mode property in persistence.xml is explicitly set to CALLBACK (and thus not to its default of AUTO), then any bean validation constraint violation will be logged separately. Due to technical limitations, this effectively means that bean validation is invoked twice. First in this method in order to be able to obtain the constraint violations and then once more while JTA is committing the transaction, but is executed beyond the scope of this method.
        Parameters:
        entity - Entity to update.
        Returns:
        Updated entity.
        Throws:
        IllegalEntityStateException - When entity is not persisted or its ID is not generated.
      • updateAndFlush

        protected E updateAndFlush​(E entity)
        Update given entity via update(BaseEntity) and immediately perform a flush so that all changes in managed entities so far in the current transaction are persisted. This is particularly useful when you intend to process the given entity further in an asynchronous service method.
        Parameters:
        entity - Entity to update.
        Returns:
        Updated entity.
        Throws:
        IllegalEntityStateException - When entity is not persisted or its ID is not generated.
      • update

        public List<E> update​(Iterable<E> entities)
        Update given entities.
        Parameters:
        entities - Entities to update.
        Returns:
        Updated entities.
        Throws:
        IllegalEntityStateException - When at least one entity has no ID.
      • update

        protected int update​(String jpql,
                             Object... parameters)
        Update or delete all entities matching the given query and positional parameters, if any.

        Usage example:

         int affectedRows = update("UPDATE Foo f SET f.bar = ?1 WHERE f.baz = ?2", bar, baz);
         

        Short jpql is also supported:

         int affectedRows = update("SET bar = ?1 WHERE baz = ?2", bar, baz);
         
        Parameters:
        jpql - The Java Persistence Query Language statement.
        parameters - The positional query parameters, if any.
        Returns:
        The number of entities updated or deleted.
        See Also:
        Query.executeUpdate()
      • update

        protected int update​(String jpql,
                             Consumer<Map<String,​Object>> parameters)
        Update or delete all entities matching the given query and mapped parameters, if any.

        Usage example:

         int affectedRows = update("UPDATE Foo f SET f.bar = :bar WHERE f.baz = :baz", params -> {
             params.put("bar", bar);
             params.put("baz", baz);
         });
         

        Short jpql is also supported:

         int affectedRows = update("SET bar = :bar WHERE baz = :baz", params -> {
             params.put("bar", bar);
             params.put("baz", baz);
         });
         
        Parameters:
        jpql - The Java Persistence Query Language statement.
        parameters - To put the mapped query parameters in, if any.
        Returns:
        The number of entities updated or deleted.
        See Also:
        Query.executeUpdate()
      • save

        public E save​(E entity)
        Save given entity. This will automatically determine based on the presence of generated entity ID, or existence of an entity in the data store whether to persist(BaseEntity) or to update(BaseEntity).
        Parameters:
        entity - Entity to save.
        Returns:
        Saved entity.
      • saveAndFlush

        protected E saveAndFlush​(E entity)
        Save given entity via save(BaseEntity) and immediately perform a flush so that all changes in managed entities so far in the current transaction are persisted. This is particularly useful when you intend to process the given entity further in an asynchronous service method.
        Parameters:
        entity - Entity to save.
        Returns:
        Saved entity.
      • manage

        protected E manage​(E entity)
        Make given entity managed. NOTE: This will discard any unmanaged changes in the given entity! This is particularly useful in case you intend to make sure that you have the most recent version at hands. This method also supports proxied entities as well as DTOs.
        Parameters:
        entity - Entity to manage.
        Returns:
        The managed entity.
        Throws:
        NullPointerException - When given entity is null.
        IllegalEntityStateException - When entity has no ID.
        EntityNotFoundException - When entity has in meanwhile been deleted.
      • manageIfNecessary

        protected <E> E manageIfNecessary​(E entity)
        Make any given entity managed if necessary. NOTE: This will discard any unmanaged changes in the given entity! This is particularly useful in case you intend to make sure that you have the most recent version at hands. This method also supports null entities as well as proxied entities as well as DTOs.
        Type Parameters:
        E - The generic entity type.
        Parameters:
        entity - Entity to manage, may be null.
        Returns:
        The managed entity, or null when null was supplied. It leniently returns the very same argument if the entity has no ID or has been deleted in the meanwhile.
        Throws:
        IllegalArgumentException - When the given entity is actually not an instance of BaseEntity.
      • reset

        public void reset​(E entity)
        Reset given entity. This will discard any changes in given entity. The given entity must be unmanaged/detached. The actual intent of this method is to have the opportunity to completely reset the state of a given entity which might have been edited in the client, without changing the reference. This is generally useful when the entity is in turn held in some collection and you'd rather not manually remove and reinsert it in the collection. This method supports proxied entities.
        Parameters:
        entity - Entity to reset.
        Throws:
        IllegalEntityStateException - When entity is already managed, or has no ID.
        EntityNotFoundException - When entity has in meanwhile been deleted.
      • countForeignKeyReferencesTo

        protected long countForeignKeyReferencesTo​(E entity)
        Returns count of all foreign key references to given entity. This is particularly useful in case you intend to check if the given entity is still referenced elsewhere in database.
        Parameters:
        entity - Entity to count all foreign key references for.
        Returns:
        Count of all foreign key references to given entity.
      • fetchLazyCollections

        protected E fetchLazyCollections​(E entity,
                                         Function<E,​Collection<?>>... getters)
        Fetch lazy collections of given entity on given getters. If no getters are supplied, then it will fetch every single PluralAttribute not of type PluralAttribute.CollectionType.MAP. Note that the implementation does for simplicitly not check if those are actually lazy or eager.

        Usage example:

         Foo fooWithBarsAndBazs = fetchLazyCollections(getById(fooId), Foo::getBars, Foo::getBazs);
         
        Parameters:
        entity - Entity instance to fetch lazy collections on.
        getters - Getters of those lazy collections.
        Returns:
        The same entity, useful if you want to continue using it immediately.
      • fetchLazyCollections

        protected Optional<E> fetchLazyCollections​(Optional<E> entity,
                                                   Function<E,​Collection<?>>... getters)
        Fetch lazy collections of given optional entity on given getters. If no getters are supplied, then it will fetch every single PluralAttribute not of type PluralAttribute.CollectionType.MAP. Note that the implementation does for simplicitly not check if those are actually lazy or eager.

        Usage example:

         Optional<Foo> fooWithBarsAndBazs = fetchLazyCollections(findById(fooId), Foo::getBars, Foo::getBazs);
         
        Parameters:
        entity - Optional entity instance to fetch lazy collections on.
        getters - Getters of those lazy collections.
        Returns:
        The same optional entity, useful if you want to continue using it immediately.
      • fetchLazyMaps

        protected E fetchLazyMaps​(E entity,
                                  Function<E,​Map<?,​?>>... getters)
        Fetch lazy maps of given entity on given getters. If no getters are supplied, then it will fetch every single PluralAttribute of type PluralAttribute.CollectionType.MAP. Note that the implementation does for simplicitly not check if those are actually lazy or eager.

        Usage example:

         Foo fooWithBarsAndBazs = fetchLazyCollections(getById(fooId), Foo::getBars, Foo::getBazs);
         
        Parameters:
        entity - Entity instance to fetch lazy maps on.
        getters - Getters of those lazy collections.
        Returns:
        The same entity, useful if you want to continue using it immediately.
      • fetchLazyMaps

        protected Optional<E> fetchLazyMaps​(Optional<E> entity,
                                            Function<E,​Map<?,​?>>... getters)
        Fetch lazy maps of given optional entity on given getters. If no getters are supplied, then it will fetch every single PluralAttribute of type PluralAttribute.CollectionType.MAP. Note that the implementation does for simplicitly not check if those are actually lazy or eager.

        Usage example:

         Optional<Foo> fooWithBarsAndBazs = fetchLazyCollections(findById(fooId), Foo::getBars, Foo::getBazs);
         
        Parameters:
        entity - Optional entity instance to fetch lazy maps on.
        getters - Getters of those lazy collections.
        Returns:
        The same optional entity, useful if you want to continue using it immediately.
      • fetchLazyBlobs

        protected E fetchLazyBlobs​(E entity)
        Fetch all lazy blobs of given entity. Note that the implementation does for simplicitly not check if those are actually lazy or eager.
        Parameters:
        entity - Entity instance to fetch all blobs on.
        Returns:
        The same entity, useful if you want to continue using it immediately.
      • fetchLazyBlobs

        protected Optional<E> fetchLazyBlobs​(Optional<E> entity)
        Fetch all lazy blobs of given optional entity. Note that the implementation does for simplicitly not check if those are actually lazy or eager.
        Parameters:
        entity - Optional entity instance to fetch all blobs on.
        Returns:
        The same optional entity, useful if you want to continue using it immediately.
      • onPage

        protected <T extends EConsumer<TypedQuery<?>> onPage​(Class<T> resultType,
                                                               boolean cacheable)
        Here you can in your BaseEntityService subclass define the callback method which needs to be invoked when any query involved in getPage(Page, boolean) is about to be executed. For example, to set a vendor specific Query hint. The default implementation sets Hibernate, EclipseLink and JPA 2.0 cache-related hints. When cacheable argument is true, then it reads from cache where applicable, else it will read from DB and force a refresh of cache. Note that this is not supported by OpenJPA.
        Type Parameters:
        T - The generic type of the entity or a DTO subclass thereof.
        Parameters:
        resultType - The result type which can be the entity type itself or a DTO subclass thereof.
        cacheable - Whether the results should be cacheable.
        Returns:
        The callback method which is invoked when any query involved in getPage(Page, boolean) is about to be executed.
      • getPage

        public org.omnifaces.utils.collection.PartialResultList<E> getPage​(Page page,
                                                                           boolean count)
        Returns a partial result list based on given Page. This will by default cache the results.

        Usage examples:

         Page first10Records = Page.of(0, 10);
         PartialResultList<Foo> foos = getPage(first10Records, true);
         
         Map<String, Object> criteria = new HashMap<>();
         criteria.put("bar", bar); // Exact match.
         criteria.put("baz", IgnoreCase.value(baz)); // Case insensitive match.
         criteria.put("faz", Like.contains(faz)); // Case insensitive LIKE match.
         criteria.put("kaz", Order.greaterThan(kaz)); // Greater than match.
         Page first10RecordsMatchingCriteriaOrderedByBar = Page.with().allMatch(criteria).orderBy("bar", true).range(0, 10);
         PartialResultList<Foo> foos = getPage(first10RecordsMatchingCriteriaOrderedByBar, true);
         
        Parameters:
        page - The page to return a partial result list for.
        count - Whether to run the COUNT(id) query to estimate total number of results. This will be available by PartialResultList.getEstimatedTotalNumberOfResults().
        Returns:
        A partial result list based on given Page.
        See Also:
        Page, Criteria
      • getPage

        protected org.omnifaces.utils.collection.PartialResultList<E> getPage​(Page page,
                                                                              boolean count,
                                                                              String... fetchFields)
        Returns a partial result list based on given Page and fetch fields. This will by default cache the results.

        Usage examples:

         Page first10Records = Page.of(0, 10);
         PartialResultList<Foo> foosWithBars = getPage(first10Records, true, "bar");
         
         Map<String, Object> criteria = new HashMap<>();
         criteria.put("bar", bar); // Exact match.
         criteria.put("baz", IgnoreCase.value(baz)); // Case insensitive match.
         criteria.put("faz", Like.contains(faz)); // Case insensitive LIKE match.
         criteria.put("kaz", Order.greaterThan(kaz)); // Greater than match.
         Page first10RecordsMatchingCriteriaOrderedByBar = Page.with().allMatch(criteria).orderBy("bar", true).range(0, 10);
         PartialResultList<Foo> foosWithBars = getPage(first10RecordsMatchingCriteriaOrderedByBar, true, "bar");
         
        Parameters:
        page - The page to return a partial result list for.
        count - Whether to run the COUNT(id) query to estimate total number of results. This will be available by PartialResultList.getEstimatedTotalNumberOfResults().
        fetchFields - Optionally, all (lazy loaded) fields to be explicitly fetched during the query. Each field can represent a JavaBean path, like as you would do in EL, such as parent.child.subchild.
        Returns:
        A partial result list based on given Page.
        See Also:
        Page, Criteria
      • getPage

        protected org.omnifaces.utils.collection.PartialResultList<E> getPage​(Page page,
                                                                              boolean count,
                                                                              boolean cacheable,
                                                                              String... fetchFields)
        Returns a partial result list based on given Page with the option whether to cache the results or not.

        Usage example: see getPage(Page, boolean) and getPage(Page, boolean, String...).

        Parameters:
        page - The page to return a partial result list for.
        count - Whether to run the COUNT(id) query to estimate total number of results. This will be available by PartialResultList.getEstimatedTotalNumberOfResults().
        cacheable - Whether the results should be cacheable.
        fetchFields - Optionally, all (lazy loaded) fields to be explicitly fetched during the query. Each field can represent a JavaBean path, like as you would do in EL, such as parent.child.subchild.
        Returns:
        A partial result list based on given Page.
        See Also:
        Page, Criteria
      • getPage

        protected org.omnifaces.utils.collection.PartialResultList<E> getPage​(Page page,
                                                                              boolean count,
                                                                              BaseEntityService.QueryBuilder<E> queryBuilder)
        Returns a partial result list based on given Page and BaseEntityService.QueryBuilder. This will by default cache the results.

        Usage example: see BaseEntityService.QueryBuilder.

        Parameters:
        page - The page to return a partial result list for.
        count - Whether to run the COUNT(id) query to estimate total number of results. This will be available by PartialResultList.getEstimatedTotalNumberOfResults().
        queryBuilder - This allows fine-graining the JPA criteria query.
        Returns:
        A partial result list based on given Page and BaseEntityService.QueryBuilder.
        See Also:
        Page, Criteria
      • getPage

        protected org.omnifaces.utils.collection.PartialResultList<E> getPage​(Page page,
                                                                              boolean count,
                                                                              boolean cacheable,
                                                                              BaseEntityService.QueryBuilder<E> queryBuilder)
        Returns a partial result list based on given Page, entity type and BaseEntityService.QueryBuilder with the option whether to cache the results or not.

        Usage example: see BaseEntityService.QueryBuilder.

        Parameters:
        page - The page to return a partial result list for.
        count - Whether to run the COUNT(id) query to estimate total number of results. This will be available by PartialResultList.getEstimatedTotalNumberOfResults().
        cacheable - Whether the results should be cacheable.
        queryBuilder - This allows fine-graining the JPA criteria query.
        Returns:
        A partial result list based on given Page and BaseEntityService.QueryBuilder.
        See Also:
        Page, Criteria
      • getPage

        protected <T extends E> org.omnifaces.utils.collection.PartialResultList<T> getPage​(Page page,
                                                                                            boolean count,
                                                                                            Class<T> resultType,
                                                                                            BaseEntityService.MappedQueryBuilder<T> mappedQueryBuilder)
        Returns a partial result list based on given Page, result type and BaseEntityService.MappedQueryBuilder. This will by default cache the results.

        Usage example: see BaseEntityService.MappedQueryBuilder.

        Type Parameters:
        T - The generic type of the entity or a DTO subclass thereof.
        Parameters:
        page - The page to return a partial result list for.
        count - Whether to run the COUNT(id) query to estimate total number of results. This will be available by PartialResultList.getEstimatedTotalNumberOfResults().
        resultType - The result type which can be the entity type itself or a DTO subclass thereof.
        mappedQueryBuilder - This allows fine-graining the JPA criteria query and must return a mapping of getters-paths.
        Returns:
        A partial result list based on given Page and BaseEntityService.MappedQueryBuilder.
        Throws:
        IllegalArgumentException - When the result type does not equal entity type and mapping is empty.
        See Also:
        Page, Criteria
      • getPage

        protected <T extends E> org.omnifaces.utils.collection.PartialResultList<T> getPage​(Page page,
                                                                                            boolean count,
                                                                                            boolean cacheable,
                                                                                            Class<T> resultType,
                                                                                            BaseEntityService.MappedQueryBuilder<T> queryBuilder)
        Returns a partial result list based on given Page, entity type and BaseEntityService.QueryBuilder with the option whether to cache the results or not.

        Usage example: see BaseEntityService.MappedQueryBuilder.

        Type Parameters:
        T - The generic type of the entity or a DTO subclass thereof.
        Parameters:
        page - The page to return a partial result list for.
        count - Whether to run the COUNT(id) query to estimate total number of results. This will be available by PartialResultList.getEstimatedTotalNumberOfResults().
        cacheable - Whether the results should be cacheable.
        resultType - The result type which can be the entity type itself or a DTO subclass thereof.
        queryBuilder - This allows fine-graining the JPA criteria query and must return a mapping of getters-paths when result type does not equal entity type.
        Returns:
        A partial result list based on given Page and BaseEntityService.MappedQueryBuilder.
        Throws:
        IllegalArgumentException - When the result type does not equal entity type and mapping is empty.
        See Also:
        Page, Criteria