org.objectweb.cjdbc.controller.backend
Class DatabaseBackend

java.lang.Object
  extended byjavax.management.StandardMBean
      extended byorg.objectweb.cjdbc.controller.jmx.AbstractStandardMBean
          extended byorg.objectweb.cjdbc.controller.backend.DatabaseBackend
All Implemented Interfaces:
DatabaseBackendMBean, javax.management.DynamicMBean, javax.management.NotificationBroadcaster, javax.management.NotificationEmitter, XmlComponent

public final class DatabaseBackend
extends AbstractStandardMBean
implements XmlComponent, DatabaseBackendMBean

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 , Jean-Bernard van Zuylen

Nested Class Summary
 
Nested classes inherited from class javax.management.StandardMBean
 
Field Summary
private  java.util.ArrayList activeTransactions
          List of started transactions.
private  java.util.HashMap connectionManagers
          Connection managers for this backend.
private  java.lang.String connectionTestStatement
          SQL statement used to check if a connection is still valid
private  java.lang.String driverClassName
          Database native JDBC driver class name.
private  DriverCompliance driverCompliance
          Driver compliance to C-JDBC requirements
private  java.lang.String driverPath
          Path for driver
private  int dynamicPrecision
          For metadata information generation
private  boolean gatherSystemTables
           
private  java.lang.String lastKnownCheckpoint
           
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  java.util.ArrayList rewritingRules
          List of AbstractRewritingRule objects.
private  java.util.Map savepoints
          List of savepoints for each transaction
private  DatabaseSchema schema
          The schema of the database.
private  boolean schemaIsDirty
          true if schema is no more up-to-date and needs a refresh
private  boolean schemaIsNeededByVdb
          true if the backend must maintain its schema dynamically for the virtual database needs
private  boolean schemaIsStatic
          true if schema is static.
private  java.lang.String schemaName
           
private  int sqlShortFormLength
          Short form of SQL statements to include in traces and exceptions
private  int state
          The current state of the backend
private  BackendStateListener stateListener
           
private  int totalReadRequest
           
private  int totalRequest
          Monitoring Values
private  int totalTransactions
           
private  int totalWriteRequest
           
private  java.lang.String url
          Real URL to access the database (JDBC URL).
private  java.lang.String virtualDatabaseName
          Name of the virtual database this backend is attached to
private  boolean writeCanBeEnabled
          A boolean to know if we should allow this backend to be enabled for write
 
Fields inherited from class org.objectweb.cjdbc.controller.jmx.AbstractStandardMBean
 
Fields inherited from class javax.management.StandardMBean
 
Fields inherited from interface org.objectweb.cjdbc.common.xml.XmlComponent
DOCTYPE_CONTROLLER, DOCTYPE_DB, XML_VERSION
 
Constructor Summary
DatabaseBackend(BackendInfo info)
          Creates a new DatabaseBackend object
DatabaseBackend(java.lang.String name, java.lang.String driverPath, java.lang.String driverClassName, java.lang.String url, java.lang.String vdbName, boolean writeCanBeEnabled, java.lang.String connectionTestStatement)
          Creates a new DatabaseBackend instance.
DatabaseBackend(java.lang.String name, java.lang.String driverPath, java.lang.String driverClassName, java.lang.String url, java.lang.String vdbName, java.lang.String connectionTestStatement, java.lang.String dynamicSchemaLevel)
          Additionnal constructor for setting a different dynamic schema level.
 
