org.addsimplicity.anicetus.hibernate
Class TelemetryInterceptor

java.lang.Object
  extended by org.hibernate.EmptyInterceptor
      extended by org.addsimplicity.anicetus.hibernate.TelemetryInterceptor
All Implemented Interfaces:
java.io.Serializable, org.hibernate.Interceptor, org.springframework.beans.factory.BeanFactoryAware

public class TelemetryInterceptor
extends org.hibernate.EmptyInterceptor
implements org.springframework.beans.factory.BeanFactoryAware

The telemetry interceptor uses the Hibernate interceptor interface to capture operations that are performed by Hibernate and create a telemetry artifact. The telemetry is created at the start of a transaction so that it can gather all of the entities and operations that are done during the transaction. The operation timer is started at the beginning of the commit so the time captured is database processing time. Note that telemetry is not captured if a Hibernate transaction is not used. The interceptor relies upon Spring to retrieve the context used for managing the state of the transactional stack.

Author:
Dan Pritchett (driveawedge@yahoo.com)
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.hibernate.EmptyInterceptor
INSTANCE
 
Constructor Summary
TelemetryInterceptor()
           
 
Method Summary
 void afterTransactionBegin(org.hibernate.Transaction tx)
          This method is called by Hibernate after the begin transaction operation.
 void afterTransactionCompletion(org.hibernate.Transaction tx)
          This method is called by Hibernate when the transaction completes.
 void beforeTransactionCompletion(org.hibernate.Transaction tx)
          This method is called by Hibernate before the transaction begins to commit to the database.
 java.lang.String getManagerName()
          Get the key used to retrieve the TelemetryContext from the Spring context.
 void onDelete(java.lang.Object entity, java.io.Serializable id, java.lang.Object[] state, java.lang.String[] propertyNames, org.hibernate.type.Type[] types)
          This method is called by Hibernate prior to an entity being deleted.
 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 method is called by Hibernate prior to an entity being updated.
 boolean onLoad(java.lang.Object entity, java.io.Serializable id, java.lang.Object[] state, java.lang.String[] propertyNames, org.hibernate.type.Type[] types)
          This method is called prior to an object being loaded from the database.
 java.lang.String onPrepareStatement(java.lang.String sql)
          This method is called by Hibernate each time a SQL statement is prepared.
 boolean onSave(java.lang.Object entity, java.io.Serializable id, java.lang.Object[] state, java.lang.String[] propertyNames, org.hibernate.type.Type[] types)
          This method is called by Hibernate each time an entity is being inserted.
 void setBeanFactory(org.springframework.beans.factory.BeanFactory factory)
          This method is called by Spring to set the context used to create the bean.
 void setManagerName(java.lang.String managerName)
          Set the Spring key that is used to retrieve the TelemetryContext from the Spring container.
 
Methods inherited from class org.hibernate.EmptyInterceptor
findDirty, getEntity, getEntityName, instantiate, isTransient, onCollectionRecreate, onCollectionRemove, onCollectionUpdate, postFlush, preFlush
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TelemetryInterceptor

public TelemetryInterceptor()
Method Detail

afterTransactionBegin

public void afterTransactionBegin(org.hibernate.Transaction tx)
This method is called by Hibernate after the begin transaction operation. A new telemetry artifact is created at the point that this method is called.

Specified by:
afterTransactionBegin in interface org.hibernate.Interceptor
Overrides:
afterTransactionBegin in class org.hibernate.EmptyInterceptor

afterTransactionCompletion

public void afterTransactionCompletion(org.hibernate.Transaction tx)
This method is called by Hibernate when the transaction completes. The telemetry status is set based on the transaction committed status.

Specified by:
afterTransactionCompletion in interface org.hibernate.Interceptor
Overrides:
afterTransactionCompletion in class org.hibernate.EmptyInterceptor

beforeTransactionCompletion

public void beforeTransactionCompletion(org.hibernate.Transaction tx)
This method is called by Hibernate before the transaction begins to commit to the database.

Specified by:
beforeTransactionCompletion in interface org.hibernate.Interceptor
Overrides:
beforeTransactionCompletion in class org.hibernate.EmptyInterceptor

getManagerName

public java.lang.String getManagerName()
Get the key used to retrieve the TelemetryContext from the Spring context.

Returns:
the key to the TelemetryContext.

onDelete

public void onDelete(java.lang.Object entity,
                     java.io.Serializable id,
                     java.lang.Object[] state,
                     java.lang.String[] propertyNames,
                     org.hibernate.type.Type[] types)
This method is called by Hibernate prior to an entity being deleted.

Specified by:
onDelete in interface org.hibernate.Interceptor
Overrides:
onDelete in class org.hibernate.EmptyInterceptor

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)
This method is called by Hibernate prior to an entity being updated.

Specified by:
onFlushDirty in interface org.hibernate.Interceptor
Overrides:
onFlushDirty in class org.hibernate.EmptyInterceptor

onLoad

public boolean onLoad(java.lang.Object entity,
                      java.io.Serializable id,
                      java.lang.Object[] state,
                      java.lang.String[] propertyNames,
                      org.hibernate.type.Type[] types)
This method is called prior to an object being loaded from the database.

Specified by:
onLoad in interface org.hibernate.Interceptor
Overrides:
onLoad in class org.hibernate.EmptyInterceptor

onPrepareStatement

public java.lang.String onPrepareStatement(java.lang.String sql)
This method is called by Hibernate each time a SQL statement is prepared.

Specified by:
onPrepareStatement in interface org.hibernate.Interceptor
Overrides:
onPrepareStatement in class org.hibernate.EmptyInterceptor

onSave

public boolean onSave(java.lang.Object entity,
                      java.io.Serializable id,
                      java.lang.Object[] state,
                      java.lang.String[] propertyNames,
                      org.hibernate.type.Type[] types)
This method is called by Hibernate each time an entity is being inserted.

Specified by:
onSave in interface org.hibernate.Interceptor
Overrides:
onSave in class org.hibernate.EmptyInterceptor

setBeanFactory

public void setBeanFactory(org.springframework.beans.factory.BeanFactory factory)
                    throws org.springframework.beans.BeansException
This method is called by Spring to set the context used to create the bean.

Specified by:
setBeanFactory in interface org.springframework.beans.factory.BeanFactoryAware
Throws:
org.springframework.beans.BeansException

setManagerName

public void setManagerName(java.lang.String managerName)
Set the Spring key that is used to retrieve the TelemetryContext from the Spring container.

Parameters:
managerName - The key to the TelemetryContext


Copyright © 2009 Add Simplicity. All Rights Reserved.