org.jboss.minerva.factories
Class XAConnectionFactory

java.lang.Object
  |
  +--org.jboss.minerva.pools.PoolObjectFactory
        |
        +--org.jboss.minerva.factories.XAConnectionFactory

public class XAConnectionFactory
extends PoolObjectFactory

Object factory for JDBC 2.0 standard extension XAConnections. You pool the XAConnections instead of the java.sql.Connections since with vendor conformant drivers, you don't have direct access to the java.sql.Connection, and any work done isn't associated with the java.sql.Connection anyway.

Note: This implementation requires that the TransactionManager be bound to a JNDI name.

Note: This implementation has special handling for Minerva JDBC 1/2 XA Wrappers. Namely, when a request comes in, if it is for a wrapper connection and it has the same current transaction as a previous active connection, the same previous connection will be returned. Otherwise, you won't be able to share changes across connections like you can with the native JDBC 2 Standard Extension implementations.

Version:
$Revision: 1.12 $
Author:
Aaron Mulder (ammulder@alumni.princeton.edu)

Constructor Summary
XAConnectionFactory()
          Creates a new factory.
 
Method Summary
 java.lang.Object createObject()
          Creates a new XAConnection from the provided XADataSource.
 void deleteObject(java.lang.Object pooledObject)
          Closes a connection.
 javax.sql.XADataSource getDataSource()
          Gets the XADataSource used to generate XAConnections.
 java.lang.String getPassword()
          Gets the password used to generate XAConnections.
 java.lang.String getTransactionManagerJNDIName()
          Gets the JNDI name that the TransactionManager is registered under.
 java.lang.String getUser()
          Gets the user name used to generate XAConnections.
 java.lang.Object isUniqueRequest()
          If a new object is requested and it is a JDBC 1/2 wrapper connection in the same Transaction as an existing connection, return that same connection.
 void poolStarted(ObjectPool pool, java.io.PrintWriter log)
          Verifies that the data source and transaction manager are accessible.
 java.lang.Object prepareObject(java.lang.Object pooledObject)
          Registers the XAConnection's XAResource with the current transaction (if there is one).
 void setDataSource(javax.sql.XADataSource dataSource)
          Sets the XADataSource used to generate XAConnections.
 void setPassword(java.lang.String password)
          Sets the password used to generate XAConnections.
 void setTransactionManagerJNDIName(java.lang.String name)
          Sets the JNDI name that the TransactionManager is registered under.
 void setUser(java.lang.String userName)
          Sets the user name used to generate XAConnections.
 
Methods inherited from class org.jboss.minerva.pools.PoolObjectFactory
poolClosing, returnObject, translateObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XAConnectionFactory

public XAConnectionFactory()
                    throws javax.naming.NamingException
Creates a new factory. You must set the XADataSource and TransactionManager JNDI name before the factory can be used.
Method Detail

setUser

public void setUser(java.lang.String userName)
Sets the user name used to generate XAConnections. This is optional, and will only be used if present.

getUser

public java.lang.String getUser()
Gets the user name used to generate XAConnections.

setPassword

public void setPassword(java.lang.String password)
Sets the password used to generate XAConnections. This is optional, and will only be used if present.

getPassword

public java.lang.String getPassword()
Gets the password used to generate XAConnections.

setDataSource

public void setDataSource(javax.sql.XADataSource dataSource)
Sets the XADataSource used to generate XAConnections. This may be supplied by the vendor, or it may use the wrappers for non-compliant drivers (see XADataSourceImpl).
See Also:
XADataSourceImpl

getDataSource

public javax.sql.XADataSource getDataSource()
Gets the XADataSource used to generate XAConnections.

setTransactionManagerJNDIName

public void setTransactionManagerJNDIName(java.lang.String name)
Sets the JNDI name that the TransactionManager is registered under.

getTransactionManagerJNDIName

public java.lang.String getTransactionManagerJNDIName()
Gets the JNDI name that the TransactionManager is registered under.

poolStarted

public void poolStarted(ObjectPool pool,
                        java.io.PrintWriter log)
Verifies that the data source and transaction manager are accessible.
Overrides:
poolStarted in class PoolObjectFactory
Following copied from class: org.jboss.minerva.pools.PoolObjectFactory
Parameters:
pool - The pool that is starting. You may decide to allow multiple pools you use your factory, or to restrict it to a one-to-one relationship.
log - A writer you can use to log messages. Use this in preference to System.xxx.println.
Throws:
java.lang.IllegalArgumentException - Occurs when the pool is null.

createObject

public java.lang.Object createObject()
Creates a new XAConnection from the provided XADataSource.
Overrides:
createObject in class PoolObjectFactory
Following copied from class: org.jboss.minerva.pools.PoolObjectFactory
See Also:
PoolObjectFactory.prepareObject(java.lang.Object)

prepareObject

public java.lang.Object prepareObject(java.lang.Object pooledObject)
Registers the XAConnection's XAResource with the current transaction (if there is one). Sets listeners that will handle deregistering and returning the XAConnection to the pool via callbacks.
Overrides:
prepareObject in class PoolObjectFactory
Following copied from class: org.jboss.minerva.pools.PoolObjectFactory
Parameters:
pooledObject - The object in the pool, as created by createObject.
Returns:
The object to return to the client. If different, the pooled object must be recoverable by translateObject and returnObject.

deleteObject

public void deleteObject(java.lang.Object pooledObject)
Closes a connection.
Overrides:
deleteObject in class PoolObjectFactory

isUniqueRequest

public java.lang.Object isUniqueRequest()
If a new object is requested and it is a JDBC 1/2 wrapper connection in the same Transaction as an existing connection, return that same connection.
Overrides:
isUniqueRequest in class PoolObjectFactory
Following copied from class: org.jboss.minerva.pools.PoolObjectFactory
Returns:
An existing object, if this request is effectively the same as a previous request and the result should be shared. null if this is a unique request and should be fulfilled by a unique object.


Copyright © 2000 The jBoss Organization. All Rights Reserved.