Class HibernateDao<T>
java.lang.Object
com.atlassian.crowd.util.persistence.hibernate.StatelessDao
com.atlassian.crowd.util.persistence.hibernate.HibernateDao<T>
- Direct Known Subclasses:
AliasDAOHibernate
,AppIssuesWithMailsScanResultDAOHibernate
,ApplicationDAOHibernate
,ApplicationDefaultGroupMembershipConfigurationDaoHibernate
,ApplicationSamlConfigurationDAOHibernate
,AuditDAOHibernate
,ClusterHeartbeatDAOHibernate
,ClusterInfoDAOHibernate
,ClusterLockDAOHibernate
,CrowdRememberMeTokenDAOHibernate
,DirectoryDAOHibernate
,DirectoryInfoDaoHibernate
,DirectorySynchronisationStatusDAOHibernate
,DirectorySynchronisationTokenDaoHibernate
,ExpirableUserTokenDaoHibernate
,GroupAdministrationGrantGroupDaoHibernate
,InternalDirectoryEntityHibernateDao
,LicensedUserDaoHibernate
,LicensingSummaryDaoHibernate
,MembershipDAOHibernate
,PropertyDAOHibernate
,SAMLTrustDAOHibernate
,TokenDAOHibernate
,TombstoneDAOHibernate
,UserAdministrationGrantGroupDaoHibernate
,UserPermissionDAOHibernate
,WebhookDAOHibernate
Generic persistence class for storing Hibernate persistence objects.
-
Field Summary
Modifier and TypeFieldDescriptionprotected BatchFinder
protected SessionBatchProcessor
protected final org.slf4j.Logger
protected StatelessSessionBatchProcessor
protected Clock
Fields inherited from class com.atlassian.crowd.util.persistence.hibernate.StatelessDao
sessionFactory
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected <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<io.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 org.hibernate.query.Query<T>
findByProperties
(Map<String, Object> properties) findByPropertiesOptional
(Map<String, Object> properties) protected org.hibernate.query.Query<T>
findByProperty
(String name, Object value) findByProperty
(String name, V value, Function<V, E> exceptionMapper) findByPropertyOptional
(String name, Object value) protected T
findByPropertyOrThrow
(String name, Object value) protected long
getCountByProperties
(Map<String, Object> properties) All subclasses of HibernateDao must implement this method forload(Serializable)
to work correctly.load
(Serializable id) Loads a persisted entity from the persistence store.protected <V extends Serializable,
E extends Exception>
TLoads a persisted entity from the persistence store.loadReference
(long id) This method calls thesession.load
method to obtain a proxy (or actual instance if the object is in session) by NOT hitting the database immediately.<U> U
loadReference
(Class<U> persistentClass, long id) This method calls thesession.load
method to obtain a proxy (or actual instance if the object is in session) by NOT hitting the database immediately.void
Removes the DAO object from the persistence store.void
Removes the DAO object with matching id from the persistence store, if present.void
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
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 valuevoid
Updates an existing DAO object, if the object does not exist it will be added to the persistence store.Methods inherited from class com.atlassian.crowd.util.persistence.hibernate.StatelessDao
setSessionFactory, withStatelessSession
-
Field Details
-
logger
protected final org.slf4j.Logger logger -
batchFinder
-
batchProcessor
-
statelessSessionBatchProcessor
-
timeSource
-
-
Constructor Details
-
HibernateDao
public HibernateDao()
-
-
Method Details
-
getPersistentClass
All subclasses of HibernateDao must implement this method forload(Serializable)
to work correctly.- Returns:
- the entity class for this DAO
-
load
Loads a persisted entity from the persistence store.- Parameters:
id
- The unique identifier of the object to load from the persistence store.- Returns:
- The populated object from the database.
- Throws:
ObjectNotFoundException
- when the requested entity is not found.
-
load
protected <V extends Serializable,E extends Exception> T load(V id, Function<V, E> exceptionMapper) throws ELoads a persisted entity from the persistence store.- Parameters:
id
- The unique identifier of the object to load from the persistence store.- Returns:
- The populated object from the database.
- Throws:
E
- when entity not found
-
loadOptional
- Parameters:
id
- The unique identifier of the object to load from the persistence store.- Returns:
- An Optional containing the populated object from the database or an empty optional
-
findByProperties
- Parameters:
properties
- entity properties to be matched- Returns:
- he
Query
object for matching properties.
-
getCountByProperties
-
findByProperty
- Parameters:
name
- property name to matchvalue
- property value to match- Returns:
- he
Query
object for matching properties.
-
findByPropertiesOptional
- Parameters:
properties
- entity properties to be matched- Returns:
- optional result matching properties.
-
findByPropertyOrThrow
- Parameters:
name
- property name to matchvalue
- property value to match- Returns:
- matching entity
- Throws:
ObjectNotFoundException
- when the requested entity is not found.
-
findByPropertyOptional
- Parameters:
name
- property name to matchvalue
- property value to match- Returns:
- optional matching entity
-
findByProperty
protected <V,E extends Exception> T findByProperty(String name, V value, Function<V, E> exceptionMapper) throws E- Parameters:
name
- property name to matchvalue
- property value to matchexceptionMapper
- will be used to throw exception when entity not found- Returns:
- matching entity
- Throws:
E
- when entity not found
-
createQuery
protected <T> org.hibernate.query.Query<T> createQuery(Class persistentClass, Map<String, Object> properties, List<io.atlassian.fugue.Pair<String, Boolean>> orderByProperties) Returns the query with matching properties.- Parameters:
persistentClass
- persistence classproperties
- entity properties to be matched- Returns:
- matched entity or
Optional.empty()
- Throws:
org.hibernate.NonUniqueResultException
- if more than one result was found
-
createQuery
-
createDeleteQuery
-
createDeleteQuery
-
toPredicates
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- Type Parameters:
T
- model class- Parameters:
properties
- map of property with value to be matchedbuilder
- criteria builderroot
- root- Returns:
- an array of predicates
-
loadReference
This method calls thesession.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.
- Parameters:
persistentClass
- the type of the entity to loadid
- unique identifier to load.- Returns:
- a proxy object (or actual instance if the object is in session)
-
loadReference
This method calls thesession.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.
- Parameters:
id
- unique identifier to load.- Returns:
- a proxy object (or actual instance if the object is in session)
-
remove
Removes the DAO object from the persistence store.- Parameters:
persistentObject
- The object to remove.- Throws:
org.springframework.dao.DataAccessException
- A persistence exception has occurred.
-
removeByIdIfPresent
Removes the DAO object with matching id from the persistence store, if present.- Parameters:
id
- id of the object to be removed
-
save
Saves a new DAO object to the persistence store.- Parameters:
persistentObject
- The object to save.- Throws:
org.springframework.dao.DataAccessException
- A persistence exception has occurred.
-
saveOrUpdate
public void saveOrUpdate(Object persistentObject) throws org.springframework.dao.DataAccessException Saves or updates DAO object to the persistence store.- Parameters:
persistentObject
- The object to save or update.- Throws:
org.springframework.dao.DataAccessException
- A persistence exception has occurred.
-
setBatchFinder
-
setBatchProcessor
-
setStatelessSessionBatchProcessor
@Autowired public void setStatelessSessionBatchProcessor(StatelessSessionBatchProcessor statelessSessionBatchProcessor) -
update
Updates an existing DAO object, if the object does not exist it will be added to the persistence store.- Parameters:
persistentObject
- The object to update.- Throws:
org.springframework.dao.DataAccessException
- A persistence exception has occurred.
-
session
protected org.hibernate.Session session() -
executeHQLQuery
- Returns:
- a results of the query
-
setClock
-
findAllInternal
-