org.objectweb.cjdbc.controller.backend
Class DatabaseBackend

java.lang.Object
  extended byorg.objectweb.cjdbc.controller.backend.DatabaseBackend
All Implemented Interfaces:
java.io.Serializable

public class DatabaseBackend
extends java.lang.Object
implements java.io.Serializable

A DatabaseBackend represents a real database backend that will have to be bound to a virtual C-JDBC database. All connections opened will use the same url but possibly different login/password.

Version:
1.0
Author:
Emmanuel Cecchet, Mathieu Peltier, Sara Bouchenak, Nicolas Modrzyk
See Also:
Serialized Form

Field Summary
private  java.util.Vector activeTransactions
          List of started transactions.
private  java.util.HashMap connectionManagers
          Connection managers for this backend.
private  java.lang.String driverClassName
          Database native JDBC driver class name.
private  DriverCompliance driverCompliance
          Driver compliance to C-JDBC requirements
private  boolean isEnabled
          Is this bakend enabled.
protected  Trace logger
          Logger instance.
private  java.lang.String name
          Logical name assigned to this backend.
private  java.util.Vector pendingRequests
          List of pending requests.
private  DatabaseSchema schema
          The schema of the database.
private  boolean schemaIsStatic
          true if schema is static.
private  java.lang.String url
          Real URL to access the database (JDBC URL).
 
Constructor Summary
DatabaseBackend(java.lang.String name, java.lang.String driverClassName, java.lang.String url, boolean isEnabled)
          Creates a new DatabaseBackend instance.
 
Method Summary
 void addConnectionManager(java.lang.String vLogin, AbstractConnectionManager connectionManager)
          Adds a ConnectionManager to this backend.
 void addPendingRequest(AbstractRequest request)
          Adds a pending request to this backend.
 void checkDatabaseSchema()
          Checks that the current database schema is compatible with all schema gathered from each connection manager.
 void checkDriverCompliance()
          Check if the driver used by this backend is compliant with C-JDBC needs.
 void disable()
          Sets the database backend state to disable.
 void enable()
          Enables the database backend.
 boolean equals(java.lang.Object other)
          Two database backends are considered equal if they have the same name, URL and driver class name.
 void finalizeConnections()
          Releases all the connections to the database held by the connection managers.
 AbstractConnectionManager getConnectionManager(java.lang.String vLogin)
          Returns the ConnectionManager associated to this backend for a given virtual login.
 DatabaseSchema getDatabaseSchema()
          Returns the schema of this database.
 java.lang.String getDriverClassName()
          Returns the database native JDBC driver class name.
 DriverCompliance getDriverCompliance()
           
 java.lang.String getInformation()
          Gets information about this backend.
 java.lang.String getName()
          Returns the backend logical name.
 java.util.Vector getPendingRequests()
          Returns the list of pending requests for this backend.
 java.lang.String getURL()
          Returns the JDBC URL used to access the database.
 java.lang.String getXmlInformation()
          Get xml information about this backend.
 boolean hasTable(java.lang.String table)
          Returns true if this backend has the given table in its schema.
 boolean hasTables(java.util.ArrayList tables)
          Returns true if this backend has the given list of tables in its schema.
 void initializeConnections()
          Initializes the connection managers' connections.
 boolean isEnabled()
          Tests if this backend is enabled (active and synchronized).
 boolean isInitialized()
          Tests if this backend is enabled (active and synchronized).
 boolean isStartedTransaction(java.lang.Integer tid)
          Returns true if the specified transaction has been started on this backend (a connection has been allocated for this transaction).
 boolean removePendingRequest(AbstractRequest request)
          Removes a pending request from this backend.
 void setDatabaseSchema(DatabaseSchema databaseSchema, boolean isStatic)
          Sets the database schema.
 void startTransaction(java.lang.Integer tid)
          Signals that a transaction has been started on this backend.
 void stopTransaction(java.lang.Integer tid)
          Signals that a transaction has been stopped on this backend.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

private java.lang.String name
Logical name assigned to this backend.


driverClassName

private java.lang.String driverClassName
Database native JDBC driver class name.


driverCompliance

private DriverCompliance driverCompliance
Driver compliance to C-JDBC requirements


url

private java.lang.String url
Real URL to access the database (JDBC URL).


isEnabled

private boolean isEnabled
Is this bakend enabled.


schema

private DatabaseSchema schema
The schema of the database.


schemaIsStatic

private boolean schemaIsStatic
true if schema is static.


connectionManagers

private java.util.HashMap connectionManagers
Connection managers for this backend.


logger

protected transient Trace logger
Logger instance.


activeTransactions

private java.util.Vector activeTransactions
List of started transactions.


pendingRequests

private java.util.Vector pendingRequests
List of pending requests.

Constructor Detail

DatabaseBackend

public DatabaseBackend(java.lang.String name,
                       java.lang.String driverClassName,
                       java.lang.String url,
                       boolean isEnabled)
Creates a new DatabaseBackend instance.

Parameters:
name - logical name assigned to this backend
driverClassName - class name of the database native JDBC driver to load
url - URL to access the database
isEnabled - true if this backend must be enabled
Method Detail

equals

public boolean equals(java.lang.Object other)
Two database backends are considered equal if they have the same name, URL and driver class name.

Parameters:
other - an object
Returns:
a boolean value

