org.objectweb.cjdbc.controller.recoverylog
Class JDBCRecoveryLog

java.lang.Object
  extended byjavax.management.StandardMBean
      extended byorg.objectweb.cjdbc.controller.jmx.AbstractStandardMBean
          extended byorg.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog
              extended byorg.objectweb.cjdbc.controller.recoverylog.JDBCRecoveryLog
All Implemented Interfaces:
AbstractRecoveryLogMBean, javax.management.DynamicMBean, javax.management.NotificationBroadcaster, javax.management.NotificationEmitter, XmlComponent

public class JDBCRecoveryLog
extends AbstractRecoveryLog
implements AbstractRecoveryLogMBean

Recovery Log using a database accessed through JDBC.

Version:
1.0
Author:
Emmanuel Cecchet , Julie Marguerite , Nicolas Modrzyk *

Nested Class Summary
 
Nested classes inherited from class javax.management.StandardMBean
 
Field Summary
private  java.lang.String backendTableCreateStatement
          Backend table
private  java.lang.String backendTableName
           
private  java.lang.String checkextraStatement
           
private  java.lang.String checkpointTableCreateStatement
           
private  java.lang.String checkpointTableName
          Checkpoint table name.
private  java.sql.Connection connection
          Connection to the database.
private  java.lang.String driverClassName
          Driver class name.
private  java.lang.String driverName
          Driver name.
private  java.lang.String idType
           
private  java.lang.String logextraStatement
           
private  JDBCLoggerThread loggerThread
           
private  java.lang.String login
          User's login.
private  java.lang.String logTableCreateStatement
           
private  long logTableId
          Current maximum value of the primary key in logTableName.
private  java.lang.String logTableName
          Name of the log table.
private  java.lang.String nameType
           
private  java.lang.String password
          User's password.
private  java.sql.PreparedStatement pstmt
          PreparedStatement used to log requests.
private  java.lang.String requestIdType
           
private  java.lang.String sqlColumnName
           
private  java.lang.String sqlType
           
private  int timeout
          Timeout for SQL requests.
private  java.lang.String transactionIdType
           
private  java.lang.String url
          Driver URL.
private  java.lang.String vloginType
           
 
Fields inherited from class org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog
logger
 
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_DB, XML_VERSION
 
Constructor Summary
JDBCRecoveryLog(java.lang.String driverName, java.lang.String driverClassName, java.lang.String url, java.lang.String login, java.lang.String password, int requestTimeout)
          Creates a new JDBCRecoveryLog instance.
 
Method Summary
 void abort(TransactionMarkerMetaData tm)
          Log a transaction abort.
 void begin(TransactionMarkerMetaData tm)
          Log the beginning of a new transaction.
 void checkRecoveryLogTables()
          Checks if the recovery log and checkpoint tables exist, and create them if they do not exist.
 void cleanRecoveryLog()
          Removes all rollbacked transaction from the recovery log.
 void commit(TransactionMarkerMetaData tm)
          Log a transaction commit.
private  void connectToDatabase()
          Gets a connection to the database.
 java.lang.String getAssociatedString()
          Allow to retrieve internationalization description on mbeans as well
 BackendRecoveryInfo getBackendInfo(java.lang.String databaseName, java.lang.String backendName)
          Retrieve recovery information on a backend.
 java.lang.String getBackendTableName()
          Returns the backendTableName value.
 java.util.ArrayList getCheckpointNames()
          Returns an array of names of all the checkpoint available in the recovery log
 long getCheckpointRequestId(java.lang.String checkpointName)
          Get the request id corresponding to a given checkpoint.
 java.lang.String getCheckpointTableName()
          Returns the checkpointTableName value.
 java.lang.String[][] getData()
          Allow to get the content of the recovery log for viewing
 long getLastTransactionId()
          Get the id of the last transaction logged in the recovery log.
 java.lang.String getLogTableName()
          Returns the logTableName value.
 java.lang.String getXmlImpl()
           
private  long incrementLogTableId()
          Increments the value of logTableId.
