|
Expresso 5-6 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectjava.lang.Thread
com.jcorporate.expresso.core.db.DBConnectionPool
a generic database connection pooling object.
Any object requiring connection to the database can request a connection from the connection pool, which will re-use connections and allocate new connections as required.
A connection pool will automatically drop connections that have been idle for more than a certain number of seconds when the pool reaches it's maximum size & a new connection is required.
It is the responsibility of the object that requests the connection to release it again as soon as possible.
| Field Summary | |
protected LinkedList |
available
Linked list of available connections to use from the connection pool |
protected boolean |
checkZeroUpdate
Check zero update setting author Peter Pilgrim, Thu Jun 21 10:30:59 BST 2001 |
protected EscapeHandler |
escapeHandler
Class that performs appropriate escaping in the strings being sent to the partuclar database. |
protected Map |
inUse
Map of connections that are currently is use. |
protected long |
lastUsed
This is a simple tag for when the last time the pool was ever used. |
static int |
LIMITATION_AFTER_ORDER_BY
Insert the limitation syntax after ORDER BY key words
SELECT {COLUMNS}... |
static int |
LIMITATION_AFTER_SELECT
Insert the limitation syntax after TABLE nomination
SELECT {limitation-syntax} {COLUMNS}... |
static int |
LIMITATION_AFTER_TABLE
Insert the limitation syntax after TABLE nomination
SELECT {COLUMNS}... |
static int |
LIMITATION_AFTER_WHERE
Insert the limitation syntax after WHERE key word
SELECT {COLUMNS}... |
static int |
LIMITATION_DISABLED
Limitation syntax database vendor specific optimisation is disabled author Peter Pilgrim, Thu Jun 21 10:30:59 BST 2001 |
protected int |
limitationPosition
Rowset Limitation Optimisation Syntax Position. |
protected String |
limitationSyntax
Rowset Limitation Optimisation Syntax String. |
protected Object |
poolLock
Object that is used as a lock for both available and isUse lists in a single object. |
protected Object |
timestampLock
object to lock finding current timestamp |
| Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
| Constructor Summary | |
DBConnectionPool()
Default Constructor |
|
| Method Summary | |
protected DBConnection |
buildNewConnection()
Creates a new database connection. |
void |
clean()
Clean the connection pool - see if any connections have been idle more than the allowed number of seconds . |
protected void |
cleanAvailable()
Iterates once through the available connections and cleans them. |
protected DBConnection |
createNewConnection()
Creates a new connection to the data source |
void |
disconnectAll()
Disconnect all of the current connections. |
protected void |
dumpDebugInfo()
Helper function that dumps all the current contents of the inUse connections. |
void |
executeExclusiveUpdate(String theSQL)
This allows an exclusive updated to be done to a database. |
boolean |
getCheckZeroUpdate()
Gets the check zero update boolean flag for this database connection pool author Peter Pilgrim |
DBConnection |
getConnection()
Find an available connection in the default connection pool, if any. |
DBConnection |
getConnection(String connectionDescrip)
Get a connection from the pool. |
String |
getDataContext()
Return the current database name/config key |
static javax.sql.DataSource |
getDataSource(String dataContext)
Retrieve a dumb datasource implementation that is compatible with items such as reporting tools, etc. |
String |
getDBName()
Return the current database name/config key |
ArrayList |
getDefaultWildCards()
Return a list of default wild card characters. |
String |
getDistinctRowsetKeyword()
Gets the SQL keyword to remove duplicate records from a database query. |
EscapeHandler |
getEscapeHandler()
Get the current character escape handler for this class. |
static DBConnectionPool |
getInstance(String dataContext)
Version of getInstance that can only get an already initialized connection pool to an alternate database |
protected static com.jcorporate.expresso.core.db.config.JDBCConfig |
getJDBCConfig(String dataContext)
Return the JDBConfig regardless of initialization by kernel package or DefaultInit servlet |
protected com.jcorporate.expresso.core.db.config.JNDIConfig |
getJNDIConfig(com.jcorporate.expresso.core.db.config.JDBCConfig curConfig)
Function that retrieves the JNDI config. |
int |
getLimitationPosition()
programmatically gets the limitation optimisation insertion position author Peter Pilgrim, Thu Jun 21 10:30:59 BST 2001 |
String |
getLimitationSyntax()
Programmatically gets the limitation syntax string author Peter Pilgrim, Thu Jun 21 10:30:59 BST 2001 |
int |
getMaxConnections()
Useful for querying the potential of the dbconnection pool's status |
ArrayList |
getPoolList()
Return the entire pool of connections as a Vector |
ArrayList |
getWildCardsList()
|
protected boolean |
isFull()
Helper function to determine if the pool is full. |
boolean |
isInitialized()
Is this connection pool initialized, or does it require database parameters? |
static void |
reInitialize()
Close all existing connections & empty the pools |
void |
release(DBConnection connectionToRelease)
Release the given connection It is the object requesting the connection's responsibility to call this method to release the connection(s) it requested. |
void |
setCheckZeroUpdate(boolean newValue)
Sets the check zero update boolean flag for this database connection pool author Peter Pilgrim |
protected void |
setDataContext(String newDBName)
Set the current database name/config key |
protected void |
setDBName(String newDBName)
Set the current database name/config key |
void |
setDistinctRowsetKeyword(String keyword)
Sets the SQL keyword to remove duplicate records from a database query. |
void |
setLimitationPosition(int pos)
programmatically sets the limitation optimisation insertion position |
void |
setLimitationPosition(String pos)
programmatically sets the limitation optimisation insertion position as readable string. |
void |
setLimitationSyntax(String syntax)
Programmatically gets the limitation syntax string |
void |
setMaxConnections(int newMax)
Sets the maximum number of connections for this pool |
void |
setTestQuery(String newTestQuery)
Set a small query to be used to "test" a connection before it's handed out |
void |
setTimeOutInterval(int newInterval)
Set the number of seconds that a connection must remain idle before it is considered "timed out" and cleared. |
boolean |
supportsTransactions()
Does this database connection support commit/rollback? |
static boolean |
supportsTransactions(String connName)
Does this database connection support commit/rollback? |
| Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, run, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected LinkedList available
protected Map inUse
protected Object poolLock
protected Object timestampLock
public static final int LIMITATION_DISABLED
public static final int LIMITATION_AFTER_TABLE
SELECT {COLUMNS}... FROM {TABLE}
{limitation-syntax}
[ WHERE {where_clause}... ]
[ ORDER BY {order_by_clause}... ]
author Peter Pilgrim, Thu Jun 21 10:30:59 BST 2001
public static final int LIMITATION_AFTER_WHERE
SELECT {COLUMNS}... FROM {TABLE}
[ WHERE {where_clause}... ]
AND {limitation-syntax}
[ ORDER BY {order_by_clause}... ]
author Peter Pilgrim, Thu Jun 21 10:30:59 BST 2001
public static final int LIMITATION_AFTER_ORDER_BY
SELECT {COLUMNS}... FROM {TABLE}
[ WHERE {where_clause}... ]
[ ORDER BY {order_by_clause}... ]
{limitation-syntax}
author Peter Pilgrim, Thu Jun 21 10:30:59 BST 2001
public static final int LIMITATION_AFTER_SELECT
SELECT {limitation-syntax} {COLUMNS}... FROM {TABLE}
[ WHERE {where_clause}... ]
[ ORDER BY {order_by_clause}... ]
author Peter Pilgrim, Thu Jun 21 10:30:59 BST 2001
protected int limitationPosition
LIMITATION_DISABLED,
LIMITATION_AFTER_TABLE,
LIMITATION_AFTER_WHERE,
LIMITATION_AFTER_ORDER_BY,
DBObject.searchAndRetrieveList(),
DBObject.getOffsetRecord(),
DBObject.setOffsetRecord( int ),
com.jcorporate.expresso.core.dbobj.DBObject#setMaxRecords(int))protected String limitationSyntax
ResultSet.
For example for MYSQL the string should be
"LIMIT %offset% , %maxrecord%"
For example for ORACLE the string should be
"ROWNUM >= %offset% AND ROWNUM <=%endrecord%"
limitationPosition,
DBObject.searchAndRetrieveList(),
DBObject.setOffsetRecord( int ),
DBObject.setMaxRecords( int )protected boolean checkZeroUpdate
protected EscapeHandler escapeHandler
protected long lastUsed
| Constructor Detail |
public DBConnectionPool()
| Method Detail |
protected DBConnection buildNewConnection()
throws DBException
DBException - upon error
protected DBConnection createNewConnection()
throws DBException
DBException - upon error
protected void cleanAvailable()
throws ConnectionPoolException
ConnectionPoolException
public void clean()
throws ConnectionPoolException,
DBException
DBException - If an error occurs releasing the stale connection
ConnectionPoolException - for other errors relating internally
to the connectionpool code.
public void disconnectAll()
throws DBException
DBException
public void executeExclusiveUpdate(String theSQL)
throws DBException
theSQL - the SQL code to execute.
DBException
public DBConnection getConnection()
throws ConnectionPoolException,
PoolFullException,
DBException
If none, make a new one if we can.
Does not set the new connection's description
This method will sleep for "interval" number of seconds if no connections are available and the pool is full. It then tries again to find or allocate a connection before failing.
DBException - If there's an error talking with the Database
PoolFullException - if we're unable to allocate a new connection because
the pool is full and we still haven't gotten a connection
ConnectionPoolException - for other connection-pool related errors.
author Yves Henri AMAIZO (Modification)
author Larry Hamel (Modification)protected void dumpDebugInfo()
protected boolean isFull()
public DBConnection getConnection(String connectionDescrip)
throws DBException
This version of getConnection sets the new connections description as well, avoiding a seperate call to setDescription
connectionDescrip - A description of the use of the database
connection
DBException - If the pool is not initialized or the connection
cannot be establishedpublic String getDBName()
public String getDataContext()
public static boolean supportsTransactions(String connName)
throws DBException
connName - the connection name
DBException
public boolean supportsTransactions()
throws DBException
DBException
public static DBConnectionPool getInstance(String dataContext)
throws DBException
DBException - If the alternate pool cannot be created,
for example if there is no connection by the given name
public static javax.sql.DataSource getDataSource(String dataContext)
throws SQLException
Note that performance of the resulting DataSource may be very slow since the datasource is a dumb connector, and does NOT consider the connection pool (because Expresso, at this time, has no way to register for a java.sql.Connection to be removed from the pool when the API programmer closes it)
dataContext - the data context to retrieve the data source for.
SQLException
public ArrayList getPoolList()
throws DBException
DBException - If the pool cannot be returnedpublic ArrayList getWildCardsList()
public boolean isInitialized()
public void release(DBConnection connectionToRelease)
connectionToRelease - The DBConnection to be released back to
the pool.public int getMaxConnections()
public void setMaxConnections(int newMax)
throws DBException
newMax - The new maximum number of connections
DBExceptionprotected void setDBName(String newDBName)
newDBName - The new dataContext to set for this connection poolprotected void setDataContext(String newDBName)
newDBName - The new dataContext to set for this connection poolpublic void setTestQuery(String newTestQuery)
newTestQuery - The string to execute as a test query
public void setTimeOutInterval(int newInterval)
throws DBException
newInterval - The new interval value in seconds
DBException
public static void reInitialize()
throws DBException
DBExceptionpublic int getLimitationPosition()
public void setLimitationPosition(int pos)
throws DBException
pos - the position
DBException - author Peter Pilgrim, Thu Jun 21 10:30:59 BST 2001public void setLimitationPosition(String pos)
pos - the position as a String
author Peter Pilgrim, Thu Jun 21 10:30:59 BST 2001public String getLimitationSyntax()
public EscapeHandler getEscapeHandler()
EscapeHandler for this data contextEscapeHandler,
DefaultEscapeHandlerpublic void setLimitationSyntax(String syntax)
syntax - the new syntax
author Peter Pilgrim, Thu Jun 21 10:30:59 BST 2001public void setDistinctRowsetKeyword(String keyword)
Sets the SQL keyword to remove duplicate records
from a database query. Most databases use the
"DISTINCT" keyword
(which is the default), other databases use
"UNIQUE".
Source: An old tatty copy of "Introduction to SQL"
keyword - the SQL keyword
author Peter PilgrimgetDistinctRowsetKeyword(),
DBObject.searchAndRetrieveList(),
DBObject.searchAndRetrieveList( String )public String getDistinctRowsetKeyword()
setDistinctRowsetKeyword( String ),
DBObject.searchAndRetrieveList(),
com.jcorporate.expresso.core.dbobj.DBObject#setFieldDistinct(java.lang.String, boolean))public void setCheckZeroUpdate(boolean newValue)
newValue - true if you want to check for zero updatespublic boolean getCheckZeroUpdate()
protected com.jcorporate.expresso.core.db.config.JNDIConfig getJNDIConfig(com.jcorporate.expresso.core.db.config.JDBCConfig curConfig)
throws ConnectionPoolException
curConfig - The current config that we hold.
ConnectionPoolException - upon error getting configuration
protected static com.jcorporate.expresso.core.db.config.JDBCConfig getJDBCConfig(String dataContext)
throws ConnectionPoolException
dataContext - The name of the data context to retrieve
ConnectionPoolException - upon error getting configurationpublic ArrayList getDefaultWildCards()
|
Expresso 5-6 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||