Package org.hibernate.event.internal
Class AbstractSaveEventListener<C>
java.lang.Object
org.hibernate.event.internal.AbstractSaveEventListener<C>
- All Implemented Interfaces:
CallbackRegistryConsumer
- Direct Known Subclasses:
DefaultMergeEventListener,DefaultPersistEventListener,DefaultReplicateEventListener
public abstract class AbstractSaveEventListener<C>
extends Object
implements CallbackRegistryConsumer
A convenience base class for listeners responding to persist or merge events.
This class contains common functionality for persisting new transient instances.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcascadeAfterSave(EventSource source, EntityPersister persister, Object entity, C context) Handles calls needed to perform post-persist cascades.protected voidcascadeBeforeSave(EventSource source, EntityPersister persister, Object entity, C context) Handles the calls needed to perform pre-persist cascades for the given entity.protected abstract CascadingAction<C> getMergeMap(C anything) voidinjectCallbackRegistry(CallbackRegistry callbackRegistry) Injection of the CallbackRegistryprotected booleanAfter the persist, will the version number be incremented if the instance is modified?protected ObjectperformSave(Object entity, Object id, EntityPersister persister, boolean useIdentityColumn, C context, EventSource source, boolean delayIdentityInserts) Prepares the persist call by checking the session caches for a pre-existing entity and performing any lifecycle callbacks.protected ObjectperformSaveOrReplicate(Object entity, EntityKey key, EntityPersister persister, boolean useIdentityColumn, C context, EventSource source, boolean delayIdentityInserts) Performs all the actual work needed to persist an entity (well to get the persist action moved to the execution queue).protected ObjectsaveWithGeneratedId(Object entity, String entityName, C context, EventSource source, boolean requiresImmediateIdAccess) Prepares the persist call using a newly generated id.protected ObjectsaveWithRequestedId(Object entity, Object requestedId, String entityName, C context, EventSource source) Prepares the persist call using the given requested id.protected booleansubstituteValuesIfNecessary(Object entity, Object id, Object[] values, EntityPersister persister, SessionImplementor source) Perform any property value substitution that is necessary (interceptor callback, version initialization...)protected booleanvisitCollectionsBeforeSave(Object entity, Object id, Object[] values, Type[] types, EventSource source)
-
Constructor Details
-
AbstractSaveEventListener
public AbstractSaveEventListener()
-
-
Method Details
-
injectCallbackRegistry
Description copied from interface:CallbackRegistryConsumerInjection of the CallbackRegistry- Specified by:
injectCallbackRegistryin interfaceCallbackRegistryConsumer- Parameters:
callbackRegistry- The CallbackRegistry
-
saveWithRequestedId
protected Object saveWithRequestedId(Object entity, Object requestedId, String entityName, C context, EventSource source) Prepares the persist call using the given requested id.- Parameters:
entity- The entity to be persistedrequestedId- The id with which to associate the entityentityName- The name of the entity being persistedcontext- Generally cascade-specific informationsource- The session which is the source of this 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 persist call using a newly generated id.- Parameters:
entity- The entity to be persistedentityName- The entity-name for the entity to be persistedcontext- Generally cascade-specific informationsource- The session which is the source of this persist eventrequiresImmediateIdAccess- 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 persist 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 persist call by checking the session caches for a pre-existing entity and performing any lifecycle callbacks.- Parameters:
entity- The entity to be persistedid- The id by which to persist the entitypersister- The entity's persister instanceuseIdentityColumn- Is an identity column being used?context- Generally cascade-specific informationsource- The session from which the event originateddelayIdentityInserts- Should the identity insert be delayed?- Returns:
- The id used to persist the entity; may be null depending on the type of id generator used and on delayIdentityInserts
-
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 persist an entity (well to get the persist action moved to the execution queue).- Parameters:
entity- The entity to be persistedkey- The id to be used for saving the entity (or null, in the case of identity columns)persister- The persister for the entityuseIdentityColumn- Should an identity column be used for id generation?context- Generally cascade-specific informationsource- The session which is the source of the current eventdelayIdentityInserts- Should the identity insert be delayed?- Returns:
- The id used to persist the entity; may be null depending on the type of id generator used and the requiresImmediateIdAccess value
-
getMergeMap
-
isVersionIncrementDisabled
protected boolean isVersionIncrementDisabled()After the persist, will the version number be incremented if the instance is modified?- Returns:
- True if the version will be incremented on an entity change after persist; 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-persist cascades for the given entity.- Parameters:
source- The session from which the persist event originatedpersister- The persister for the entityentity- The entity to be persistedcontext- Generally cascade-specific data
-
cascadeAfterSave
protected void cascadeAfterSave(EventSource source, EntityPersister persister, Object entity, C context) Handles calls needed to perform post-persist cascades.- Parameters:
source- The session from which the event originatedpersister- The persister for the entityentity- The entity being persistedcontext- Generally cascade-specific data
-
getCascadeAction
-