org.apache.james.util.mordred
Class JdbcDataSource

java.lang.Object
  |
  +--org.apache.avalon.framework.logger.AbstractLoggable
        |
        +--org.apache.james.util.mordred.JdbcDataSource
All Implemented Interfaces:
org.apache.avalon.framework.component.Component, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.excalibur.datasource.DataSourceComponent, org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.logger.Loggable, java.lang.Runnable, org.apache.avalon.framework.thread.ThreadSafe

public class JdbcDataSource
extends org.apache.avalon.framework.logger.AbstractLoggable
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: 1.2 $ $Date: 2001/12/07 22:09:38 $
Author:
Serge Knystautas

Field Summary
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)
          Configure and set up DB connection.
protected  void debug(java.lang.String message)
           
 void dispose()
          Need to clean up all connections
 java.sql.Connection getConnection()
          Implements the ConnDefinition behavior when a connection is needed.
protected  void info(java.lang.String message)
           
 void killAllConnections()
          Deprecated. This was left over code from Town... but not exposed in Avalon.
 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.AbstractLoggable
getLogger, setLogger, 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

CONN_IDLE_LIMIT

public static final long CONN_IDLE_LIMIT
Constructor Detail

JdbcDataSource

public JdbcDataSource()
Method Detail

configure

public void configure(org.apache.avalon.framework.configuration.Configuration configuration)
               throws org.apache.avalon.framework.configuration.ConfigurationException
Configure and set up DB connection. Here we set the connection information needed to create the Connection objects.
Specified by:
configure in interface org.apache.avalon.framework.configuration.Configurable
Parameters:
conf - The Configuration object needed to describe the connection.
Throws:
org.apache.avalon.framework.configuration.ConfigurationException -  

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:
java.sql.Connection -  

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:
java.sql.Connection - the connection that had problems

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

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

killAllConnections

public void killAllConnections()
Deprecated. This was left over code from Town... but not exposed in Avalon.

Close all connections. The connection pooler will recreate these connections if something starts requesting them again.

dispose

public void dispose()
Need to clean up all connections
Specified by:
dispose in interface org.apache.avalon.framework.activity.Disposable

warn

protected void warn(java.lang.String message)

info

protected void info(java.lang.String message)

debug

protected void debug(java.lang.String message)


"Copyright © 2001 Apache Jakarta Project. All Rights Reserved."