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:
AbstractDesignElementDataVectorService
,AbstractFilteringVoEnabledService
,AbstractVoEnabledService
,AnnotationAssociationServiceImpl
,AuditTrailServiceImpl
,BlatAssociationServiceImpl
,ChromosomeServiceImpl
,CoexpressionAnalysisServiceImpl
,CompoundServiceImpl
,ContactServiceImpl
,DifferentialExpressionAnalysisServiceImpl
,DifferentialExpressionResultServiceImpl
,ExperimentalDesignServiceImpl
,ExpressionExperimentSubSetServiceImpl
,ExternalDatabaseServiceImpl
,Gene2GOAssociationServiceImpl
,GeneDiffExMetaAnalysisServiceImpl
,PhenotypeAssociationServiceImpl
,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 Modifier and Type Field Description protected static org.apache.commons.logging.Log
log
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractService(BaseDao<O> mainDao)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description long
countAll()
Collection<O>
create(Collection<O> entities)
Creates all the given entities in a persistent storageO
create(O entity)
Creates 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 sessionO
find(O entity)
Does a search for the entity in the persistent storageO
findOrCreate(O entity)
Does a search for the entity in the persistent storage, and if not found, creates it.O
findOrFail(O entity)
Does a search for the entity in the persistent storage, raising aNullPointerException
if not found.Class<? extends O>
getElementClass()
O
load(Long id)
Loads object with given ID.Collection<O>
load(Collection<Long> ids)
Loads objects with given ids.Collection<O>
loadAll()
Loads all the entities of specific type.O
loadOrFail(Long id)
Convenience for runningBaseReadOnlyService.load(Long)
and checking if the result is null.<T extends Exception>
OloadOrFail(Long id, Function<String,T> exceptionSupplier)
Load an entity or fail with the supplied exception; the message is generated automatically.<T extends Exception>
OloadOrFail(Long id, Function<String,T> exceptionSupplier, String message)
Load an entity or fail with the supplied exception and message.<T extends Exception>
OloadOrFail(Long id, Supplier<T> exceptionSupplier)
Load an entity or fail with the supplied exception.void
remove(Long id)
Removes the entity with given ID from the persistent storage.void
remove(Collection<O> entities)
Removes all the given entities from persistent storage.void
remove(O entity)
Removes the given entity from the persistent storage.Collection<O>
save(Collection<O> entities)
O
save(O entity)
void
update(Collection<O> entities)
Updates all entities in the given collection in the persistent storage.void
update(O entity)
Updates the given entity in the persistent storage.
-
-
-
Method Detail
-
getElementClass
public Class<? extends O> getElementClass()
- Specified by:
getElementClass
in interfaceBaseReadOnlyService<O extends Identifiable>
-
find
@Transactional(readOnly=true) public O find(O entity)
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
@Nonnull @Transactional(readOnly=true) public O findOrFail(O entity)
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
@Transactional public O findOrCreate(O entity)
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
@Transactional public Collection<O> create(Collection<O> entities)
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
@Transactional @OverridingMethodsMustInvokeSuper public O create(O entity)
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
@Transactional public Collection<O> save(Collection<O> entities)
- Specified by:
save
in interfaceBaseService<O extends Identifiable>
- See Also:
BaseDao.save(Collection)
-
save
@Transactional @OverridingMethodsMustInvokeSuper public O save(O entity)
- Specified by:
save
in interfaceBaseService<O extends Identifiable>
- See Also:
BaseDao.save(Object)
-
load
@Transactional(readOnly=true) public Collection<O> load(Collection<Long> ids)
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
@Transactional(readOnly=true) public O load(Long id)
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
@Nonnull @Transactional(readOnly=true) public O loadOrFail(Long id)
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 extends Exception
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 storageT extends Exception
-
loadOrFail
@Nonnull @Transactional(readOnly=true) public <T extends Exception> O loadOrFail(Long id, Function<String,T> exceptionSupplier) throws T extends Exception
Description 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 storageT extends Exception
-
loadOrFail
@Nonnull @Transactional(readOnly=true) public <T extends Exception> O loadOrFail(Long id, Function<String,T> exceptionSupplier, String message) throws T extends Exception
Description 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 storageT extends Exception
-
loadAll
@Transactional(readOnly=true) public Collection<O> 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>
-
remove
@Transactional public void remove(Collection<O> entities)
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
@Transactional public void remove(Long id)
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
@Transactional @OverridingMethodsMustInvokeSuper public void remove(O entity)
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
@Transactional public void update(Collection<O> entities)
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
@Transactional @OverridingMethodsMustInvokeSuper public void update(O entity)
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 @CheckReturnValue protected O ensureInSession(O entity)
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 @CheckReturnValue 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 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:
ensureInSession(Identifiable)
-
-