jodd.db.pool
Class CoreConnectionPool

java.lang.Object
  extended byjodd.db.pool.CoreConnectionPool
All Implemented Interfaces:
ConnectionPool, java.lang.Runnable

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

A class for preallocating, recycling, and managing JDBC connections. It uses threads for opening a new connection. When no connection availiable it will wait until a connection is released.

To Do:
add thread for cleaning non-necessary connections, from time to time.

Constructor Summary
CoreConnectionPool()
           
 
Method Summary
 void close()
          Close all the connections.
 void freeConnection(java.sql.Connection connection)
          Returns connection to connection pool.
 java.sql.Connection getConnection()
          Get one free connection from the connection pool.
 void init()
          Initialize pool with current object state.
 void run()
           
 void setDriver(java.lang.String s)
           
 void setMaxConnections(int i)
           
 void setMinConnections(int i)
           
 void setPassword(java.lang.String s)
           
 void setUrl(java.lang.String s)
           
 void setUser(java.lang.String s)
           
 void setWaitIfBusy(boolean b)
           
 int totalConnections()
           
 
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

setDriver

public void setDriver(java.lang.String s)

setUrl

public void setUrl(java.lang.String s)

setUser

public void setUser(java.lang.String s)

setPassword

public void setPassword(java.lang.String s)

setMaxConnections

public void setMaxConnections(int i)

setMinConnections

public void setMinConnections(int i)

setWaitIfBusy

public void setWaitIfBusy(boolean b)

init

public void init()
          throws java.sql.SQLException
Description copied from interface: ConnectionPool
Initialize pool with current object state.

Specified by:
init in interface ConnectionPool
Throws:
java.sql.SQLException

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Description copied from interface: ConnectionPool
Get one free connection from the connection pool.

Specified by:
getConnection in interface ConnectionPool
Returns:
Connection object representing free database connection
Throws:
java.sql.SQLException

run

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

freeConnection

public void freeConnection(java.sql.Connection connection)
Description copied from interface: ConnectionPool
Returns connection to connection pool.

Specified by:
freeConnection in interface ConnectionPool
Parameters:
connection - database connection

totalConnections

public int totalConnections()

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 ConnectionPool


Jodd v0.24.5 Javadoc