org.opensubsystems.core.persist.db.connectionpool
Class J2EEDatabaseConnectionFactoryImpl

java.lang.Object
  extended by org.opensubsystems.core.persist.db.DatabaseConnectionFactoryImpl
      extended by org.opensubsystems.core.persist.db.connectionpool.PooledDatabaseConnectionFactoryImpl
          extended by org.opensubsystems.core.persist.db.connectionpool.J2EEDatabaseConnectionFactoryImpl
All Implemented Interfaces:
DatabaseConnectionFactory

public class J2EEDatabaseConnectionFactoryImpl
extends PooledDatabaseConnectionFactoryImpl

Base class for implementation of j2ee factories for retrieving and returning of database connections, which are maintained in a pool of always ready connections.

Version:
$Id: J2EEDatabaseConnectionFactoryImpl.java,v 1.6 2007/01/07 06:14:58 bastafidli Exp $
Author:
Julo Legeny
Code reviewer:
Miroslav Halas
Code reviewed:
1.3 2005/11/08 06:12:47 bastafidli

Field Summary
static java.lang.String DATASOURCE_NAME_PREFIX_JBOSS
          Prefix of the data source that will be used for all data sources specified in JBoss server.
static java.lang.String DATASOURCE_NAME_PREFIX_WEBSPHERE
          Prefix of the data source that will be used for all data sources specified in IBM WebSphere server.
 
Fields inherited from class org.opensubsystems.core.persist.db.connectionpool.PooledDatabaseConnectionFactoryImpl
DEFAULT_DATASOURCE_NAME, m_defaultConnectionPool, m_mpConnectionPoolCrossRef, m_mpConnectionPools, m_mpNotPooledConnections
 
Fields inherited from class org.opensubsystems.core.persist.db.DatabaseConnectionFactoryImpl
ADMIN_DATASOURCE_NAME, DATABASE_ADMIN_PASSWORD, DATABASE_ADMIN_USER, DATABASE_DRIVER, DATABASE_PASSWORD, DATABASE_URL, DATABASE_USE_ADMIN_DATAROURCE, DATABASE_USE_ADMIN_DATAROURCE_DEFAULT, DATABASE_USER, m_bUseAdminDataSource, m_iRequestedConnectionCount, m_strDatabaseAdminPassword, m_strDatabaseAdminUser, m_strDatabaseDriver, m_strDatabasePassword, m_strDatabaseURL, m_strDatabaseUser, m_strRealDatabaseDriver, m_transactionFactory, SPY_CONFIG_FILE_NAME, SPY_DRIVER_IDENTIFICATION, SPY_REALDRIVER
 
Constructor Summary
J2EEDatabaseConnectionFactoryImpl()
           
 
Method Summary
protected  void closeConnectionPool(org.opensubsystems.core.persist.db.connectionpool.PooledDatabaseConnectionFactoryImpl.ConnectionPoolDefinition connectionpool)
          Close the specified connection pool and all connections maintained to database by this connection pool.
protected  java.lang.Object createConnectionPool(java.lang.String strConnectionPoolName, java.lang.String strDriverName, java.lang.String strUrl, java.lang.String strUser, java.lang.String strPassword)
          Create new connection pool with specified parameters.
 java.lang.String getDatabaseAdminPassword()
          Returns the database administration password.
 java.lang.String getDatabaseAdminUser()
          Returns the database administration user.
 java.lang.String getDatabaseDriver()
          Returns the database driver identification.
 java.lang.String getDatabasePassword()
          Returns the database password.
 java.lang.String getDatabaseURL()
          Returns the database URL.
 java.lang.String getDatabaseUser()
          Returns the database user.
protected  java.sql.Connection getPooledConnection(org.opensubsystems.core.persist.db.connectionpool.PooledDatabaseConnectionFactoryImpl.ConnectionPoolDefinition connectionpool)
          Get connection for given connection pool.
protected  java.sql.Connection getPooledConnection(org.opensubsystems.core.persist.db.connectionpool.PooledDatabaseConnectionFactoryImpl.ConnectionPoolDefinition connectionpool, java.lang.String strUser, java.lang.String strPassword)
          Get connection using the same settings as given connection pool but get the connection under different name and password.
 java.lang.String getRealDatabaseDriver()
          Get real driver name which is used to connect to database.