private  void intializeDatabase()
          Checks if the tables (log and checkpoint) already exist, and create them if needed.
 void logRequest(AbstractWriteRequest request)
          Log a write request.
 void logRequest(StoredProcedure proc, boolean isRead)
          Log a call to a stored procedure.
 RecoveryTask recoverNextRequest(long previousRequestId)
          Get the next request (begin/commit/rollback or WriteRequest) from the recovery log given the id of the previously recovered request.
private  java.lang.String recreateSkeleton(java.lang.String sql)
          Recreate the skeleton of the query from the query itself with the param tag
 void removeCheckpoint(java.lang.String checkpointName)
          Remove a checkpoint from the recovery.
 void rollback(TransactionMarkerMetaData tm)
          Log a transaction rollback.
 void setBackendTableCreateStatement(java.lang.String tableName, java.lang.String checkpointNameType, java.lang.String backendNameType, java.lang.String backendStateType, java.lang.String databaseNameType, java.lang.String extraStatement)
          Sets the backend table create statement
 void setCheckpointTableCreateStatement(java.lang.String tableName, java.lang.String nameType, java.lang.String requestIdType, java.lang.String extraStatement)
          Sets the checkpoint table name and create statement.
private  void setDriverProcessedAndSkeleton(AbstractRequest request)
          Set the driverProcessed flag of the given request according to its SQL content and rebuild the SQL skeleton if necessary.
 void setLogTableCreateStatement(java.lang.String tableName, java.lang.String idType, java.lang.String vloginType, java.lang.String sqlName, java.lang.String sqlType, java.lang.String transactionIdType, java.lang.String extraStatement)
          Sets the log table name and create statement.
 void storeBackendInfo(java.lang.String databaseName, java.lang.String backendName, java.lang.String checkpoint, int state)
          Store the state of the backend in the recovery log
 void storeCheckpoint(java.lang.String checkpointName)
          Store a Checkpoint using the current log state.
 void storeCheckpoint(java.lang.String checkpointName, long requestId)
          Store a Checkpoint using the given request id.
private  boolean validCheckpointName(java.lang.String checkpointName)
          Checks if a checkpoint with the name checkpointName is already stored in the database.
private  void waitForTransactionsEnd(boolean forceRollback)
           
 
Methods inherited from class org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog
beginRecovery, endRecovery, getRecoveringNb, getXml, isRecovering
 
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, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.objectweb.cjdbc.common.jmx.mbeans.AbstractRecoveryLogMBean
getRecoveringNb, isRecovering
 

Field Detail

driverClassName

private java.lang.String driverClassName
Driver class name.


driverName

private java.lang.String driverName
Driver name.


url

private java.lang.String url
Driver URL.


login

private java.lang.String login
User's login.


password

private java.lang.String password
User's password.


logTableName

private java.lang.String logTableName
Name of the log table.


logTableCreateStatement

private java.lang.String logTableCreateStatement

idType

private java.lang.String idType

vloginType

private java.lang.String vloginType

sqlType

private java.lang.String sqlType

transactionIdType

private java.lang.String transactionIdType

logextraStatement

private java.lang.String logextraStatement

checkpointTableName

private java.lang.String checkpointTableName
Checkpoint table name.


checkpointTableCreateStatement

private java.lang.String checkpointTableCreateStatement

backendTableCreateStatement

private java.lang.String backendTableCreateStatement
Backend table

See Also:
#setBackendTableCreateStatement()

backendTableName

private java.lang.String backendTableName

nameType

private java.lang.String nameType

requestIdType

private java.lang.String requestIdType

checkextraStatement

private java.lang.String checkextraStatement

connection

private java.sql.Connection connection
Connection to the database.


pstmt

private java.sql.PreparedStatement pstmt
PreparedStatement used to log requests.


logTableId

private long logTableId
Current maximum value of the primary key in logTableName.


timeout

private int timeout
Timeout for SQL requests.


loggerThread

private JDBCLoggerThread loggerThread

sqlColumnName

private java.lang.String sqlColumnName
Constructor Detail

JDBCRecoveryLog

public JDBCRecoveryLog(java.lang.String driverName,
                       java.lang.String driverClassName,
                       java.lang.String url,
                       java.lang.String login,
                       java.lang.String password,
                       int requestTimeout)
                throws javax.management.NotCompliantMBeanException