hasTables

public boolean hasTables(java.util.ArrayList tables)
Returns true if this backend has the given list of tables in its schema. The caller must ensure that the database schema has been defined, using the setDatabaseSchema(DatabaseSchema, boolean) or checkDatabaseSchema() methods.

Parameters:
tables - the list of table names (ArrayList of String) to look for
Returns:
true if all the tables are found

hasTable

public boolean hasTable(java.lang.String table)
Returns true if this backend has the given table in its schema. The caller must ensure that the database schema has been defined, using the setDatabaseSchema(DatabaseSchema, boolean) or checkDatabaseSchema()

Parameters:
table - The table name to look for
Returns:
true if tables is found in the schema

initializeConnections

public void initializeConnections()
                           throws java.sql.SQLException
Initializes the connection managers' connections. The caller must ensure that the driver has already been loaded else an exception will be thrown.

Throws:
java.sql.SQLException - if an error occurs

finalizeConnections

public void finalizeConnections()
                         throws java.sql.SQLException
Releases all the connections to the database held by the connection managers.

Throws:
java.sql.SQLException - if an error occurs

addConnectionManager

public void addConnectionManager(java.lang.String vLogin,
                                 AbstractConnectionManager connectionManager)
Adds a ConnectionManager to this backend. Note that the ConnectionManager is not initialized in this method.

Parameters:
vLogin - the virtual login corresponding to this connection manager
connectionManager - the ConnectionManager to add

startTransaction

public void startTransaction(java.lang.Integer tid)
Signals that a transaction has been started on this backend. It means that a connection has been allocated for this transaction.

Parameters:
tid - transaction identifier

stopTransaction

public void stopTransaction(java.lang.Integer tid)
Signals that a transaction has been stopped on this backend. It means that the connection has been released for this transaction.

Parameters:
tid - transaction identifier

isStartedTransaction

public boolean isStartedTransaction(java.lang.Integer tid)
Returns true if the specified transaction has been started on this backend (a connection has been allocated for this transaction).

Parameters:
tid - transaction identifier
Returns:
true if the transaction has been started

isInitialized

public final boolean isInitialized()
                            throws java.sql.SQLException
Tests if this backend is enabled (active and synchronized).

Returns:
true if this backend is enabled
Throws:
java.sql.SQLException - if an error occurs

isEnabled

public final boolean isEnabled()
Tests if this backend is enabled (active and synchronized).

Returns:
true if this backend is enabled.

enable

public void enable()
Enables the database backend. This method should only be called when the backend is synchronized with the others.


disable

public void disable()
Sets the database backend state to disable. This state is just an indication and it has no semantic effect. It is up to the request manager (especially the load balancer) to ensure that no more requests are sent to this backend.


getConnectionManager

public AbstractConnectionManager getConnectionManager(java.lang.String vLogin)
Returns the ConnectionManager associated to this backend for a given virtual login.

Parameters:
vLogin - the virtual login
Returns:
an AbstractConnectionManager instance

getDriverClassName

public java.lang.String getDriverClassName()
Returns the database native JDBC driver class name.

Returns:
the driver class name

getName

public java.lang.String getName()
Returns the backend logical name.

Returns:
the backend logical name

getPendingRequests

public java.util.Vector getPendingRequests()
Returns the list of pending requests for this backend.

Returns:
Vector of AbstractRequests

addPendingRequest

public void addPendingRequest(AbstractRequest request)
Adds a pending request to this backend. Note that the underlying vector is synchronized.

Parameters:
request - the request to add

removePendingRequest

public boolean removePendingRequest(AbstractRequest request)
Removes a pending request from this backend. Note that the underlying vector is synchronized.

Parameters:
request - the request to remove
Returns:
true if the request has been found and removed

getDatabaseSchema

public DatabaseSchema getDatabaseSchema()
Returns the schema of this database.

Returns:
the schema of this database. Returns null if the schema has not been set.
See Also:
setDatabaseSchema(org.objectweb.cjdbc.sql.schema.DatabaseSchema, boolean)

setDatabaseSchema

public void setDatabaseSchema(DatabaseSchema databaseSchema,
                              boolean isStatic)
Sets the database schema.

Parameters:
databaseSchema - the schema to set
isStatic - true if the schema should be static
See Also:
getDatabaseSchema()

checkDatabaseSchema

public void checkDatabaseSchema()
Checks that the current database schema is compatible with all schema gathered from each connection manager.

If no schema has been defined, the first gathered schema is used as the current database schema.

For each schema that is not compatible with the current schema, a warning is issued on the logger.


getDriverCompliance

public DriverCompliance getDriverCompliance()
Returns:
the driver compliance to C-JDBC requirements.

checkDriverCompliance

public void checkDriverCompliance()
                           throws java.sql.SQLException
Check if the driver used by this backend is compliant with C-JDBC needs.

Throws:
java.sql.SQLException - if the driver is not compliant

getURL

public java.lang.String getURL()
Returns the JDBC URL used to access the database.

Returns:
a JDBC URL

getXmlInformation

public java.lang.String getXmlInformation()
Get xml information about this backend.

Returns:
xml formatted information on this database backend.

getInformation

public java.lang.String getInformation()
Gets information about this backend.

Returns:
String containing information


Copyright © 2002, 2003 - ObjectWeb Consortium - All Rights Reserved.