jrun.sql.pool
Class JDBCPool

jrun.sql.pool.JDBCPool

public class JDBCPool

JDBCPool is an ObjectPool of JDBC connection objects. It is also a javax.sql.ConnectionEventListener, so it can respond to events fired by the XAConnection implementation, JRunConnection.

Author:
PS Neville

Field Summary
protected  SQLCache sqlcache
           
 
Constructor Summary
JDBCPool(PoolMetaData metad)
           
 
Method Summary
 void checkCredentials(java.lang.String username, java.lang.String password)
           
protected  java.lang.Object checkOut(java.lang.String username, java.lang.String password)
          Checkout cycles through the available objects and returns the first valid object it finds.
 void cleanPooledStatements(java.sql.Connection con)
          Cleans PreparedStatements that have been produced by this Connection
 void closeAllResources()
          Overriden in order to ensure that JNDI resources are disposed of properly.
static void closeConnection(java.sql.Connection con)
           
static void closeResources(java.sql.Connection con, java.sql.Statement statement, java.sql.ResultSet resultset)
          Static method that closes the Connection, Statement and ResultSets in one place.
static void closeResources(java.sql.Statement statement, java.sql.ResultSet resultSet)
          Static method that closes the statement and result sets in one place; this is here as a convenience to shorten the finally block in statements.
static void closeResultSet(java.sql.ResultSet rs)
          This method closes the given resultset.
static void closeStatement(java.sql.Statement statement)
          Closes the given statement.
 void connectionClosed(javax.sql.ConnectionEvent event)
          Responds to a ConnectionClosed ConnectionEvent.
 void connectionErrorOccurred(javax.sql.ConnectionEvent event)
          Responds to an error event.
protected  java.lang.Object create()
          Creates a physical Connection and JRunConnection wrapper for it.
protected  java.lang.Object create(java.lang.String username, java.lang.String password)
          Creates a physical Connection and JRunConnection wrapper for it using username and password passed in.
 void deployDataSource()
           
 boolean equals(java.lang.Object o)
           
protected  void expire(java.lang.Object o)
          Closes both the pooled and the physical database connection.
 SQLCache getCache()
           
 javax.sql.DataSource getDataSource()
           
 java.lang.String getDriver()
           
 int getIsolationLevel()
           
 java.lang.String getPassword()
           
 java.lang.String getTransactionDomain()
           
 java.lang.String getURL()
           
 java.lang.String getUserName()
           
protected  boolean holdingLock(java.lang.Object o)
           
 void init()
           
 void initEncrypter()
           
 boolean isDataSourceDeployed()
           
 boolean isUsingNativeResults()
           
protected  boolean matchSecurityInfo(java.lang.String username, java.lang.String password, java.lang.Object conn)
          Verifies if username and password match with the one from the connection Neither username nor password can be null, returns false if either one is null
 int numPooledStatements(java.lang.String sql)
           
 int numStatementPools()
           
 void refreshCache()
          Force the cache to refresh.
 java.sql.Connection requestConnection()
          Retrieves a JRunConnection and returns its Handle.
 java.sql.Connection requestConnection(java.lang.String username, java.lang.String password)
          Retrieves a JRunConnection and returns its Handle.
 java.sql.PreparedStatement requestPooledStatement(java.lang.String sql)
           
 void returnConnection(JRunConnection pcon)
          Returns a JRunConnection to the pool.
 void returnPooledStatement(JRunPreparedStatement ps)
          Retuns a PreparedStatement to the statement pool
 void setCache(SQLCache cache)
          Associates a SQLCache with this pool.
 void setDataSource(JRunDataSource ds)
          Associates a DataSource view with this pool.
 void undeployDataSource()
           
 boolean usingCache()
          Determine whether or not this pool is using a SQLCache (configured in poolman.props and disabled by default).
protected  boolean validate(java.lang.Object o)
           
 boolean validateJRunConnection(JRunConnection jcon)
           
 

Field Detail

sqlcache

protected SQLCache sqlcache
Constructor Detail

JDBCPool

public JDBCPool(PoolMetaData metad)
Method Detail

init

public void init()
          throws java.lang.Exception

setDataSource

public void setDataSource(JRunDataSource ds)
Associates a DataSource view with this pool.

getDataSource

public javax.sql.DataSource getDataSource()

deployDataSource

public void deployDataSource()

undeployDataSource

public void undeployDataSource()

isDataSourceDeployed

public boolean isDataSourceDeployed()

setCache

public void setCache(SQLCache cache)
Associates a SQLCache with this pool.