Creates a new JDBCRecoveryLog instance.

Parameters:
driverName - the driverClassName name.
driverClassName - the driverClassName class name.
url - the JDBC URL.
login - the login to use to connect to the database.
password - the password to connect to the database.
requestTimeout - timeout in seconds for update queries.
Throws:
javax.management.NotCompliantMBeanException - if the MBean is not JMX compliant
Method Detail

checkRecoveryLogTables

public void checkRecoveryLogTables()
Checks if the recovery log and checkpoint tables exist, and create them if they do not exist. This method also starts the logger thread.


getLastTransactionId

public long getLastTransactionId()
                          throws java.sql.SQLException
Description copied from interface: AbstractRecoveryLogMBean
Get the id of the last transaction logged in the recovery log.

Specified by:
getLastTransactionId in interface AbstractRecoveryLogMBean
Specified by:
getLastTransactionId in class AbstractRecoveryLog
Returns:
the last transaction id.
Throws:
java.sql.SQLException - if an error occured while retrieving the id.
See Also:
AbstractRecoveryLog.getLastTransactionId()

setLogTableCreateStatement

public void setLogTableCreateStatement(java.lang.String tableName,
                                       java.lang.String idType,
                                       java.lang.String vloginType,
                                       java.lang.String sqlName,
                                       java.lang.String sqlType,
                                       java.lang.String transactionIdType,
                                       java.lang.String extraStatement)
Sets the log table name and create statement.

Parameters:
tableName - of the log table
idType - of the id column
vloginType - of the login column
sqlName - name of the sql statement column
sqlType - of the sql column
transactionIdType - of the transaction column
extraStatement - like primary keys ...

setCheckpointTableCreateStatement

public void setCheckpointTableCreateStatement(java.lang.String tableName,
                                              java.lang.String nameType,
                                              java.lang.String requestIdType,
                                              java.lang.String extraStatement)
Sets the checkpoint table name and create statement.

Parameters:
tableName - name of the checkpoint table.
nameType - type for the name column
requestIdType - type for the requestId column
extraStatement - like primary keys

setBackendTableCreateStatement

public void setBackendTableCreateStatement(java.lang.String tableName,
                                           java.lang.String checkpointNameType,
                                           java.lang.String backendNameType,
                                           java.lang.String backendStateType,
                                           java.lang.String databaseNameType,
                                           java.lang.String extraStatement)
Sets the backend table create statement

Parameters:
tableName - the backend table name
checkpointNameType - type for the checkpointName column
backendNameType - type for the backendName column
backendStateType - type for the backendState column
databaseNameType - type for the databaseName column
extraStatement - like primary keys

incrementLogTableId

private long incrementLogTableId()
Increments the value of logTableId.


intializeDatabase

private void intializeDatabase()
                        throws java.sql.SQLException
Checks if the tables (log and checkpoint) already exist, and create them if needed.

Throws:
java.sql.SQLException

connectToDatabase

private void connectToDatabase()
                        throws java.sql.SQLException
Gets a connection to the database.

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

logRequest

public void logRequest(AbstractWriteRequest request)
                throws java.sql.SQLException
Description copied from class: AbstractRecoveryLog
Log a write request.

Specified by:
logRequest in class AbstractRecoveryLog
Parameters:
request - The write request to log
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractRecoveryLog.logRequest(AbstractWriteRequest)

logRequest

public void logRequest(StoredProcedure proc,
                       boolean isRead)
                throws java.sql.SQLException
Description copied from class: AbstractRecoveryLog
Log a call to a stored procedure.

Specified by:
logRequest in class AbstractRecoveryLog
Parameters:
proc - The stored procedure call to log
isRead - True if the stored procedure call returns a ResultSet
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractRecoveryLog.logRequest(org.objectweb.cjdbc.common.sql.StoredProcedure,boolean)

begin

public void begin(TransactionMarkerMetaData tm)
           throws java.sql.SQLException
Description copied from class: AbstractRecoveryLog
Log the beginning of a new transaction.

Specified by:
begin in class AbstractRecoveryLog
Parameters:
tm - The transaction marker metadata
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractRecoveryLog.begin(TransactionMarkerMetaData)

