FileDocCategorySizeDatePackage
LocalTxDataSource.javaAPI DocJBoss 4.2.19455Fri Jul 13 21:01:12 BST 2007org.jboss.resource.adapter.jdbc.local

LocalTxDataSource

public class LocalTxDataSource extends Object
This is a pojo that instantiates a Local tx connection pool. It provides same functionality as ds.xml files
author
Bill Burke
version
$Revision: 57189 $

Fields Summary
protected static Logger
log
private org.jboss.resource.connectionmanager.CachedConnectionManager
cachedConnectionManager
private TransactionManager
transactionManager
private String
jndiName
private InternalManagedConnectionPool.PoolParams
poolParams
private LocalManagedConnectionFactory
mcf
private JBossManagedConnectionPool.OnePool
pool
private org.jboss.resource.connectionmanager.TxConnectionManager
connectionManager
private Object
datasource
protected Hashtable
initialContextProperties
protected InitialContext
initialContext
Constructors Summary
public LocalTxDataSource()



    
   
   
Methods Summary
protected voidbindConnectionFactory()
Bind the connection factory into jndi

      InitialContext ctx = initialContext;
      try
      {
         Name name = ctx.getNameParser("").parse(jndiName);
         String key = name.toString();
         if( true == true && name.size() > 1 )
         {
            int size = name.size() - 1;
            Util.createSubcontext(initialContext, name.getPrefix(size));
         }
         NonSerializableFactory.rebind(initialContext, key, datasource);
         log.info("Bound datasource to JNDI name '" + jndiName + "'");
      }
      catch (NamingException ne)
      {
         throw new DeploymentException("Could not bind ConnectionFactory into jndi: " + jndiName, ne);
      }
      finally
      {
         ctx.close();
      }
   
public intgetBlockingTimeout()

      return poolParams.blockingTimeout;
   
public java.lang.StringgetCheckValidConnectionSQL()

      return mcf.getCheckValidConnectionSQL();
   
public java.lang.StringgetConnectionURL()

      return mcf.getConnectionURL();
   
public java.lang.ObjectgetDatasource()

      return datasource;
   
public java.lang.StringgetDriverClass()

      return mcf.getDriverClass();
   
public java.lang.StringgetExceptionSorterClassName()

      return mcf.getExceptionSorterClassName();
   
public longgetIdleTimeout()

      return poolParams.idleTimeout;
   
public java.lang.StringgetJndiName()

      return jndiName;
   
public intgetMaxSize()

      return poolParams.maxSize;
   
public intgetMinSize()

      return poolParams.minSize;
   
public java.lang.StringgetNewConnectionSQL()

      return mcf.getNewConnectionSQL();
   
public intgetPreparedStatementCacheSize()

      return mcf.getPreparedStatementCacheSize();
   
public booleangetSharePreparedStatements()

      return mcf.getSharePreparedStatements();
   
public java.lang.StringgetTrackStatements()

      return mcf.getTrackStatements();
   
public java.lang.StringgetTransactionIsolation()

      return mcf.getTransactionIsolation();
   
public javax.transaction.TransactionManagergetTransactionManager()

      return transactionManager;
   
public booleangetTxQueryTimeout()

      return mcf.isTransactionQueryTimeout();
   
public java.lang.StringgetValidConnectionCheckerClassName()

      return mcf.getValidConnectionCheckerClassName();
   
public voidsetBlockingTimeout(int blockingTimeout)

      poolParams.blockingTimeout = blockingTimeout;
   
public voidsetCachedConnectionManager(org.jboss.resource.connectionmanager.CachedConnectionManagerReference cachedConnectionManager)

      this.cachedConnectionManager = cachedConnectionManager.getCachedConnectionManager();
   
public voidsetCheckValidConnectionSQL(java.lang.String checkValidConnectionSQL)

      mcf.setCheckValidConnectionSQL(checkValidConnectionSQL);
   
public voidsetConnectionURL(java.lang.String connectionURL)

      mcf.setConnectionURL(connectionURL);
   
public voidsetDriverClass(java.lang.String driverClass)

      mcf.setDriverClass(driverClass);
   
public voidsetExceptionSorterClassName(java.lang.String exceptionSorterClassName)

      mcf.setExceptionSorterClassName(exceptionSorterClassName);
   
public voidsetIdleTimeout(long idleTimeout)

      poolParams.idleTimeout = idleTimeout;
   
public voidsetInitialContextProperties(java.util.Hashtable initialContextProperties)

      this.initialContextProperties = initialContextProperties;
   
public voidsetJndiName(java.lang.String jndiName)

      this.jndiName = jndiName;
   
public voidsetMaxSize(int maxSize)

      poolParams.maxSize = maxSize;
   
public voidsetMinSize(int minSize)

      poolParams.minSize = minSize;
   
public voidsetNewConnectionSQL(java.lang.String newConnectionSQL)

      mcf.setNewConnectionSQL(newConnectionSQL);
   
public voidsetPassword(java.lang.String password)

      mcf.setPassword(password);
   
public voidsetPreparedStatementCacheSize(int size)

      mcf.setPreparedStatementCacheSize(size);
   
public voidsetSharePreparedStatements(boolean sharePS)

      mcf.setSharePreparedStatements(sharePS);
   
public voidsetTrackStatements(java.lang.String value)

      mcf.setTrackStatements(value);
   
public voidsetTransactionIsolation(java.lang.String transactionIsolation)

      mcf.setTransactionIsolation(transactionIsolation);
   
public voidsetTransactionManager(javax.transaction.TransactionManager transactionManager)

      this.transactionManager = transactionManager;
   
public voidsetTxQueryTimeout(boolean qt)

      mcf.setTransactionQueryTimeout(qt);
   
public voidsetUserName(java.lang.String userName)

      mcf.setUserName(userName);
   
public voidsetValidConnectionCheckerClassName(java.lang.String value)

      mcf.setValidConnectionCheckerClassName(value);
   
public voidstart()

      if (initialContextProperties == null) initialContext = new InitialContext();
      else initialContext = new InitialContext(initialContextProperties);
      
      connectionManager = new TxConnectionManager(cachedConnectionManager, pool, transactionManager);
      connectionManager.setLocalTransactions(true);
      connectionManager.setTrackConnectionByTx(true);
      pool.setConnectionListenerFactory(connectionManager);
      datasource = connectionManager.getPoolingStrategy().getManagedConnectionFactory().createConnectionFactory(new ConnectionManagerDelegate());
      bindConnectionFactory();
   
protected voidunbindConnectionFactory()

      InitialContext ctx = initialContext;
      try
      {                                              
         ctx.unbind(jndiName);
         NonSerializableFactory.unbind(jndiName);
         log.info("Unbound datasource for JNDI name '" + jndiName + "'");
      }
      catch (NamingException ne)
      {
         log.error("Could not unbind datasource from jndi: " + jndiName, ne);
      }
      finally
      {
         ctx.close();
      }