Package org.hibernate.event.internal
Class AbstractSaveEventListener<C>
- java.lang.Object
-
- org.hibernate.event.internal.AbstractReassociateEventListener
-
- org.hibernate.event.internal.AbstractSaveEventListener<C>
-
- All Implemented Interfaces:
CallbackRegistryConsumer
- Direct Known Subclasses:
DefaultMergeEventListener
,DefaultPersistEventListener
,DefaultReplicateEventListener
,DefaultSaveOrUpdateEventListener
public abstract class AbstractSaveEventListener<C> extends AbstractReassociateEventListener implements CallbackRegistryConsumer
A convenience base class for listeners responding to save events.
-
-
Constructor Summary
Constructors Constructor Description AbstractSaveEventListener()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
cascadeAfterSave(EventSource source, EntityPersister persister, Object entity, C context)
Handles calls needed to perform post-save cascades.protected void
cascadeBeforeSave(EventSource source, EntityPersister persister, Object entity, C context)
Handles the calls needed to perform pre-save cascades for the given entity.protected abstract CascadingAction<C>
getCascadeAction()
protected Map<Object,Object>
getMergeMap(C anything)
void
injectCallbackRegistry(CallbackRegistry callbackRegistry)
Injection of the CallbackRegistryprotected boolean
invokeSaveLifecycle(Object entity, EntityPersister persister, EventSource source)
protected boolean
isVersionIncrementDisabled()
After the save, will te version number be incremented if the instance is modified?protected Object
performSave(Object entity, Object id, EntityPersister persister, boolean useIdentityColumn, C context, EventSource source, boolean delayIdentityInserts)
Prepares the save call by checking the session caches for a pre-existing entity and performing any lifecycle callbacks.protected Object
performSaveOrReplicate(Object entity, EntityKey key, EntityPersister persister, boolean useIdentityColumn, C context, EventSource source, boolean delayIdentityInserts)
Performs all the actual work needed to save an entity (well to get the save moved to the execution queue).protected Object
saveWithGeneratedId(Object entity, String entityName, C context, EventSource source, boolean requiresImmediateIdAccess)
Prepares the save call using a newly generated id.protected Object
saveWithRequestedId(Object entity, Object requestedId, String entityName, C context, EventSource source)
Prepares the save call using the given requested id.protected boolean
substituteValuesIfNecessary(Object entity, Object id, Object[] values, EntityPersister persister, SessionImplementor source)
Perform any property value substitution that is necessary (interceptor callback, version initialization...)protected boolean
visitCollectionsBeforeSave(Object entity, Object id, Object[] values, Type[] types, EventSource source)
-
Methods inherited from class org.hibernate.event.internal.AbstractReassociateEventListener
reassociate
-
-
-
-
Method Detail
-
injectCallbackRegistry
public void injectCallbackRegistry(CallbackRegistry callbackRegistry)
Description copied from interface:CallbackRegistryConsumer
Injection of the CallbackRegistry- Specified by:
injectCallbackRegistry
in interfaceCallbackRegistryConsumer
- Parameters:
callbackRegistry
- The CallbackRegistry
-
saveWithRequestedId
protected Object saveWithRequestedId(Object entity, Object requestedId, String entityName, C context, EventSource source)
Prepares the save call using the given requested id.- Parameters:
entity
- The entity to be saved.requestedId
- The id to which to associate the entity.entityName
- The name of the entity being saved.context
- Generally cascade-specific information.source
- The session which is the source of this save event.- Returns:
- The id used to save the entity.
-
saveWithGeneratedId
protected Object saveWithGeneratedId(Object entity, String entityName, C context, EventSource source, boolean requiresImmediateIdAccess)
Prepares the save call using a newly generated id.- Parameters:
entity
- The entity to be savedentityName
- The entity-name for the entity to be savedcontext
- Generally cascade-specific information.source
- The session which is the source of this save event.requiresImmediateIdAccess
- does the event context require access to the identifier immediately after execution of this method (if not, post-insert style id generators may be postponed if we are outside a transaction).- Returns:
- The id used to save the entity; may be null depending on the type of id generator used and the requiresImmediateIdAccess value
-
performSave
protected Object performSave(Object entity, Object id, EntityPersister persister, boolean useIdentityColumn, C context, EventSource source, boolean delayIdentityInserts)
Prepares the save call by checking the session caches for a pre-existing entity and performing any lifecycle callbacks.- Parameters:
entity
- The entity to be saved.id
- The id by which to save the entity.persister
- The entity's persister instance.useIdentityColumn
- Is an identity column being used?context
- Generally cascade-specific information.source
- The session from which the event originated.delayIdentityInserts
- Should the identity insert be delayed?- Returns:
- The id used to save the entity; may be null depending on the type of id generator used and on delayIdentityInserts
-
invokeSaveLifecycle
protected boolean invokeSaveLifecycle(Object entity, EntityPersister persister, EventSource source)
-
performSaveOrReplicate
protected Object performSaveOrReplicate(Object entity, EntityKey key, EntityPersister persister, boolean useIdentityColumn, C context, EventSource source, boolean delayIdentityInserts)
Performs all the actual work needed to save an entity (well to get the save moved to the execution queue).- Parameters:
entity
- The entity to be savedkey
- The id to be used for saving the entity (or null, in the case of identity columns)persister
- The entity's persister instance.useIdentityColumn
- Should an identity column be used for id generation?context
- Generally cascade-specific information.source
- The session which is the source of the current event.delayIdentityInserts
- Should the identity insert be delayed?- Returns:
- The id used to save the entity; may be null depending on the type of id generator used and the requiresImmediateIdAccess value
-
isVersionIncrementDisabled
protected boolean isVersionIncrementDisabled()
After the save, will te version number be incremented if the instance is modified?- Returns:
- True if the version will be incremented on an entity change after save; false otherwise.
-
visitCollectionsBeforeSave
protected boolean visitCollectionsBeforeSave(Object entity, Object id, Object[] values, Type[] types, EventSource source)
-
substituteValuesIfNecessary
protected boolean substituteValuesIfNecessary(Object entity, Object id, Object[] values, EntityPersister persister, SessionImplementor source)
Perform any property value substitution that is necessary (interceptor callback, version initialization...)- Parameters:
entity
- The entityid
- The entity identifiervalues
- The snapshot entity statepersister
- The entity persistersource
- The originating session- Returns:
- True if the snapshot state changed such that reinjection of the values into the entity is required.
-
cascadeBeforeSave
protected void cascadeBeforeSave(EventSource source, EntityPersister persister, Object entity, C context)
Handles the calls needed to perform pre-save cascades for the given entity.- Parameters:
source
- The session from which the save event originated.persister
- The entity's persister instance.entity
- The entity to be saved.context
- Generally cascade-specific data
-
cascadeAfterSave
protected void cascadeAfterSave(EventSource source, EntityPersister persister, Object entity, C context)
Handles calls needed to perform post-save cascades.- Parameters:
source
- The session from which the event originated.persister
- The entity's persister instance.entity
- The entity being saved.context
- Generally cascade-specific data
-
getCascadeAction
protected abstract CascadingAction<C> getCascadeAction()
-
-