atg.service.jdbc
Class FakeXADataSource

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.service.jdbc.FakeXADataSource
All Implemented Interfaces:
atg.naming.AbsoluteNameable, NameContextBindingListener, NameContextElement, atg.naming.NameContextParentable, NameResolver, AdminableService, atg.nucleus.Configured, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener, javax.sql.CommonDataSource, javax.sql.XADataSource

public class FakeXADataSource
extends GenericService
implements javax.sql.XADataSource

A "fake" XADataSource implemented on top of the old JDBC 1.0 architecture or a non-XA DataSource. The peculiar behaviour of this class should be taken into consideration before using it. This class is designed only for use with the MonitoredDataSource and the XAOnlyDataSource.

As indicated by it's namesake, this XADataSource is not a real XADataSource, nor do it's connections behave like connections from a real XADataSource. Most notably, two-phase commits are NOT supported. In a two-phase commit, connections from this XADataSource commit on the commit phase ignoring the prepare phase completely. Setting the property "commitOnPrepare" to true will cause commits to be performed on the prepare phase. Either way is problematic since commiting on the prepare phase will prevent rollbacks should one of the other enlisted resources request a rollback and commiting on the commit phase will produce an error should the fake XAConnection's commit fail.

In a distributed transaction two connections from the same DB in the same transaction should be able to see each other's changes. This fake XADataSource will attempt to insure that the same underlying connection is returned each time getConnection() is called within the same transaction. As such, any given transaction should have only one connection out of the pool at a time. This condition is not enforced however. If this condition is not adhered to and a transaction nests calls to getConnection(), there is potential for the nested call to step on result sets still in use by the first connection.

This fake XADataSource can be configured to use either a non-XA DataSource or a JDBC 1.0 style driver. To configure for a non-XA DataSource look at the properties:

To configure for a JDBC 1.0 style driver look at the properties:


Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
FakeXADataSource()
          Constructs an uninitialized JDBCConnectionPool.
 
Method Summary
 void doStartService()
          Called after properties have been set on this instance.
 java.util.Properties getAdditionalConnectionProperties()
          Returns property additionalConnectionProperties.
 boolean getCloseOrphanedConnections()
          Whether to close orphaned connections at the end of a transaction.
 java.lang.String getConnectionPasswordAlias()
          Returns property connectionPasswordAlias
 java.lang.String getDatabase()
          Returns property database.
 javax.sql.DataSource getDataSource()
          Returns property dataSource.
 java.util.Properties getDataSourceJNDIEnvironment()
          Returns property dataSourceJNDIEnvironment.
 java.lang.String getDataSourceJNDIName()
          Returns property dataSourceJNDIName.
 java.lang.String getDriver()
          Returns property driver.
 atg.nucleus.PropertyValueDecoder getLoginDecoder()
          Returns the LoginDecoder used to decode the user and password values before connecting to the database
 int getLoginTimeout()
          This property from the DataSource interface is not used.
 java.io.PrintWriter getLogWriter()
          This property from the DataSource interface is ignored.
 boolean getNeedsSeparateUserInfo()
          Returns property needsSeparateUserInfo.
 java.lang.String getPassword()
          Returns property password.
 atg.security.AliasedPasswordBroker getPasswordBroker()
          Returns property passwordBroker
 boolean getReadOnly()
          Returns property readOnly.
 java.lang.String getServer()
          Returns property server.
 java.lang.String getURL()
          Returns property URL.
 java.lang.String getUser()
          Returns property user.
 javax.sql.XAConnection getXAConnection()
          Returns a fake XAConnection wrapping a Connection from the underlying JDBC driver.
 javax.sql.XAConnection getXAConnection(java.lang.String pUsername, java.lang.String pPassword)
          Returns a fake XAConnection wrapping a Connection from the underlying JDBC driver using the supplied username and password.
 boolean isCommitOnPrepare()
          Returns property commitOnPrepare.
 void setAdditionalConnectionProperties(java.util.Properties pAdditionalConnectionProperties)
          Sets property additionalConnectionProperties.
 void setCloseOrphanedConnections(boolean pCloseOrphanedConnections)
          Whether to close orphaned connections at the end of a transaction.
 void setCommitOnPrepare(boolean pCommitOnPrepare)
          Sets property commitOnPrepare.
 void setConnectionPasswordAlias(java.lang.String pConnectionPasswordAlias)
          Sets property connectionPasswordAlias
 void setDatabase(java.lang.String pDatabase)
          Sets property database.
 void setDataSource(javax.sql.DataSource pDataSource)
          Sets the property dataSource.
 void setDataSourceJNDIEnvironment(java.util.Properties pDataSourceJNDIEnvironment)
          Sets property dataSourceJNDIEnvironment.
 void setDataSourceJNDIName(java.lang.String pDataSourceJNDIName)
          Sets property dataSourceJNDIName.
 void setDriver(java.lang.String pDriver)
          Sets property driver.
 void setLoginDecoder(atg.nucleus.PropertyValueDecoder pLoginDecoder)
          Sets the Decoder to be used to decode the user and password values before connecting to the database
 void setLoginTimeout(int pLoginTimeout)
          This property from the DataSource interface is not used.
 void setLogWriter(java.io.PrintWriter pLogWriter)
          This property from the DataSource interface is ignored.
 void setNeedsSeparateUserInfo(boolean pNeedsSeparateUserInfo)
          Sets property needsSeparateUserInfo.
 void setPassword(java.lang.String pPassword)
          Sets property password.
 void setPasswordBroker(atg.security.AliasedPasswordBroker pPasswordBroker)
          Sets property passwordBroker
 void setReadOnly(boolean pReadOnly)
          Sets property readOnly.
 void setServer(java.lang.String pServer)
          Sets property server.
 void setURL(java.lang.String pURL)
          Sets property URL.
 void setUser(java.lang.String pUser)
          Sets property user.
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStopService, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

