tyrex.resource.jdbc.xa

Class EnabledDataSource

public class EnabledDataSource extends XADataSourceImpl implements DataSource, Referenceable, ObjectFactory, Serializable

Implements a JDBC 2.0 javax.sql.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 EnabledDataSource specifies the class of the JDBC driver to be loaded.

The JDBC URL is specified by EnabledDataSource. 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

Constructor Summary
EnabledDataSource()
Method Summary
protected StringcreateJDBCURL()
Construct the JDBC URL used to connect to the database.
booleanequals(Object other)
Returns true if this datasource and the other are equal.
ConnectiongetConnection()
ConnectiongetConnection(String user, String password)
StringgetDescription()
Returns the description of this datasource.
StringgetDriverClassName()
Returns the class name of the JDBC driver to use.
StringgetDriverName()
Returns the URL name of the JDBC driver to use.
StringgetIsolationLevelAsString()
Returns the transaction isolation level used with all new transactions, or null if the driver's default isolation level is used.
intgetLoginTimeout()
PrintWritergetLogWriter()
ObjectgetObjectInstance(Object refObj, Name name, Context nameCtx, Hashtable env)
StringgetPassword()
Returns the database password.
ReferencegetReference()
StringgetUser()
Returns the user's account name.
voidsetDescription(String description)
Sets the description of this datasource.
voidsetDriverClassName(String className)
Sets the class name of the JDBC driver to use, e.g.
voidsetDriverName(String driverName)
Sets the JDBC URL for the JDBC driver to use.
voidsetIsolationLevel(String level)
Sets the transaction isolation level used with all new transactions, or null if the driver's default isolation level should be used.
voidsetLoginTimeout(int seconds)
voidsetLogWriter(PrintWriter writer)
voidsetPassword(String password)
Sets the database password.
voidsetUser(String user)
Sets the user's account name.
StringtoString()

Constructor Detail

EnabledDataSource

public EnabledDataSource()

Method Detail

createJDBCURL

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

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

equals

public boolean equals(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.

getConnection

public Connection getConnection()

getConnection

public Connection getConnection(String user, String password)

getDescription

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

Returns: The description of this datasource

getDriverClassName

public 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

getDriverName

public 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

getIsolationLevelAsString

public 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 EnabledDataSource.

Returns: The transaction isolation level

getLoginTimeout

public int getLoginTimeout()

getLogWriter

public PrintWriter getLogWriter()

getObjectInstance

public Object getObjectInstance(Object refObj, Name name, Context nameCtx, Hashtable env)

getPassword

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

Returns: The database password

getReference

public Reference getReference()

getUser

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

Returns: The user's account name

setDescription

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

Parameters: description The description of this datasource

setDriverClassName

public void setDriverClassName(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

setDriverName

public void setDriverName(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

setIsolationLevel

public void setIsolationLevel(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

setLoginTimeout

public void setLoginTimeout(int seconds)

setLogWriter

public void setLogWriter(PrintWriter writer)

setPassword

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

Parameters: password The database password

setUser

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

Parameters: user The user's account name

toString

public String toString()
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.