public abstract class HibernateDao<T> extends StatelessDao
Modifier and Type | Field and Description |
---|---|
protected BatchFinder |
batchFinder |
protected SessionBatchProcessor |
batchProcessor |
protected org.slf4j.Logger |
logger |
protected StatelessSessionBatchProcessor |
statelessSessionBatchProcessor |
protected Clock |
timeSource |
sessionFactory
Constructor and Description |
---|
HibernateDao() |
Modifier and Type | Method and Description |
---|---|
protected <T> org.hibernate.query.Query<T> |
createDeleteQuery(Class persistentClass,
Map<String,Object> properties) |
protected <T> org.hibernate.query.Query<T> |
createDeleteQuery(Map<String,Object> properties) |
protected <T> org.hibernate.query.Query<T> |
createQuery(Class persistentClass,
Map<String,Object> properties,
List<com.atlassian.fugue.Pair<String,Boolean>> orderByProperties)
Returns the query with matching properties.
|
protected <T> org.hibernate.query.Query<T> |
createQuery(Map<String,Object> properties) |
protected <R> List<R> |
executeHQLQuery(HQLQuery hqlQuery)
|
protected List<T> |
findAllInternal() |
protected org.hibernate.query.Query<T> |
findByProperties(Map<String,Object> properties) |
protected Optional<T> |
findByPropertiesOptional(Map<String,Object> properties) |
protected org.hibernate.query.Query<T> |
findByProperty(String name,
Object value) |
protected <V,E extends Exception> |
findByProperty(String name,
V value,
Function<V,E> exceptionMapper) |
protected Optional<T> |
findByPropertyOptional(String name,
Object value) |
protected T |
findByPropertyOrThrow(String name,
Object value) |
protected long |
getCountByProperties(Map<String,Object> properties) |
abstract Class<T> |
getPersistentClass()
All subclasses of HibernateDao must implement this method for
load(Serializable) to work
correctly. |
T |
load(Serializable id)
Loads a persisted entity from the persistence store.
|
protected <V extends Serializable,E extends Exception> |
load(V id,
Function<V,E> exceptionMapper)
Loads a persisted entity from the persistence store.
|
protected Optional<T> |
loadOptional(Serializable id) |
<U> U |
loadReference(Class<U> persistentClass,
long id)
This method calls the
session.load method to obtain a proxy (or actual instance if the object is in
session) by NOT hitting the database immediately. |
T |
loadReference(long id)
This method calls the
session.load method to obtain a proxy (or actual instance if the object is in
session) by NOT hitting the database immediately. |
void |
remove(Object persistentObject)
Removes the DAO object from the persistence store.
|
void |
removeByIdIfPresent(Serializable id)
Removes the DAO object with matching id from the persistence store, if present.
|
void |
save(Object persistentObject)
Saves a new DAO object to the persistence store.
|
void |
saveOrUpdate(Object persistentObject)
Saves or updates DAO object to the persistence store.
|
protected org.hibernate.Session |
session() |
void |
setBatchFinder(BatchFinder batchFinder) |
void |
setBatchProcessor(SessionBatchProcessor batchProcessor) |
void |
setClock(Clock timeSource) |
void |
setStatelessSessionBatchProcessor(StatelessSessionBatchProcessor statelessSessionBatchProcessor) |
protected <T> javax.persistence.criteria.Predicate[] |
toPredicates(Map<String,Object> properties,
javax.persistence.criteria.CriteriaBuilder builder,
javax.persistence.criteria.Root<T> root)
Prepares a collection of predicates matching each of the properties with it's corresponding value
|
void |
update(Object persistentObject)
Updates an existing DAO object, if the object does not exist it will be added to the persistence store.
|
setSessionFactory, withStatelessSession
protected final org.slf4j.Logger logger
protected BatchFinder batchFinder
protected SessionBatchProcessor batchProcessor
protected StatelessSessionBatchProcessor statelessSessionBatchProcessor
protected Clock timeSource
public abstract Class<T> getPersistentClass()
load(Serializable)
to work
correctly.public T load(Serializable id) throws ObjectNotFoundException
id
- The unique identifier of the object to load from the persistence store.ObjectNotFoundException
- when the requested entity is not found.protected <V extends Serializable,E extends Exception> T load(V id, Function<V,E> exceptionMapper) throws E extends Exception
id
- The unique identifier of the object to load from the persistence store.E
- when entity not foundE extends Exception
protected Optional<T> loadOptional(Serializable id)
id
- The unique identifier of the object to load from the persistence store.protected org.hibernate.query.Query<T> findByProperties(Map<String,Object> properties)
properties
- entity properties to be matchedQuery
object for matching properties.protected org.hibernate.query.Query<T> findByProperty(String name, Object value)
name
- property name to matchvalue
- property value to matchQuery
object for matching properties.protected Optional<T> findByPropertiesOptional(Map<String,Object> properties)
properties
- entity properties to be matchedprotected T findByPropertyOrThrow(String name, Object value) throws ObjectNotFoundException
name
- property name to matchvalue
- property value to matchObjectNotFoundException
- when the requested entity is not found.protected Optional<T> findByPropertyOptional(String name, Object value)
name
- property name to matchvalue
- property value to matchprotected <V,E extends Exception> T findByProperty(String name, V value, Function<V,E> exceptionMapper) throws E extends Exception
name
- property name to matchvalue
- property value to matchexceptionMapper
- will be used to throw exception when entity not foundE
- when entity not foundE extends Exception
protected <T> org.hibernate.query.Query<T> createQuery(Class persistentClass, Map<String,Object> properties, List<com.atlassian.fugue.Pair<String,Boolean>> orderByProperties)
persistentClass
- persistence classproperties
- entity properties to be matchedOptional.empty()
org.hibernate.NonUniqueResultException
- if more than one result was foundprotected <T> org.hibernate.query.Query<T> createDeleteQuery(Class persistentClass, Map<String,Object> properties)
protected <T> org.hibernate.query.Query<T> createDeleteQuery(Map<String,Object> properties)
protected <T> javax.persistence.criteria.Predicate[] toPredicates(Map<String,Object> properties, javax.persistence.criteria.CriteriaBuilder builder, javax.persistence.criteria.Root<T> root)
T
- model classproperties
- map of property with value to be matchedbuilder
- criteria builderroot
- rootpublic <U> U loadReference(Class<U> persistentClass, long id)
session.load
method to obtain a proxy (or actual instance if the object is in
session) by NOT hitting the database immediately.
Do NOT call this method unless you are SURE that the object with the supplied identifier exists.
persistentClass
- the type of the entity to loadid
- unique identifier to load.public T loadReference(long id)
session.load
method to obtain a proxy (or actual instance if the object is in
session) by NOT hitting the database immediately.
Do NOT call this method unless you are SURE that the object with the supplied identifier exists.
id
- unique identifier to load.public void remove(Object persistentObject) throws org.springframework.dao.DataAccessException
persistentObject
- The object to remove.org.springframework.dao.DataAccessException
- A persistence exception has occurred.public void removeByIdIfPresent(Serializable id)
id
- id of the object to be removedpublic void save(Object persistentObject) throws org.springframework.dao.DataAccessException
persistentObject
- The object to save.org.springframework.dao.DataAccessException
- A persistence exception has occurred.public void saveOrUpdate(Object persistentObject) throws org.springframework.dao.DataAccessException
persistentObject
- The object to save or update.org.springframework.dao.DataAccessException
- A persistence exception has occurred.@Autowired public void setBatchFinder(BatchFinder batchFinder)
@Autowired public void setBatchProcessor(SessionBatchProcessor batchProcessor)
@Autowired public void setStatelessSessionBatchProcessor(StatelessSessionBatchProcessor statelessSessionBatchProcessor)
public void update(Object persistentObject) throws org.springframework.dao.DataAccessException
persistentObject
- The object to update.org.springframework.dao.DataAccessException
- A persistence exception has occurred.protected org.hibernate.Session session()
protected <R> List<R> executeHQLQuery(HQLQuery hqlQuery)
public void setClock(Clock timeSource)
Copyright © 2024 Atlassian. All rights reserved.