Package org.openbravo.dal.core
Class OBInterceptor
- java.lang.Object
-
- org.hibernate.EmptyInterceptor
-
- org.openbravo.dal.core.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 Summary
Constructors Constructor Description OBInterceptor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterTransactionBegin(org.hibernate.Transaction tx)
void
afterTransactionCompletion(org.hibernate.Transaction tx)
void
beforeTransactionCompletion(org.hibernate.Transaction tx)
protected void
doEvent(Object object, Object[] currentState, String[] propertyNames)
String
getEntityName(Object entity)
org.hibernate.Interceptor
getInterceptorListener()
Boolean
isTransient(Object entity)
Determines if the object is transient (==new and not yet persisted in Hibernate).void
onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, org.hibernate.type.Type[] types)
Performs security checks, is the user present in theOBContext
allowed to delete this entity and is the entity deletable (@seeEntity.isDeletable()
.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.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.protected void
onUpdate(Traceable t, String[] propertyNames, Object[] currentState)
void
postFlush(Iterator entities)
void
preFlush(Iterator entities)
static void
setDisableCheckReferencedOrganizations(boolean value)
If true is passed then the checkReferencedOrganizations check is not donevoid
setInterceptorListener(org.hibernate.Interceptor interceptorListener)
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.
-
-
-
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 interfaceorg.hibernate.Interceptor
- Overrides:
isTransient
in classorg.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 theOBContext
allowed to delete this entity and is the entity deletable (@seeEntity.isDeletable()
.- Specified by:
onDelete
in interfaceorg.hibernate.Interceptor
- Overrides:
onDelete
in classorg.hibernate.EmptyInterceptor
- Parameters:
entity
- the business object which is deletedid
- the id of the entitystate
- the value of the propertiespropertyNames
- the name of the properties of the entitytypes
- 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 interfaceorg.hibernate.Interceptor
- Overrides:
onFlushDirty
in classorg.hibernate.EmptyInterceptor
- Parameters:
entity
- the business object which is deletedid
- the id of the entitycurrentState
- the current value of the propertiespreviousState
- the previous value of the properties, i.e. the values when the entity was loaded from the databasepropertyNames
- the name of the properties of the entitytypes
- 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 interfaceorg.hibernate.Interceptor
- Overrides:
onSave
in classorg.hibernate.EmptyInterceptor
- Parameters:
entity
- the business object which is deletedid
- the id of the entitycurrentState
- the current value of the propertiespropertyNames
- the name of the properties of the entitytypes
- 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
-
postFlush
public void postFlush(Iterator entities)
- Specified by:
postFlush
in interfaceorg.hibernate.Interceptor
- Overrides:
postFlush
in classorg.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 interfaceorg.hibernate.Interceptor
- Overrides:
afterTransactionBegin
in classorg.hibernate.EmptyInterceptor
-
afterTransactionCompletion
public void afterTransactionCompletion(org.hibernate.Transaction tx)
- Specified by:
afterTransactionCompletion
in interfaceorg.hibernate.Interceptor
- Overrides:
afterTransactionCompletion
in classorg.hibernate.EmptyInterceptor
-
beforeTransactionCompletion
public void beforeTransactionCompletion(org.hibernate.Transaction tx)
- Specified by:
beforeTransactionCompletion
in interfaceorg.hibernate.Interceptor
- Overrides:
beforeTransactionCompletion
in classorg.hibernate.EmptyInterceptor
-
preFlush
public void preFlush(Iterator entities)
- Specified by:
preFlush
in interfaceorg.hibernate.Interceptor
- Overrides:
preFlush
in classorg.hibernate.EmptyInterceptor
-
-