Class OBInterceptor

  • All Implemented Interfaces:
    Serializable, org.hibernate.Interceptor

    public class OBInterceptor
    extends org.hibernate.EmptyInterceptor
    This interceptor is used by Hibernate as a kind of save, update and delete event listener. This event listener catches save or update events to set the client and organization and the updated/created fields. In addition security checks are performed.
    Author:
    mtaal
    See Also:
    Serialized Form
    • Constructor Detail

      • OBInterceptor

        public OBInterceptor()
    • Method Detail

      • setPreventUpdateInfoChange

        public static void setPreventUpdateInfoChange​(boolean value)
        If true is passed and we are in adminMode then the update info (updated/updatedBy) is not updated when an object gets updated.
        Parameters:
        value -
      • setDisableCheckReferencedOrganizations

        public static void setDisableCheckReferencedOrganizations​(boolean value)
        If true is passed then the checkReferencedOrganizations check is not done
        Parameters:
        value -
      • isTransient

        public Boolean isTransient​(Object entity)
        Determines if the object is transient (==new and not yet persisted in Hibernate).
        Specified by:
        isTransient in interface org.hibernate.Interceptor
        Overrides:
        isTransient in class org.hibernate.EmptyInterceptor
        Parameters:
        entity - the object for which it is determined if it is new
        Returns:
        true if the object has a null id or has been explicitly set to being new (@see BaseOBObject#isNewOBObject()}, returns false otherwise.
      • onDelete

        public void onDelete​(Object entity,
                             Serializable id,
                             Object[] state,
                             String[] propertyNames,
                             org.hibernate.type.Type[] types)
        Performs security checks, is the user present in the OBContext allowed to delete this entity and is the entity deletable (@see Entity.isDeletable().
        Specified by:
        onDelete in interface org.hibernate.Interceptor
        Overrides:
        onDelete in class org.hibernate.EmptyInterceptor
        Parameters:
        entity - the business object which is deleted
        id - the id of the entity
        state - the value of the properties
        propertyNames - the name of the properties of the entity
        types - the hibernate type definition of the properties
        See Also:
        BaseOBObject, Entity, Property
      • onFlushDirty

        public boolean onFlushDirty​(Object entity,
                                    Serializable id,
                                    Object[] currentState,
                                    Object[] previousState,
                                    String[] propertyNames,
                                    org.hibernate.type.Type[] types)
        Is called when the entity object is dirty (a value of a property has changed) and the state of the object is about to be flushed to the database using sql update statements. This method updates the audit info fields (updated, updatedBy) and performs security checks.
        Specified by:
        onFlushDirty in interface org.hibernate.Interceptor
        Overrides:
        onFlushDirty in class org.hibernate.EmptyInterceptor
        Parameters:
        entity - the business object which is deleted
        id - the id of the entity
        currentState - the current value of the properties
        previousState - the previous value of the properties, i.e. the values when the entity was loaded from the database
        propertyNames - the name of the properties of the entity
        types - the hibernate type definition of the properties
        Returns:
        true if the state of the object has changed, this is the case when the entity has audit info because the updated/updatedBy properties are updated here, false is returned in other cases
      • onSave

        public boolean onSave​(Object entity,
                              Serializable id,
                              Object[] currentState,
                              String[] propertyNames,
                              org.hibernate.type.Type[] types)
        Is called when a new entity object is persisted in the database. This method sets the audit info fields (created/createdBy/updated/updatedBy) and performs several security checks.
        Specified by:
        onSave in interface org.hibernate.Interceptor
        Overrides:
        onSave in class org.hibernate.EmptyInterceptor
        Parameters:
        entity - the business object which is deleted
        id - the id of the entity
        currentState - the current value of the properties
        propertyNames - the name of the properties of the entity
        types - the hibernate type definition of the properties
        Returns:
        true if the state of the object has changed, this is the case when the entity has audit info because the updated/updatedBy properties are updated here, false is returned in other cases
      • doEvent

        protected void doEvent​(Object object,
                               Object[] currentState,
                               String[] propertyNames)
      • postFlush

        public void postFlush​(Iterator entities)
        Specified by:
        postFlush in interface org.hibernate.Interceptor
        Overrides:
        postFlush in class org.hibernate.EmptyInterceptor
      • getInterceptorListener

        public org.hibernate.Interceptor getInterceptorListener()
      • setInterceptorListener

        public void setInterceptorListener​(org.hibernate.Interceptor interceptorListener)
      • afterTransactionBegin

        public void afterTransactionBegin​(org.hibernate.Transaction tx)
        Specified by:
        afterTransactionBegin in interface org.hibernate.Interceptor
        Overrides:
        afterTransactionBegin in class org.hibernate.EmptyInterceptor
      • afterTransactionCompletion

        public void afterTransactionCompletion​(org.hibernate.Transaction tx)
        Specified by:
        afterTransactionCompletion in interface org.hibernate.Interceptor
        Overrides:
        afterTransactionCompletion in class org.hibernate.EmptyInterceptor
      • beforeTransactionCompletion

        public void beforeTransactionCompletion​(org.hibernate.Transaction tx)
        Specified by:
        beforeTransactionCompletion in interface org.hibernate.Interceptor
        Overrides:
        beforeTransactionCompletion in class org.hibernate.EmptyInterceptor
      • preFlush

        public void preFlush​(Iterator entities)
        Specified by:
        preFlush in interface org.hibernate.Interceptor
        Overrides:
        preFlush in class org.hibernate.EmptyInterceptor
      • getEntityName

        public String getEntityName​(Object entity)
        Specified by:
        getEntityName in interface org.hibernate.Interceptor
        Overrides:
        getEntityName in class org.hibernate.EmptyInterceptor