org.paneris.jal.model
Class DBConnectionManager

java.lang.Object
  extended by org.paneris.jal.model.DBConnectionManager

public class DBConnectionManager
extends java.lang.Object

This class is a Singleton that provides access to one or many connection pools for databases defined in a Property file. A client gets access to the single instance through the static getInstance() method and can then check-out and check-in connections from a pool. When the client shuts down it should call the release() method to close all open connections and do other clean up.


Field Summary
static int ACCESS
           
static int MYSQL
           
static int POSTGRES
           
static int UNKNOWN
          Constants representing different RDBMSs
 
Method Summary
 void freeConnection(java.lang.String name, java.sql.Connection con)
          Returns a connection to the named pool.
 java.sql.Connection getConnection(java.lang.String callingClass, java.lang.String name)
          Returns an open connection.
 java.sql.Connection getConnection(java.lang.String callingClass, java.lang.String name, long time)
          Returns an open connection.
 int getDatabaseEngineType(java.lang.String db)
          get the database name
 java.lang.String getDatabaseProductVersion(java.lang.String db)
          get the database version
static DBConnectionManager getInstance()
          Returns the single instance, creating one if it's the first time this method is called.
 java.util.Hashtable getPools()
          get the pool names
 java.lang.String getUploadDir()
          get the upload directory
 void release()
          Closes all open connections and deregisters all drivers.
 java.lang.String sqlFalse(java.lang.String db)
          Database-dependent representation of a 'false' boolean value
 java.lang.String sqlToday(java.lang.String db)
          Database-dependent SQL operator to insert today's date
 java.lang.String sqlTrue(java.lang.String db)
          Database-dependent representation of a 'true' boolean value
 java.lang.String sqlUppercaseOperator(java.lang.String db)
          Database-dependent SQL operator to uppercase a value
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNKNOWN

public static final int UNKNOWN
Constants representing different RDBMSs

See Also:
Constant Field Values

POSTGRES

public static final int POSTGRES
See Also:
Constant Field Values

ACCESS

public static final int ACCESS
See Also:
Constant Field Values

MYSQL

public static final int MYSQL
See Also:
Constant Field Values
Method Detail

getInstance

public static DBConnectionManager getInstance()
Returns the single instance, creating one if it's the first time this method is called.

Returns:
DBConnectionManager The single instance.

freeConnection

public void freeConnection(java.lang.String name,
                           java.sql.Connection con)
Returns a connection to the named pool.

Parameters:
name - The pool name as defined in the properties file
con - The Connection

getPools

public java.util.Hashtable getPools()
get the pool names

Returns:
Enumeration A list of names

getUploadDir

public java.lang.String getUploadDir()
get the upload directory


getDatabaseEngineType

public int getDatabaseEngineType(java.lang.String db)
get the database name

Parameters:
db - The name of the database
Returns:
int A list of names

getDatabaseProductVersion

public java.lang.String getDatabaseProductVersion(java.lang.String db)
                                           throws java.lang.Exception
get the database version

Throws:
java.lang.Exception

getConnection

public java.sql.Connection getConnection(java.lang.String callingClass,
                                         java.lang.String name)
Returns an open connection. If no one is available, and the max number of connections has not been reached, a new connection is created.

Parameters:
name - The pool name as defined in the properties file
Returns:
Connection The connection or null

getConnection

public java.sql.Connection getConnection(java.lang.String callingClass,
                                         java.lang.String name,
                                         long time)
Returns an open connection. If no one is available, and the max number of connections has not been reached, a new connection is created. If the max number has been reached, waits until one is available or the specified time has elapsed.

Parameters:
name - The pool name as defined in the properties file
time - The number of milliseconds to wait
Returns:
Connection The connection or null

release

public void release()
Closes all open connections and deregisters all drivers.


sqlUppercaseOperator

public java.lang.String sqlUppercaseOperator(java.lang.String db)
                                      throws java.lang.Exception
Database-dependent SQL operator to uppercase a value

Parameters:
db - The name of the database
Returns:
Connection The connection or null
Throws:
java.lang.Exception

sqlToday

public java.lang.String sqlToday(java.lang.String db)
                          throws java.lang.Exception
Database-dependent SQL operator to insert today's date

Throws:
java.lang.Exception

sqlTrue

public java.lang.String sqlTrue(java.lang.String db)
Database-dependent representation of a 'true' boolean value


sqlFalse

public java.lang.String sqlFalse(java.lang.String db)
Database-dependent representation of a 'false' boolean value



Copyright © 2000-2008 PanEris. All Rights Reserved.