tyrex.resource.jdbc.xa
Class EnabledDataSource

java.lang.Object
  extended bytyrex.resource.jdbc.xa.XADataSourceImpl
      extended bytyrex.resource.jdbc.xa.EnabledDataSource
All Implemented Interfaces:
javax.sql.ConnectionPoolDataSource, javax.sql.DataSource, javax.naming.spi.ObjectFactory, javax.naming.Referenceable, java.lang.Runnable, java.io.Serializable, javax.sql.XADataSource

public class EnabledDataSource
extends XADataSourceImpl
implements javax.sql.DataSource, javax.naming.Referenceable, javax.naming.spi.ObjectFactory, java.io.Serializable

Implements a JDBC 2.0 DataSource for any arbitrary JDBC driver with JNDI persistance support. XA and pooled connection support is also available, but the application must used the designated DataSource interface to obtain them.

The driver class name setDriverClassName(java.lang.String) specifies the class of the JDBC driver to be loaded.

The JDBC URL is specified by setDriverName(java.lang.String). The JDBC URL is of the form jdbc:subprotocol:subname. The initial "jdbc:" is optional so that subprocol:subname is also valid.

The supported data source properties are:

 driverName          (required)
 description         (required, default)
 loginTimeout        (required, default from driver)
 driverClassName     (optional) 
 user                (optional)
 password            (optional)
 transactionTimeout  (optional, default from driver)
 isolationLevel      (optional, defaults to serializable)
 
This data source may be serialized and stored in a JNDI directory. Example of how to create a new data source and register it with JNDI:
 EnabledDataSource ds;
 InitialContext    ctx;

 ds = new EnabledDataSource();
 ds.setDriverClassName( "..." );
 ds.setDriverName( "jdbc:subprotocol:subname" );
 ds.setUser( "me" );
 ds.setPassword( "secret" );
 ctx = new InitialContext();
 ctx.rebind( "/comp/jdbc/test", ds );
 
Example for obtaining the data source from JNDI and opening a new connections:
 InitialContext       ctx;
 DataSource           ds;
 
 ctx = new InitialContext();
 ds = (DataSource) ctx.lookup( "/comp/jdbc/test" );
 ds.getConnection();
 

Version:
1.0
Author:
Assaf Arkin
See Also:
XADataSourceImpl, DataSource, Connection, Serialized Form

Field Summary
 
Fields inherited from class tyrex.resource.jdbc.xa.XADataSourceImpl
DEFAULT_ISOLATION_LEVEL, DEFAULT_TX_TIMEOUT
 
Constructor Summary
EnabledDataSource()
           
 
Method Summary
protected  java.lang.String createJDBCURL()
          Construct the JDBC URL used to connect to the database.
 boolean equals(java.lang.Object other)
          Returns true if this datasource and the other are equal.
 java.sql.Connection getConnection()
           
 java.sql.Connection getConnection(java.lang.String user, java.lang.String password)
           
 java.lang.String getDescription()
          Returns the description of this datasource.
 java.lang.String getDriverClassName()
          Returns the class name of the JDBC driver to use.
 java.lang.String getDriverName()
          Returns the URL name of the JDBC driver to use.
 java.lang.String getIsolationLevelAsString()
          Returns the transaction isolation level used with all new transactions, or null if the driver's default isolation level is used.
 int getLoginTimeout()
           
 java.io.PrintWriter getLogWriter()
          This method is defined in the interface and implemented in the derived class, we re-define it just to make sure it does not throw an SQLException and that we do not need to catch one.
 java.lang.Object getObjectInstance(java.lang.Object refObj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable env)
           
 java.lang.String getPassword()
          Returns the database password.
 javax.naming.Reference getReference()
           
 java.lang.String getUser()
          Returns the user's account name.
 void setDescription(java.lang.String description)
          Sets the description of this datasource.
 void setDriverClassName(java.lang.String className)
          Sets the class name of the JDBC driver to use, e.g.
 void setDriverName(java.lang.String driverName)
          Sets the JDBC URL for the JDBC driver to use.
 void setIsolationLevel(java.lang.String level)
          Sets the transaction isolation level used with all new transactions, or null if the driver's default isolation level should be used.
 void setLoginTimeout(int seconds)
           
 void setLogWriter(java.io.PrintWriter writer)
           
 void setPassword(java.lang.String password)
          Sets the database password.
 void setUser(java.lang.String user)
          Sets the user's account name.
 java.lang.String toString()
           
 
Methods inherited from class tyrex.resource.jdbc.xa.XADataSourceImpl
debug, getIgnoreIsolationLevel, getIsolationLevel, getPooledConnection, getPooledConnection, getPruneFactor, getTransactionTimeout, getTxConnection, getTxRecover, getXAConnection, getXAConnection, newConnection, releaseConnection, run, setIgnoreIsolationLevel, setIsolationLevel, setPruneFactor, setTransactionTimeout, setTxConnection
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EnabledDataSource

