org.rimudb
Class CompoundDatabase

java.lang.Object
  extended by org.rimudb.CompoundDatabase

public class CompoundDatabase
extends java.lang.Object

This class represents the connections to all the configured databases.

Author:
Simon Ritchie

Constructor Summary
CompoundDatabase(java.lang.String jdbcConfigurationFile, boolean validateXML)
          Create a CompositeDatabase from a configuration XML document.
 
Method Summary
protected  void assignDatabases()
           
 void connect(java.lang.String databaseID)
          Connect to the database identified by databaseID.
 void connect(java.lang.String databaseID, java.lang.String userID, java.lang.String password)
          Connect to the database identified by databaseID.
 void connectUsingCredentials()
          Connect to the database(s) using the DatabaseCredientials previously set.
 Session createSession(java.lang.Class<? extends DataObject> dataObjectClass)
           
 void createTable(java.lang.Class<? extends DataObject> dataObjectClass, boolean ignoreIfExists)
          Create the table for the dataObjectClass.
 void disconnectAll()
          Disconnect from all databases.
 void disconnectAllNoException()
          This is a convenience method for wrapping disconnectAll() in a try/catch.
 Database[] getAllDatabases()
          Return all databases.
 CompoundDatabaseLoader getConfigurationLoader()
           
 java.lang.String getCreateTableSQL(java.lang.Class<? extends DataObject> dataObjectClass, boolean ignoreIfExists, boolean prettyFormat)
          Return the create table statement for a data object class If no connected database can be found for the dataObjectClass, then a DatabaseException is thrown.
 java.util.List<DatabaseCredentials> getCredentialList()
          Return the list of DatabaseCredentials
 Database getDatabase(java.lang.Class<? extends DataObject> dataObjectClass)
          Return the Database for a Data Object class.
 Database getDatabase(java.lang.String databaseID)
          Return the Database identified by Database ID
 java.lang.String getDatabaseHost(java.lang.String databaseID)
          Return the database host for the databaseID.
 boolean isAnyConnected()
          Return true if at least one Database is connected.
 void setCredentialList(java.util.List<DatabaseCredentials> credentialList)
          Set the List of DatabaseCredentials.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompoundDatabase

public CompoundDatabase(java.lang.String jdbcConfigurationFile,
                        boolean validateXML)
                 throws java.lang.Exception
Create a CompositeDatabase from a configuration XML document. The XML document contains database connection information and dataobject association information. If validateXML is true, then the xml document will be validated against the XML schema.

Parameters:
jdbcConfigurationFile - String
validateXML - boolean
Throws:
java.lang.Exception
Method Detail

assignDatabases

protected void assignDatabases()
                        throws RimuDBException
Throws:
RimuDBException

connect

public void connect(java.lang.String databaseID)
             throws RimuDBException
Connect to the database identified by databaseID.

Parameters:
databaseID - String
Throws:
RimuDBException

connect

public void connect(java.lang.String databaseID,
                    java.lang.String userID,
                    java.lang.String password)
             throws RimuDBException
Connect to the database identified by databaseID.

Parameters:
databaseID - String
userID - String
password - String
Throws:
RimuDBException

createTable

public void createTable(java.lang.Class<? extends DataObject> dataObjectClass,
                        boolean ignoreIfExists)
                 throws RimuDBException
Create the table for the dataObjectClass. This is method is primarily intended for use in Unit Tests, where tables need to be created for in-memory databases. If no connected database can be found for the dataObjectClass, then a DatabaseException is thrown. If the URL for the database is not a supported in-memory database, a DatabaseException is thrown.

Parameters:
dataObjectClass -
ignoreIfExists -
Throws:
RimuDBException

getCreateTableSQL

public java.lang.String getCreateTableSQL(java.lang.Class<? extends DataObject> dataObjectClass,
                                          boolean ignoreIfExists,
                                          boolean prettyFormat)
                                   throws RimuDBException
Return the create table statement for a data object class If no connected database can be found for the dataObjectClass, then a DatabaseException is thrown. Set prettyFormat to true to return the DDL in an easily readable format.

Parameters:
dataObjectClass - Class
ignoreIfExists -
prettyFormat - boolean If true then the DDL is returned in an easily readable format.
Returns:
String
Throws:
RimuDBException

getDatabase

public Database getDatabase(java.lang.String databaseID)
Return the Database identified by Database ID

Parameters:
databaseID - String
Returns:
Database

getDatabase

public Database getDatabase(java.lang.Class<? extends DataObject> dataObjectClass)
                     throws RimuDBConfigurationException
Return the Database for a Data Object class. Only connected databases are returned. If no connected databases are found then a DatabaseException is thrown.

Parameters:
dataObjectClass - Class
Returns:
Database
Throws:
RimuDBException
RimuDBConfigurationException

getAllDatabases

public Database[] getAllDatabases()
Return all databases.

Returns:
Database[]

disconnectAll

public void disconnectAll()
                   throws RimuDBException
Disconnect from all databases.

Throws:
RimuDBException

disconnectAllNoException

public void disconnectAllNoException()
This is a convenience method for wrapping disconnectAll() in a try/catch. disconnectAll() throws a DatabaseException, but since we're in close or shutdown mode, the Exception is probably unrecoverable or we don't care. So, this method avoid having to have another try/catch in every finally block that CompositeDatabase is used.


isAnyConnected

public boolean isAnyConnected()
Return true if at least one Database is connected.

Returns:
boolean

getConfigurationLoader

public CompoundDatabaseLoader getConfigurationLoader()

createSession

public Session createSession(java.lang.Class<? extends DataObject> dataObjectClass)
                      throws RimuDBException
Throws:
RimuDBException

setCredentialList

public void setCredentialList(java.util.List<DatabaseCredentials> credentialList)
Set the List of DatabaseCredentials. This method can be used together with connectUsingCredentials() instead of the connect(databaseID...) methods.

Parameters:
credentialList - List

getCredentialList

public java.util.List<DatabaseCredentials> getCredentialList()
Return the list of DatabaseCredentials

Returns:
List

connectUsingCredentials

public void connectUsingCredentials()
                             throws RimuDBException
Connect to the database(s) using the DatabaseCredientials previously set.

Throws:
RimuDBException

getDatabaseHost

public java.lang.String getDatabaseHost(java.lang.String databaseID)
                                 throws RimuDBException
Return the database host for the databaseID.

Parameters:
databaseID -
Returns:
The database host
Throws:
RimuDBException


Copyright © 2008-2011 Simon Ritchie. All Rights Reserved.