DODS 7.6 API

com.lutris.appserver.server.sql.datasource
Class DataSourceConnectionAllocator

java.lang.Object
  extended by com.lutris.appserver.server.sql.datasource.DataSourceConnectionAllocator
All Implemented Interfaces:
ConnectionAllocator, ExtendedConnectionAllocator

public class DataSourceConnectionAllocator
extends java.lang.Object
implements ExtendedConnectionAllocator

Manages a pool (set) of connections to a database. The pool is owned by logical database. A connection considered part of the pool, even if its allocated to a thread. These objects are all publicly accessed via the Database Manager, not directly.

If an error occurs in a connection, it is dropped from the pool. A generation number is used to close down all connections that were open when the error occured, allowing new connections to be allocated.

The configuration data is specified in the section: DatabaseManager.DB. dbName .Connection

Configuration sub fields are:


Field Summary
protected  java.lang.String connectionAllocateCheckSql
          /** database "ConnectionCheckSql" string
protected  java.lang.String connectionReleaseCheckSql
          database "ConnectionReleaseCheckSql" string
protected  javax.sql.DataSource dataSource
          JDBC DataSource of database.
protected  boolean disableConnectionPool
          Indicates dods not to use connection pool.
protected  int generation
          Generation number.
protected  int initWaitingConnections
           
protected  LogicalDatabase logicalDatabase
          Reference to the logical database for easy access to the connection pool.
protected  int maxPreparedStatements
          Maximum number of prepared statements to use; if less-than zero, then JDBC is queried for this value.
protected  int maxWaitingConnections
          JP Patch Maximum number of DBConnections that will be waiting in the pool
protected  long numRequests
          Number of queries or transactions on this logical database.
protected  java.lang.String password
          SQL password..
protected  int queryTimeOut
          Maximum amount of time in seconds to block on a query.
protected  java.lang.String shutDownStr
          database "ShutDown" string
protected  boolean sqlLogging
          Indicates if logging is enabled.
protected  int transactionTimeOut
          Maximum amount of time in seconds to block on a transaction.
protected  java.lang.String url
          JDBC URL of database.
protected  java.lang.String user
          SQL user name.
 
Constructor Summary
DataSourceConnectionAllocator(LogicalDatabase logicalDatabase, Config conConfig)
          /** Creates instance of StandardConnectionAllocator object.
 
Method Summary
 DBConnection allocate()
          Allocate new connection from pool.
protected  DBConnection createConnection()
          Create a new connection in the pool.
 void drop(DBConnection dbConnection)
          Called when a connection in this pool has an SQL error.
 void dropAllNow()
          Called when the database manager is shutting down: Close all connections immediately.
protected  void finalize()
          Finalizer.
 int getActiveCount()
          Return the number of currently active connections.
 java.lang.String getDatabaseName()
           
 int getMaxCount()
          Return the maximum number of connections active at one time.
 java.util.Date getMaxCountDate()
          Return the time when the maximum connection count occured.
 long getRequestCount()
          Return the number of database requests.
 void incrementRequesteCount()
           
 boolean performRollbackOnReset()
           
 void release(DBConnection dbConnection)
           
 void resetMaxCount()
          Reset the maximum connection count and date.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logicalDatabase

protected LogicalDatabase logicalDatabase
Reference to the logical database for easy access to the connection pool.


dataSource

protected javax.sql.DataSource dataSource
JDBC DataSource of database.


shutDownStr

protected java.lang.String shutDownStr
database "ShutDown" string


url

protected java.lang.String url
JDBC URL of database.


user

protected java.lang.String user
SQL user name.


password

protected java.lang.String password
SQL password..


connectionAllocateCheckSql

protected java.lang.String connectionAllocateCheckSql
/** database "ConnectionCheckSql" string


connectionReleaseCheckSql

protected java.lang.String connectionReleaseCheckSql
database "ConnectionReleaseCheckSql" string


numRequests

protected long numRequests
Number of queries or transactions on this logical database.


maxWaitingConnections

protected int maxWaitingConnections
JP Patch Maximum number of DBConnections that will be waiting in the pool


initWaitingConnections

protected int initWaitingConnections

sqlLogging

protected boolean sqlLogging
Indicates if logging is enabled.


disableConnectionPool

protected boolean disableConnectionPool
Indicates dods not to use connection pool.


queryTimeOut

protected int queryTimeOut
Maximum amount of time in seconds to block on a query. The DBQuery object will retrieve this value from the connection.


transactionTimeOut

protected int transactionTimeOut
Maximum amount of time in seconds to block on a transaction. The DBTransaction object will retrieve this value from the connection.


maxPreparedStatements

protected int maxPreparedStatements
Maximum number of prepared statements to use; if less-than zero, then JDBC is queried for this value.


generation

protected int generation
Generation number. When an SQL error occurs, all objects of the same generation or earlier are dropped.

Constructor Detail

DataSourceConnectionAllocator

public DataSourceConnectionAllocator(LogicalDatabase logicalDatabase,
                                     Config conConfig)
                              throws ConfigException
/** Creates instance of StandardConnectionAllocator object.

Parameters:
logicalDatabase - LogicalDatabase that is owner of this ConnectionAllocator object.
conConfig - Connection allocator configuration object.
Throws:
ConfigException
Method Detail

createConnection

protected DBConnection createConnection()
                                 throws java.sql.SQLException
Create a new connection in the pool.

Throws:
java.sql.SQLException - If a SQL error occures.

allocate

public DBConnection allocate()
                      throws java.sql.SQLException
Allocate new connection from pool.

Specified by:
allocate in interface ConnectionAllocator
Throws:
java.sql.SQLException
See Also:
ConnectionAllocator.allocate()

release

public void release(DBConnection dbConnection)
Specified by:
release in interface ConnectionAllocator

drop

public void drop(DBConnection dbConnection)
Called when a connection in this pool has an SQL error. All unallocated connections in the pool are dropped if they have a generation number less than or equal to the error connection. If the current generation number is the same as this generation number, increment it. This way so that all outstanding connections (including the one passed in) of the same generation are dropped when returned.

Specified by:
drop in interface ConnectionAllocator
Parameters:
dbConnection - The connection object to drop. The connection should be returned to the pool after this function returns.

dropAllNow

public void dropAllNow()
Called when the database manager is shutting down: Close all connections immediately.

Specified by:
dropAllNow in interface ConnectionAllocator

getActiveCount

public int getActiveCount()
Return the number of currently active connections.

Specified by:
getActiveCount in interface ConnectionAllocator
Returns:
The number of connections.

getMaxCount

public int getMaxCount()
Return the maximum number of connections active at one time.

Specified by:
getMaxCount in interface ConnectionAllocator
Returns:
The number of connections.

getMaxCountDate

public java.util.Date getMaxCountDate()
Return the time when the maximum connection count occured.

Specified by:
getMaxCountDate in interface ConnectionAllocator
Returns:
The Date when the maximum connection count occured.

resetMaxCount

public void resetMaxCount()
Reset the maximum connection count and date.

Specified by:
resetMaxCount in interface ConnectionAllocator

getRequestCount

public long getRequestCount()
Return the number of database requests.

Specified by:
getRequestCount in interface ConnectionAllocator
Returns:
The number of database requests (queries or transactions).

finalize

protected void finalize()
Finalizer. If any connections allocated by this object have not been closed, this method ensures that garbage collection does so.

Overrides:
finalize in class java.lang.Object

getDatabaseName

public java.lang.String getDatabaseName()
Specified by:
getDatabaseName in interface ConnectionAllocator
Returns:
database name of current connection

incrementRequesteCount

public void incrementRequesteCount()
Specified by:
incrementRequesteCount in interface ExtendedConnectionAllocator

performRollbackOnReset

public boolean performRollbackOnReset()
Specified by:
performRollbackOnReset in interface ExtendedConnectionAllocator

DODS 7.6 API