org.tentackle.db
Class DefaultDbPool

java.lang.Object
  extended by org.tentackle.db.DefaultDbPool
All Implemented Interfaces:
DbPool

public class DefaultDbPool
extends Object
implements DbPool

An implementation of a database pool.
It allows min/max sizes, fixed increments and timeouts for unused instances.

The pool can be used with any ConnectionManager. If used with the DefaultConnectionManager, each Db instance corresponds to a physical JDBC-connection. If used with an MpxConnectionManager, the Db instances map to virtual connections that will be attached temporarily during db-operations, i.e. the AppDbObjectCache will retain its data across sessions (if not closed due to idle timeout). This is the preferred configuration in server applications with a lot of clients. In order to clear the AppDbCache on db-close, you have to override the closeDb method.


Constructor Summary
DefaultDbPool(String name, ConnectionManager conMgr, UserInfo userInfo, int iniSize, int incSize, int minSize, int maxSize, int maxMinutes)
          Creates a pool.
DefaultDbPool(UserInfo ui)
          Creates a pool useful for most servers.
Using the default connection manager.
 
Method Summary
protected  Db cloneDb(Db db)
          Clones the masterDb to create a new Db instance.
The method can be overridden if there is something to do after/before close.
protected  void closeDb(Db db)
          Closes a db.
The method can be overridden if there is something to do after/before close.
 Db getDb()
          Gets a Db instance from the pool.
 int getMaxSize()
          Gets the maximum poolsize.
 int getSize()
          Gets the current number of Db instances.
 void putDb(Db db)
          Returns a Db instance to the pool.
 void shutdown()
          Closes all databases in the pool, cleans up and makes the pool unusable.
 String toString()
          Gets the pool's name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DefaultDbPool

public DefaultDbPool(String name,
                     ConnectionManager conMgr,
                     UserInfo userInfo,
                     int iniSize,
                     int incSize,
                     int minSize,
                     int maxSize,
                     int maxMinutes)
Creates a pool.

Parameters:
name - the name of the pool
conMgr - the connection manager to use for new Db instances
userInfo - the userinfo for the created Db
iniSize - the initial poolsize
incSize - the number of Db instances to enlarge the pool if all in use
minSize - the minimum number of Db instances to keep in pool
maxSize - the maximum number of Db instances, 0 = unlimited
maxMinutes - the timeout in minutes to close unused Db instances, 0 = never close

DefaultDbPool

public DefaultDbPool(UserInfo ui)
Creates a pool useful for most servers.
Using the default connection manager. Starts with 8 Db instances, increments by 2, minSize 4, maxSize from connection manager. Timeout 1 hour.

Parameters:
ui - the userinfo for the created Db
Method Detail

toString

public String toString()
Gets the pool's name

Overrides:
toString in class Object
Returns:
a string representation of the object.

closeDb

protected void closeDb(Db db)
Closes a db.
The method can be overridden if there is something to do after/before close. For example, cleaning up the cache, etc...

Parameters:
db - the Db instance to close

cloneDb

protected Db cloneDb(Db db)
Clones the masterDb to create a new Db instance.
The method can be overridden if there is something to do after/before close.

Parameters:
db - the master Db instance to clone
Returns:
the cloned db

shutdown

public void shutdown()
Closes all databases in the pool, cleans up and makes the pool unusable.

Specified by:
shutdown in interface DbPool

getMaxSize

public int getMaxSize()
Description copied from interface: DbPool
Gets the maximum poolsize.

Specified by:
getMaxSize in interface DbPool
Returns:
the max. number of concurrent Db instances, 0 = unlimited

getSize

public int getSize()
Description copied from interface: DbPool
Gets the current number of Db instances.

Specified by:
getSize in interface DbPool
Returns:
the number of Db managed by this pool

getDb

public Db getDb()
         throws DbRuntimeException
Description copied from interface: DbPool
Gets a Db instance from the pool.

Specified by:
getDb in interface DbPool
Returns:
an open Db ready for use, never null
Throws:
DbRuntimeException - if pool is exhausted

putDb

public void putDb(Db db)
           throws DbRuntimeException
Description copied from interface: DbPool
Returns a Db instance to the pool.

Notice: returning a Db to the pool more than once is allowed.

Specified by:
putDb in interface DbPool
Parameters:
db - the Db instance
Throws:
DbRuntimeException - if the Db cannot be returned


Copyright © 2001-2008 Harald Krake, Bergstr. 48, 78098 Triberg, Germany, harald@krake.de