abort

public void abort(TransactionMarkerMetaData tm)
           throws java.sql.SQLException
Description copied from class: AbstractRecoveryLog
Log a transaction abort. This is used only for transaction that were started but where no request was executed, which is in fact an empty transaction. The underlying implementation might safely discard the corresponding begin from the log as an optimization.

Specified by:
abort in class AbstractRecoveryLog
Parameters:
tm - The transaction marker metadata
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractRecoveryLog.abort(org.objectweb.cjdbc.controller.requestmanager.TransactionMarkerMetaData)

commit

public void commit(TransactionMarkerMetaData tm)
            throws java.sql.SQLException
Description copied from class: AbstractRecoveryLog
Log a transaction commit.

Specified by:
commit in class AbstractRecoveryLog
Parameters:
tm - The transaction marker metadata
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractRecoveryLog.commit(TransactionMarkerMetaData)

rollback

public void rollback(TransactionMarkerMetaData tm)
              throws java.sql.SQLException
Description copied from class: AbstractRecoveryLog
Log a transaction rollback.

Specified by:
rollback in class AbstractRecoveryLog
Parameters:
tm - The transaction marker metadata
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractRecoveryLog.rollback(TransactionMarkerMetaData)

storeCheckpoint

public void storeCheckpoint(java.lang.String checkpointName)
                     throws java.sql.SQLException
Description copied from interface: AbstractRecoveryLogMBean
Store a Checkpoint using the current log state.

Specified by:
storeCheckpoint in interface AbstractRecoveryLogMBean
Specified by:
storeCheckpoint in class AbstractRecoveryLog
Parameters:
checkpointName - Name of the checkpoint
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractRecoveryLog.storeCheckpoint(String)

validCheckpointName

private boolean validCheckpointName(java.lang.String checkpointName)
                             throws java.sql.SQLException
Checks if a checkpoint with the name checkpointName is already stored in the database.

Parameters:
checkpointName - name of the checkpoint.
Returns:
ResultSet empty if no checkpoint was found.
Throws:
java.sql.SQLException

storeCheckpoint

public void storeCheckpoint(java.lang.String checkpointName,
                            long requestId)
                     throws java.sql.SQLException
Description copied from interface: AbstractRecoveryLogMBean
Store a Checkpoint using the given request id.

Specified by:
storeCheckpoint in interface AbstractRecoveryLogMBean
Specified by:
storeCheckpoint in class AbstractRecoveryLog
Parameters:
checkpointName - Name of the checkpoint
requestId - request identifier
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractRecoveryLog.storeCheckpoint(String, long)

waitForTransactionsEnd

private void waitForTransactionsEnd(boolean forceRollback)

getCheckpointRequestId

public long getCheckpointRequestId(java.lang.String checkpointName)
                            throws java.sql.SQLException
Description copied from interface: AbstractRecoveryLogMBean
Get the request id corresponding to a given checkpoint. This is the first step in a recovery process. Following steps consist in calling recoverNextRequest.

Specified by:
getCheckpointRequestId in interface AbstractRecoveryLogMBean
Specified by:
getCheckpointRequestId in class AbstractRecoveryLog
Parameters:
checkpointName - Name of the checkpoint
Returns:
int the request identifier corresponding to this checkpoint.
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractRecoveryLog.getCheckpointRequestId(String)

recoverNextRequest

public RecoveryTask recoverNextRequest(long previousRequestId)
                                throws java.sql.SQLException
Description copied from class: AbstractRecoveryLog
Get the next request (begin/commit/rollback or WriteRequest) from the recovery log given the id of the previously recovered request.

The id of the request before the first one to recover is given by getCheckpointRequestId.

Specified by:
recoverNextRequest in class AbstractRecoveryLog
Parameters:
previousRequestId - id of the previously recovered request
Returns:
AbstractTask task corresponding to the next request to recover
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractRecoveryLog.recoverNextRequest(long)

setDriverProcessedAndSkeleton

private void setDriverProcessedAndSkeleton(AbstractRequest request)
Set the driverProcessed flag of the given request according to its SQL content and rebuild the SQL skeleton if necessary.

