Package com.flowlogix.jeedao
Class DaoHelper<TT,KT>
java.lang.Object
com.flowlogix.jeedao.DaoHelper<TT,KT>
- Type Parameters:
TT
- Entity TypeKT
- Primary Key Type
Lightweight wrapper around common JPA methods
This is the primary class in the
com.flowlogix.jeedao
package
Main value-add is ability to easily add hints and query criteria to
findAll()
and findRange(int, int)
methods,
as well as count()
methods
Another differentiator is that this class doesn't require inheritance,
although some use cases could inherit from InheritableDaoHelper
class.
Simple Example:
@Stateless
public class ExampleDAO {
@PersistenceContext
EntityManager em;
@Delegate
DaoHelper<UserEntity, Long> helper = new DaoHelper<>(() -> em, UserEntity.class);
}
- Author:
- lprimak
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <TT,
KT> DaoHelper.DaoHelperBuilder<TT, KT> builder()
<RR> QueryCriteria<RR>
buildQueryCriteria
(Class<RR> cls) int
count()
<FF extends Function<DaoHelper.Parameters.ParametersBuilder<TT>,
DaoHelper.Parameters<TT>>>
intcount
(FF paramsBuilder) createNativeQuery
(String sql, Class<?> resultClass) createNativeQuery
(String sql, String resultMapping) findAll()
<FF extends Function<DaoHelper.Parameters.ParametersBuilder<TT>,
DaoHelper.Parameters<TT>>>
List<TT>findAll
(FF paramsBuilder) find all with added criteria and hintsfindRange
(int min, int max) <FF extends Function<DaoHelper.Parameters.ParametersBuilder<TT>,
DaoHelper.Parameters<TT>>>
List<TT>findRange
(int min, int max, FF paramsBuilder) find range with added criteria and hintsentity classjakarta.persistence.EntityManager
-
Constructor Details
-
DaoHelper
@ConstructorProperties({"entityManager","entityClass"}) public DaoHelper(@NonNull @NonNull Supplier<jakarta.persistence.EntityManager> entityManager, @NonNull @NonNull Class<TT> entityClass)
-
-
Method Details
-
findAll
-
findAll
public <FF extends Function<DaoHelper.Parameters.ParametersBuilder<TT>,DaoHelper.Parameters<TT>>> List<TT> findAll(FF paramsBuilder) find all with added criteria and hintsExample:
findAll(builder -> builder.build())
- Parameters:
paramsBuilder
-- Returns:
-
findRange
-
findRange
public <FF extends Function<DaoHelper.Parameters.ParametersBuilder<TT>,DaoHelper.Parameters<TT>>> List<TT> findRange(int min, int max, FF paramsBuilder) find range with added criteria and hints- Parameters:
min
-max
-paramsBuilder
-- Returns:
-
count
public int count() -
count
public <FF extends Function<DaoHelper.Parameters.ParametersBuilder<TT>,DaoHelper.Parameters<TT>>> int count(FF paramsBuilder) -
getEntityManager
public jakarta.persistence.EntityManager getEntityManager()- Returns:
- entity manager
-
buildQueryCriteria
-
buildQueryCriteria
-
createNativeQuery
-
createNativeQuery
-
builder
-
getEntityClass
entity class
-