Method Summary
 void addConnectionManager(java.lang.String vLogin, AbstractConnectionManager connectionManager)
          Adds a ConnectionManager to this backend.
 void addPendingReadRequest(java.lang.Object request)
          Adds a pending request (or task) to this backend.
 void addPendingWriteRequest(java.lang.Object request)
          Adds a pending request (or task) to this backend.
 void addRewritingRule(AbstractRewritingRule rule)
          Add a AbstractRewritingRule at the end of the rule list.
 void addSavepoint(java.lang.Long tid, java.sql.Savepoint savepoint)
          Adds a savepoint to a given transaction
 boolean 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.
 DatabaseBackend copy(java.lang.String newName, java.util.Map parameters)
          Returns a deeply copied clone of this backend Will use the same rewriting rules and will get new instance of connection managers with the same configuration
 void disable()
          Sets the database backend state to disable.
 void disableRead()
          Disables the database backend for reads.
 void disableWrite()
          Disables the database backend for writes.
 void enableRead()
          Enables the database backend for reads.
 void enableWrite()
          Enables the database backend for writes.
 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.
 java.util.ArrayList getActiveTransactions()
          Returns the list of active transactions for this backend.
 java.lang.String getAssociatedString()
          Allow to retrieve internationalization description on mbeans as well
 java.lang.String[] getBackendData()
          Get data about this backend.
 BackendStatistics getBackendStats()
          Get the statistics of the backend.
 java.sql.Connection getConnectionForTransactionAndLazyBeginIfNeeded(java.lang.Long tid, AbstractConnectionManager cm, int transactionIsolationLevel)
          Retrieve a connection for a given transaction or create a new connection and start a new transaction.
 AbstractConnectionManager getConnectionManager(java.lang.String vLogin)
          Returns the ConnectionManager associated to this backend for a given virtual login.
 java.util.HashMap getConnectionManagers()
          Returns a HashMap of all the ConnectionManager associated with this DatabaseBackend
 java.lang.String getConnectionTestStatement()
          Returns the SQL statement to use to check the connection validity.
 java.lang.String getDatabaseProductName()
          Returns the databaseProductName value.
 DatabaseSchema getDatabaseSchema()
          Returns the schema of this database.
 MetadataContainer getDatabaseStaticMetadata()
          Get the Database static metadata from this backend using a connection from the first available connection manager.
 java.lang.String getDriverClassName()
          Returns the database native JDBC driver class name.
 DriverCompliance getDriverCompliance()
           
 java.lang.String getDriverPath()
          Returns the driver path.
 int getDynamicPrecision()
           
 java.lang.String getLastKnownCheckpoint()
          Returns the lastKnownCheckpoint value.
 java.lang.String getName()
          Returns the backend logical name.
 java.util.Vector getPendingRequests()
          Returns the list of pending requests for this backend.
 java.util.ArrayList getPendingRequestsDescription(int count, boolean fromFirst, boolean clone)
          Returns the list of pending requests for this backend.
 java.util.ArrayList getRewritingRules()
          Returns the rewritingRules value.
 java.sql.Savepoint getSavepoint(java.lang.Long tid, java.lang.String savepointName)
          Retrieves a savepoint object by its name for a given transaction
 java.lang.String getSchemaName()
          Returns the schemaName value.
 java.lang.String getSchemaXml(boolean expandSchema)
          The getXml() method does not return the schema if it is not static anymore, to avoid confusion between static and dynamic schema.
 int getSQLShortFormLength()
          Return the sql short form length to use when reporting an error.
 java.lang.String getState()
          Retrieve the state of the backend.
 int getStateValue()
          Return the integer value corresponding to the state of the backend.
 java.util.ArrayList getTables()
          Get all the names of tables of this database
 long getTotalActiveConnections()
          Get the total number of active connections for this backend
 int getTotalReadRequest()
          Returns the total number of read requests executed by this backend.
 int getTotalRequest()
          Returns the total number of requests executed by this backend.
 int getTotalTransactions()
          Returns the total number of transactions executed by this backend.
 int getTotalWriteRequest()
          Returns the total number of write requests executed by this backend.
 java.lang.String getURL()
          Returns the JDBC URL used to access the database.
 java.lang.String getVirtualDatabaseName()
          Returns the virtual database name this backend belongs to.
 java.lang.String getXml()
          Get xml information about this backend.
 boolean hasSavepointForTransaction(java.lang.Long tid, java.lang.String savepointName)
          Checks if this backend has a savepoint with given name for a given transaction
 boolean hasStoredProcedure(java.lang.String procedureName)
          Returns true if this backend has the given stored procedure in its schema.
 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 isBackuping()
          Returns the isBackuping value.
 boolean isDisabled()
          Is the backend completely disabled ?
 boolean isDisabling()
          Returns the isDisabling value.
 boolean isGatherSystemTables()
          Returns the gatherSystemTables value.
 boolean isInitialized()
          Tests if this backend is enabled (active and synchronized).
 boolean isJDBCConnected()
          Is the backend accessible ?
 boolean isKilled()
          Returns true if the backend cannot be used anymore
 boolean isReadEnabled()
          Tests if this backend is read enabled (active and synchronized).
 boolean isRecovering()
          Returns the isRecovering value.
 boolean isSchemaDirty()
          Returns the schemaIsDirty value.
 boolean isSchemaNeededByVdb()
          Returns true if an up-to-date schema is needed by the virtual database.
 boolean isSchemaStatic()
           
 boolean isStartedTransaction(java.lang.Long tid)
          Returns true if the specified transaction has been started on this backend (a connection has been allocated for this transaction).
 boolean isValidConnection(java.sql.Connection connection)
          Check if the given connection is valid or not.
 boolean isWriteCanBeEnabled()
          Returns the writeCanBeEnabled value.
 boolean isWriteEnabled()
          Tests if this backend is write enabled (active and synchronized).
 void notifyJmx(java.lang.String type)
          Sends JMX notification
