jodd.db.pool
Class CoreConnectionPool

java.lang.Object
  extended by jodd.db.pool.CoreConnectionPool
All Implemented Interfaces:
java.lang.Runnable, ConnectionProvider

public class CoreConnectionPool
extends java.lang.Object
implements java.lang.Runnable, ConnectionProvider

A class for pre-allocating, recycling, and managing JDBC connections.

It uses threads for opening a new connection. When no connection available it will wait until a connection is released.


Nested Class Summary
static class CoreConnectionPool.SizeSnapshot
          Just a statistic class.
 
Constructor Summary
CoreConnectionPool()
           
 
Method Summary
 void close()
          Close all the connections.
 void closeConnection(java.sql.Connection connection)
          Dispose of a used connection.
 java.sql.Connection getConnection()
          Get a connection.
 CoreConnectionPool.SizeSnapshot getConnectionsCount()
          Returns connection stats.
 java.lang.String getDriver()
           
 int getMaxConnections()
           
 int getMinConnections()
           
 java.lang.String getPassword()
           
 java.lang.String getUrl()
           
 java.lang.String getUser()
           
 java.lang.String getValidationQuery()
           
 long getValidationTimeout()
           
 void init()
          Initialize the connection provider.
 boolean isValidateConnection()
           
 boolean isWaitIfBusy()
           
 void run()
           
 void setDefaultValidationQuery()
          Sets default validation query (select 1);
 void setDriver(java.lang.String driver)
          Specifies driver class name.
 void setMaxConnections(int maxConnections)
          Sets max number of connections.
 void setMinConnections(int minConnections)
          Sets minimum number of open connections.
 void setPassword(java.lang.String password)
          Specifies db password.
 void setUrl(java.lang.String url)
          Specifies JDBC url.
 void setUser(java.lang.String user)
          Specifies db username.
 void setValidateConnection(boolean validateConnection)
          Specifies if connections should be validated before returned.
 void setValidationQuery(java.lang.String validationQuery)
          Specifies query to be used for validating connections.
 void setValidationTimeout(long validationTimeout)
          Specifies number of milliseconds from connection creation when connection is considered as opened and valid.
 void setWaitIfBusy(boolean waitIfBusy)
          Sets if pool should wait for connection to be freed when none is available.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CoreConnectionPool

public CoreConnectionPool()
Method Detail

getDriver

public java.lang.String getDriver()

setDriver

public void setDriver(java.lang.String driver)
Specifies driver class name.


getUrl

public java.lang.String getUrl()

setUrl

public void setUrl(java.lang.String url)
Specifies JDBC url.


getUser

public java.lang.String getUser()

setUser

public void setUser(java.lang.String user)
Specifies db username.


getPassword

public java.lang.String getPassword()

setPassword

public void setPassword(java.lang.String password)
Specifies db password.


getMaxConnections

public int getMaxConnections()

setMaxConnections

public void setMaxConnections(int maxConnections)
Sets max number of connections.


getMinConnections

public int getMinConnections()

setMinConnections

public void setMinConnections(int minConnections)
Sets minimum number of open connections.


isWaitIfBusy

public boolean isWaitIfBusy()

setWaitIfBusy

public void setWaitIfBusy(boolean waitIfBusy)
Sets if pool should wait for connection to be freed when none is available. If wait for busy is false exception will be thrown when max connection is reached.


getValidationTimeout

public long getValidationTimeout()

setValidationTimeout

public void setValidationTimeout(long validationTimeout)
Specifies number of milliseconds from connection creation when connection is considered as opened and valid.


getValidationQuery

public java.lang.String getValidationQuery()

setValidationQuery

public void setValidationQuery(java.lang.String validationQuery)
Specifies query to be used for validating connections. If set to null validation will be performed by invoking Connection#isClosed method.


setDefaultValidationQuery

public void setDefaultValidationQuery()
Sets default validation query (select 1);


isValidateConnection

public boolean isValidateConnection()

setValidateConnection

public void setValidateConnection(boolean validateConnection)
Specifies if connections should be validated before returned.


init

public void init()
Initialize the connection provider. Properties are provided either with constructor either with bean setters.

Specified by:
init in interface ConnectionProvider

getConnection

public java.sql.Connection getConnection()
Get a connection.

Specified by:
getConnection in interface ConnectionProvider

run

public void run()
Specified by:
run in interface java.lang.Runnable

closeConnection

public void closeConnection(java.sql.Connection connection)
Description copied from interface: ConnectionProvider
Dispose of a used connection.

Specified by:
closeConnection in interface ConnectionProvider

close

public void close()
Close all the connections. Use with caution: be sure no connections are in use before calling. Note that you are not required to call this when done with a ConnectionPool, since connections are guaranteed to be closed when garbage collected. But this method gives more control regarding when the connections are closed.

Specified by:
close in interface ConnectionProvider

getConnectionsCount

public CoreConnectionPool.SizeSnapshot getConnectionsCount()
Returns connection stats.



Copyright © 2003-2011 Jodd Team