org.jcreme.sql
Class WrappedConnectionPool

java.lang.Object
  extended byorg.jcreme.pool.ObjectPool
      extended byorg.jcreme.sql.WrappedConnectionPool
All Implemented Interfaces:
ConnectionPool

public class WrappedConnectionPool
extends ObjectPool
implements ConnectionPool

This implementation of the ConnectionPool interface enables to pool WrappedConnection instances.

Version:
$Revision: 1.2 $
Author:
$Author: dbregeon $

Constructor Summary
WrappedConnectionPool(int minSize, int maxSize, java.lang.String url, java.util.Properties properties, IsolationLevel isolationLevel)
           
 
Method Summary
protected  java.lang.Object buildNew()
          This method enabled to build a new object when needed.
 void close()
          This method signals the pool it should close all the available connections.
 java.sql.Connection getConnection()
          This method provides a Connection to the database from the pool.
 java.sql.Connection getConnection(int waitingPeriod)
          This method provides a Connection to the database from the pool.
 void releaseConnection(java.sql.Connection conn)
          This method enables to return a Connection to the pool.
protected  void removeOld(java.lang.Object obj)
          This method enabled to remove an old object when needed.
 void setAutoCommit(boolean autoCommit)
          This method enables to change the commit policy of the ConnectionPool.
 void setTransactionIsolation(IsolationLevel isolationLevel)
          This method enables to change the isolation level used in the ConnectionPool.
 
Methods inherited from class org.jcreme.pool.ObjectPool
getFreeObjects, getObject, getObject, getObjectFromFree, getObjectFromFree, getObjectFromUsed, getUsedObjects, initPool, putInFreeObjects, putInUsedObjects, releaseObject, setMaximumSize, setMinimumSize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jcreme.sql.ConnectionPool
setMaximumSize, setMinimumSize
 

Constructor Detail

WrappedConnectionPool

public WrappedConnectionPool(int minSize,
                             int maxSize,
                             java.lang.String url,
                             java.util.Properties properties,
                             IsolationLevel isolationLevel)
Parameters:
minSize -
maxSize -
url -
properties -
isolationLevel -
Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
This method provides a Connection to the database from the pool. The Connection may be created on the spot or already exists. The pool guarantees that the Connection was released by its previous user, not that the previous user actually ceased to use it.

Specified by:
getConnection in interface ConnectionPool
Returns:
a ready to use Connection.
Throws:
java.sql.SQLException - if a problem occurs while trying to get a Connection.

getConnection

public java.sql.Connection getConnection(int waitingPeriod)
                                  throws java.sql.SQLException
This method provides a Connection to the database from the pool. The Connection may be created on the spot or already exists. The pool guarantees that the Connection was released by its previous user, not that the previous user actually ceased to use it. If the waiting period expires and no connection was available, it will return null.

Specified by:
getConnection in interface ConnectionPool
Parameters:
waitingPeriod - the number of milliseconds for which the method call will be blocked waiting for an available connection.
Returns:
a ready to use Connection or null if the waiting period expired.
Throws:
java.sql.SQLException - if a problem occurs while trying to get a Connection.

releaseConnection

public void releaseConnection(java.sql.Connection conn)
                       throws java.sql.SQLException
This method enables to return a Connection to the pool. Nothing is done if the Connection does not belong to the pool. The Connection should not be used after being released.

Specified by:
releaseConnection in interface ConnectionPool
Parameters:
conn - the Connection to be returned.
Throws:
java.sql.SQLException - if a problem occurs while trying to release a Connection.

close

public void close()
           throws java.sql.SQLException
This method signals the pool it should close all the available connections. This method usually is called when exiting an application. Connections provided by this pool should not be used after the close method has been called.

Specified by:
close in interface ConnectionPool
Throws:
java.sql.SQLException - if an error occurs while closing the pool.

buildNew

protected final java.lang.Object buildNew()
This method enabled to build a new object when needed. Any parameters needed should be provided by the actual ObjectPool implementation.

Specified by:
buildNew in class ObjectPool
Returns:
an new object for the pool.

setTransactionIsolation

public void setTransactionIsolation(IsolationLevel isolationLevel)
                             throws java.sql.SQLException
This method enables to change the isolation level used in the ConnectionPool.

Specified by:
setTransactionIsolation in interface ConnectionPool
Parameters:
isolationLevel - the new isolation level to apply.
Throws:
java.sql.SQLException - if a problem occurs while changing the isolation level.

setAutoCommit

public void setAutoCommit(boolean autoCommit)
                   throws java.sql.SQLException
This method enables to change the commit policy of the ConnectionPool.

Specified by:
setAutoCommit in interface ConnectionPool
Parameters:
autoCommit - the new commit policy to apply.
Throws:
java.sql.SQLException - if a problem occurs while changing the commit policy.

removeOld

protected void removeOld(java.lang.Object obj)
This method enabled to remove an old object when needed. It enables to free resources when an object is permanently removed from the ObjectPool.

Specified by:
removeOld in class ObjectPool
Parameters:
obj - the object to remove.


Copyright 2006 null. All Rights Reserved.