protected  void initializeConnection(java.sql.Connection cntDBConnection, boolean bAutoCommit)
          Initialize connection to the default state so it can be used to work with the database.
 
Methods inherited from class org.opensubsystems.core.persist.db.connectionpool.PooledDatabaseConnectionFactoryImpl
addDataSource, debug, getDefaultDataSourceName, getRequestedConnectionCount, getRequestedConnectionCount, isDataSourceDefined, requestNonTransactionalConnection, requestNonTransactionalConnection, requestNonTransactionalConnection, requestNonTransactionalConnection, returnNonTransactionalConnection, returnPooledConnection, setDefaultDataSourceName, start, stop
 
Methods inherited from class org.opensubsystems.core.persist.db.DatabaseConnectionFactoryImpl
getInstance, getTotalRequestedConnectionCount, getUseAdminDataSource, initializeDriver, loadDefaultDatabaseProperties, requestConnection, requestConnection, requestConnection, requestConnection, returnConnection, setDatabaseAdminPassword, setDatabaseAdminUser, setDatabaseDriver, setDatabasePassword, setDatabaseURL, setDatabaseUser, setInstance, setTransactionFactory, setUseAdminDataSource
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DATASOURCE_NAME_PREFIX_JBOSS

public static final java.lang.String DATASOURCE_NAME_PREFIX_JBOSS
Prefix of the data source that will be used for all data sources specified in JBoss server.

See Also:
Constant Field Values

DATASOURCE_NAME_PREFIX_WEBSPHERE

public static final java.lang.String DATASOURCE_NAME_PREFIX_WEBSPHERE
Prefix of the data source that will be used for all data sources specified in IBM WebSphere server. Originally WebSphere allowed to access datasources using JNDI name jdbc/datasourcename. Since version 6 WebSPphere prints warning that this naming convention and a full JNDI referrence should be used, see http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/topic/com.ibm.websphere.express.doc/info/exp/ae/rdat_jnditips.html I have tried to change this to java:comp/env/jdbc/ as described in http://publib.boulder.ibm.com/infocenter/wasinfo/v6r0/topic/com.ibm.websphere.express.doc/info/exp/ae/tdat_accdfac.html but when the war file was deployed in WebSphere, the application couldn't find the datasource.

See Also:
Constant Field Values
Constructor Detail

J2EEDatabaseConnectionFactoryImpl

public J2EEDatabaseConnectionFactoryImpl()
Method Detail

getRealDatabaseDriver

public java.lang.String getRealDatabaseDriver()
Get real driver name which is used to connect to database. This can be wrapped for example in a spy driver.

Specified by:
getRealDatabaseDriver in interface DatabaseConnectionFactory
Overrides:
getRealDatabaseDriver in class DatabaseConnectionFactoryImpl
Returns:
String - real JDBC driver name.

getDatabaseDriver

public java.lang.String getDatabaseDriver()
Returns the database driver identification.

Specified by:
getDatabaseDriver in interface DatabaseConnectionFactory
Overrides:
getDatabaseDriver in class DatabaseConnectionFactoryImpl
Returns:
String

getDatabaseURL

public java.lang.String getDatabaseURL()
Returns the database URL.

Specified by:
getDatabaseURL in interface DatabaseConnectionFactory
Overrides:
getDatabaseURL in class DatabaseConnectionFactoryImpl
Returns:
String

getDatabaseAdminUser

public java.lang.String getDatabaseAdminUser()
Returns the database administration user.

Specified by:
getDatabaseAdminUser in interface DatabaseConnectionFactory
Overrides:
getDatabaseAdminUser in class DatabaseConnectionFactoryImpl
Returns:
String

getDatabaseAdminPassword

public java.lang.String getDatabaseAdminPassword()
Returns the database administration password.

Specified by:
getDatabaseAdminPassword in interface DatabaseConnectionFactory
Overrides:
getDatabaseAdminPassword in class DatabaseConnectionFactoryImpl
Returns:
String

