@Repository public class BaseJpaDaoImpl extends Object implements BaseJpaDao
| Modifier and Type | Field and Description |
|---|---|
protected javax.persistence.EntityManager |
entityManager |
| Constructor and Description |
|---|
BaseJpaDaoImpl() |
| Modifier and Type | Method and Description |
|---|---|
<T> void |
delete(T entity)
Deletes an entity.
|
<T> void |
detach(T entity)
Detaches an entity.
|
protected <T> T |
executeSingleResultQuery(javax.persistence.criteria.CriteriaQuery<T> criteria,
String message)
Executes query, validates if result list contains no more than record and returns the query result.
|
<T> List<T> |
findAll(Class<T> entityClass)
Gets a list of entities based on the entity class.
|
<T> T |
findById(Class<T> entityClass,
Object entityId)
Get an entity based on its class and entity Id.
|
<T> List<T> |
findByNamedProperties(Class<T> entityClass,
Map<String,?> params)
Finds a collection of entities based on an entity class name and named parameters.
|
<T> T |
findUniqueByNamedProperties(Class<T> entityClass,
Map<String,?> params)
Finds an entity based on an entity class name and named parameters.
|
Timestamp |
getCurrentTimestamp()
Gets the current timestamp.
|
javax.persistence.EntityManager |
getEntityManager()
Gets the entity manager instance.
|
protected <T> javax.persistence.criteria.Predicate |
getPredicateForInClause(javax.persistence.criteria.CriteriaBuilder builder,
javax.persistence.criteria.Path<T> path,
List<T> values)
Gets an "in" clause predicate for a list of values.
|
<T> List<T> |
query(String queryString)
Executes a query string and returns the results.
|
<T> List<T> |
queryByNamedParams(String queryString,
Map<String,?> params)
Executes a query string with a named set of parameters.
|
<T> T |
save(T entity)
Saves an entity.
|
<T> T |
saveAndRefresh(T entity)
Saves, flushes, and refreshes an entity.
|
public <T> void delete(T entity)
BaseJpaDaodelete in interface BaseJpaDaoT - the type of entity.entity - the entity to delete.public <T> void detach(T entity)
BaseJpaDaodetach in interface BaseJpaDaoT - the type of entity.entity - the entity to detach.public <T> List<T> findAll(Class<T> entityClass)
BaseJpaDaofindAll in interface BaseJpaDaoT - the type of class.entityClass - the entity class.public <T> T findById(Class<T> entityClass, Object entityId)
BaseJpaDaofindById in interface BaseJpaDaoT - the type of class.entityClass - the entity class.entityId - the entity Id.public <T> List<T> findByNamedProperties(Class<T> entityClass, Map<String,?> params)
BaseJpaDaofindByNamedProperties in interface BaseJpaDaoT - the type of class.entityClass - the entity class to retrieve.params - the named parameters.public <T> T findUniqueByNamedProperties(Class<T> entityClass, Map<String,?> params)
BaseJpaDaofindUniqueByNamedProperties in interface BaseJpaDaoT - the type of class.entityClass - the entity class to retrieve.params - the named parameters.public Timestamp getCurrentTimestamp()
BaseJpaDaogetCurrentTimestamp in interface BaseJpaDaopublic javax.persistence.EntityManager getEntityManager()
BaseJpaDaogetEntityManager in interface BaseJpaDaopublic <T> List<T> query(String queryString)
BaseJpaDaoquery in interface BaseJpaDaoT - the type of entity being returned.queryString - the query string.public <T> List<T> queryByNamedParams(String queryString, Map<String,?> params)
BaseJpaDaoqueryByNamedParams in interface BaseJpaDaoT - the type of class to be returned.queryString - the query string.params - the named parameter map.public <T> T save(T entity)
BaseJpaDaosave in interface BaseJpaDaoT - the type of entity.entity - the entity to save.public <T> T saveAndRefresh(T entity)
BaseJpaDaosaveAndRefresh in interface BaseJpaDaoT - the type of entity.entity - the entity to save.protected <T> T executeSingleResultQuery(javax.persistence.criteria.CriteriaQuery<T> criteria,
String message)
T - The type of the root entity classcriteria - the criteria select query to be executedmessage - the exception message to use if the query returns failsprotected <T> javax.persistence.criteria.Predicate getPredicateForInClause(javax.persistence.criteria.CriteriaBuilder builder,
javax.persistence.criteria.Path<T> path,
List<T> values)
T - the type referenced by the path.builder - the criteria builder.path - the path to the field that is being filtered.values - the list of values to place in the in clause.Copyright © 2021. All rights reserved.