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 instances of specific class in the persistent storage.create(Collection<T> entities) Crates all the given entities in the persistent storage.Create an object.Does a look up for the given entity in the persistent storage, usually looking for a specific identifier ( either id or a string property).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 TfindOneByProperty(String propertyName, Object propertyValue) Retrieve one entity whose given property matches the given value.findOrCreate(T entity) Calls the find method, and if this method returns null, creates a new instance in the persistent storage.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 instanced of specific class from the persistent storage.loadReference(Long id) Load reference for an entity.loadReference(Collection<Long> ids) Load references for all the given IDs.reload(Collection<T> entities) Reload an entity from the persistent storage.Reload an entity from the persistent storage.voidRemove a persistent instance based on its ID.voidremove(Collection<T> entities) voidRemove a persistent instancesave(Collection<T> entities) Save all the given entities in the persistent storage.Create or update an entity whether it is transient.Stream all instance ofBaseDaofrom the persistent storage.streamAll(boolean createNewSession) Stream all instances ofBaseDaofrom 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) void
-
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:BaseDaoCrates 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 instances in the persistent storage that were created.
-
create
Description copied from interface:BaseDaoCreate an object. If the entity type is immutable, this may also remove any existing entities identified by an appropriate 'find' method.- Specified by:
createin interfaceBaseDao<T extends Identifiable>- Parameters:
entity- the entity to create- Returns:
- the persistent version of the entity
-
save
Description copied from interface:BaseDaoSave 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 or update an entity whether it is transient.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.
-
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 instanced of specific class from the persistent storage.- Specified by:
loadAllin interfaceBaseDao<T extends Identifiable>- Returns:
- a collection containing all instances that are currently accessible.
-
loadReference
Description copied from interface:BaseDaoLoad references for all the given IDs.Entities already in the 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 instances of specific class in the persistent storage.- Specified by:
countAllin interfaceBaseDao<T extends Identifiable>- Returns:
- number that is the amount of instances currently accessible.
-
streamAll
Description copied from interface:BaseDaoStream all instance ofBaseDaofrom the persistent storage.- Specified by:
streamAllin interfaceBaseDao<T extends Identifiable>
-
streamAll
Description copied from interface:BaseDaoStream all instances ofBaseDaofrom the persistent storage.- 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
- Specified by:
removein interfaceBaseDao<T extends Identifiable>
-
remove
Description copied from interface:BaseDaoRemove a persistent instance based on its ID.The implementer is trusted to know what type of object to remove.
Note that this method is to be avoided for
Securable, because it will leave cruft in the ACL tables. We may fix this by having this method return the removed object.- Specified by:
removein interfaceBaseDao<T extends Identifiable>- Parameters:
id- the ID of the entity to be removed
-
remove
Description copied from interface:BaseDaoRemove a persistent instance- Specified by:
removein interfaceBaseDao<T extends Identifiable>- Parameters:
entity- the entity to be removed
-
update
- Specified by:
updatein interfaceBaseDao<T extends Identifiable>- Parameters:
entities- Update the entities. Not supported if the entities are immutable.
-
update
- Specified by:
updatein interfaceBaseDao<T extends Identifiable>- Parameters:
entity- Update the entity. Not supported if the entity is immutable.
-
find
Description copied from interface:BaseDaoDoes a look up for the given entity in the persistent storage, usually looking for a specific identifier ( either id or a string property).- 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 the find method, and if this method returns null, creates a new instance in the persistent storage.- 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
-
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.
-