getDatabaseUser

public java.lang.String getDatabaseUser()
Returns the database user.

Specified by:
getDatabaseUser in interface DatabaseConnectionFactory
Overrides:
getDatabaseUser in class DatabaseConnectionFactoryImpl
Returns:
String

getDatabasePassword

public java.lang.String getDatabasePassword()
Returns the database password.

Specified by:
getDatabasePassword in interface DatabaseConnectionFactory
Overrides:
getDatabasePassword in class DatabaseConnectionFactoryImpl
Returns:
String

getPooledConnection

protected java.sql.Connection getPooledConnection(org.opensubsystems.core.persist.db.connectionpool.PooledDatabaseConnectionFactoryImpl.ConnectionPoolDefinition connectionpool)
                                           throws OSSDatabaseAccessException
Get connection for given connection pool.

Specified by:
getPooledConnection in class PooledDatabaseConnectionFactoryImpl
Parameters:
connectionpool - - connection pool to get connection for
Returns:
Connection - this can be null if connection is not available
Throws:
OSSDatabaseAccessException - - an error getting connection

getPooledConnection

protected java.sql.Connection getPooledConnection(org.opensubsystems.core.persist.db.connectionpool.PooledDatabaseConnectionFactoryImpl.ConnectionPoolDefinition connectionpool,
                                                  java.lang.String strUser,
                                                  java.lang.String strPassword)
                                           throws OSSDatabaseAccessException
Get connection using the same settings as given connection pool but get the connection under different name and password.

Specified by:
getPooledConnection in class PooledDatabaseConnectionFactoryImpl
Parameters:
connectionpool - - connection pool defining settings to get connection for
strUser - - user name to get the connection for
strPassword - - password to get the connection for
Returns:
Connection - this can be null if connection is not available
Throws:
OSSDatabaseAccessException - - an error getting connection

createConnectionPool

protected java.lang.Object createConnectionPool(java.lang.String strConnectionPoolName,
                                                java.lang.String strDriverName,
                                                java.lang.String strUrl,
                                                java.lang.String strUser,
                                                java.lang.String strPassword)
                                         throws OSSException
Create new connection pool with specified parameters.

Specified by:
createConnectionPool in class PooledDatabaseConnectionFactoryImpl
Parameters:
strConnectionPoolName - - connection pool name
strDriverName - - name of the JDBC driver
strUrl - - url by which data source connects to the database
strUser - - user name to connects to the database
strPassword - - password to connects to the database
Returns:
Object - connection pool
Throws:
OSSException - - an error has occured during creation of connection pool

closeConnectionPool

protected void closeConnectionPool(org.opensubsystems.core.persist.db.connectionpool.PooledDatabaseConnectionFactoryImpl.ConnectionPoolDefinition connectionpool)
                            throws OSSException
Close the specified connection pool and all connections maintained to database by this connection pool.

Specified by:
closeConnectionPool in class PooledDatabaseConnectionFactoryImpl
Parameters:
connectionpool - - connection pool to close.
Throws:
OSSException - - an error has occured during closing of the connection pool

initializeConnection

protected void initializeConnection(java.sql.Connection cntDBConnection,
                                    boolean bAutoCommit)
                             throws java.sql.SQLException
Initialize connection to the default state so it can be used to work with the database. The most common setup is that we will set the autocommit by default to true when transaction is not in progress and to false if there is a pending transaction. This is mainly because if selects are executed without transaction and transaction isolation is set to for example serializable, it can come to a deadlock since the select may block table when different connection tries to modify it.

Overrides:
initializeConnection in class DatabaseConnectionFactoryImpl
Parameters:
cntDBConnection - - valid connection to the database
bAutoCommit - - The desired autocommit state of the connection. If this connection is invoked in global (JTA) transaction then the autocommit is false regardless of what value is specified here. Use true here if the client only reads the data and false if the client also modifies the data. Use DatabaseTransactionFactory.commitTransaction to commit the transaction.
Throws:
java.sql.SQLException - - problem initializing the connection


Copyright © 2003 - 2006 OpenSubsystems s.r.o.