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 TypeMethodDescriptionlong
countAll()
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 O
ensureInSession
(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 aNullPointerException
if 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.void
Removes the entity with given ID from the persistent storage.void
remove
(Collection<O> entities) Removes all the given entities from persistent storage.void
Removes the given entity from the persistent storage.save
(Collection<O> entities) streamAll
(boolean createNewSession) void
update
(Collection<O> entities) Updates all entities in the given collection in the persistent storage.void
Updates 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:
getElementClass
in interfaceBaseReadOnlyService<O extends Identifiable>
-
find
Description copied from interface:BaseReadOnlyService
Does a search for the entity in the persistent storage- Specified by:
find
in 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:BaseReadOnlyService
Does a search for the entity in the persistent storage, raising aNullPointerException
if not found.- Specified by:
findOrFail
in 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:BaseImmutableService
Does a search for the entity in the persistent storage, and if not found, creates it.- Specified by:
findOrCreate
in 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:BaseImmutableService
Creates all the given entities in a persistent storage- Specified by:
create
in 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:BaseImmutableService
Creates the given entity in the persistent storage.- Specified by:
create
in interfaceBaseImmutableService<O extends Identifiable>
- Parameters:
entity
- the entity to be created.- Returns:
- object referencing the persistent instance of the given entity.
-
save
- Specified by:
save
in interfaceBaseService<O extends Identifiable>
- See Also:
-
save
- Specified by:
save
in interfaceBaseService<O extends Identifiable>
- See Also:
-
load
Description copied from interface:BaseReadOnlyService
Loads objects with given ids.- Specified by:
load
in interfaceBaseReadOnlyService<O extends Identifiable>
- Parameters:
ids
- the ids of objects to be loaded.- Returns:
- collection containing object with given IDs.
-
load
Description copied from interface:BaseReadOnlyService
Loads object with given ID.- Specified by:
load
in 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:BaseReadOnlyService
Convenience for runningBaseReadOnlyService.load(Long)
and checking if the result is null.- Specified by:
loadOrFail
in 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:BaseReadOnlyService
Load an entity or fail with the supplied exception.- Specified by:
loadOrFail
in 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:BaseReadOnlyService
Load an entity or fail with the supplied exception; the message is generated automatically.- Specified by:
loadOrFail
in 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:BaseReadOnlyService
Load an entity or fail with the supplied exception and message.- Specified by:
loadOrFail
in interfaceBaseReadOnlyService<O extends Identifiable>
- Throws:
T
- if the entity does not exist in the persistent storage
-
loadAll
Description copied from interface:BaseReadOnlyService
Loads all the entities of specific type.- Specified by:
loadAll
in interfaceBaseReadOnlyService<O extends Identifiable>
- Returns:
- collection of all entities currently available in the persistent storage.
-
countAll
@Transactional(readOnly=true) public long countAll()- Specified by:
countAll
in interfaceBaseReadOnlyService<O extends Identifiable>
-
streamAll
- Specified by:
streamAll
in interfaceBaseReadOnlyService<O extends Identifiable>
-
streamAll
- Specified by:
streamAll
in interfaceBaseReadOnlyService<O extends Identifiable>
-
remove
Description copied from interface:BaseImmutableService
Removes all the given entities from persistent storage.- Specified by:
remove
in interfaceBaseImmutableService<O extends Identifiable>
- Parameters:
entities
- the entities to be removed.
-
remove
Description copied from interface:BaseImmutableService
Removes the entity with given ID from the persistent storage.- Specified by:
remove
in interfaceBaseImmutableService<O extends Identifiable>
- Parameters:
id
- the ID of entity to be removed.
-
remove
Description copied from interface:BaseImmutableService
Removes the given entity from the persistent storage.- Specified by:
remove
in interfaceBaseImmutableService<O extends Identifiable>
- Parameters:
entity
- the entity to be removed.
-
update
Description copied from interface:BaseService
Updates all entities in the given collection in the persistent storage.- Specified by:
update
in interfaceBaseService<O extends Identifiable>
- Parameters:
entities
- the entities to be updated.
-
update
Description copied from interface:BaseService
Updates the given entity in the persistent storage.- Specified by:
update
in 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:
-