FakeXADataSource

public FakeXADataSource()
Constructs an uninitialized JDBCConnectionPool.

Method Detail

setConnectionPasswordAlias

public void setConnectionPasswordAlias(java.lang.String pConnectionPasswordAlias)
Sets property connectionPasswordAlias

Parameters:
pConnectionPasswordAlias - alias to access the connection password

getConnectionPasswordAlias

public java.lang.String getConnectionPasswordAlias()
Returns property connectionPasswordAlias

Returns:
alias to access the connection password

setPasswordBroker

public void setPasswordBroker(atg.security.AliasedPasswordBroker pPasswordBroker)
Sets property passwordBroker

Parameters:
pPasswordBroker - password broker for accessing passwords

getPasswordBroker

public atg.security.AliasedPasswordBroker getPasswordBroker()
Returns property passwordBroker

Returns:
password broker for accessing passwords

setCommitOnPrepare

public void setCommitOnPrepare(boolean pCommitOnPrepare)
Sets property commitOnPrepare.
Whether or not to commit on phase one of a two phase commit, i.e. on the prepare call.

Parameters:
pCommitOnPrepare - new value to set

isCommitOnPrepare

public boolean isCommitOnPrepare()
Returns property commitOnPrepare.
Whether or not to commit on phase one of a two phase commit, i.e. on the prepare call.

Returns:
boolean

setDriver

public void setDriver(java.lang.String pDriver)
Sets property driver.
The full package path of the JDBC driver, e.g. foo.jdbc.Driver.

Parameters:
pDriver - new value to set

getDriver

public java.lang.String getDriver()
Returns property driver.
The full package path of the JDBC driver, e.g. foo.jdbc.Driver.

Returns:
String

setURL

public void setURL(java.lang.String pURL)
Sets property URL.
The JDBC URL used for opening connections.

Parameters:
pURL - new value to set

getURL

public java.lang.String getURL()
Returns property URL.
The JDBC URL used for opening connections.

Returns:
String

setServer

public void setServer(java.lang.String pServer)
Sets property server.
Then DB server name to connect to.

Parameters:
pServer - new value to set

getServer

public java.lang.String getServer()
Returns property server.
Then DB server name to connect to.

Returns:
String

setDatabase

public void setDatabase(java.lang.String pDatabase)
Sets property database.
The name of the specific database on the server to connect to.

Parameters:
pDatabase - new value to set

getDatabase

public java.lang.String getDatabase()
Returns property database.
The name of the specific database on the server to connect to.

Returns:
String

setLoginDecoder

public void setLoginDecoder(atg.nucleus.PropertyValueDecoder pLoginDecoder)
Sets the Decoder to be used to decode the user and password values before connecting to the database


getLoginDecoder

public atg.nucleus.PropertyValueDecoder getLoginDecoder()
Returns the LoginDecoder used to decode the user and password values before connecting to the database

Returns:

setUser

public void setUser(java.lang.String pUser)
Sets property user.
The user name to log into the DB server as.

Parameters:
pUser - new value to set

getUser

public java.lang.String getUser()
Returns property user.
The user name to log into the DB server as.

Returns:
String

setPassword

public void setPassword(java.lang.String pPassword)
Sets property password.
The password for the user to log into the DB server as.

Parameters:
pPassword - new value to set

getPassword

public java.lang.String getPassword()
Returns property password.
The password for the user to log into the DB server as.

Returns:
String

setAdditionalConnectionProperties

public void setAdditionalConnectionProperties(java.util.Properties pAdditionalConnectionProperties)
Sets property additionalConnectionProperties.
A set of properties that should be used to create new connections. Some drivers require additional properties be set for new connections, such as charsets for international DBs. This property will pass such a set of properties on to the DriverManager for the creation of new connections.

Parameters:
pAdditionalConnectionProperties - new value to set

getAdditionalConnectionProperties

public java.util.Properties getAdditionalConnectionProperties()
Returns property additionalConnectionProperties.
A set of properties that should be used to create new connections. Some drivers require additional properties be set for new connections, such as charsets for international DBs. This property will pass such a set of properties on to the DriverManager for the creation of new connections.

Returns:
Properties

