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.Loglog
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractService(BaseDao<O> mainDao)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description longcountAll()Collection<O>create(Collection<O> entities)Creates all the given entities in a persistent storageOcreate(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 OensureInSession(O entity)Deprecated.avoid using this if possible and ensure that all operations are properly enclosed by a single Hibernate sessionOfind(O entity)Does a search for the entity in the persistent storageOfindOrCreate(O entity)Does a search for the entity in the persistent storage, and if not found, creates it.OfindOrFail(O entity)Does a search for the entity in the persistent storage, raising aNullPointerExceptionif not found.Class<? extends O>getElementClass()Oload(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.OloadOrFail(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.voidremove(Long id)Removes the entity with given ID from the persistent storage.voidremove(Collection<O> entities)Removes all the given entities from persistent storage.voidremove(O entity)Removes the given entity from the persistent storage.Collection<O>save(Collection<O> entities)Osave(O entity)voidupdate(Collection<O> entities)Updates all entities in the given collection in the persistent storage.voidupdate(O entity)Updates the given entity in the persistent storage.
-
-
-
Method Detail
-
getElementClass
public Class<? extends O> getElementClass()
- Specified by:
getElementClassin interfaceBaseReadOnlyService<O extends Identifiable>
-
find
@Transactional(readOnly=true) public O find(O entity)
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
@Nonnull @Transactional(readOnly=true) public O findOrFail(O entity)
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
@Transactional public O findOrCreate(O entity)
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
@Transactional public Collection<O> create(Collection<O> entities)
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
@Transactional @OverridingMethodsMustInvokeSuper public O create(O entity)
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
@Transactional public Collection<O> save(Collection<O> entities)
- Specified by:
savein interfaceBaseService<O extends Identifiable>- See Also:
BaseDao.save(Collection)
-
save
@Transactional @OverridingMethodsMustInvokeSuper public O save(O entity)
- Specified by:
savein interfaceBaseService<O extends Identifiable>- See Also:
BaseDao.save(Object)
-
load
@Transactional(readOnly=true) public Collection<O> load(Collection<Long> ids)
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.
-
load
@Transactional(readOnly=true) public O load(Long id)
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
@Nonnull @Transactional(readOnly=true) public O loadOrFail(Long id)
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 extends Exception
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 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: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 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: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 storageT extends Exception
-
loadAll
@Transactional(readOnly=true) public Collection<O> 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>
-
remove
@Transactional public void remove(Collection<O> entities)
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
@Transactional public void remove(Long id)
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
@Transactional @OverridingMethodsMustInvokeSuper public void remove(O entity)
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
@Transactional public void update(Collection<O> entities)
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
@Transactional @OverridingMethodsMustInvokeSuper public void update(O entity)
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 @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)
-
-