private  void notifyJmx(java.lang.String type, java.lang.String level, java.lang.String message)
           
 void notifyJmxError(java.lang.String type, java.lang.Exception e)
          Sends JMX error notification
 void notifyStateChange()
          Notify the state of the backend has changed.
private  void refreshSchema()
          Erase the current schema and force a re-fetch of all the meta data
 boolean removePendingRequest(java.lang.Object request)
          Removes a pending request from this backend.
 void removeSavepoint(java.lang.Long tid, java.sql.Savepoint savepoint)
          Removes a savepoint for a given transaction
 java.lang.String rewriteQuery(java.lang.String sqlQuery)
          Rewrite the current query according to the rewriting rules.
 void setDatabaseSchema(DatabaseSchema databaseSchema, boolean isStatic)
          Sets the database schema.
 void setDisabling()
          Deprecated. not used anymore. Please use the setState method instead
 void setDynamicPrecision(int dynamicPrecision, boolean gatherSystemTables, java.lang.String schemaName)
          Set the amount of information that must be gathered when fetching database schema information.
 void setLastKnownCheckpoint(java.lang.String checkpoint)
          setLastKnownCheckpoint for this backend
 void setRewritingRules(java.util.ArrayList rewritingRules)
          Sets the rewritingRules value.
 void setSchemaIsDirty(boolean schemaIsDirty)
          Sets the schemaIsDirty value if the backend schema needs to be refreshed.
 void setSchemaIsNeededByVdb(boolean schemaIsNeededByVdb)
          Sets the schemaIsNeededByVdb value.
 void setSqlShortFormLength(int sqlShortFormLength)
          Sets the sqlShortFormLength value.
 void setState(int state)
          Set the state of a backend
 void setStateListener(BackendStateListener stateListener)
          Sets the stateListener value.
 void startTransaction(java.lang.Long tid)
          Signals that a transaction has been started on this backend.
 void stopTransaction(java.lang.Long tid)
          Signals that a transaction has been stopped on this backend.
 java.lang.String toString()
          String description
 void updateDatabaseBackendSchema(AbstractWriteRequest request)
          Update the DatabaseBackend schema definition according to the successful execution of the provided request.
 void waitForAllTransactionsToComplete()
          This method waits until all currently open transactions on this backend complete.
 
Methods inherited from class org.objectweb.cjdbc.controller.jmx.AbstractStandardMBean
addNotificationListener, getDescription, getDescription, getDescription, getDescription, getDescription, getDescription, getNotificationInfo, getParameterName, getParameterName, removeNotificationListener, removeNotificationListener, sendNotification
 
Methods inherited from class javax.management.StandardMBean
cacheMBeanInfo, getAttribute, getAttributes, getCachedMBeanInfo, getClassName, getConstructors, getDescription, getImpact, getImplementation, getImplementationClass, getMBeanInfo, getMBeanInterface, invoke, setAttribute, setAttributes, setImplementation
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

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


driverPath

private java.lang.String driverPath
Path for driver


driverClassName

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


driverCompliance

private transient DriverCompliance driverCompliance
Driver compliance to C-JDBC requirements


url

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


virtualDatabaseName

private java.lang.String virtualDatabaseName
Name of the virtual database this backend is attached to


writeCanBeEnabled

private boolean writeCanBeEnabled
A boolean to know if we should allow this backend to be enabled for write


connectionTestStatement

private java.lang.String connectionTestStatement
SQL statement used to check if a connection is still valid


schema

private transient DatabaseSchema schema
The schema of the database. This should be accessed in a synchronized(this) block since it can be updated dynamically.


schemaIsStatic

private boolean schemaIsStatic
true if schema is static.


schemaIsNeededByVdb

private boolean schemaIsNeededByVdb
true if the backend must maintain its schema dynamically for the virtual database needs


schemaIsDirty

private boolean schemaIsDirty
true if schema is no more up-to-date and needs a refresh


connectionManagers

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


logger

protected transient Trace logger
Logger instance.


activeTransactions

private transient java.util.ArrayList activeTransactions
List of started transactions.


