com.xenonsoft.bridgetown.aop.transaction.support
Class JNDIDataSourceResourceController

java.lang.Object
  extended bycom.xenonsoft.bridgetown.aop.transaction.support.JNDIDataSourceResourceController
All Implemented Interfaces:
IResourceController, java.io.Serializable

public class JNDIDataSourceResourceController
extends java.lang.Object
implements IResourceController, java.io.Serializable

An implementation of a data source resource controller for global transaction support. This resource controller, obviously, works with both XA and non-XA connections, because the retrieval of such data sources is defined by the application server configuration and EAR administration. The class retrieves a data source from JNDI provider, which can be externally configured from the environment properties setEnvironment(Properties).

This resource controller does not implement the suspension or resumption of resources; nor does it explicitly call commit Connection.commit() or rollback Connection.rollback() or change the auto commit mode Connection.setAutoCommit(boolean) on JDBC connections because such calls are prohibited by the JTA specification.

Use this class with the JTA (platform) transaction service manager JtaTransactionServiceManager, which is specifically designed to delegate calls to a true JTA transaction manager implementation.

In order to use to this lookup bean simply define environment properties for your particular application server.

The following defines a secure WebLogic JNDI Provider:

 java.naming.factory.initial = weblogic.jndi.WLInitialContextFactory
 java.naming.provider.url = t3://localhost:7001
 java.naming.security.principal = username
 java.naming.security.credentials = password
 java.naming.security.protocol = ssl
 

The last three properties are optional, for example, if the JNDI provider is not secured by a login user and obviously SSL. These values would, then, become the environment property for this object.

The lookupName defines the name of the data source to retrieve from the JNDI provider. The data source is acquired on the call to openResource(ITransactionContext). This method attempts to open the JDBC connection from the newly derived data source. The acquired JDBC connection, again, is closed on a call to closeResource(ITransactionContext)

The connection can be retrieved by calling the standard accessor getResourceConnection() or alternatively by getConnection(). The former method is call is used by an AOP transaction method interceptor to inject the resource into the advised target bean.

Version:
$Id: JNDIDataSourceResourceController.java,v 1.2 2005/03/17 02:34:01 peter_pilgrim Exp $
Author:
Peter Pilgrim, 11-Feb-2005 18:07:43
See Also:
Serialized Form

Field Summary
protected  java.sql.Connection connection
          JDBC connection
protected  javax.sql.DataSource dataSource
          JDBC data source
protected  java.util.Properties environment
          The properties optionally defined for JNDI initial context
protected  java.lang.String lookupName
          The name bean to retrieve using JNDI
protected  TransactionIsolationEnum requestedIsolationLevel
          Requested isolation level
protected  int requestedTransactionTimeout
          Requested transaction timeout
 
Constructor Summary
JNDIDataSourceResourceController()
          Default constructor
JNDIDataSourceResourceController(java.lang.String lookupName)
          Standard constructor
JNDIDataSourceResourceController(java.lang.String lookupName, java.util.Properties environment)
          Standard constructor
 
Method Summary
 void closeResource(ITransactionContext tx)
          Implements / overrides closeResource.
 void commitResource(ITransactionContext tx)
          Implements / overrides commitResource.
 java.sql.Connection getConnection()
          Gets the connection
 javax.sql.DataSource getDataSource()
          Gets the JDBC dataSource
 java.util.Properties getEnvironment()
          Gets the environment for accessing the JNDI provider
 java.lang.String getLookupName()
          Gets the name of the data source to be looked up in JNDI
 TransactionIsolationEnum getRequestedIsolationLevel()
          Gets the requestedIsolationLevel
 int getRequestedTransactionTimeout()
          Gets the requestedTransactionTimeout
 java.lang.Object getResourceConnection()
          Retrieves the connection resource that binds to the application to the transactional resource.
 boolean isResourceOpen(ITransactionContext tx)
          Implements / overrides isResourceOpen
 void openResource(ITransactionContext tx)
          Implements / overrides openResource
 boolean prepareToCommit(ITransactionContext tx)
          Implements / overrides prepareToCommit.
 void resumeResource(ITransactionContext tx)
          Implements / overrides resumeResource.
 void rollbackResource(ITransactionContext tx)
          Implements / overrides rollbackResource.
 void setEnvironment(java.util.Properties environment)
          Sets the environment for accessing the JNDI provider
 void setLookupName(java.lang.String lookupName)
          Sets the name of the data source to be looked up in JNDI
 void setRequestedIsolationLevel(TransactionIsolationEnum requestedIsolationLevel)
          Sets the requestedIsolationLevel
 void setRequestedTransactionTimeout(int requestedTransactionTimeout)
          Sets the requestedTransactionTimeout.
 void suspendResource(ITransactionContext tx)
          Implements / overrides suspendResource.
 java.lang.String toString()
          Returns a human readable string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

lookupName

protected java.lang.String lookupName
The name bean to retrieve using JNDI


environment

protected java.util.Properties environment
The properties optionally defined for JNDI initial context


dataSource

protected transient javax.sql.DataSource dataSource
JDBC data source


connection

protected transient java.sql.Connection connection
JDBC connection


requestedIsolationLevel

protected TransactionIsolationEnum requestedIsolationLevel
Requested isolation level


requestedTransactionTimeout

protected int requestedTransactionTimeout
Requested transaction timeout

Constructor Detail

JNDIDataSourceResourceController

public JNDIDataSourceResourceController()
Default constructor


JNDIDataSourceResourceController

public JNDIDataSourceResourceController(java.lang.String lookupName)
Standard constructor