Parameters:
request - Request to process

recreateSkeleton

private java.lang.String recreateSkeleton(java.lang.String sql)
Recreate the skeleton of the query from the query itself with the param tag

Parameters:
sql - the sql query as it is recorded in the recovery log
Returns:
the sql skelton with '?' instead of the tags

cleanRecoveryLog

public void cleanRecoveryLog()
                      throws java.sql.SQLException
Removes all rollbacked transaction from the recovery log.

Specified by:
cleanRecoveryLog in interface AbstractRecoveryLogMBean
Specified by:
cleanRecoveryLog in class AbstractRecoveryLog
Throws:
java.sql.SQLException - if an error occurs.

removeCheckpoint

public void removeCheckpoint(java.lang.String checkpointName)
                      throws java.sql.SQLException
Description copied from interface: AbstractRecoveryLogMBean
Remove a checkpoint from the recovery. This is useful for recovery maintenant

Specified by:
removeCheckpoint in interface AbstractRecoveryLogMBean
Specified by:
removeCheckpoint in class AbstractRecoveryLog
Parameters:
checkpointName - to remove
Throws:
java.sql.SQLException - if an error occurs
See Also:
AbstractRecoveryLog.removeCheckpoint(java.lang.String)

getCheckpointNames

public java.util.ArrayList getCheckpointNames()
                                       throws java.sql.SQLException
Description copied from interface: AbstractRecoveryLogMBean
Returns an array of names of all the checkpoint available in the recovery log

Specified by:
getCheckpointNames in interface AbstractRecoveryLogMBean
Specified by:
getCheckpointNames in class AbstractRecoveryLog
Returns:
ArrayList of String checkpoint names
Throws:
java.sql.SQLException - if fails
See Also:
AbstractRecoveryLog.getCheckpointNames()

storeBackendInfo

public void storeBackendInfo(java.lang.String databaseName,
                             java.lang.String backendName,
                             java.lang.String checkpoint,
                             int state)
                      throws java.sql.SQLException
Description copied from interface: AbstractRecoveryLogMBean
Store the state of the backend in the recovery log

Specified by:
storeBackendInfo in interface AbstractRecoveryLogMBean
Specified by:
storeBackendInfo in class AbstractRecoveryLog
Parameters:
databaseName - name of the virtual database
backendName - name of the backend
checkpoint - lastknown check point for this backend
state - the state of the backend
Throws:
java.sql.SQLException - if cannot proceed
See Also:
AbstractRecoveryLog.storeBackendInfo(java.lang.String, java.lang.String, java.lang.String, int)

getBackendInfo

public BackendRecoveryInfo getBackendInfo(java.lang.String databaseName,
                                          java.lang.String backendName)
Description copied from interface: AbstractRecoveryLogMBean
Retrieve recovery information on a backend. This includes, the last known state of the backend, and the last known checkpoint

Specified by:
getBackendInfo in interface AbstractRecoveryLogMBean
Specified by:
getBackendInfo in class AbstractRecoveryLog
Parameters:
databaseName - the virtual database name
backendName - the backend name
Returns:
BackendRecoveryInfo instance or null if the backend does not exist
See Also:
AbstractRecoveryLog.getBackendInfo(java.lang.String, java.lang.String)

getXmlImpl

public java.lang.String getXmlImpl()
Specified by:
getXmlImpl in class AbstractRecoveryLog
See Also:
AbstractRecoveryLog.getXmlImpl()

getBackendTableName

public java.lang.String getBackendTableName()
Returns the backendTableName value.

Returns:
Returns the backendTableName.

getCheckpointTableName

public java.lang.String getCheckpointTableName()
Returns the checkpointTableName value.

Returns:
Returns the checkpointTableName.

getLogTableName

public java.lang.String getLogTableName()
Returns the logTableName value.

Returns:
Returns the logTableName.

getData

public java.lang.String[][] getData()
Description copied from class: AbstractRecoveryLog
Allow to get the content of the recovery log for viewing

Specified by:
getData in class AbstractRecoveryLog
Returns:
String[][]
See Also:
AbstractRecoveryLog.getData()

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


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