org.openmrs.api.db.hibernate
Class AuditableInterceptor

java.lang.Object
  extended by org.hibernate.EmptyInterceptor
      extended by org.openmrs.api.db.hibernate.AuditableInterceptor
All Implemented Interfaces:
java.io.Serializable, org.hibernate.Interceptor

public class AuditableInterceptor
extends org.hibernate.EmptyInterceptor

This class looks for Auditable that are being inserted into the database. When found, if the class is an update (instead of an insert) then the changedBy and dateChanged fields are set to the current user and the current time.

This class replaces the logic that was in the AuditableSaveHandler. It is here so that the cascading does NOT happen for dateChanged/changedBy to child OpenmrsObjects (because all handlers recurse on lists of OpenmrsObjects.

Since:
1.9
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.hibernate.EmptyInterceptor
INSTANCE
 
Constructor Summary
AuditableInterceptor()
           
 
Method Summary
 boolean onFlushDirty(java.lang.Object entity, java.io.Serializable id, java.lang.Object[] currentState, java.lang.Object[] previousState, java.lang.String[] propertyNames, org.hibernate.type.Type[] types)
          This class method is only called when flushing an updated dirty object, not inserting objects
 
Methods inherited from class org.hibernate.EmptyInterceptor
afterTransactionBegin, afterTransactionCompletion, beforeTransactionCompletion, findDirty, getEntity, getEntityName, instantiate, isTransient, onCollectionRecreate, onCollectionRemove, onCollectionUpdate, onDelete, onLoad, onPrepareStatement, onSave, postFlush, preFlush
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AuditableInterceptor

public AuditableInterceptor()
Method Detail

onFlushDirty

public boolean onFlushDirty(java.lang.Object entity,
                            java.io.Serializable id,
                            java.lang.Object[] currentState,
                            java.lang.Object[] previousState,
                            java.lang.String[] propertyNames,
                            org.hibernate.type.Type[] types)
                     throws org.hibernate.CallbackException
This class method is only called when flushing an updated dirty object, not inserting objects

Specified by:
onFlushDirty in interface org.hibernate.Interceptor
Overrides:
onFlushDirty in class org.hibernate.EmptyInterceptor
Returns:
true if the object got the changedBy and dateChanged fields set
Throws:
org.hibernate.CallbackException
See Also:
EmptyInterceptor.onFlushDirty(java.lang.Object, java.io.Serializable, java.lang.Object[], java.lang.Object[], java.lang.String[], org.hibernate.type.Type[])
Expected behavior:
return false for non Auditable objects, set the dateChanged field, set the changedBy field, be called when saving an Auditable

OpenMRS-1.7.x

Generated Apr 27 2012 10:06 PM. NOTE - these libraries are in active development and subject to change