Parameters:
lookupName - the lookup name for retrieving the data source from JNDI provider

JNDIDataSourceResourceController

public JNDIDataSourceResourceController(java.lang.String lookupName,
                                        java.util.Properties environment)
Standard constructor

Parameters:
lookupName - the lookup name for retrieving the data source from JNDI provider
environment - the JNDI provider environment
Method Detail

toString

public java.lang.String toString()
Returns a human readable string. Implements / overrides toString

Returns:
See Also:
Object.toString()

getEnvironment

public java.util.Properties getEnvironment()
Gets the environment for accessing the JNDI provider

Returns:
Returns the environment.

setEnvironment

public void setEnvironment(java.util.Properties environment)
Sets the environment for accessing the JNDI provider

Parameters:
environment - the new value for environment

getLookupName

public java.lang.String getLookupName()
Gets the name of the data source to be looked up in JNDI

Returns:
Returns the lookupName.

setLookupName

public void setLookupName(java.lang.String lookupName)
Sets the name of the data source to be looked up in JNDI

Parameters:
lookupName - the new value for lookupName

getDataSource

public javax.sql.DataSource getDataSource()
Gets the JDBC dataSource

Returns:
Returns the dataSource.

getConnection

public java.sql.Connection getConnection()
Gets the connection

Returns:
Returns the connection.

getRequestedIsolationLevel

public TransactionIsolationEnum getRequestedIsolationLevel()
Gets the requestedIsolationLevel

Returns:
Returns the requestedIsolationLevel.

setRequestedIsolationLevel

public void setRequestedIsolationLevel(TransactionIsolationEnum requestedIsolationLevel)
Sets the requestedIsolationLevel

Specified by:
setRequestedIsolationLevel in interface IResourceController
Parameters:
requestedIsolationLevel - The requestedIsolationLevel to set.

getRequestedTransactionTimeout

public int getRequestedTransactionTimeout()
Gets the requestedTransactionTimeout

Returns:
Returns the requestedTransactionTimeout.

setRequestedTransactionTimeout

public void setRequestedTransactionTimeout(int requestedTransactionTimeout)
Sets the requestedTransactionTimeout.

NB: This value is not used at all, because the Setting the timeout of the current global transaction timeout is the responsibility of the Jta TSM JtaTransactionServiceManager

Specified by:
setRequestedTransactionTimeout in interface IResourceController
Parameters:
requestedTransactionTimeout - The requestedTransactionTimeout to set.

getResourceConnection

public java.lang.Object getResourceConnection()
Retrieves the connection resource that binds to the application to the transactional resource.

For instance, for a JDBC resource controller, this method would return the Connection.

Specified by:
getResourceConnection in interface IResourceController
Returns:
the resource connection object

isResourceOpen

public boolean isResourceOpen(ITransactionContext tx)
Implements / overrides isResourceOpen

Specified by:
isResourceOpen in interface IResourceController
Parameters:
tx -
Returns:
See Also:
IResourceController.isResourceOpen(com.xenonsoft.bridgetown.aop.transaction.ITransactionContext)

openResource

public void openResource(ITransactionContext tx)
Implements / overrides openResource

Specified by:
openResource in interface IResourceController
Parameters:
tx - the transaction context
See Also:
IResourceController.openResource(com.xenonsoft.bridgetown.aop.transaction.ITransactionContext)

suspendResource

public void suspendResource(ITransactionContext tx)
Implements / overrides suspendResource. This is handled by a JTA transaction manager implementation

Specified by:
suspendResource in interface IResourceController
Parameters:
tx - the transaction context
See Also:
IResourceController.suspendResource(com.xenonsoft.bridgetown.aop.transaction.ITransactionContext)

resumeResource

public void resumeResource(ITransactionContext tx)
Implements / overrides resumeResource. This is handled by a JTA transaction manager implementation.

Specified by:
resumeResource in interface IResourceController
Parameters:
tx - the transaction context
See Also:
IResourceController.resumeResource(com.xenonsoft.bridgetown.aop.transaction.ITransactionContext)

prepareToCommit

public boolean prepareToCommit(ITransactionContext tx)
Implements / overrides prepareToCommit. This is handled by a JTA transaction manager implementation

With JTA transactions this is alway true!

Specified by:
prepareToCommit in interface IResourceController
Parameters:
tx - the transaction context
Returns:
always returns boolean true to indicate to platform transaction service manager that the underlying transaction should commit.
See Also:
IResourceController.prepareToCommit(com.xenonsoft.bridgetown.aop.transaction.ITransactionContext)

commitResource

public void commitResource(ITransactionContext tx)
Implements / overrides commitResource. This is handled by a JTA transaction manager implementation.

Specified by:
commitResource in interface IResourceController
Parameters:
tx - the transaction context
See Also:
IResourceController.commitResource(com.xenonsoft.bridgetown.aop.transaction.ITransactionContext)

rollbackResource

public void rollbackResource(ITransactionContext tx)
Implements / overrides rollbackResource. This is handled by a JTA transaction manager implementation.

Specified by:
rollbackResource in interface IResourceController
Parameters:
tx - the transaction context
See Also:
IResourceController.rollbackResource(com.xenonsoft.bridgetown.aop.transaction.ITransactionContext)

closeResource

public void closeResource(ITransactionContext tx)
Implements / overrides closeResource. This is handled by a JTA transaction manager implementation.

Specified by:
closeResource in interface IResourceController
Parameters:
tx - the transaction context
See Also:
IResourceController.closeResource(com.xenonsoft.bridgetown.aop.transaction.ITransactionContext)


Copyright © 2005 XeNoNSoFT.com. All Rights Reserved.