Project Wonder 5.0

er.extensions.jdbc
Class ERXJDBCConnectionBroker

java.lang.Object
  extended by er.extensions.jdbc.ERXJDBCConnectionBroker
All Implemented Interfaces:
ERXJDBCAdaptor.ConnectionBroker

public class ERXJDBCConnectionBroker
extends java.lang.Object
implements ERXJDBCAdaptor.ConnectionBroker

Creates and manages a pool of JDBC connections. Useful for SQL statements without using / blocking EOF. Maintains one broker per each distinct connection dictionary. Connections are created on demand but not freed. You can change the behaviour of the broker by setting some parameters either via the system properties as dbSomePropertyGLOBAL, ModelName.DBSomeProperty or as someProperty in the connection dictionary.

minConnections
Minimum number of connections, default 1
maxConnections
Maximum number of connections, default 1
maxCheckout
Maximum number of seconds a connection should stay checked out, default 600
connectionRecycle
Number of days a connection should stay active, default 1.0
The er.extensions.components.ERXConfigurationManager adds these entries to each EOModels connectionDictionary.
Usage: check out a connection:
 java.sql.Connection con = ERXJDBCConnectionBroker.connectionBrokerForModel(myModel).getConnection();
 try {
     java.sql.Statement s = con.createStatement();
     //now do something with the Statement
 } finally {
     ERXJDBCConnectionBroker.connectionBrokerForModel(myModel).freeConnection(con);
 }
 

Author:
Marc A. Mnich, based on version 1.0.13 3/12/02, david@cluster9.com original Wonder version, ak Major refactoring

Field Summary
static org.apache.log4j.Logger log
           
 
Method Summary
static ERXJDBCConnectionBroker connectionBrokerForAdaptor(com.webobjects.eoaccess.EOAdaptor adaptor)
           
static ERXJDBCConnectionBroker connectionBrokerForEntityNamed(java.lang.String ename)
           
static ERXJDBCConnectionBroker connectionBrokerForEoInEditingContext(com.webobjects.eocontrol.EOEnterpriseObject eo)
           
static ERXJDBCConnectionBroker connectionBrokerForModel(com.webobjects.eoaccess.EOModel model)
           
static ERXJDBCConnectionBroker connectionBrokerForModelWithName(java.lang.String modelName)
           
 void freeConnection(java.sql.Connection conn)
          Frees a connection.
 java.sql.Connection getConnection()
          This method hands out the connections in round-robin order.
 boolean supportsTransaction()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log

public static final org.apache.log4j.Logger log
Method Detail

connectionBrokerForModelWithName

public static ERXJDBCConnectionBroker connectionBrokerForModelWithName(java.lang.String modelName)

connectionBrokerForModel

public static ERXJDBCConnectionBroker connectionBrokerForModel(com.webobjects.eoaccess.EOModel model)

connectionBrokerForEoInEditingContext

public static ERXJDBCConnectionBroker connectionBrokerForEoInEditingContext(com.webobjects.eocontrol.EOEnterpriseObject eo)

connectionBrokerForEntityNamed

public static ERXJDBCConnectionBroker connectionBrokerForEntityNamed(java.lang.String ename)

connectionBrokerForAdaptor

public static ERXJDBCConnectionBroker connectionBrokerForAdaptor(com.webobjects.eoaccess.EOAdaptor adaptor)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getConnection

public java.sql.Connection getConnection()
This method hands out the connections in round-robin order. This prevents a faulty connection from locking up an application entirely. A browser 'refresh' will get the next connection while the faulty connection is cleaned up by the housekeeping thread. If the min number of threads are ever exhausted, new threads are added up the the max thread count. Finally, if all threads are in use, this method waits 2 seconds and tries again, up to ten times. After that, it returns a null.

Specified by:
getConnection in interface ERXJDBCAdaptor.ConnectionBroker

freeConnection

public void freeConnection(java.sql.Connection conn)
Frees a connection. Replaces connection back into the main pool for reuse.

Specified by:
freeConnection in interface ERXJDBCAdaptor.ConnectionBroker

supportsTransaction

public boolean supportsTransaction()

Last updated: Tue, Feb 21, 2017 • 05:45 PM CET

Copyright © 2002 – 2007 Project Wonder.