com.xenonsoft.bridgetown.aop.helper
Class SimpleJDBCTransactionInterceptor

java.lang.Object
  extended bycom.xenonsoft.bridgetown.aop.helper.SimpleJDBCTransactionInterceptor
All Implemented Interfaces:
IMethodInterceptor, java.io.Serializable

public class SimpleJDBCTransactionInterceptor
extends java.lang.Object
implements IMethodInterceptor, java.io.Serializable

A simple JDBC Transaction interceptor that advises a target bean. This interceptor acquires a JDBC connection from an external bean source. In the auto commit of the connection is saved and then switched to false. It then proceed to inject the connection in the target bean using a property (setter injection). The interceptor executes the target method.

If the inteception method returns normally then the connection is committed.

If the inteception method returns abnormally by raising an exception, then the connection is rolled back.

Regardlessly of normal or abnormal execution, the connection is alway released after used. If the close on release flag is set, the connection will be closed.

Version:
$Id: SimpleJDBCTransactionInterceptor.java,v 1.4 2005/03/17 02:24:50 peter_pilgrim Exp $
Author:
Peter Pilgrim, 15-Oct-2004 19:55:19
See Also:
Serialized Form

Field Summary
protected  boolean closeOnRelease
          Close when we release the connection boolean flag
protected  java.lang.Object connectionBean
          The bean that has the JDBC connection
protected  java.lang.String connectionProperty
          The property name of the connection bean that will return a JDBC connection
protected  java.lang.String targetProperty
          The property name of the Advised bean that expects the JDBC connection
 
Constructor Summary
SimpleJDBCTransactionInterceptor()
          Default constructor
 
Method Summary
 java.sql.Connection acquireConnection()
          Acquire the JDBC connection
 java.lang.Object getConnectionBean()
          Gets the JDBC connection bean
 java.lang.String getConnectionProperty()
          Gets the JDBC connection property of the bean
 java.lang.String getTargetProperty()
          Gets the property of the target bean being advised
 void injectConnectionDependency(java.lang.Object targetBean, java.sql.Connection conn)
          Inject the connection into the target bean being advised
 java.lang.Object invocation(IInterceptionContext context)
          Implements / overrides method invocation
 boolean isCloseOnRelease()
          Gets the close on release connection flag
 void releaseConnection(java.sql.Connection conn)
          Release the previously acquired JDBC connection
 void setCloseOnRelease(boolean closeOnRelease)
          Sets the close on release connection flag
 void setConnectionBean(java.lang.Object connectionBean)
          Sets the JDBC connection bean
 void setConnectionProperty(java.lang.String connectionProperty)
          Sets the JDBC connection property of the bean
 void setTargetProperty(java.lang.String targetProperty)
          Sets the property of the target bean being advised
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

connectionBean

protected java.lang.Object connectionBean
The bean that has the JDBC connection


connectionProperty

protected java.lang.String connectionProperty
The property name of the connection bean that will return a JDBC connection


targetProperty

protected java.lang.String targetProperty
The property name of the Advised bean that expects the JDBC connection


closeOnRelease

protected boolean closeOnRelease
Close when we release the connection boolean flag

Constructor Detail

SimpleJDBCTransactionInterceptor

public SimpleJDBCTransactionInterceptor()
Default constructor

Method Detail

isCloseOnRelease

public boolean isCloseOnRelease()
Gets the close on release connection flag

Returns:
Returns the closeOnRelease.

setCloseOnRelease

public void setCloseOnRelease(boolean closeOnRelease)
Sets the close on release connection flag

Parameters:
closeOnRelease - the new value for closeOnRelease

getConnectionBean

public java.lang.Object getConnectionBean()
Gets the JDBC connection bean

Returns:
Returns the connectionBean.

setConnectionBean

public void setConnectionBean(java.lang.Object connectionBean)
Sets the JDBC connection bean

Parameters:
connectionBean - the new value for connectionBean

getConnectionProperty

public java.lang.String getConnectionProperty()
Gets the JDBC connection property of the bean

Returns:
Returns the connectionProperty.

setConnectionProperty

public void setConnectionProperty(java.lang.String connectionProperty)
Sets the JDBC connection property of the bean

Parameters:
connectionProperty - the new value for connectionProperty

getTargetProperty

public java.lang.String getTargetProperty()
Gets the property of the target bean being advised

Returns:
Returns the targetProperty.

setTargetProperty

public void setTargetProperty(java.lang.String targetProperty)
Sets the property of the target bean being advised

Parameters:
targetProperty - the new value for targetProperty

invocation

public java.lang.Object invocation(IInterceptionContext context)
                            throws java.lang.Throwable
Implements / overrides method invocation

Specified by:
invocation in interface IMethodInterceptor
Parameters:
context - contextual informal about the intercepted method
Returns:
the result of the target being advised
Throws:
java.lang.Throwable
See Also:
IMethodInterceptor.invocation(com.xenonsoft.bridgetown.aop.IInterceptionContext)

acquireConnection

public java.sql.Connection acquireConnection()
Acquire the JDBC connection

Returns:
Throws:
java.lang.RuntimeException

releaseConnection

public void releaseConnection(java.sql.Connection conn)
Release the previously acquired JDBC connection

Parameters:
conn - the JDBC connection

injectConnectionDependency

public void injectConnectionDependency(java.lang.Object targetBean,
                                       java.sql.Connection conn)
Inject the connection into the target bean being advised

Parameters:
targetBean - the target bean
conn - the JDBC connection
Throws:
InterceptionWeaveException - failure to inject dependency


Copyright © 2005 XeNoNSoFT.com. All Rights Reserved.