Package ubic.gemma.persistence.service
Class AbstractService<O extends Identifiable>
java.lang.Object
ubic.gemma.persistence.service.AbstractService<O>
- Type Parameters:
O- the Identifiable Object type that this service is handling.
- All Implemented Interfaces:
BaseImmutableService<O>,BaseReadOnlyService<O>,BaseService<O>
- Direct Known Subclasses:
AbstractBulkExpressionDataVectorService,AbstractFilteringVoEnabledService,AbstractVoEnabledService,AnnotationAssociationServiceImpl,AuditTrailServiceImpl,BlatAssociationServiceImpl,ChromosomeServiceImpl,CoexpressionAnalysisServiceImpl,CompoundServiceImpl,ContactServiceImpl,DifferentialExpressionAnalysisServiceImpl,DifferentialExpressionResultServiceImpl,ExperimentalDesignServiceImpl,ExpressionExperimentSubSetServiceImpl,ExternalDatabaseServiceImpl,Gene2GOAssociationServiceImpl,GeneDiffExMetaAnalysisServiceImpl,PrincipalComponentAnalysisServiceImpl,ProtocolServiceImpl
public abstract class AbstractService<O extends Identifiable>
extends Object
implements BaseService<O>
Base for all services handling DAO access.
- Author:
- tesarst
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongcountAll()create(Collection<O> entities) Creates all the given entities in a persistent storageCreates the given entity in the persistent storage.protected Collection<O> ensureInSession(Collection<O> entities) Deprecated.avoid using this if possible and ensure that all operations are properly enclosed by a single Hibernate sessionprotected OensureInSession(O entity) Deprecated.avoid using this if possible and ensure that all operations are properly enclosed by a single Hibernate sessionDoes a search for the entity in the persistent storagefindOrCreate(O entity) Does a search for the entity in the persistent storage, and if not found, creates it.findOrFail(O entity) Does a search for the entity in the persistent storage, raising aNullPointerExceptionif not found.Loads object with given ID.load(Collection<Long> ids) Loads objects with given ids.loadAll()Loads all the entities of specific type.loadOrFail(Long id) Convenience for runningBaseReadOnlyService.load(Long)and checking if the result is null.loadOrFail(Long id, Function<String, T> exceptionSupplier) Load an entity or fail with the supplied exception; the message is generated automatically.loadOrFail(Long id, Function<String, T> exceptionSupplier, String message) Load an entity or fail with the supplied exception and message.loadOrFail(Long id, Supplier<T> exceptionSupplier) Load an entity or fail with the supplied exception.loadOrFail(Collection<Long> ids) Load multiple objects or fail with aNullPointerExceptionif any of the objects does not exist in the persistent storage.<T extends Exception>
Collection<O> loadOrFail(Collection<Long> ids, Function<String, T> exceptionSupplier) voidRemoves the entity with given ID from the persistent storage.voidremove(Collection<O> entities) Removes all the given entities from persistent storage.voidRemoves the given entity from the persistent storage.save(Collection<O> entities) streamAll(boolean createNewSession) voidupdate(Collection<O> entities) Updates all entities in the given collection in the persistent storage.voidUpdates the given entity in the persistent storage.
-
Field Details
-
log
protected static final org.apache.commons.logging.Log log
-
-
Constructor Details
-
AbstractService
-
-
Method Details
-
getElementClass
- Specified by:
getElementClassin interfaceBaseReadOnlyService<O extends Identifiable>
-
find
Description copied from interface:BaseReadOnlyServiceDoes a search for the entity in the persistent storage- Specified by:
findin interfaceBaseReadOnlyService<O extends Identifiable>- Parameters:
entity- the entity to be searched for- Returns:
- the version of entity retrieved from the persistent storage, if found, otherwise null.
-
findOrFail
Description copied from interface:BaseReadOnlyServiceDoes a search for the entity in the persistent storage, raising aNullPointerExceptionif not found.- Specified by:
findOrFailin interfaceBaseReadOnlyService<O extends Identifiable>- Parameters:
entity- the entity to be searched for- Returns:
- the version of entity retrieved from persistent storage
-
findOrCreate
Description copied from interface:BaseImmutableServiceDoes a search for the entity in the persistent storage, and if not found, creates it.- Specified by:
findOrCreatein interfaceBaseImmutableService<O extends Identifiable>- Parameters:
entity- the entity to look for, and create if not found.- Returns:
- the entity retrieved from the persistent storage, either found or created.
-
create
Description copied from interface:BaseImmutableServiceCreates all the given entities in a persistent storage- Specified by:
createin interfaceBaseImmutableService<O extends Identifiable>- Parameters:
entities- the entities to be created.- Returns:
- collection of objects referencing the persistent instances of given entities.
-
create
Description copied from interface:BaseImmutableServiceCreates the given entity in the persistent storage.- Specified by:
createin interfaceBaseImmutableService<O extends Identifiable>- Parameters:
entity- the entity to be created.- Returns:
- object referencing the persistent instance of the given entity.
-
save
- Specified by:
savein interfaceBaseService<O extends Identifiable>- See Also:
-
save
- Specified by:
savein interfaceBaseService<O extends Identifiable>- See Also:
-
load
Description copied from interface:BaseReadOnlyServiceLoads objects with given ids.- Specified by:
loadin interfaceBaseReadOnlyService<O extends Identifiable>- Parameters:
ids- the ids of objects to be loaded.- Returns:
- collection containing object with given IDs.
-
loadOrFail
@Transactional(readOnly=true) public Collection<O> loadOrFail(Collection<Long> ids) throws NullPointerException Description copied from interface:BaseReadOnlyServiceLoad multiple objects or fail with aNullPointerExceptionif any of the objects does not exist in the persistent storage.- Specified by:
loadOrFailin interfaceBaseReadOnlyService<O extends Identifiable>- Throws:
NullPointerException
-
loadOrFail
@Transactional(readOnly=true) public <T extends Exception> Collection<O> loadOrFail(Collection<Long> ids, Function<String, T> exceptionSupplier) throws T- Specified by:
loadOrFailin interfaceBaseReadOnlyService<O extends Identifiable>- Throws:
T
-
load
Description copied from interface:BaseReadOnlyServiceLoads object with given ID.- Specified by:
loadin interfaceBaseReadOnlyService<O extends Identifiable>- Parameters:
id- the ID of entity to be loaded.- Returns:
- the entity with matching ID, or null if the entity does not exist or if the passed ID was null
-
loadOrFail
Description copied from interface:BaseReadOnlyServiceConvenience for runningBaseReadOnlyService.load(Long)and checking if the result is null.- Specified by:
loadOrFailin interfaceBaseReadOnlyService<O extends Identifiable>- Parameters:
id- the ID used to retrieve the entity- Returns:
- the entity as per
BaseReadOnlyService.load(Long), never null
-
loadOrFail
@Nonnull @Transactional(readOnly=true) public <T extends Exception> O loadOrFail(Long id, Supplier<T> exceptionSupplier) throws T Description copied from interface:BaseReadOnlyServiceLoad an entity or fail with the supplied exception.- Specified by:
loadOrFailin interfaceBaseReadOnlyService<O extends Identifiable>- Throws:
T- if the entity does not exist in the persistent storage
-
loadOrFail
@Nonnull @Transactional(readOnly=true) public <T extends Exception> O loadOrFail(Long id, Function<String, T> exceptionSupplier) throws TDescription copied from interface:BaseReadOnlyServiceLoad an entity or fail with the supplied exception; the message is generated automatically.- Specified by:
loadOrFailin interfaceBaseReadOnlyService<O extends Identifiable>- Throws:
T- if the entity does not exist in the persistent storage
-
loadOrFail
@Nonnull @Transactional(readOnly=true) public <T extends Exception> O loadOrFail(Long id, Function<String, T> exceptionSupplier, String message) throws TDescription copied from interface:BaseReadOnlyServiceLoad an entity or fail with the supplied exception and message.- Specified by:
loadOrFailin interfaceBaseReadOnlyService<O extends Identifiable>- Throws:
T- if the entity does not exist in the persistent storage
-
loadAll
Description copied from interface:BaseReadOnlyServiceLoads all the entities of specific type.- Specified by:
loadAllin interfaceBaseReadOnlyService<O extends Identifiable>- Returns:
- collection of all entities currently available in the persistent storage.
-
countAll
@Transactional(readOnly=true) public long countAll()- Specified by:
countAllin interfaceBaseReadOnlyService<O extends Identifiable>
-
streamAll
- Specified by:
streamAllin interfaceBaseReadOnlyService<O extends Identifiable>
-
streamAll
- Specified by:
streamAllin interfaceBaseReadOnlyService<O extends Identifiable>
-
remove
Description copied from interface:BaseImmutableServiceRemoves all the given entities from persistent storage.- Specified by:
removein interfaceBaseImmutableService<O extends Identifiable>- Parameters:
entities- the entities to be removed.
-
remove
Description copied from interface:BaseImmutableServiceRemoves the entity with given ID from the persistent storage.- Specified by:
removein interfaceBaseImmutableService<O extends Identifiable>- Parameters:
id- the ID of entity to be removed.
-
remove
Description copied from interface:BaseImmutableServiceRemoves the given entity from the persistent storage.- Specified by:
removein interfaceBaseImmutableService<O extends Identifiable>- Parameters:
entity- the entity to be removed.
-
update
Description copied from interface:BaseServiceUpdates all entities in the given collection in the persistent storage.- Specified by:
updatein interfaceBaseService<O extends Identifiable>- Parameters:
entities- the entities to be updated.
-
update
Description copied from interface:BaseServiceUpdates the given entity in the persistent storage.- Specified by:
updatein interfaceBaseService<O extends Identifiable>- Parameters:
entity- the entity to be updated.
-
ensureInSession
Deprecated.avoid using this if possible and ensure that all operations are properly enclosed by a single Hibernate sessionEnsure that a given entity is in the current session.If not found in the current session, it will be retrieved from the persistent storage.
-
ensureInSession
Deprecated.avoid using this if possible and ensure that all operations are properly enclosed by a single Hibernate sessionEnsure that a collection of entities are in the current session.Implementation note: if all entities are already in the session - or are transient, this call is very fast and does not involve any database interaction, otherwise the persistent entities are fetched in bulk.
- See Also:
-