Package ubic.gemma.persistence.persister
Class AbstractPersister
- java.lang.Object
-
- ubic.gemma.persistence.persister.AbstractPersister
-
- All Implemented Interfaces:
Persister
- Direct Known Subclasses:
CommonPersister
public abstract class AbstractPersister extends Object implements Persister
Base class forPersister
implementations.Important note: persisting is a somewhat complicated process, and for some reason we cannot afford to let Hibernate flush changes to the database until the whole operation is completed. This is why we use the
FlushMode.MANUAL
, manually flush, and we subsequently restore it to the defaultFlushMode.AUTO
when done.- Author:
- pavlidis
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractPersister.Caches
Various caches to refer back to not-yet persisted entities (and thus not easily obtainable from the persistence context).
-
Field Summary
Fields Modifier and Type Field Description protected static org.apache.commons.logging.Log
log
Shared logger for all persisters.protected static int
REPORT_BATCH_SIZE
Size if batch to report when persisting multiple entities withdoPersist(Collection, Caches)
.
-
Constructor Summary
Constructors Constructor Description AbstractPersister()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Object
doPersist(Object entity, AbstractPersister.Caches caches)
protected List<?>
doPersist(Collection<?> entities, AbstractPersister.Caches caches)
protected Object
doPersistOrUpdate(Object entity, AbstractPersister.Caches caches)
protected SessionFactory
getSessionFactory()
Object
persist(Object entity)
Persist a single object.List<?>
persist(Collection<?> col)
Persist all the objects in a collection.Object
persistOrUpdate(Object entity)
Persist or update a single object.
-
-
-
Field Detail
-
log
protected static final org.apache.commons.logging.Log log
Shared logger for all persisters.
-
REPORT_BATCH_SIZE
protected static final int REPORT_BATCH_SIZE
Size if batch to report when persisting multiple entities withdoPersist(Collection, Caches)
.Implementations can use this to have a consistent batch size when reporting.
- See Also:
- Constant Field Values
-
-
Method Detail
-
persist
@Transactional public Object persist(Object entity)
Description copied from interface:Persister
Persist a single object. Non-nullable dependencies are checked and persisted first, if the reference is detached, or converted into a reference to a persistent object identified by the objects business key. If a matching object already exists, it will not be changed.
-
persistOrUpdate
@Transactional public Object persistOrUpdate(Object entity)
Description copied from interface:Persister
Persist or update a single object. If the object already exists in the system, it will be replaced with the supplied instance. This means that any existing data may be lost. Otherwise a new persistent instance will be created from the supplied instance. Non-nullable dependencies will be replaced with existing persistent ones or created anew: Associated objects will not be updated if they already exist. Therefore this method has limited usefulness: when the provided object has new data but the associated objects are either new or already existing. If you want to update associated objects you must update them explicitly (perhaps with a call to persistOrUpdate on them).- Specified by:
persistOrUpdate
in interfacePersister
- Parameters:
entity
- the object- Returns:
- the persistent version of the object.
-
persist
@Transactional public List<?> persist(Collection<?> col)
Description copied from interface:Persister
Persist all the objects in a collection. Non-nullable dependencies are checked and persisted first, if the reference is detached, or converted into a reference to a persistent object identified by the objects business key. Matching instances are not changed.
-
getSessionFactory
protected SessionFactory getSessionFactory()
-
doPersist
@OverridingMethodsMustInvokeSuper protected Object doPersist(Object entity, AbstractPersister.Caches caches)
-
doPersist
protected final List<?> doPersist(Collection<?> entities, AbstractPersister.Caches caches)
-
doPersistOrUpdate
@OverridingMethodsMustInvokeSuper protected Object doPersistOrUpdate(Object entity, AbstractPersister.Caches caches)
-
-