Package org.hibernate
Class EmptyInterceptor
- java.lang.Object
-
- org.hibernate.EmptyInterceptor
-
- All Implemented Interfaces:
Serializable,Interceptor
public class EmptyInterceptor extends Object implements Interceptor, Serializable
An interceptor that does nothing. May be used as a base class for application-defined custom interceptors.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static InterceptorINSTANCEThe singleton reference.
-
Constructor Summary
Constructors Modifier Constructor Description protectedEmptyInterceptor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterTransactionBegin(Transaction tx)Called when a Hibernate transaction is begun via the Hibernate Transaction API.voidafterTransactionCompletion(Transaction tx)Called after a transaction is committed or rolled back.voidbeforeTransactionCompletion(Transaction tx)Called before a transaction is committed (but not before rollback).int[]findDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types)Called from flush().ObjectgetEntity(String entityName, Serializable id)Get a fully loaded entity instance that is cached externally.StringgetEntityName(Object object)Get the entity name for a persistent or transient instance.Objectinstantiate(String entityName, EntityMode entityMode, Serializable id)Instantiate the entity class.BooleanisTransient(Object entity)Called to distinguish between transient and detached entities.voidonCollectionRecreate(Object collection, Serializable key)Called before a collection is (re)created.voidonCollectionRemove(Object collection, Serializable key)Called before a collection is deleted.voidonCollectionUpdate(Object collection, Serializable key)Called before a collection is updated.voidonDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)Called before an object is deleted.booleanonFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types)Called when an object is detected to be dirty, during a flush.booleanonLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)Called just before an object is initialized.StringonPrepareStatement(String sql)Called when sql string is being prepared.booleanonSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)Called before an object is saved.voidpostFlush(Iterator entities)Called after a flush that actually ends in execution of the SQL statements required to synchronize in-memory state with the database.voidpreFlush(Iterator entities)Called before a flush.
-
-
-
Field Detail
-
INSTANCE
public static final Interceptor INSTANCE
The singleton reference.
-
-
Method Detail
-
onDelete
public void onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
Description copied from interface:InterceptorCalled before an object is deleted. It is not recommended that the interceptor modify the state.- Specified by:
onDeletein interfaceInterceptor- Parameters:
entity- The entity instance being deletedid- The identifier of the entitystate- The state of the entitypropertyNames- The names of the entity properties.types- The types of the entity properties
-
onFlushDirty
public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types)
Description copied from interface:InterceptorCalled when an object is detected to be dirty, during a flush. The interceptor may modify the detected currentState, which will be propagated to both the database and the persistent object. Note that not all flushes end in actual synchronization with the database, in which case the new currentState will be propagated to the object, but not necessarily (immediately) to the database. It is strongly recommended that the interceptor not modify the previousState. NOTE: The indexes across the currentState, previousState, propertyNames and types arrays match.- Specified by:
onFlushDirtyin interfaceInterceptor- Parameters:
entity- The entity instance detected as being dirty and being flushedid- The identifier of the entitycurrentState- The entity's current statepreviousState- The entity's previous (load time) state.propertyNames- The names of the entity propertiestypes- The types of the entity properties- Returns:
trueif the user modified the currentState in any way.
-
onLoad
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
Description copied from interface:InterceptorCalled just before an object is initialized. The interceptor may change the state, which will be propagated to the persistent object. Note that when this method is called, entity will be an empty uninitialized instance of the class. NOTE: The indexes across the state, propertyNames and types arrays match.- Specified by:
onLoadin interfaceInterceptor- Parameters:
entity- The entity instance being loadedid- The identifier value being loadedstate- The entity state (which will be pushed into the entity instance)propertyNames- The names of the entity properties, corresponding to the state.types- The types of the entity properties, corresponding to the state.- Returns:
trueif the user modified the state in any way.
-
onSave
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types)
Description copied from interface:InterceptorCalled before an object is saved. The interceptor may modify the state, which will be used for the SQL INSERT and propagated to the persistent object.- Specified by:
onSavein interfaceInterceptor- Parameters:
entity- The entity instance whose state is being insertedid- The identifier of the entitystate- The state of the entity which will be insertedpropertyNames- The names of the entity properties.types- The types of the entity properties- Returns:
- true if the user modified the state in any way.
-
postFlush
public void postFlush(Iterator entities)
Description copied from interface:InterceptorCalled after a flush that actually ends in execution of the SQL statements required to synchronize in-memory state with the database.- Specified by:
postFlushin interfaceInterceptor- Parameters:
entities- The entities that were flushed.
-
preFlush
public void preFlush(Iterator entities)
Description copied from interface:InterceptorCalled before a flush.- Specified by:
preFlushin interfaceInterceptor- Parameters:
entities- The entities to be flushed.
-
isTransient
public Boolean isTransient(Object entity)
Description copied from interface:InterceptorCalled to distinguish between transient and detached entities. The return value determines the state of the entity with respect to the current session.- Boolean.TRUE - the entity is transient
- Boolean.FALSE - the entity is detached
- null - Hibernate uses the unsaved-value mapping and other heuristics to determine if the object is unsaved
- Specified by:
isTransientin interfaceInterceptor- Parameters:
entity- a transient or detached entity- Returns:
- Boolean or null to choose default behaviour
-
instantiate
public Object instantiate(String entityName, EntityMode entityMode, Serializable id)
Description copied from interface:InterceptorInstantiate the entity class. Return null to indicate that Hibernate should use the default constructor of the class. The identifier property of the returned instance should be initialized with the given identifier.- Specified by:
instantiatein interfaceInterceptor- Parameters:
entityName- the name of the entityentityMode- The type of entity instance to be returned.id- the identifier of the new instance- Returns:
- an instance of the class, or null to choose default behaviour
-
findDirty
public int[] findDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types)
Description copied from interface:InterceptorCalled from flush(). The return value determines whether the entity is updated- an array of property indices - the entity is dirty
- an empty array - the entity is not dirty
- null - use Hibernate's default dirty-checking algorithm
- Specified by:
findDirtyin interfaceInterceptor- Parameters:
entity- The entity for which to find dirty properties.id- The identifier of the entitycurrentState- The current entity state as taken from the entity instancepreviousState- The state of the entity when it was last synchronized (generally when it was loaded)propertyNames- The names of the entity properties.types- The types of the entity properties- Returns:
- array of dirty property indices or
nullto indicate Hibernate should perform default behaviour
-
getEntityName
public String getEntityName(Object object)
Description copied from interface:InterceptorGet the entity name for a persistent or transient instance.- Specified by:
getEntityNamein interfaceInterceptor- Parameters:
object- an entity instance- Returns:
- the name of the entity
-
getEntity
public Object getEntity(String entityName, Serializable id)
Description copied from interface:InterceptorGet a fully loaded entity instance that is cached externally.- Specified by:
getEntityin interfaceInterceptor- Parameters:
entityName- the name of the entityid- the instance identifier- Returns:
- a fully initialized entity
-
afterTransactionBegin
public void afterTransactionBegin(Transaction tx)
Description copied from interface:InterceptorCalled when a Hibernate transaction is begun via the Hibernate Transaction API. Will not be called if transactions are being controlled via some other mechanism (CMT, for example).- Specified by:
afterTransactionBeginin interfaceInterceptor- Parameters:
tx- The Hibernate transaction facade object
-
afterTransactionCompletion
public void afterTransactionCompletion(Transaction tx)
Description copied from interface:InterceptorCalled after a transaction is committed or rolled back.- Specified by:
afterTransactionCompletionin interfaceInterceptor- Parameters:
tx- The Hibernate transaction facade object
-
beforeTransactionCompletion
public void beforeTransactionCompletion(Transaction tx)
Description copied from interface:InterceptorCalled before a transaction is committed (but not before rollback).- Specified by:
beforeTransactionCompletionin interfaceInterceptor- Parameters:
tx- The Hibernate transaction facade object
-
onPrepareStatement
public String onPrepareStatement(String sql)
Description copied from interface:InterceptorCalled when sql string is being prepared.- Specified by:
onPrepareStatementin interfaceInterceptor- Parameters:
sql- sql to be prepared- Returns:
- original or modified sql
-
onCollectionRemove
public void onCollectionRemove(Object collection, Serializable key) throws CallbackException
Description copied from interface:InterceptorCalled before a collection is deleted.- Specified by:
onCollectionRemovein interfaceInterceptor- Parameters:
collection- The collection instance.key- The collection key value.- Throws:
CallbackException- Thrown if the interceptor encounters any problems handling the callback.
-
onCollectionRecreate
public void onCollectionRecreate(Object collection, Serializable key) throws CallbackException
Description copied from interface:InterceptorCalled before a collection is (re)created.- Specified by:
onCollectionRecreatein interfaceInterceptor- Parameters:
collection- The collection instance.key- The collection key value.- Throws:
CallbackException- Thrown if the interceptor encounters any problems handling the callback.
-
onCollectionUpdate
public void onCollectionUpdate(Object collection, Serializable key) throws CallbackException
Description copied from interface:InterceptorCalled before a collection is updated.- Specified by:
onCollectionUpdatein interfaceInterceptor- Parameters:
collection- The collection instance.key- The collection key value.- Throws:
CallbackException- Thrown if the interceptor encounters any problems handling the callback.
-
-