|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectsnaq.util.ObjectPool<CacheConnection>
snaq.db.ConnectionPool
public class ConnectionPool
Implementation of a database connection pool.
CacheConnection,
CachedCallableStatement,
CachedPreparedStatement| Field Summary |
|---|
| Fields inherited from class snaq.util.ObjectPool |
|---|
logger |
| Constructor Summary | |
|---|---|
ConnectionPool(String name,
int minPool,
int maxPool,
int maxSize,
long idleTimeout,
String url,
Properties props)
Creates a new ConnectionPool instance. |
|
ConnectionPool(String name,
int minPool,
int maxPool,
int maxSize,
long idleTimeout,
String url,
String username,
String password)
Creates a new ConnectionPool instance. |
|
ConnectionPool(String name,
int maxPool,
int maxSize,
long idleTimeout,
String url,
Properties props)
Creates a new ConnectionPool instance (with minPool=0). |
|
ConnectionPool(String name,
int maxPool,
int maxSize,
long idleTimeout,
String url,
String username,
String password)
Creates a new ConnectionPool instance (with minPool=0). |
|
| Method Summary | |
|---|---|
void |
addConnectionPoolListener(ConnectionPoolListener listener)
Adds a ConnectionPoolListener to the event notification list. |
protected CacheConnection |
create()
Creates a new Connection object. |
protected void |
destroy(CacheConnection cc)
Closes the specified CacheConnection object. |
protected void |
freeConnection(Connection c)
Returns a Connection to the pool (for internal use only). |
Connection |
getConnection()
Gets a Connection from the pool. |
Connection |
getConnection(long timeout)
Gets a Connection from the pool, waiting a maximum of
timeout milliseconds for one to become available,
returning null if not. |
protected float |
getIdleTimeoutMultiplier()
Returns the multiplier for adjusting the idle timeout unit. |
protected long |
getMaximumCleaningInterval()
Specifies the maximum time interval between cleaning attempts of the Cleaner thread. |
protected long |
getMinimumCleaningInterval()
Specifies the minimum time interval between cleaning attempts of the Cleaner thread. |
PasswordDecoder |
getPasswordDecoder()
Returns the current PasswordDecoder class. |
int |
getPoolSize()
Deprecated. Use ObjectPool.getMaxPool() instead. |
ConnectionValidator |
getValidator()
Returns the current ConnectionValidator class. |
boolean |
isCachingCallableStatements()
Returns whether the pool caches CallableStatement instances for each connection. |
boolean |
isCachingPreparedStatements()
Returns whether the pool caches PreparedStatement instances for each connection. |
boolean |
isCachingStatements()
Returns whether the pool caches Statement instances for each connection. |
boolean |
isRecycleAfterDelegateUse()
Returns whether connections may be recycled if the underlying raw/delegate connection has been used. |
protected boolean |
isValid(CacheConnection cc)
Validates a CacheConnection object. |
protected void |
postRelease()
Method to give a sub-class the opportunity to cleanup resources after the pool is officially released. |
void |
registerMBean()
Registers this pool with the platform MBean server. |
void |
removeConnectionPoolListener(ConnectionPoolListener listener)
Removes a ConnectionPoolListener from the event notification list. |
void |
setCaching(boolean b)
Determines whether to perform statement caching. |
void |
setCaching(boolean ss,
boolean ps,
boolean cs)
Determines whether to perform statement caching. |
void |
setPasswordDecoder(PasswordDecoder pd)
Sets the PasswordDecoder class. |
protected void |
setPoolAccessFIFO()
Sets the pool access method to FIFO (first-in, first-out: a queue). |
protected void |
setPoolAccessLIFO()
Sets the pool access method to LIFO (last-in, first-out: a stack). |
protected void |
setPoolAccessRandom()
Sets the pool access method to random (a random connection is selected for check-out). |
void |
setRecycleAfterDelegateUse(boolean b)
Sets whether the connection may be recycled if the underlying raw/delegate connection has been used (default: false). |
void |
setValidator(ConnectionValidator cv)
Sets the validator class for Connection instances. |
void |
unregisterMBean()
Removes this pool from the platform MBean server registration list. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public ConnectionPool(String name,
int minPool,
int maxPool,
int maxSize,
long idleTimeout,
String url,
String username,
String password)
ConnectionPool instance.
name - pool nameminPool - minimum number of pooled connections, or 0 for nonemaxPool - maximum number of pooled connections, or 0 for nonemaxSize - maximum number of possible connections, or 0 for no limitidleTimeout - idle timeout (seconds) for idle pooled connections, or 0 for no timeouturl - JDBC connection URLusername - database usernamepassword - password for the database username supplied
public ConnectionPool(String name,
int maxPool,
int maxSize,
long idleTimeout,
String url,
String username,
String password)
ConnectionPool instance (with minPool=0).
name - pool namemaxPool - maximum number of pooled connections, or 0 for nonemaxSize - maximum number of possible connections, or 0 for no limitidleTimeout - idle timeout (seconds) for idle pooled connections, or 0 for no timeouturl - JDBC connection URLusername - database usernamepassword - password for the database username supplied
public ConnectionPool(String name,
int minPool,
int maxPool,
int maxSize,
long idleTimeout,
String url,
Properties props)
ConnectionPool instance.
name - pool nameminPool - minimum number of pooled connections, or 0 for nonemaxPool - maximum number of pooled connections, or 0 for nonemaxSize - maximum number of possible connections, or 0 for no limitidleTimeout - idle timeout (seconds) for idle pooled connections, or 0 for no timeouturl - JDBC connection URLprops - connection properties
public ConnectionPool(String name,
int maxPool,
int maxSize,
long idleTimeout,
String url,
Properties props)
ConnectionPool instance (with minPool=0).
name - pool namemaxPool - maximum number of pooled connections, or 0 for nonemaxSize - maximum number of possible connections, or 0 for no limitidleTimeout - idle timeout (seconds) for idle pooled connections, or 0 for no timeouturl - JDBC connection URLprops - connection properties| Method Detail |
|---|
public void registerMBean()
javax.management API.
public void unregisterMBean()
javax.management API.
protected CacheConnection create()
throws SQLException
Connection object.
create in class ObjectPool<CacheConnection>SQLExceptionprotected boolean isValid(CacheConnection cc)
CacheConnection object.
isValid in class ObjectPool<CacheConnection>@Deprecated public final int getPoolSize()
ObjectPool.getMaxPool() instead.
public void setValidator(ConnectionValidator cv)
Connection instances.
public ConnectionValidator getValidator()
ConnectionValidator class.
public void setPasswordDecoder(PasswordDecoder pd)
PasswordDecoder class.
public PasswordDecoder getPasswordDecoder()
PasswordDecoder class.
protected void destroy(CacheConnection cc)
CacheConnection object.
destroy in class ObjectPool<CacheConnection>
public Connection getConnection()
throws SQLException
Connection from the pool.
null if nothing available
SQLException - if there is an error creating a new connection
public Connection getConnection(long timeout)
throws SQLException
Connection from the pool, waiting a maximum of
timeout milliseconds for one to become available,
returning null if not.
timeout - timeout value in milliseconds
null if nothing available within timeout period
SQLException - if there is an error getting a connection
protected void freeConnection(Connection c)
throws SQLException
Connection to the pool (for internal use only).
Connections obtained from the pool should be returned by calling
Connection.close().
SQLExceptionprotected void postRelease()
ObjectPoolObjectPool release implementation.
Be aware that the event-dispatch thread, cleaner thread, any init threads,
and the custom log have all been terminated before this method is called.
postRelease in class ObjectPool<CacheConnection>protected float getIdleTimeoutMultiplier()
ObjectPool
getIdleTimeoutMultiplier in class ObjectPool<CacheConnection>public void setCaching(boolean b)
public void setCaching(boolean ss,
boolean ps,
boolean cs)
ss - whether to cache Statement objectsps - whether to cache PreparedStatement objectscs - whether to cache CallableStatement objectspublic boolean isCachingStatements()
Statement instances for each connection.
public boolean isCachingPreparedStatements()
PreparedStatement instances for each connection.
public boolean isCachingCallableStatements()
CallableStatement instances for each connection.
protected final void setPoolAccessFIFO()
protected final void setPoolAccessLIFO()
protected final void setPoolAccessRandom()
public final void setRecycleAfterDelegateUse(boolean b)
Each CacheConnection instance tracks whether a call to
CacheConnection.getDelegateConnection() has been made, and by default
prevents recycling of the connection if so, in order to help maintain
integrity of the pool. In certain circumstances it may be beneficial in
terms of performance to enable such recycling, provided the raw connections
are not compromised in any way, and the CacheConnection.close()
method is called on each CacheConnection instance and NOT the
raw connection.
public boolean isRecycleAfterDelegateUse()
protected long getMinimumCleaningInterval()
Cleaner thread.
getMinimumCleaningInterval in class ObjectPool<CacheConnection>protected long getMaximumCleaningInterval()
Cleaner thread.
getMaximumCleaningInterval in class ObjectPool<CacheConnection>public final void addConnectionPoolListener(ConnectionPoolListener listener)
ConnectionPoolListener to the event notification list.
public final void removeConnectionPoolListener(ConnectionPoolListener listener)
ConnectionPoolListener from the event notification list.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||