savepoints

private transient java.util.Map savepoints
List of savepoints for each transaction


pendingRequests

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


totalRequest

private int totalRequest
Monitoring Values


totalWriteRequest

private int totalWriteRequest

totalReadRequest

private int totalReadRequest

totalTransactions

private int totalTransactions

rewritingRules

private java.util.ArrayList rewritingRules
List of AbstractRewritingRule objects.


dynamicPrecision

private int dynamicPrecision
For metadata information generation


gatherSystemTables

private boolean gatherSystemTables

schemaName

private java.lang.String schemaName

sqlShortFormLength

private int sqlShortFormLength
Short form of SQL statements to include in traces and exceptions


lastKnownCheckpoint

private java.lang.String lastKnownCheckpoint

state

private int state
The current state of the backend

See Also:
BackendState

stateListener

private transient BackendStateListener stateListener
Constructor Detail

DatabaseBackend

public DatabaseBackend(java.lang.String name,
                       java.lang.String driverPath,
                       java.lang.String driverClassName,
                       java.lang.String url,
                       java.lang.String vdbName,
                       boolean writeCanBeEnabled,
                       java.lang.String connectionTestStatement)
                throws javax.management.NotCompliantMBeanException
Creates a new DatabaseBackend instance.

Parameters:
name - logical name assigned to this backend
driverPath - path for driver
driverClassName - class name of the database native JDBC driver to load
url - URL to access the database
vdbName - Name of the virtual database this backend is attached to
writeCanBeEnabled - if writes can be enabled on this backend
connectionTestStatement - SQL statement used to check if a connection is still valid
Throws:
javax.management.NotCompliantMBeanException - if the mbean can not be created (unless we refactor the code this cannot happend)

DatabaseBackend

public DatabaseBackend(BackendInfo info)
                throws javax.management.NotCompliantMBeanException
Creates a new DatabaseBackend object

Parameters:
info - a backend info object to create a database backend object from
Throws:
javax.management.NotCompliantMBeanException - if mbean is not compliant (unless we refactor the code this cannot happend)

DatabaseBackend

public DatabaseBackend(java.lang.String name,
                       java.lang.String driverPath,
                       java.lang.String driverClassName,
                       java.lang.String url,
                       java.lang.String vdbName,
                       java.lang.String connectionTestStatement,
                       java.lang.String dynamicSchemaLevel)
                throws javax.management.NotCompliantMBeanException
Additionnal constructor for setting a different dynamic schema level. Default was to gather all information Creates a new DatabaseBackend instance.

Parameters:
name - logical name assigned to this backend
driverPath - path for driver
driverClassName - class name of the database native JDBC driver to load
url - URL to access the database
vdbName - Name of the virtual database this backend is attached to
connectionTestStatement - SQL statement used to check if a connection is still valid
dynamicSchemaLevel - for dynamically gathering schema from backend
Throws:
javax.management.NotCompliantMBeanException - (unless we refactor the code this cannot happend)
Method Detail

setSqlShortFormLength

public void setSqlShortFormLength(int sqlShortFormLength)
Sets the sqlShortFormLength value.

Parameters:
sqlShortFormLength - The sqlShortFormLength to set.

getSQLShortFormLength

public int getSQLShortFormLength()
Return the sql short form length to use when reporting an error.

Returns:
sql short form length
See Also:
AbstractRequest.getSQLShortForm(int)

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.

Specified by:
hasTables in interface DatabaseBackendMBean
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()

Specified by:
hasTable in interface DatabaseBackendMBean
Parameters:
table - The table name to look for
Returns:
true if tables is found in the schema

getTables

public java.util.ArrayList getTables()
Get all the names of tables of this database

Returns:
ArrayList of DatabaseTable

hasStoredProcedure

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

Specified by:
hasStoredProcedure in interface DatabaseBackendMBean
Parameters:
procedureName - The stored procedure name to look for
Returns:
true if procedure name 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

isValidConnection

public boolean isValidConnection(java.sql.Connection connection)
Check if the given connection is valid or not. This function issues the connectionTestStatement query on the connection and if it succeeds then the connection is declared valid. If an exception occurs, the connection is declared invalid.

Parameters:
connection - the connection to test
Returns:
true if the connection is valid

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

getConnectionForTransactionAndLazyBeginIfNeeded

