org.apache.james.util.mordred
Class JdbcDataSource

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.james.util.mordred.JdbcDataSource
All Implemented Interfaces:
java.lang.Runnable, org.apache.avalon.excalibur.datasource.DataSourceComponent, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.component.Component, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.logger.LogEnabled, org.apache.avalon.framework.thread.ThreadSafe

public class JdbcDataSource
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements org.apache.avalon.framework.configuration.Configurable, java.lang.Runnable, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.excalibur.datasource.DataSourceComponent

This is a reliable DataSource implementation, based on the pooling logic written for Town and the configuration found in Avalon's excalibur code.

This uses the normal java.sql.Connection object and java.sql.DriverManager. The Configuration is like this:

   <jdbc>
     <pool-controller min="5" max="10" connection-class="my.overrided.ConnectionClass">
       <keep-alive>select 1</keep-alive>
     </pool-controller>
     <driver>com.database.jdbc.JdbcDriver</driver>
     <dburl>jdbc:driver://host/mydb</dburl>
     <user>username</user>
     <password>password</password>
   </jdbc>
 

Since:
4.0
Version:
CVS $Revision: 494012 $

Field Summary
static long ACTIVE_CONN_HARD_TIME_LIMIT
           
static long ACTIVE_CONN_TIME_LIMIT
           
static long CONN_IDLE_LIMIT
           
 
Fields inherited from interface org.apache.avalon.excalibur.datasource.DataSourceComponent
ROLE
 
Constructor Summary
JdbcDataSource()
           
 
Method Summary
 void configure(org.apache.avalon.framework.configuration.Configuration configuration)
           
protected  void debug(java.lang.String message)
           
 void dispose()
          The dispose operation is called at the end of a components lifecycle.
 java.sql.Connection getConnection()
          Implements the ConnDefinition behavior when a connection is needed.
protected  void info(java.lang.String message)
           
 void killConnection(PoolConnEntry entry)
          Deprecated. - No longer used in the new approach.
 void releaseConnection(PoolConnEntry entry)
          Implements the ConnDefinition behavior when a connection is no longer needed.
 void run()
          Background thread that checks if there are fewer connections open than minConn specifies, and checks whether connections have been checked out for too long, killing them.
protected  void warn(java.lang.String message)
           
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ACTIVE_CONN_TIME_LIMIT

public static final long ACTIVE_CONN_TIME_LIMIT
See Also:
Constant Field Values

ACTIVE_CONN_HARD_TIME_LIMIT

public static final long ACTIVE_CONN_HARD_TIME_LIMIT
See Also:
Constant Field Values

CONN_IDLE_LIMIT

public static final long CONN_IDLE_LIMIT
See Also:
Constant Field Values
Constructor Detail

JdbcDataSource

public JdbcDataSource()
Method Detail

getConnection

public java.sql.Connection getConnection()
                                  throws java.sql.SQLException
Implements the ConnDefinition behavior when a connection is needed. Checks the pool of connections to see if there is one available. If there is not and we are below the max number of connections limit, it tries to create another connection. It retries this 10 times until a connection is available or can be created

Specified by:
getConnection in interface org.apache.avalon.excalibur.datasource.DataSourceComponent
Returns:
java.sql.Connection
Throws:
java.sql.SQLException - Document throws!

configure

public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Throws:
org.apache.avalon.framework.configuration.ConfigurationException
See Also:
Configurable.configure(Configuration)

dispose

public void dispose()
The dispose operation is called at the end of a components lifecycle. Cleans up all JDBC connections.

Specified by:
dispose in interface org.apache.avalon.framework.activity.Disposable
Throws:
java.lang.Exception - if an error is encountered during shutdown

killConnection

public void killConnection(PoolConnEntry entry)
Deprecated. - No longer used in the new approach.

Implements the ConnDefinition behavior when something bad has happened to a connection. If a sql command was provided in the properties file, it will run this and attempt to determine whether the connection is still valid. If it is, it recycles this connection back into the pool. If it is not, it closes the connection.

Parameters:
entry - the connection that had problems

releaseConnection

public void releaseConnection(PoolConnEntry entry)
Implements the ConnDefinition behavior when a connection is no longer needed. This resets flags on the wrapper of the connection to allow others to use this connection.

Parameters:
entry -

run

public void run()
Background thread that checks if there are fewer connections open than minConn specifies, and checks whether connections have been checked out for too long, killing them.

Specified by:
run in interface java.lang.Runnable

debug

protected void debug(java.lang.String message)

info

protected void info(java.lang.String message)

warn

protected void warn(java.lang.String message)


Copyright © 2002-2007 The Apache Software Foundation. All Rights Reserved.