Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.lutris.appserver.server.sql
Class StandardDatabaseManager  view StandardDatabaseManager download StandardDatabaseManager.java

java.lang.Object
  extended bycom.lutris.appserver.server.sql.StandardDatabaseManager
All Implemented Interfaces:
DatabaseManager

public class StandardDatabaseManager
extends java.lang.Object
implements DatabaseManager

The standard database manager implementation. A database manager manages logical databases. It provides a single object from which database connections, object ids (OIDs), transactions and queries can be obtained. The configuration file specifies what logical database to create.

The configuration data is specified as follows:

For each logical database, there is a set of entry names in the form DatabaseManager.DB.dbname. Where dbname is one of the listed logical databases.

DatabaseManager.DB.dbname.ClassType - This is an optional field which specifies the class of the logical database implementation or a symbolic name if one on the standard types are selected. This is recommended because although JDBC abstracts the data access, the functionality of each database is slightly different and this parameter allows for optimised usage. The following are standard types:

Note that since a single SQL user is used to access the database by the entire application, connections maybe kept open, thus saving this overhead on each request. Connections are opened as desired until the maximum configured is reached.

If a thread needs to process a transaction, it requests a connection. If none are available, then a new connection is created up to the configured maximum. A thread is queued waiting for a connection to be returned if a new connection can't be created.

Note also that multiple logical names may map to the same actual database, making it easy to migrate databases if necessary and to provide access through multiple users.

Since:
LBS1.8
Version:
$Revision: 1.20.12.1 $

Field Summary
protected  boolean debug
          Controls debugging for Transactions and Queries.
private  LogicalDatabase defaultLogicalDatabase
          Default logical database.
private  java.util.Hashtable logicalDatabases
          Table of named logical databases.
 
Constructor Summary
StandardDatabaseManager(com.lutris.util.Config config)
          Creates a new DatabaseManager object and configures the logical databases defined in the config file.
 
Method Summary
 DBConnection allocateConnection()
          Allocate a connection to a thread.
 DBConnection allocateConnection(java.lang.String dbName)
          Allocate a connection to a thread.
 ObjectId allocateObjectId()
          Allocate an object id from the specified logical database.
 ObjectId allocateObjectId(java.lang.String dbName)
          Allocate an object id from the specified logical database.
 DBQuery createQuery()
          Create a query object for the default logical database.
 DBQuery createQuery(java.lang.String dbName)
          Create a query object for the specified logical database.
 DBTransaction createTransaction()
          Create a transaction object for the default logical database.
 DBTransaction createTransaction(java.lang.String dbName)
          Create a transaction object for the specified logical database.
private  LogicalDatabase findLogicalDatabase(java.lang.String dbName)
          Find the named logical database in hash table.
 int getActiveConnectionCount(java.lang.String dbName)
          Gets the number of currently active connections.
 java.lang.String[] getLogicalDatabaseNames()
          Returns the list of managed logical databases.
 int getMaxConnectionCount(java.lang.String dbName)
          Gets the maximum number of concurent connections that existed at any time since this object was created, or resetMaxConnectionCount() was called.
 java.util.Date getMaxConnectionCountDate(java.lang.String dbName)
          Gets the time when the maximum refered to by maxConnectionCount() occured.
 long getRequestCount(java.lang.String dbName)
          Gets the number of requests made to the database since startup time.
 java.lang.String getType(java.lang.String dbName)
          Returns a description of the logical database type.
 LogicalDatabase loadLogicalDatabase(java.lang.String dbName, com.lutris.util.Config dbConfig)
          Actually load the specified logical database.
 void resetMaxConnectionCount(java.lang.String dbName)
          Reset the maximum connection count.
 void setDebugLogging(boolean condition)
          Turn debugging on or off.
 void setDefaultDatabase(java.lang.String dbName)
          Set the default logical database.
 void shutdown()
          Shutdown the database manager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logicalDatabases

private java.util.Hashtable logicalDatabases
Table of named logical databases.


defaultLogicalDatabase

private LogicalDatabase defaultLogicalDatabase
Default logical database.


debug

protected boolean debug
Controls debugging for Transactions and Queries.

Constructor Detail

StandardDatabaseManager

public StandardDatabaseManager(com.lutris.util.Config config)
                        throws com.lutris.util.ConfigException,
                               DatabaseManagerException,
                               java.sql.SQLException
Creates a new DatabaseManager object and configures the logical databases defined in the config file.

Method Detail

loadLogicalDatabase

public LogicalDatabase loadLogicalDatabase(java.lang.String dbName,
                                           com.lutris.util.Config dbConfig)
                                    throws DatabaseManagerException