getCache

public SQLCache getCache()
Returns:
SQLCache The SQLCache associated with this pool.

initEncrypter

public void initEncrypter()

usingCache

public boolean usingCache()
Determine whether or not this pool is using a SQLCache (configured in poolman.props and disabled by default).

refreshCache

public void refreshCache()
Force the cache to refresh.

getDriver

public java.lang.String getDriver()

getURL

public java.lang.String getURL()

getUserName

public java.lang.String getUserName()

getPassword

public java.lang.String getPassword()

getIsolationLevel

public int getIsolationLevel()

isUsingNativeResults

public boolean isUsingNativeResults()

getTransactionDomain

public java.lang.String getTransactionDomain()

equals

public boolean equals(java.lang.Object o)

checkCredentials

public void checkCredentials(java.lang.String username,
                             java.lang.String password)
                      throws java.sql.SQLException

connectionClosed

public void connectionClosed(javax.sql.ConnectionEvent event)
Responds to a ConnectionClosed ConnectionEvent.

connectionErrorOccurred

public void connectionErrorOccurred(javax.sql.ConnectionEvent event)
Responds to an error event.

checkOut

protected java.lang.Object checkOut(java.lang.String username,
                                    java.lang.String password)
                             throws java.lang.Exception
Checkout cycles through the available objects and returns the first valid object it finds. if there are no valid objects, checkOut will create one, unless the client specified amount of objects have already been created, and then it will block until it finds an appropriate object Uses username password if passed in

holdingLock

protected boolean holdingLock(java.lang.Object o)

create

protected java.lang.Object create()
                           throws java.sql.SQLException
Creates a physical Connection and JRunConnection wrapper for it.

create

protected java.lang.Object create(java.lang.String username,
                                  java.lang.String password)
                           throws java.sql.SQLException
Creates a physical Connection and JRunConnection wrapper for it using username and password passed in.

validateJRunConnection

public boolean validateJRunConnection(JRunConnection jcon)

matchSecurityInfo

protected boolean matchSecurityInfo(java.lang.String username,
                                    java.lang.String password,
                                    java.lang.Object conn)
Verifies if username and password match with the one from the connection Neither username nor password can be null, returns false if either one is null

validate

protected boolean validate(java.lang.Object o)

expire

protected void expire(java.lang.Object o)
Closes both the pooled and the physical database connection.

requestConnection

public java.sql.Connection requestConnection()
                                      throws java.sql.SQLException
Retrieves a JRunConnection and returns its Handle.

requestConnection

public java.sql.Connection requestConnection(java.lang.String username,
                                             java.lang.String password)
                                      throws java.sql.SQLException
Retrieves a JRunConnection and returns its Handle.

returnConnection

public void returnConnection(JRunConnection pcon)
Returns a JRunConnection to the pool.

requestPooledStatement

public java.sql.PreparedStatement requestPooledStatement(java.lang.String sql)

returnPooledStatement

public void returnPooledStatement(JRunPreparedStatement ps)
Retuns a PreparedStatement to the statement pool

cleanPooledStatements

public void cleanPooledStatements(java.sql.Connection con)
                           throws java.sql.SQLException
Cleans PreparedStatements that have been produced by this Connection

numStatementPools

public int numStatementPools()

numPooledStatements

public int numPooledStatements(java.lang.String sql)

closeAllResources

public void closeAllResources()
Overriden in order to ensure that JNDI resources are disposed of properly.

closeResources

public static void closeResources(java.sql.Connection con,
                                  java.sql.Statement statement,
                                  java.sql.ResultSet resultset)
Static method that closes the Connection, Statement and ResultSets in one place.

closeResources

public static void closeResources(java.sql.Statement statement,
                                  java.sql.ResultSet resultSet)
Static method that closes the statement and result sets in one place; this is here as a convenience to shorten the finally block in statements. Both arguments may be null;
Parameters:
statement - the statement to be closed
resultSet - the resultSet to be closed

closeConnection

public static void closeConnection(java.sql.Connection con)

closeStatement

public static void closeStatement(java.sql.Statement statement)
Closes the given statement. It is here to get rid of the extra try block in finally blocks that need to close statements
Parameters:
statement - the statement to be closed. may be null

closeResultSet

public static void closeResultSet(java.sql.ResultSet rs)
This method closes the given resultset. It is here to get rid of the extra try block in finally blocks.
Parameters:
rs - the ResultSet to be closed. may be null


Copyright � 2002 Macromedia Corporation. All Rights Reserved.