ERXJDBCConnectionBroker Class Reference

Inherits er::extensions::jdbc::ERXJDBCAdaptor::ConnectionBroker.

Collaboration diagram for ERXJDBCConnectionBroker:

Collaboration graph
[legend]

List of all members.

Classes

class  ConnectionWrapper

Public Member Functions

void freeConnection (Connection conn)
Connection getConnection ()
boolean supportsTransaction ()
String toString ()

Static Public Member Functions

static ERXJDBCConnectionBroker connectionBrokerForAdaptor (EOAdaptor adaptor)
static ERXJDBCConnectionBroker connectionBrokerForEntityNamed (String ename)
static ERXJDBCConnectionBroker connectionBrokerForEoInEditingContext (EOEnterpriseObject eo)
static ERXJDBCConnectionBroker connectionBrokerForModel (EOModel model)
static ERXJDBCConnectionBroker connectionBrokerForModelWithName (String modelName)

Static Public Attributes

static final Logger log = Logger.getLogger(ERXJDBCConnectionBroker.class)

Package Attributes

long maxConnectionMillis

Private Member Functions

Connection createConnection () throws SQLException
synchronized void createWrapper () throws SQLException
void destroy (int millis) throws SQLException
 ERXJDBCConnectionBroker (NSDictionary dict)
int getOpenChannelCount ()
void setup (NSDictionary dict, int maxCheckoutSecond)
ConnectionWrapper wrapperForConnection (Connection conn)

Static Private Member Functions

static synchronized
ERXJDBCConnectionBroker 
connectionBrokerForConnectionDictionary (NSDictionary d)
static ERXJDBCConnectionBroker newConnectionBrokerWithConnectionDictionary (NSDictionary dict)

Private Attributes

boolean active = true
int activeConnections
String dbDriver
String dbLogin
String dbPassword
String dbServer
int lastRoundRobinIndex
int maxCheckoutMillis
int maximumConnections
int minimumConnections
Thread pinger
Thread reaper
boolean supportsTransactions = false
ConnectionWrapper[] wrappers

Static Private Attributes

static Hashtable brokers = new Hashtable()
static final int DEFAULTMAXCHECKOUTSECONDS = 600


Detailed Description

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


Constructor & Destructor Documentation

ERXJDBCConnectionBroker ( NSDictionary  dict  )  [private]


Member Function Documentation

static ERXJDBCConnectionBroker connectionBrokerForAdaptor ( EOAdaptor  adaptor  )  [static]

static synchronized ERXJDBCConnectionBroker connectionBrokerForConnectionDictionary ( NSDictionary  d  )  [static, private]

static ERXJDBCConnectionBroker connectionBrokerForEntityNamed ( String  ename  )  [static]

static ERXJDBCConnectionBroker connectionBrokerForEoInEditingContext ( EOEnterpriseObject  eo  )  [static]

static ERXJDBCConnectionBroker connectionBrokerForModel ( EOModel  model  )  [static]

static ERXJDBCConnectionBroker connectionBrokerForModelWithName ( String  modelName  )  [static]

Connection createConnection (  )  throws SQLException [private]

synchronized void createWrapper (  )  throws SQLException [private]

void destroy ( int  millis  )  throws SQLException [private]

void freeConnection ( Connection  conn  ) 

Frees a connection. Replaces connection back into the main pool for reuse.

Implements ERXJDBCAdaptor.ConnectionBroker.

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.

Implements ERXJDBCAdaptor.ConnectionBroker.

int getOpenChannelCount (  )  [private]

static ERXJDBCConnectionBroker newConnectionBrokerWithConnectionDictionary ( NSDictionary  dict  )  [static, private]

void setup ( NSDictionary  dict,
int  maxCheckoutSecond 
) [private]

Housekeeping thread. Runs in the background with low CPU overhead. Connections are checked for warnings and closure and are periodically restarted. This thread is a catchall for corrupted connections and prevents the buildup of open cursors. (Open cursors result when the application fails to close a Statement). This method acts as fault tolerance for bad connection/statement programming.

Less safe shutdown. Uses default timeout value. This method simply calls the destroy() method with a millis value of 10000 (10 seconds) and ignores SQLException thrown by that method.

See also:
destroy(int)

boolean supportsTransaction (  ) 

String toString (  ) 

ConnectionWrapper wrapperForConnection ( Connection  conn  )  [private]

Returns the local JDBC ID for a connection.


Member Data Documentation

boolean active = true [private]

int activeConnections [private]

Hashtable brokers = new Hashtable() [static, private]

String dbDriver [private]

String dbLogin [private]

String dbPassword [private]

String dbServer [private]

final int DEFAULTMAXCHECKOUTSECONDS = 600 [static, private]

int lastRoundRobinIndex [private]

final Logger log = Logger.getLogger(ERXJDBCConnectionBroker.class) [static]

int maxCheckoutMillis [private]

long maxConnectionMillis [package]

int maximumConnections [private]

int minimumConnections [private]

Thread pinger [private]

Thread reaper [private]

boolean supportsTransactions = false [private]


The documentation for this class was generated from the following file:

Generated on Sat May 26 06:43:15 2012 for Project Wonder by  doxygen 1.5.8