Actually load the specified logical database. This method provides an easy way to override the default behavour.


allocateConnection

public DBConnection allocateConnection(java.lang.String dbName)
                                throws DatabaseManagerException,
                                       java.sql.SQLException
Allocate a connection to a thread. The connection should be returned to the allocator by calling its release() function. A thread will wait if no connections are available. Interupted exceptions are converted to errors. N.B. Can't be synchronized, as connection allocator allocate may wait.

Specified by:
allocateConnection in interface DatabaseManager

allocateConnection

public DBConnection allocateConnection()
                                throws DatabaseManagerException,
                                       java.sql.SQLException
Allocate a connection to a thread. The connection should be returned to the allocator by calling its release() function. A thread will wait if no connections are available. Interupted exceptions are converted to errors. The connection is allocated from the default logical database.

Specified by:
allocateConnection in interface DatabaseManager

allocateObjectId

public ObjectId allocateObjectId(java.lang.String dbName)
                          throws DatabaseManagerException,
                                 ObjectIdException
Allocate an object id from the specified logical database.

Specified by:
allocateObjectId in interface DatabaseManager

allocateObjectId

public ObjectId allocateObjectId()
                          throws DatabaseManagerException,
                                 ObjectIdException
Allocate an object id from the specified logical database.

Specified by:
allocateObjectId in interface DatabaseManager

createTransaction

public DBTransaction createTransaction(java.lang.String dbName)
                                throws DatabaseManagerException,
                                       java.sql.SQLException
Create a transaction object for the specified logical database.

Specified by:
createTransaction in interface DatabaseManager

createTransaction

public DBTransaction createTransaction()
                                throws DatabaseManagerException,
                                       java.sql.SQLException
Create a transaction object for the default logical database.

Specified by:
createTransaction in interface DatabaseManager

createQuery

public DBQuery createQuery(java.lang.String dbName)
                    throws DatabaseManagerException,
                           java.sql.SQLException
Create a query object for the specified logical database.

Specified by:
createQuery in interface DatabaseManager

createQuery

public DBQuery createQuery()
                    throws DatabaseManagerException,
                           java.sql.SQLException
Create a query object for the default logical database.

Specified by:
createQuery in interface DatabaseManager

findLogicalDatabase

private LogicalDatabase findLogicalDatabase(java.lang.String dbName)
                                     throws DatabaseManagerException
Find the named logical database in hash table.


setDefaultDatabase

public void setDefaultDatabase(java.lang.String dbName)
                        throws DatabaseManagerException
Set the default logical database. This should only be called after the logical database ( has been established.

Specified by:
setDefaultDatabase in interface DatabaseManager

shutdown

public void shutdown()
Shutdown the database manager. All logical databases will be shutdown and all connections closed.

Specified by:
shutdown in interface DatabaseManager

getLogicalDatabaseNames

public java.lang.String[] getLogicalDatabaseNames()
Returns the list of managed logical databases.

Specified by:
getLogicalDatabaseNames in interface DatabaseManager

getType

public java.lang.String getType(java.lang.String dbName)
                         throws DatabaseManagerException
Returns a description of the logical database type.

Specified by:
getType in interface DatabaseManager

getRequestCount

public long getRequestCount(java.lang.String dbName)
                     throws DatabaseManagerException
Gets the number of requests made to the database since startup time.

Specified by:
getRequestCount in interface DatabaseManager

getActiveConnectionCount

public int getActiveConnectionCount(java.lang.String dbName)
                             throws DatabaseManagerException
Gets the number of currently active connections.

Specified by:
getActiveConnectionCount in interface DatabaseManager

getMaxConnectionCount

public int getMaxConnectionCount(java.lang.String dbName)
                          throws DatabaseManagerException
Gets the maximum number of concurent connections that existed at any time since this object was created, or resetMaxConnectionCount() was called. This is a historical highwater mark. If you do not implement this feature, return -1.

Specified by:
getMaxConnectionCount in interface DatabaseManager

getMaxConnectionCountDate

public java.util.Date getMaxConnectionCountDate(java.lang.String dbName)
                                         throws DatabaseManagerException
Gets the time when the maximum refered to by maxConnectionCount() occured.

Specified by:
getMaxConnectionCountDate in interface DatabaseManager

resetMaxConnectionCount

public void resetMaxConnectionCount(java.lang.String dbName)
                             throws DatabaseManagerException
Reset the maximum connection count. See maxConnectionCount(). The highwater mark should be reset to the current number of connections.

Specified by:
resetMaxConnectionCount in interface DatabaseManager

setDebugLogging

public void setDebugLogging(boolean condition)
Turn debugging on or off.