Package org.hibernate

Class EmptyInterceptor

  • All Implemented Interfaces:
    java.io.Serializable, Interceptor

    public class EmptyInterceptor
    extends java.lang.Object
    implements Interceptor, java.io.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 Interceptor INSTANCE
      The singleton reference.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected EmptyInterceptor()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void afterTransactionBegin​(Transaction tx)
      Called when a Hibernate transaction is begun via the Hibernate Transaction API.
      void afterTransactionCompletion​(Transaction tx)
      Called after a transaction is committed or rolled back.
      void beforeTransactionCompletion​(Transaction tx)
      Called before a transaction is committed (but not before rollback).
      int[] findDirty​(java.lang.Object entity, java.io.Serializable id, java.lang.Object[] currentState, java.lang.Object[] previousState, java.lang.String[] propertyNames, Type[] types)
      Called from flush().
      java.lang.Object getEntity​(java.lang.String entityName, java.io.Serializable id)
      Get a fully loaded entity instance that is cached externally.
      java.lang.String getEntityName​(java.lang.Object object)
      Get the entity name for a persistent or transient instance.
      java.lang.Object instantiate​(java.lang.String entityName, EntityMode entityMode, java.io.Serializable id)
      Instantiate the entity class.
      java.lang.Boolean isTransient​(java.lang.Object entity)
      Called to distinguish between transient and detached entities.
      void onCollectionRecreate​(java.lang.Object collection, java.io.Serializable key)
      Called before a collection is (re)created.
      void onCollectionRemove​(java.lang.Object collection, java.io.Serializable key)
      Called before a collection is deleted.
      void onCollectionUpdate​(java.lang.Object collection, java.io.Serializable key)
      Called before a collection is updated.
      void onDelete​(java.lang.Object entity, java.io.Serializable id, java.lang.Object[] state, java.lang.String[] propertyNames, Type[] types)
      Called before an object is deleted.
      boolean onFlushDirty​(java.lang.Object entity, java.io.Serializable id, java.lang.Object[] currentState, java.lang.Object[] previousState, java.lang.String[] propertyNames, Type[] types)
      Called when an object is detected to be dirty, during a flush.
      boolean onLoad​(java.lang.Object entity, java.io.Serializable id, java.lang.Object[] state, java.lang.String[] propertyNames, Type[] types)
      Called just before an object is initialized.
      java.lang.String onPrepareStatement​(java.lang.String sql)
      Called when sql string is being prepared.
      boolean onSave​(java.lang.Object entity, java.io.Serializable id, java.lang.Object[] state, java.lang.String[] propertyNames, Type[] types)
      Called before an object is saved.
      void postFlush​(java.util.Iterator entities)
      Called after a flush that actually ends in execution of the SQL statements required to synchronize in-memory state with the database.
      void preFlush​(java.util.Iterator entities)
      Called before a flush.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • INSTANCE

        public static final Interceptor INSTANCE
        The singleton reference.
    • Constructor Detail

      • EmptyInterceptor

        protected EmptyInterceptor()
    • Method Detail

      • onDelete

        public void onDelete​(java.lang.Object entity,
                             java.io.Serializable id,
                             java.lang.Object[] state,
                             java.lang.String[] propertyNames,
                             Type[] types)
        Description copied from interface: Interceptor
        Called before an object is deleted. It is not recommended that the interceptor modify the state.
        Specified by:
        onDelete in interface Interceptor
        Parameters:
        entity - The entity instance being deleted
        id - The identifier of the entity
        state - The state of the entity
        propertyNames - The names of the entity properties.
        types - The types of the entity properties
      • onFlushDirty

        public boolean onFlushDirty​(java.lang.Object entity,
                                    java.io.Serializable id,
                                    java.lang.Object[] currentState,
                                    java.lang.Object[] previousState,
                                    java.lang.String[] propertyNames,
                                    Type[] types)
        Description copied from interface: Interceptor
        Called 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:
        onFlushDirty in interface Interceptor
        Parameters:
        entity - The entity instance detected as being dirty and being flushed
        id - The identifier of the entity
        currentState - The entity's current state
        previousState - The entity's previous (load time) state.
        propertyNames - The names of the entity properties
        types - The types of the entity properties
        Returns:
        true if the user modified the currentState in any way.
      • onLoad

        public boolean onLoad​(java.lang.Object entity,
                              java.io.Serializable id,
                              java.lang.Object[] state,
                              java.lang.String[] propertyNames,
                              Type[] types)
        Description copied from interface: Interceptor
        Called 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:
        onLoad in interface Interceptor
        Parameters:
        entity - The entity instance being loaded
        id - The identifier value being loaded
        state - 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:
        true if the user modified the state in any way.
      • onSave

        public boolean onSave​(java.lang.Object entity,
                              java.io.Serializable id,
                              java.lang.Object[] state,
                              java.lang.String[] propertyNames,
                              Type[] types)
        Description copied from interface: Interceptor
        Called 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:
        onSave in interface Interceptor
        Parameters:
        entity - The entity instance whose state is being inserted
        id - The identifier of the entity
        state - The state of the entity which will be inserted
        propertyNames - 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​(java.util.Iterator entities)
        Description copied from interface: Interceptor
        Called after a flush that actually ends in execution of the SQL statements required to synchronize in-memory state with the database.
        Specified by:
        postFlush in interface Interceptor
        Parameters:
        entities - The entities that were flushed.
      • preFlush

        public void preFlush​(java.util.Iterator entities)
        Description copied from interface: Interceptor
        Called before a flush.
        Specified by:
        preFlush in interface Interceptor
        Parameters:
        entities - The entities to be flushed.
      • isTransient

        public java.lang.Boolean isTransient​(java.lang.Object entity)
        Description copied from interface: Interceptor
        Called 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:
        isTransient in interface Interceptor
        Parameters:
        entity - a transient or detached entity
        Returns:
        Boolean or null to choose default behaviour
      • instantiate

        public java.lang.Object instantiate​(java.lang.String entityName,
                                            EntityMode entityMode,
                                            java.io.Serializable id)
        Description copied from interface: Interceptor
        Instantiate 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:
        instantiate in interface Interceptor
        Parameters:
        entityName - the name of the entity
        entityMode - 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​(java.lang.Object entity,
                               java.io.Serializable id,
                               java.lang.Object[] currentState,
                               java.lang.Object[] previousState,
                               java.lang.String[] propertyNames,
                               Type[] types)
        Description copied from interface: Interceptor
        Called 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:
        findDirty in interface Interceptor
        Parameters:
        entity - The entity for which to find dirty properties.
        id - The identifier of the entity
        currentState - The current entity state as taken from the entity instance
        previousState - 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 null to indicate Hibernate should perform default behaviour
      • getEntityName

        public java.lang.String getEntityName​(java.lang.Object object)
        Description copied from interface: Interceptor
        Get the entity name for a persistent or transient instance.
        Specified by:
        getEntityName in interface Interceptor
        Parameters:
        object - an entity instance
        Returns:
        the name of the entity
      • getEntity

        public java.lang.Object getEntity​(java.lang.String entityName,
                                          java.io.Serializable id)
        Description copied from interface: Interceptor
        Get a fully loaded entity instance that is cached externally.
        Specified by:
        getEntity in interface Interceptor
        Parameters:
        entityName - the name of the entity
        id - the instance identifier
        Returns:
        a fully initialized entity
      • afterTransactionBegin

        public void afterTransactionBegin​(Transaction tx)
        Description copied from interface: Interceptor
        Called 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:
        afterTransactionBegin in interface Interceptor
        Parameters:
        tx - The Hibernate transaction facade object
      • afterTransactionCompletion

        public void afterTransactionCompletion​(Transaction tx)
        Description copied from interface: Interceptor
        Called after a transaction is committed or rolled back.
        Specified by:
        afterTransactionCompletion in interface Interceptor
        Parameters:
        tx - The Hibernate transaction facade object
      • beforeTransactionCompletion

        public void beforeTransactionCompletion​(Transaction tx)
        Description copied from interface: Interceptor
        Called before a transaction is committed (but not before rollback).
        Specified by:
        beforeTransactionCompletion in interface Interceptor
        Parameters:
        tx - The Hibernate transaction facade object
      • onPrepareStatement

        public java.lang.String onPrepareStatement​(java.lang.String sql)
        Description copied from interface: Interceptor
        Called when sql string is being prepared.
        Specified by:
        onPrepareStatement in interface Interceptor
        Parameters:
        sql - sql to be prepared
        Returns:
        original or modified sql
      • onCollectionRemove

        public void onCollectionRemove​(java.lang.Object collection,
                                       java.io.Serializable key)
                                throws CallbackException
        Description copied from interface: Interceptor
        Called before a collection is deleted.
        Specified by:
        onCollectionRemove in interface Interceptor
        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​(java.lang.Object collection,
                                         java.io.Serializable key)
                                  throws CallbackException
        Description copied from interface: Interceptor
        Called before a collection is (re)created.
        Specified by:
        onCollectionRecreate in interface Interceptor
        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​(java.lang.Object collection,
                                       java.io.Serializable key)
                                throws CallbackException
        Description copied from interface: Interceptor
        Called before a collection is updated.
        Specified by:
        onCollectionUpdate in interface Interceptor
        Parameters:
        collection - The collection instance.
        key - The collection key value.
        Throws:
        CallbackException - Thrown if the interceptor encounters any problems handling the callback.