public java.sql.Connection getConnectionForTransactionAndLazyBeginIfNeeded(java.lang.Long tid,
                                                                           AbstractConnectionManager cm,
                                                                           int transactionIsolationLevel)
                                                                    throws UnreachableBackendException,
                                                                           NoTransactionStartWhenDisablingException,
                                                                           java.sql.SQLException
Retrieve a connection for a given transaction or create a new connection and start a new transaction.
This method is synchronized so that concurrent writes within the same transaction that are allowed to execute out of order will not open separate connection if they race on transaction begin.

Parameters:
tid - transaction identifier
cm - connection manager to get the connection from
transactionIsolationLevel - transaction isolation level to use for a new transaction (does nothing if equals to Connection.DEFAULT_TRANSACTION_ISOLATION_LEVEL)
Returns:
the connection for the given transaction id
Throws:
UnreachableBackendException - if the backend is no more reachable
NoTransactionStartWhenDisablingException - if a new transaction needed to be started but the backend is in the disabling state
java.sql.SQLException - if another error occurs

startTransaction

public void startTransaction(java.lang.Long 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.Long 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

waitForAllTransactionsToComplete

public void waitForAllTransactionsToComplete()
This method waits until all currently open transactions on this backend complete. If no transaction are currently running on this backend, this method immediately returns.


isStartedTransaction

public boolean isStartedTransaction(java.lang.Long 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

addSavepoint

public void addSavepoint(java.lang.Long tid,
                         java.sql.Savepoint savepoint)
Adds a savepoint to a given transaction

Parameters:
tid - transaction identifier
savepoint - savepoint to add

removeSavepoint

public void removeSavepoint(java.lang.Long tid,
                            java.sql.Savepoint savepoint)
Removes a savepoint for a given transaction

Parameters:
tid - transaction identifier
savepoint - savepoint to remove

getSavepoint

public java.sql.Savepoint getSavepoint(java.lang.Long tid,
                                       java.lang.String savepointName)
Retrieves a savepoint object by its name for a given transaction

Parameters:
tid - transaction identifier
savepointName - name of the savepoint
Returns:
a savepoint

hasSavepointForTransaction

public boolean hasSavepointForTransaction(java.lang.Long tid,
                                          java.lang.String savepointName)
Checks if this backend has a savepoint with given name for a given transaction

Parameters:
tid - transaction identifier
savepointName - name of the savepoint
Returns:
true if this backend has a savepoint with a given name for a given transaction

isInitialized

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

Specified by:
isInitialized in interface DatabaseBackendMBean
Returns:
true if this backend is enabled
Throws:
java.sql.SQLException - if an error occurs

isJDBCConnected

public boolean isJDBCConnected()
Is the backend accessible ?

Specified by:
isJDBCConnected in interface DatabaseBackendMBean
Returns:
true if a jdbc connection is still possible from the controller

isReadEnabled

public boolean isReadEnabled()
Tests if this backend is read enabled (active and synchronized).

Specified by:
isReadEnabled in interface DatabaseBackendMBean
Returns:
true if this backend is enabled.

isWriteEnabled

public boolean isWriteEnabled()
Tests if this backend is write enabled (active and synchronized).

Specified by:
isWriteEnabled in interface DatabaseBackendMBean
Returns:
true if this backend is enabled.

isRecovering

public boolean isRecovering()
Returns the isRecovering value.

Returns:
Returns the isRecovering.

isDisabling

public boolean isDisabling()
Returns the isDisabling value.

Returns:
Returns the isDisabling.

isDisabled

public boolean isDisabled()
Description copied from interface: DatabaseBackendMBean
Is the backend completely disabled ? This usually means it has a known state with a checkpoint associated to it.

Specified by:
isDisabled in interface DatabaseBackendMBean
Returns:
true if the backend is disabled
See Also:
DatabaseBackendMBean.isDisabled()

isKilled

public boolean isKilled()
Returns true if the backend cannot be used anymore

Returns:
Returns true if the backend was removed from activity by the load balancer

getState

public java.lang.String getState()
Retrieve the state of the backend.

Specified by:
getState in interface DatabaseBackendMBean
Returns:
one of the above
See Also:
CjdbcNotificationList.VIRTUALDATABASE_BACKEND_DISABLED, CjdbcNotificationList.VIRTUALDATABASE_BACKEND_RECOVERING, CjdbcNotificationList.VIRTUALDATABASE_BACKEND_BACKINGUP, CjdbcNotificationList.VIRTUALDATABASE_BACKEND_DISABLING, CjdbcNotificationList.VIRTUALDATABASE_BACKEND_ENABLED, CjdbcNotificationList.VIRTUALDATABASE_BACKEND_DISABLED

getStateValue

public int getStateValue()
Return the integer value corresponding to the state of the backend. The values are defined in BackendState

Returns:
int value
See Also:
BackendState

enableRead

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

Specified by:
enableRead in interface DatabaseBackendMBean

disableRead

public void disableRead()
Description copied from interface: DatabaseBackendMBean
Disables the database backend for reads. This does not affect write ability

Specified by:
disableRead in interface DatabaseBackendMBean
See Also:
DatabaseBackendMBean.disableRead()

disableWrite

public void disableWrite()
Description copied from interface: DatabaseBackendMBean
Disables the database backend for writes. This does not affect read ability although the backend will not be coherent anymore as soon as a write as occured. This should be used in conjunction with a checkpoint to recover missing writes.

Specified by:
disableWrite in interface DatabaseBackendMBean
See Also:
DatabaseBackendMBean.disableWrite()

enableWrite

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

Specified by:
enableWrite in interface DatabaseBackendMBean

setDisabling

public void setDisabling()
Deprecated. not used anymore. Please use the setState method instead

This is used when the backend must be disabled but currently open transactions must terminate. This is a transitional state. When disabling is complete the caller must set the backend state to disabled.

Reads are no more allowed on the backend and the state is updated so that isReadEnabled() returns false.

See Also:
disable(), isReadEnabled()

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.

Specified by:
disable in interface DatabaseBackendMBean

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

getConnectionManagers

public java.util.HashMap getConnectionManagers()
Returns a HashMap of all the ConnectionManager associated with this DatabaseBackend

Returns:
the hashmap of connection managers

getConnectionTestStatement

public java.lang.String getConnectionTestStatement()
Returns the SQL statement to use to check the connection validity.

Specified by:
getConnectionTestStatement in interface DatabaseBackendMBean
Returns:
a String containing a SQL statement

getDriverPath

public java.lang.String getDriverPath()
Description copied from interface: DatabaseBackendMBean
Returns the driver path.

Specified by:
getDriverPath in interface DatabaseBackendMBean
Returns:
the driver path
See Also:
DatabaseBackendMBean.getDriverPath()

getAssociatedString

public java.lang.String getAssociatedString()
Description copied from class: AbstractStandardMBean
Allow to retrieve internationalization description on mbeans as well

Specified by:
getAssociatedString in class AbstractStandardMBean
Returns:
part of the key to look for in the translation file.
See Also:
AbstractStandardMBean.getAssociatedString()

getDriverClassName

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

Specified by:
getDriverClassName in interface DatabaseBackendMBean
Returns:
the driver class name

getName

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

Specified by:
getName in interface DatabaseBackendMBean
Returns:
the backend logical name

getVirtualDatabaseName

public java.lang.String getVirtualDatabaseName()
Returns the virtual database name this backend belongs to.

Returns:
Returns the virtual database name.

getPendingRequests

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

Returns:
Vector of AbstractRequests or AbstractTask objects

getPendingRequestsDescription

public java.util.ArrayList getPendingRequestsDescription(int count,
                                                         boolean fromFirst,
                                                         boolean clone)
Description copied from interface: DatabaseBackendMBean
Returns the list of pending requests for this backend.

Specified by:
getPendingRequestsDescription in interface DatabaseBackendMBean
Parameters:
count - number of requests to retrieve, if 0, return all.
fromFirst - count the request from first if true, or from last if false
clone - should clone the pending request if true, block it if false
Returns:
ArrayList of String description of each request.
See Also:
DatabaseBackendMBean.getPendingRequestsDescription(int, boolean, boolean)

addPendingReadRequest

public void addPendingReadRequest(java.lang.Object request)
Adds a pending request (or task) to this backend. Note that the underlying vector is synchronized.

Parameters:
request - the request to add

addPendingWriteRequest

public void addPendingWriteRequest(java.lang.Object request)
Adds a pending request (or task) to this backend. Note that the underlying vector is synchronized.

Parameters:
request - the request to add

removePendingRequest

public boolean removePendingRequest(java.lang.Object 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

checkDatabaseSchema

public boolean checkDatabaseSchema()
Description copied from interface: DatabaseBackendMBean
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 for that backend

Specified by:
checkDatabaseSchema in interface DatabaseBackendMBean
Returns:
true if comptaible, false otherwise
See Also:
DatabaseBackendMBean.checkDatabaseSchema()

getDatabaseSchema

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

Specified by:
getDatabaseSchema in interface DatabaseBackendMBean
Returns:
the schema of this database. Returns null if the schema has not been set.
See Also:
setDatabaseSchema(DatabaseSchema, boolean)

getDatabaseStaticMetadata

public MetadataContainer getDatabaseStaticMetadata()
Get the Database static metadata from this backend using a connection from the first available connection manager.

Returns:
Static metadata information

getDynamicPrecision

public int getDynamicPrecision()
Returns:
Returns the dynamicPrecision.

getSchemaName

public java.lang.String getSchemaName()
Returns the schemaName value.

Returns:
Returns the schemaName.

isGatherSystemTables

public boolean isGatherSystemTables()
Returns the gatherSystemTables value.

Returns:
Returns the gatherSystemTables.

isSchemaDirty

public boolean isSchemaDirty()
Returns the schemaIsDirty value.

Returns:
Returns true if the backend database schema is dirty and needs a refresh.

isSchemaStatic

public boolean isSchemaStatic()
Specified by:
isSchemaStatic in interface DatabaseBackendMBean
Returns:
Returns the schemaIsStatic.

isSchemaNeededByVdb

public boolean isSchemaNeededByVdb()
Returns true if an up-to-date schema is needed by the virtual database.

Returns:
Returns the schemaIsNeededByVdb.

refreshSchema

private void refreshSchema()
Erase the current schema and force a re-fetch of all the meta data


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()

setDynamicPrecision

public void setDynamicPrecision(int dynamicPrecision,
                                boolean gatherSystemTables,
                                java.lang.String schemaName)
Set the amount of information that must be gathered when fetching database schema information.

Parameters:
dynamicPrecision - The dynamicPrecision to set.
gatherSystemTables - True if we must gather system tables
schemaName - Schema name to use to gather tables

setSchemaIsDirty

public void setSchemaIsDirty(boolean schemaIsDirty)
Sets the schemaIsDirty value if the backend schema needs to be refreshed.

Parameters:
schemaIsDirty - The schemaIsDirty to set.

setSchemaIsNeededByVdb

public void setSchemaIsNeededByVdb(boolean schemaIsNeededByVdb)
Sets the schemaIsNeededByVdb value.

Parameters:
schemaIsNeededByVdb - The schemaIsNeededByVdb to set.

updateDatabaseBackendSchema

public void updateDatabaseBackendSchema(AbstractWriteRequest request)
Update the DatabaseBackend schema definition according to the successful execution of the provided request. Note that the schema is only updated it the provided request is a DDL statement.

Parameters:
request - the request that possibly updates the schema

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.

Specified by:
checkDriverCompliance in interface DatabaseBackendMBean
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.

Specified by:
getURL in interface DatabaseBackendMBean
Returns:
a JDBC URL

addRewritingRule

public void addRewritingRule(AbstractRewritingRule rule)
Add a AbstractRewritingRule at the end of the rule list.

Parameters:
rule - a AbstractRewritingRule

rewriteQuery

public java.lang.String rewriteQuery(java.lang.String sqlQuery)
Rewrite the current query according to the rewriting rules.

Parameters:
sqlQuery - request to rewrite
Returns:
the rewritten SQL query according to rewriting rules.

getXml

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

Specified by:
getXml in interface XmlComponent
Returns:
xml formatted information on this database backend.

getSchemaXml

public java.lang.String getSchemaXml(boolean expandSchema)
Description copied from interface: DatabaseBackendMBean
The getXml() method does not return the schema if it is not static anymore, to avoid confusion between static and dynamic schema. This method returns a static view of the schema, whatever the dynamic precision is.

Specified by:
getSchemaXml in interface DatabaseBackendMBean
Parameters:
expandSchema - if we should force the schema to be expanded. This is needed as the default getXml should call this method.
Returns:
an xml formatted string
See Also:
DatabaseBackendMBean.getSchemaXml(boolean)

getActiveTransactions

public java.util.ArrayList getActiveTransactions()
Description copied from interface: DatabaseBackendMBean
Returns the list of active transactions for this backend.

Specified by:
getActiveTransactions in interface DatabaseBackendMBean
Returns:
Returns the activeTransactions.

getBackendData

public java.lang.String[] getBackendData()
Get data about this backend. Format is:
 data[0] = this.name;
 data[1] = this.driverClassName;
 data[2] = this.url;
 data[3] = String.valueOf(this.activeTransactions.size());
 data[4] = String.valueOf(this.pendingRequests.size());
 data[5] = String.valueOf(this.isReadEnabled());
 data[6] = String.valueOf(this.isWriteEnabled());
 data[7] = String.valueOf(this.isInitialized());
 data[8] = String.valueOf(this.schemaIsStatic);
 data[9] = String.valueOf(this.connectionManagers.size());
 data[10] = String.valueOf(getTotalActiveConnections());
 data[11] = String.valueOf(totalRequest);
 data[12] = String.valueOf(totalTransactions);
 data[13] = lastKnownCheckpoint;

Returns:
an array of strings

getBackendStats

public BackendStatistics getBackendStats()
Get the statistics of the backend.

Returns:
a BackendStatistics

getTotalActiveConnections

public long getTotalActiveConnections()
Get the total number of active connections for this backend

Returns:
number of active connections for all AbstractConnectionManager connected to this backend

getTotalTransactions

public int getTotalTransactions()
Returns the total number of transactions executed by this backend.

Returns:
Total number of transactions.

getTotalReadRequest

public int getTotalReadRequest()
Returns the total number of read requests executed by this backend.

Returns:
Returns the totalReadRequest.

getTotalWriteRequest

public int getTotalWriteRequest()
Returns the total number of write requests executed by this backend.

Returns:
Returns the totalWriteRequest.

getTotalRequest

public int getTotalRequest()
Returns the total number of requests executed by this backend.

Returns:
Returns the totalRequest.

setLastKnownCheckpoint

public void setLastKnownCheckpoint(java.lang.String checkpoint)
setLastKnownCheckpoint for this backend

Specified by:
setLastKnownCheckpoint in interface DatabaseBackendMBean
Parameters:
checkpoint - the checkpoint

getLastKnownCheckpoint

public java.lang.String getLastKnownCheckpoint()
Returns the lastKnownCheckpoint value.

Specified by:
getLastKnownCheckpoint in interface DatabaseBackendMBean
Returns:
Returns the lastKnownCheckpoint.

getDatabaseProductName

public java.lang.String getDatabaseProductName()
Returns the databaseProductName value.

Returns:
Returns the databaseProductName.

getRewritingRules

public java.util.ArrayList getRewritingRules()
Returns the rewritingRules value.

Returns:
Returns the rewritingRules.

setRewritingRules

public void setRewritingRules(java.util.ArrayList rewritingRules)
Sets the rewritingRules value.

Parameters:
rewritingRules - The rewritingRules to set.

copy

public DatabaseBackend copy(java.lang.String newName,
                            java.util.Map parameters)
                     throws java.lang.Exception
Returns a deeply copied clone of this backend Will use the same rewriting rules and will get new instance of connection managers with the same configuration

Parameters:
newName - the new name for this new backend
parameters - a set of parameters to use to replace values from the copied backend.
The different parameters are:
  • driverPath: the path to the driver
  • driver: the driver class name
  • url: the url to connect to the database
  • connectionTestStatement: the query to test the connection

Returns:
DatabaseBackend instance
Throws:
java.lang.Exception - if cannot proceed the copy

isBackuping

public boolean isBackuping()
Returns the isBackuping value.

Returns:
Returns the isBackuping.

setState

public void setState(int state)
Set the state of a backend

Parameters:
state - see BackendState for a possible list of the different state
See Also:
BackendState

notifyStateChange

public void notifyStateChange()
Notify the state of the backend has changed. This does two things: 1. Change the state of the backend stored in the recovery log 2. Sends a jmx notification. This method has all the data prefilled because we know all the parameters in advance, except the type of the notification.

See Also:
CjdbcNotificationList

notifyJmx

public void notifyJmx(java.lang.String type)
Sends JMX notification

Parameters:
type - notification type
See Also:
CjdbcNotificationList

notifyJmxError

public void notifyJmxError(java.lang.String type,
                           java.lang.Exception e)
Sends JMX error notification

Parameters:
e - Exception object. Only the message will be used
type - notification type
See Also:
CjdbcNotificationList

notifyJmx

private void notifyJmx(java.lang.String type,
                       java.lang.String level,
                       java.lang.String message)

isWriteCanBeEnabled

public boolean isWriteCanBeEnabled()
Returns the writeCanBeEnabled value.

Returns:
Returns the writeCanBeEnabled.

setStateListener

public void setStateListener(BackendStateListener stateListener)
Sets the stateListener value.

Parameters:
stateListener - The stateListener to set.

toString

public java.lang.String toString()
String description

Returns:
a string description of the backend.


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