setNeedsSeparateUserInfo

public void setNeedsSeparateUserInfo(boolean pNeedsSeparateUserInfo)
Sets property needsSeparateUserInfo.
A flag indicating whether this driver needs to use the special getConnection(url, user, password) form of the connection call. The oracle thin driver currently requires this to be used.

Parameters:
pNeedsSeparateUserInfo - new value to set

getNeedsSeparateUserInfo

public boolean getNeedsSeparateUserInfo()
Returns property needsSeparateUserInfo.
A flag indicating whether this driver needs to use the special getConnection(url, user, password) form of the connection call. The oracle thin driver currently requires this to be used.

Returns:
boolean

setReadOnly

public void setReadOnly(boolean pReadOnly)
Sets property readOnly.
Whether or not DriverManager Connections should be set Read-Only.

Parameters:
pReadOnly - new value to set

getReadOnly

public boolean getReadOnly()
Returns property readOnly.
Whether or not DriverManager Connections should be set Read-Only.

Returns:
boolean

setDataSourceJNDIName

public void setDataSourceJNDIName(java.lang.String pDataSourceJNDIName)
Sets property dataSourceJNDIName.
JNDI name of the DataSource to get Connections from.

Parameters:
pDataSourceJNDIName - new value to set

getDataSourceJNDIName

public java.lang.String getDataSourceJNDIName()
Returns property dataSourceJNDIName.
JNDI name of the DataSource to get Connections from.

Returns:
String

setDataSourceJNDIEnvironment

public void setDataSourceJNDIEnvironment(java.util.Properties pDataSourceJNDIEnvironment)
Sets property dataSourceJNDIEnvironment.
An optional set of properties needed by JNDI to resolve the DataSource.

Parameters:
pDataSourceJNDIEnvironment - new value to set

getDataSourceJNDIEnvironment

public java.util.Properties getDataSourceJNDIEnvironment()
Returns property dataSourceJNDIEnvironment.
An optional set of properties needed by JNDI to resolve the DataSource.

Returns:
Properties

setDataSource

public void setDataSource(javax.sql.DataSource pDataSource)
Sets the property dataSource.
The DataSource to get new Connections for the pool from. This method is used to set the property directly. Alternatively, the properties dataSourceJNDIName and dataSourceJNDIEnvironment can be used.

Parameters:
pDataSource - new value to set

getDataSource

public javax.sql.DataSource getDataSource()
Returns property dataSource.
The DataSource to get new Connections for the pool from. This property is either the DataSource set via the setDataSource() method or resolved via JNDI from the dataSourceJNDIName property.

Returns:
DataSource null if JNDI name did not resolve or was not set

setLoginTimeout

public void setLoginTimeout(int pLoginTimeout)
This property from the DataSource interface is not used.

Specified by:
setLoginTimeout in interface javax.sql.CommonDataSource
Parameters:
pLoginTimeout - new value to set

getLoginTimeout

public int getLoginTimeout()
This property from the DataSource interface is not used.

Specified by:
getLoginTimeout in interface javax.sql.CommonDataSource
Returns:
int

setLogWriter

public void setLogWriter(java.io.PrintWriter pLogWriter)
This property from the DataSource interface is ignored. All of the pool and objects generated by the pool write log messages to the ApplicationLogging interfaces.

Specified by:
setLogWriter in interface javax.sql.CommonDataSource

getLogWriter

public java.io.PrintWriter getLogWriter()
This property from the DataSource interface is ignored. All of the pool and objects generated by the pool write log messages to the ApplicationLogging interfaces.

Specified by:
getLogWriter in interface javax.sql.CommonDataSource

setCloseOrphanedConnections

public void setCloseOrphanedConnections(boolean pCloseOrphanedConnections)
Whether to close orphaned connections at the end of a transaction. That is, whether connections that were opened during the transaction, but not closed should be cleaned up. Should never be used in a production environment, since it is far better to fix the offending code.


getCloseOrphanedConnections

public boolean getCloseOrphanedConnections()
Whether to close orphaned connections at the end of a transaction. That is, whether connections that were opened during the transaction, but not closed should be cleaned up. Should never be used in a production environment, since it is far better to fix the offending code.


doStartService

public void doStartService()
                    throws ServiceException
Called after properties have been set on this instance. Initializes the connection password

Overrides:
doStartService in class GenericService
Throws:
ServiceException - if the Service had a problem starting up

getXAConnection

public javax.sql.XAConnection getXAConnection()
                                       throws java.sql.SQLException
Returns a fake XAConnection wrapping a Connection from the underlying JDBC driver.

Specified by:
getXAConnection in interface javax.sql.XADataSource
Throws:
java.sql.SQLException

getXAConnection

public javax.sql.XAConnection getXAConnection(java.lang.String pUsername,
                                              java.lang.String pPassword)
                                       throws java.sql.SQLException
Returns a fake XAConnection wrapping a Connection from the underlying JDBC driver using the supplied username and password.

Specified by:
getXAConnection in interface javax.sql.XADataSource
Throws:
java.sql.SQLException