Class AbstractDao<T extends Identifiable>
- All Implemented Interfaces:
BaseDao<T>
- Direct Known Subclasses:
AbstractDesignElementDataVectorDao,AbstractVoEnabledDao,AnnotationAssociationDaoImpl,AuditEventDaoImpl,AuditTrailDaoImpl,BlatAssociationDaoImpl,ChromosomeDaoImpl,CoexpressionAnalysisDaoImpl,CoexpressionNodeDegreeDaoImpl,CompoundDaoImpl,ContactDaoImpl,DifferentialExpressionResultDaoImpl,ExperimentalDesignDaoImpl,ExpressionExperimentSubSetDaoImpl,ExternalDatabaseDaoImpl,Gene2GOAssociationDaoImpl,GeneAliasDaoImpl,GeneDiffExMetaAnalysisDaoImpl,GeneSetDaoImpl,GeneSetMemberDaoImpl,PersonDaoImpl,PrincipalComponentAnalysisDaoImpl,ProtocolDaoImpl,ReferenceAssociationDaoImpl,StatementDaoImpl,UnitDaoImpl,UserDaoImpl,UserGroupDaoImpl
- Author:
- Anton, Nicolas
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractDao(Class<? extends T> elementClass, SessionFactory sessionFactory) protectedAbstractDao(Class<? extends T> elementClass, SessionFactory sessionFactory, ClassMetadata classMetadata) -
Method Summary
Modifier and TypeMethodDescriptionlongcountAll()Counts all entities ofBaseDaoin the persistent storage.create(Collection<T> entities) Create all the given entities in the persistent storage.Create an entity in the persistent storage.Does a look-up for the given entity in the persistent storage, usually looking for a specific identifier ifIdentifiable.getId()is set or a business key.findByProperty(String propertyName, Object propertyValue) Does a search on given property and its value.findByPropertyIn(String propertyName, Collection<?> propertyValues) Perform a search on a given property and all its possible values.protected LongfindIdByProperty(String propertyName, Object propertyValue) protected TfindOneByProperty(String propertyName, Object propertyValue) Retrieve one entity whose given property matches the given value.findOrCreate(T entity) Calls theBaseDao.find(Identifiable)method, and if this method returns null, creates a new entity in the persistent storage pas perBaseDao.create(Identifiable).protected final intObtain the element class ofBaseDao.protected Stringprotected Stringprotected final SessionFactoryLoads the entity with given id from the persistent storage.load(Collection<Long> ids) This implementation is temporary and attempts to best replicate the behaviour of loading entities by multiple IDs introduced in Hibernate 5.loadAll()Loads all entities of typeBaseDaofrom the persistent storage.loadReference(Long id) Load reference for an entity.loadReference(Collection<Long> ids) Load references of entities of typeBaseDaofor all the given IDs.reload(Collection<T> entities) Reload an entity from the persistent storage.Reload an entity from the persistent storage.voidremove(Collection<T> entities) Remove all given persistent entities.voidRemove a persistent entity.save(Collection<T> entities) Create (if transient) or update all the given entities in the persistent storage.Create (if transient) or update an entity.Stream all entities ofBaseDaofrom the persistent storage.streamAll(boolean createNewSession) Stream all entities of typeBaseDaofrom the persistent storage.protected <U> Stream<U> streamQuery(Function<Session, Query> queryCreator, Class<U> resultType, int fetchSize, boolean useCursorFetchIfSupported, boolean isStateless, boolean createNewSession) Produce a stream over aQuerywith a new session if desired.voidupdate(Collection<T> entities) Update the given entities.voidUpdate the given entity.
-
Field Details
-
log
protected final org.apache.commons.logging.Log log
-
-
Constructor Details
-
AbstractDao
-
AbstractDao
protected AbstractDao(Class<? extends T> elementClass, SessionFactory sessionFactory, ClassMetadata classMetadata) - Parameters:
classMetadata- the class metadata to use to retrieve information aboutAbstractDao
-
-
Method Details
-
getElementClass
Description copied from interface:BaseDaoObtain the element class ofBaseDao.- Specified by:
getElementClassin interfaceBaseDao<T extends Identifiable>
-
getEntityName
-
getIdentifierPropertyName
-
create
Description copied from interface:BaseDaoCreate all the given entities in the persistent storage.- Specified by:
createin interfaceBaseDao<T extends Identifiable>- Parameters:
entities- the entities to be crated.- Returns:
- collection of entities representing the entities in the persistent storage that were created.
-
create
Description copied from interface:BaseDaoCreate an entity in the persistent storage.- Specified by:
createin interfaceBaseDao<T extends Identifiable>- Parameters:
entity- the entity to create- Returns:
- the persistent version of the entity
- See Also:
-
save
Description copied from interface:BaseDaoCreate (if transient) or update all the given entities in the persistent storage.Unlike
BaseDao.update(Collection), this method does not attach the given entities to the persistence context; the returned values must be used instead.- Specified by:
savein interfaceBaseDao<T extends Identifiable>- See Also:
-
save
Description copied from interface:BaseDaoCreate (if transient) or update an entity.Unlike
BaseDao.update(Identifiable), this method does not attach the given entity to the persistence context and the returned value must be used instead.- Specified by:
savein interfaceBaseDao<T extends Identifiable>- See Also:
-
load
This implementation is temporary and attempts to best replicate the behaviour of loading entities by multiple IDs introduced in Hibernate 5. Read more about this.- Specified by:
loadin interfaceBaseDao<T extends Identifiable>- Parameters:
ids- the IDs of entities to be loaded. If some IDs are not found or null, they are skipped.- Returns:
- collection of entities with given ids.
- See Also:
-
load
Description copied from interface:BaseDaoLoads the entity with given id from the persistent storage.- Specified by:
loadin interfaceBaseDao<T extends Identifiable>- Parameters:
id- the id of entity to load.- Returns:
- the entity with given ID, or null if such entity does not exist or if the passed ID was null
- See Also:
-
loadAll
Description copied from interface:BaseDaoLoads all entities of typeBaseDaofrom the persistent storage.- Specified by:
loadAllin interfaceBaseDao<T extends Identifiable>- Returns:
- a collection containing all entities that are currently accessible.
-
loadReference
Description copied from interface:BaseDaoLoad references of entities of typeBaseDaofor all the given IDs.Entities already in the current session will be returned directly.
- Specified by:
loadReferencein interfaceBaseDao<T extends Identifiable>
-
loadReference
Description copied from interface:BaseDaoLoad reference for an entity.If the entity is already in the session, it will be returned instead. Note that unlike
BaseDao.load(Long), this method will not return null if the entity does not exist.You may freely access the
Identifiable.getId()field without triggering proxy initialization.- Specified by:
loadReferencein interfaceBaseDao<T extends Identifiable>- See Also:
-
reload
Description copied from interface:BaseDaoReload an entity from the persistent storage.This does nothing if the entity is already in the session.
- Specified by:
reloadin interfaceBaseDao<T extends Identifiable>
-
reload
Description copied from interface:BaseDaoReload an entity from the persistent storage.This does nothing for entities already in the session.
- Specified by:
reloadin interfaceBaseDao<T extends Identifiable>
-
countAll
public long countAll()Description copied from interface:BaseDaoCounts all entities ofBaseDaoin the persistent storage.- Specified by:
countAllin interfaceBaseDao<T extends Identifiable>- Returns:
- number that is the amount of entities currently accessible.
-
streamAll
Description copied from interface:BaseDaoStream all entities ofBaseDaofrom the persistent storage.Note that the stream will only be valid while the current database session is active. To create a stream that can outlive the current session, use
BaseDao.streamAll(boolean)passingtrue.- Specified by:
streamAllin interfaceBaseDao<T extends Identifiable>
-
streamAll
Description copied from interface:BaseDaoStream all entities of typeBaseDaofrom the persistent storage.If creating a new session, the caller is responsible for closing the stream to avoid resource leaks. It is recommended to use try-with-resource statement.
- Specified by:
streamAllin interfaceBaseDao<T extends Identifiable>- Parameters:
createNewSession- whether to create a new session for the stream, it will be closed when the stream is closed
-
streamQuery
protected <U> Stream<U> streamQuery(Function<Session, Query> queryCreator, Class<U> resultType, int fetchSize, boolean useCursorFetchIfSupported, boolean isStateless, boolean createNewSession) Produce a stream over aQuerywith a new session if desired.- Parameters:
createNewSession- if true, a new session is created and will be closed when the stream is closed. Be extremely careful with the resulting stream. Use a try-with-resources block to ensure the session is closed properly.- See Also:
-
remove
Description copied from interface:BaseDaoRemove all given persistent entities.- Specified by:
removein interfaceBaseDao<T extends Identifiable>
-
remove
Description copied from interface:BaseDaoRemove a persistent entity.- Specified by:
removein interfaceBaseDao<T extends Identifiable>- Parameters:
entity- the entity to be removed
-
update
Description copied from interface:BaseDaoUpdate the given entities.Not supported if the entity is immutable or loaded in read-only mode.
- Specified by:
updatein interfaceBaseDao<T extends Identifiable>
-
update
Description copied from interface:BaseDaoUpdate the given entity.Not supported if the entity is immutable or loaded in read-only mode.
- Specified by:
updatein interfaceBaseDao<T extends Identifiable>
-
find
Description copied from interface:BaseDaoDoes a look-up for the given entity in the persistent storage, usually looking for a specific identifier ifIdentifiable.getId()is set or a business key.- Specified by:
findin interfaceBaseDao<T extends Identifiable>- Parameters:
entity- the entity to look for.- Returns:
- an entity that was found in the persistent storage, or null if no such entity was found.
-
findOrCreate
Description copied from interface:BaseDaoCalls theBaseDao.find(Identifiable)method, and if this method returns null, creates a new entity in the persistent storage pas perBaseDao.create(Identifiable).- Specified by:
findOrCreatein interfaceBaseDao<T extends Identifiable>- Parameters:
entity- the entity to look for and persist if not found.- Returns:
- the given entity, guaranteed to be representing an entity present in the persistent storage.
-
getSessionFactory
-
getBatchSize
protected final int getBatchSize() -
findOneByProperty
Retrieve one entity whose given property matches the given value.Note: the property should have a unique index, otherwise a
NonUniqueResultExceptionwill be raised.- Parameters:
propertyName- the name of property to be matched.propertyValue- the value to look for.- Returns:
- an entity whose property matched the given value
-
findIdByProperty
-
findByProperty
Does a search on given property and its value.- Parameters:
propertyName- the name of property to be matched.propertyValue- the value to look for.- Returns:
- an entity whose property first matched the given value.
-
findByPropertyIn
Perform a search on a given property and all its possible values.
-