public class LoggingInterceptor extends EmptyInterceptor
SessionFactory
since this class is
not thread-safe.
The interceptor uses onSave
, onDelete
and
onFlushDirty
to collect information about what has happened.
The LogManagerFactory
is asked to create EntityLogger
:s
for each modified/created/deleted item. The actual logging takes place
in the postFlush
method that calls EntityLogger.logChanges(LogManager, EntityDetails)
on each entity logger.
NOTE! For new items, the ID is not available until after the flush
to the database has been done. Eg. new items has a 0 id when
LogManagerFactory.getEntityLogger(LogManager, Object)
is called.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
LoggingInterceptor.LogDetails |
(package private) static class |
LoggingInterceptor.LogManagerAndFactory |
Modifier and Type | Field and Description |
---|---|
private java.util.List<LoggingInterceptor.LogDetails> |
changes |
private static java.lang.Object[] |
EMTPY_OBJECT_ARRAY |
private static java.lang.String[] |
EMTPY_STRING_ARRAY |
private static Type[] |
EMTPY_TYPE_ARRAY |
private LogControl |
logControl |
private java.util.List<LoggingInterceptor.LogManagerAndFactory> |
logHandlers |
private ExtensionsInvoker<LogManagerFactory> |
logInvoker |
private static long |
serialVersionUID |
INSTANCE
Constructor and Description |
---|
LoggingInterceptor(LogControl logControl,
ExtensionsInvoker<LogManagerFactory> logInvoker)
Creates a new interceptor.
|
Modifier and Type | Method and Description |
---|---|
private void |
addChange(ChangeType action,
java.lang.Object entity,
java.lang.Object[] state,
java.lang.Object[] previousState,
java.lang.String[] propertyNames,
Type[] types,
boolean logImmediately)
If the log manager factory creates an entity logger, add
information about the change to the internal list.
|
void |
addManualSingleChange(ChangeType action,
java.lang.Object entity)
Adds a manual non-Hibernate change to the log system.
|
void |
addManualSingleChange(ChangeType action,
java.lang.Object entity,
java.lang.Object newValue,
java.lang.Object oldValue,
java.lang.String property,
Type type)
Adds a manual non-Hibernate change to the log system.
|
void |
afterTransactionCompletion(Transaction tx)
Signals successful commit or rollback to the log manager.
|
void |
beforeTransactionCompletion(Transaction tx)
Flush remaining changes in the log control.
|
void |
onDelete(java.lang.Object entity,
java.io.Serializable id,
java.lang.Object[] state,
java.lang.String[] propertyNames,
Type[] types)
Adds a DELETE event to the log.
|
boolean |
onFlushDirty(java.lang.Object entity,
java.io.Serializable id,
java.lang.Object[] currentState,
java.lang.Object[] previousState,
java.lang.String[] propertyNames,
Type[] types)
Adds an UPDATE event to the log.
|
boolean |
onSave(java.lang.Object entity,
java.io.Serializable id,
java.lang.Object[] state,
java.lang.String[] propertyNames,
Type[] types)
Adds a CREATE event to the log.
|
void |
postFlush(java.util.Iterator entities)
Collects all log events and sends them to the each
EntityLogger . |
private void |
readObject(java.io.ObjectInputStream ois) |
private void |
writeObject(java.io.ObjectOutputStream ois) |
afterTransactionBegin, findDirty, getEntity, getEntityName, instantiate, isTransient, onCollectionRecreate, onCollectionRemove, onCollectionUpdate, onLoad, onPrepareStatement, preFlush
private static final long serialVersionUID
private static final java.lang.Object[] EMTPY_OBJECT_ARRAY
private static final java.lang.String[] EMTPY_STRING_ARRAY
private static final Type[] EMTPY_TYPE_ARRAY
private final LogControl logControl
private final ExtensionsInvoker<LogManagerFactory> logInvoker
private java.util.List<LoggingInterceptor.LogManagerAndFactory> logHandlers
private java.util.List<LoggingInterceptor.LogDetails> changes
public LoggingInterceptor(LogControl logControl, ExtensionsInvoker<LogManagerFactory> logInvoker)
logControl
- The LogControl that is managing the current transactionlogInvoker
- The extension invoker that create log manager factoriespublic boolean onSave(java.lang.Object entity, java.io.Serializable id, java.lang.Object[] state, java.lang.String[] propertyNames, Type[] types)
onSave
in interface Interceptor
onSave
in class EmptyInterceptor
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)
onFlushDirty
in interface Interceptor
onFlushDirty
in class EmptyInterceptor
public void onDelete(java.lang.Object entity, java.io.Serializable id, java.lang.Object[] state, java.lang.String[] propertyNames, Type[] types)
onDelete
in interface Interceptor
onDelete
in class EmptyInterceptor
public void postFlush(java.util.Iterator entities)
EntityLogger
.postFlush
in interface Interceptor
postFlush
in class EmptyInterceptor
public void beforeTransactionCompletion(Transaction tx)
beforeTransactionCompletion
in interface Interceptor
beforeTransactionCompletion
in class EmptyInterceptor
public void afterTransactionCompletion(Transaction tx)
afterTransactionCompletion
in interface Interceptor
afterTransactionCompletion
in class EmptyInterceptor
public void addManualSingleChange(ChangeType action, java.lang.Object entity, java.lang.Object newValue, java.lang.Object oldValue, java.lang.String property, Type type)
public void addManualSingleChange(ChangeType action, java.lang.Object entity)
private void addChange(ChangeType action, java.lang.Object entity, java.lang.Object[] state, java.lang.Object[] previousState, java.lang.String[] propertyNames, Type[] types, boolean logImmediately)
postFlush(Iterator)
method.private void readObject(java.io.ObjectInputStream ois) throws java.lang.ClassNotFoundException, java.io.IOException
java.lang.ClassNotFoundException
java.io.IOException
private void writeObject(java.io.ObjectOutputStream ois) throws java.io.IOException
java.io.IOException