public EnabledDataSource()
Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection(java.lang.String user,
                                         java.lang.String password)
                                  throws java.sql.SQLException
Specified by:
getConnection in interface javax.sql.DataSource
Throws:
java.sql.SQLException

createJDBCURL

protected java.lang.String createJDBCURL()
Construct the JDBC URL used to connect to the database.

Returns:
the JDBC URL used to connect to the database.

getLogWriter

public java.io.PrintWriter getLogWriter()
Description copied from class: XADataSourceImpl
This method is defined in the interface and implemented in the derived class, we re-define it just to make sure it does not throw an SQLException and that we do not need to catch one.

Specified by:
getLogWriter in interface javax.sql.DataSource
Specified by:
getLogWriter in class XADataSourceImpl

setLogWriter

public void setLogWriter(java.io.PrintWriter writer)
Specified by:
setLogWriter in interface javax.sql.DataSource

setDriverName

public void setDriverName(java.lang.String driverName)
Sets the JDBC URL for the JDBC driver to use. The JDBC URL is of the form jdbc:subprotocol:subname. The initial "jdbc:" is optional so that subprocol:subname is also valid. The standard name for this property is driverName.

Parameters:
driverName - The URL name of the JDBC driver to use

getDriverName

public java.lang.String getDriverName()
Returns the URL name of the JDBC driver to use. The JDBC URL is of the form jdbc:subprotocol:subname. The initial "jdbc:" is optional so that subprocol:subname is also valid. The standard name for this property is driverName.

Returns:
The URL name of the JDBC driver to use

setDriverClassName

public void setDriverClassName(java.lang.String className)
Sets the class name of the JDBC driver to use, e.g. postgresql.Driver. The standard name for this property is driverClassName.

Parameters:
className - The class name of the JDBC driver to use

getDriverClassName

public java.lang.String getDriverClassName()
Returns the class name of the JDBC driver to use. The standard name for this property is driverClassName.

Returns:
The class name of the JDBC driver to use, null if not specified

setLoginTimeout

public void setLoginTimeout(int seconds)
Specified by:
setLoginTimeout in interface javax.sql.DataSource

getLoginTimeout

public int getLoginTimeout()
Specified by:
getLoginTimeout in interface javax.sql.DataSource

setDescription

public void setDescription(java.lang.String description)
Sets the description of this datasource. The standard name for this property is description.

Parameters:
description - The description of this datasource

getDescription

public java.lang.String getDescription()
Returns the description of this datasource. The standard name for this property is description.

Returns:
The description of this datasource

setPassword

public void setPassword(java.lang.String password)
Sets the database password. The standard name for this property is password.

Parameters:
password - The database password

getPassword

public java.lang.String getPassword()
Returns the database password. The standard name for this property is password.

Returns:
The database password

setUser

public void setUser(java.lang.String user)
Sets the user's account name. The standard name for this property is user.

Parameters:
user - The user's account name

getUser

public java.lang.String getUser()
Returns the user's account name. The standard name for this property is user.

Returns:
The user's account name

getIsolationLevelAsString

public java.lang.String getIsolationLevelAsString()
Returns the transaction isolation level used with all new transactions, or null if the driver's default isolation level is used. For a list of isolation names, see setIsolationLevel(java.lang.String).

Returns:
The transaction isolation level

setIsolationLevel

public void setIsolationLevel(java.lang.String level)
Sets the transaction isolation level used with all new transactions, or null if the driver's default isolation level should be used. Supported values are: The standard name for this property is isolationLevel.

Parameters:
level - The transaction isolation level

equals

public boolean equals(java.lang.Object other)
Returns true if this datasource and the other are equal. The two datasources are equal if and only if they will produce the exact same connections. Connection properties like database name, user name, etc are comapred. Setup properties like description, log writer, etc are not compared.


toString

public java.lang.String toString()

getReference

public javax.naming.Reference getReference()
Specified by:
getReference in interface javax.naming.Referenceable

getObjectInstance

public java.lang.Object getObjectInstance(java.lang.Object refObj,
                                          javax.naming.Name name,
                                          javax.naming.Context nameCtx,
                                          java.util.Hashtable env)
                                   throws javax.naming.NamingException
Specified by:
getObjectInstance in interface javax.naming.spi.ObjectFactory
Throws:
javax.naming.NamingException


Original code is Copyright (c) 1999-2001, Intalio, Inc. All Rights Reserved. Contributions by MetaBoss team are Copyright (c) 2003-2005, Softaris Pty. Ltd. All Rights Reserved.