|
DODS 6.5 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lutris.appserver.server.sql.StandardDatabaseManager
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:
DatabaseManager.Databases
-
A list of logical SQL database names.
DatabaseManager.DefaultDatabase
-
The default logical database used by this application. Optional,
if not specified, then the first entry in
"DatabaseManager.Databases" is used.
DatabaseManager.Debug
-
Specify true to enable Query and Transaction logging, false to
disable it. Optional, false if not specified.
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.
Field Summary | |
protected java.lang.String |
confDir
|
protected com.lutris.util.Config |
config
|
protected boolean |
debug
Controls debugging for Transactions and Queries. |
protected java.lang.String |
defaultDB
|
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. |
void |
checkOId(ObjectId oid)
Check does oid belong to Object id's range [minOId, currentOId] for default database |
void |
checkOId(java.lang.String dbName,
ObjectId oid)
Check does oid belong to Object id's range [minOId, currentOId] |
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. |
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. |
boolean |
getAllReadOnly()
Return allReadOnly parameter (given in config file) |
java.lang.String |
getAppName()
Return AppName parameter (given in config file) |
com.lutris.util.Config |
getConfig()
Return main configuration class |
DatabaseManagerConfiguration |
getDatabaseManagerConfiguration()
|
java.lang.String |
getDefaultDB()
Return default database name (given in config file) |
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. |
com.lutris.util.Config |
getParentConfig()
Return main application configuration class |
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. |
void |
initAllDodsCaches(com.lutris.util.Config config,
java.lang.ClassLoader cls)
Init chaches for all Databases specified in DatabaseManager section of application conf file. |
void |
initChaches(java.lang.ClassLoader clsLoader)
|
LogicalDatabase |
loadLogicalDatabase(java.lang.String dbName,
com.lutris.util.Config dbConfig)
Actually load the specified logical database. |
java.lang.String |
logicalDatabaseType()
Return a loical database type for the default logical database. |
java.lang.String |
logicalDatabaseType(java.lang.String dbName)
Return a loical database type for the specified logical database. |
static DatabaseManager |
newInstance(java.lang.String fileName)
Creates new StandardDatabaseManager instance. |
static DatabaseManager |
newInstance(java.net.URL confURL,
java.lang.String confFile)
Creates new StandardDatabaseManager instance. |
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 |
protected boolean debug
protected java.lang.String defaultDB
protected com.lutris.util.Config config
protected java.lang.String confDir
Constructor Detail |
public StandardDatabaseManager(com.lutris.util.Config config) throws com.lutris.util.ConfigException, DatabaseManagerException, java.sql.SQLException
DatabaseManager
object and configures
the logical databases defined in the config file.
config
- The configuration data for logical databases.
com.lutris.util.ConfigException
- If there is an error in the configuration file.
DatabaseManagerException
- If a logical database name is specified twice in the configuration file.
java.sql.SQLException
- If a SQL error occurs.Method Detail |
public void initChaches(java.lang.ClassLoader clsLoader)
public static DatabaseManager newInstance(java.net.URL confURL, java.lang.String confFile) throws com.lutris.util.ConfigException, DatabaseManagerException, java.sql.SQLException
StandardDatabaseManager
instance.
confURL
- Additional path to folder or *.jar file with configuration file. If null use DODS classpathconfFile
- Name of conf file relativ to *.jar file or to specifide folder (from confURL/DODS claspath).
StandardDatabaseManager
instance.
com.lutris.util.ConfigException
DatabaseManagerException
java.sql.SQLException
public static DatabaseManager newInstance(java.lang.String fileName) throws com.lutris.util.ConfigException, DatabaseManagerException, java.sql.SQLException
StandardDatabaseManager
instance.
fileName
- full path name of the application configuration file.
StandardDatabaseManager
instance.
com.lutris.util.ConfigException
DatabaseManagerException
java.sql.SQLException
public com.lutris.util.Config getConfig()
getConfig
in interface DatabaseManager
public com.lutris.util.Config getParentConfig()
public LogicalDatabase loadLogicalDatabase(java.lang.String dbName, com.lutris.util.Config dbConfig) throws DatabaseManagerException
DatabaseManagerException
- if an error occurs creating the logical database.public java.lang.String getDefaultDB()
getDefaultDB
in interface DatabaseManager
public DBConnection allocateConnection(java.lang.String dbName) throws DatabaseManagerException, java.sql.SQLException
allocate
may wait.
allocateConnection
in interface DatabaseManager
dbName
- Logical name of the database to allocate a connection to.
DatabaseManagerException
- If a nonexistent logical database name is supplied.
java.sql.SQLException
- If a SQL error occures.public DBConnection allocateConnection() throws DatabaseManagerException, java.sql.SQLException
allocateConnection
in interface DatabaseManager
DatabaseManagerException
- If no default logical database has been set.
java.sql.SQLException
- If a SQL error occurs.setDefaultDatabase(java.lang.String)
public ObjectId allocateObjectId(java.lang.String dbName) throws DatabaseManagerException, ObjectIdException
allocateObjectId
in interface DatabaseManager
dbName
- Logical name of the database from which to obtain an object id.
DatabaseManagerException
- If a nonexistent logical database name is supplied.
ObjectIdException
- If a problem (e.g. SQL error) occured in obtaining the OID.public ObjectId allocateObjectId() throws DatabaseManagerException, ObjectIdException
allocateObjectId
in interface DatabaseManager
DatabaseManagerException
- If a nonexistent default logical database has been set.
ObjectIdException
- If a problem (e.g. SQL error) occured in obtaining the OID.setDefaultDatabase(java.lang.String)
public void checkOId(java.lang.String dbName, ObjectId oid) throws DatabaseManagerException, ObjectIdException
checkOId
in interface DatabaseManager
dbName
- Logical name of the database from which to check an object id.oid
- oid which will be checked.
DatabaseManagerException
- If a nonexistent logical database name is supplied.
ObjectIdException
- If a oid does't belong to range.public void checkOId(ObjectId oid) throws DatabaseManagerException, ObjectIdException
checkOId
in interface DatabaseManager
oid
- oid which will be checked.
DatabaseManagerException
- If a nonexistent default logical database has been set.
ObjectIdException
- If a oid does't belong to range.public DBTransaction createTransaction(java.lang.String dbName) throws DatabaseManagerException, java.sql.SQLException
createTransaction
in interface DatabaseManager
dbName
- Logical name of the database from which to obtain a transaction.
DatabaseManagerException
- If a nonexistent or invalid logical database name is supplied.
java.sql.SQLException
- If a problem occured creating the transaction.public DBTransaction createTransaction() throws DatabaseManagerException, java.sql.SQLException
createTransaction
in interface DatabaseManager
DatabaseManagerException
- If a nonexistent default logical database has been set.
java.sql.SQLException
- If a problem occured creating the transaction.setDefaultDatabase(java.lang.String)
public DBQuery createQuery(java.lang.String dbName) throws DatabaseManagerException, java.sql.SQLException
createQuery
in interface DatabaseManager
dbName
- Logical name of the database from which to obtain a query.
DatabaseManagerException
- If a nonexistent or invalid logical database name is supplied.
java.sql.SQLException
- If a problem occured creating the query.public DBQuery createQuery() throws DatabaseManagerException, java.sql.SQLException
createQuery
in interface DatabaseManager
DatabaseManagerException
- If a nonexistent default logical database has been set.
java.sql.SQLException
- If a problem occured creating the query.setDefaultDatabase(java.lang.String)
public java.lang.String logicalDatabaseType(java.lang.String dbName) throws DatabaseManagerException, java.sql.SQLException
logicalDatabaseType
in interface DatabaseManager
dbName
- Logical name of the database from which to obtain a query.
DatabaseManagerException
- If a nonexistent or invalid logical database name is supplied.
java.sql.SQLException
- If a problem occured creating the query.DatabaseManager.setDefaultDatabase(java.lang.String)
public java.lang.String logicalDatabaseType() throws DatabaseManagerException, java.sql.SQLException
logicalDatabaseType
in interface DatabaseManager
DatabaseManagerException
- If a nonexistent default logical database has been set.
java.sql.SQLException
- If a problem occured creating the query.setDefaultDatabase(java.lang.String)
public LogicalDatabase findLogicalDatabase(java.lang.String dbName) throws DatabaseManagerException
findLogicalDatabase
in interface DatabaseManager
dbName
- Logical name of the database to locate.
DatabaseManagerException
- If a nonexistant logical database
name is supplied.public void setDefaultDatabase(java.lang.String dbName) throws DatabaseManagerException
setDefaultDatabase
in interface DatabaseManager
dbName
- The default logical database.
DatabaseManagerException
- if the logical database name is invalid or not found.public void shutdown()
shutdown
in interface DatabaseManager
public java.lang.String[] getLogicalDatabaseNames()
getLogicalDatabaseNames
in interface DatabaseManager
public java.lang.String getType(java.lang.String dbName) throws DatabaseManagerException
getType
in interface DatabaseManager
dbName
- The logical database name.
DatabaseManagerException
- If a nonexistent logical database name is supplied.public long getRequestCount(java.lang.String dbName) throws DatabaseManagerException
getRequestCount
in interface DatabaseManager
dbName
- The name of the logical database.
DatabaseManagerException
- If a nonexistent logical database name is supplied.public int getActiveConnectionCount(java.lang.String dbName) throws DatabaseManagerException
getActiveConnectionCount
in interface DatabaseManager
dbName
- The name of the logical database.
DatabaseManagerException
- If a nonexistent logical database name is supplied.public int getMaxConnectionCount(java.lang.String dbName) throws DatabaseManagerException
resetMaxConnectionCount()
was called.
This is a historical highwater mark.
If you do not implement this feature, return -1.
getMaxConnectionCount
in interface DatabaseManager
dbName
- The name of the logical database.
DatabaseManagerException
- If a nonexistent logical database name is supplied.public java.util.Date getMaxConnectionCountDate(java.lang.String dbName) throws DatabaseManagerException
maxConnectionCount()
occured.
getMaxConnectionCountDate
in interface DatabaseManager
dbName
- The name of the logical database.
DatabaseManagerException
- If a nonexistent logical database name is supplied.public void resetMaxConnectionCount(java.lang.String dbName) throws DatabaseManagerException
maxConnectionCount()
. The highwater mark should be
reset to the current number of connections.
resetMaxConnectionCount
in interface DatabaseManager
dbName
- The name of the logical database.
DatabaseManagerException
- If a nonexistent logical database name is supplied.public void setDebugLogging(boolean condition)
condition
- on of off.public boolean getAllReadOnly()
public java.lang.String getAppName()
public DatabaseManagerConfiguration getDatabaseManagerConfiguration()
public void initAllDodsCaches(com.lutris.util.Config config, java.lang.ClassLoader cls)
config
- DatabaseManager section of app configuration file.cls
- application classLoader
|
DODS 6.5 API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |