org.objectweb.cjdbc.controller.recoverylog
Class JDBCRecoveryLog

java.lang.Object
  extended byorg.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog
      extended byorg.objectweb.cjdbc.controller.recoverylog.JDBCRecoveryLog

public class JDBCRecoveryLog
extends AbstractRecoveryLog

Recovery Log using a database accessed through JDBC.

Version:
1.0
Author:
Emmanuel Cecchet, Julie Marguerite

Field Summary
private  java.lang.String checkpointTable
          Checkpoint table name.
private  java.lang.String checkpointTableCreateStatement
           
private  java.sql.Connection connection
          Connection to the database.
private  java.lang.String driver
          Driver name.
private  JDBCLoggerThread loggerThread
           
private  java.lang.String login
          User's login.
private  java.lang.String logTable
          Name of the log table.
private  java.lang.String logTableCreateStatement
           
private  int logTableId
          Current maximum value of the primary key in logTable.
private  java.lang.String password
          User's password.
private  java.sql.PreparedStatement pstmt
          PreparedStatement used to log requests.
private  int timeout
          Timeout for SQL requests.
private  java.lang.String url
          Driver URL.
 
Fields inherited from class org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog
logger
 
Constructor Summary
JDBCRecoveryLog(java.lang.String driver, java.lang.String url, java.lang.String login, java.lang.String password, int requestTimeout)
          Creates a new JDBCRecoveryLog instance.
 
Method Summary
 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 and deletes all begin/commit statements for completed transactions.
 void commit(TransactionMarkerMetaData tm)
          Log a transaction commit.
private  void connectToDatabase()
          Gets a connection to the database.
 int getCheckpointRequestId(java.lang.String checkpointName)
          Get the request id corresponding to a given checkpoint.
 int getLogTableId()
          Returns the value of logTableId.
 java.lang.String getXmlInformation()
          Get xml information of the current recovery load in the system.
private  int incrementLogTableId()
          Increments the value of logTableId.
private  void intializeDatabase()
          Checks if the tables (log and checkpoint) already exist, else, it creates missing tables on the database.
 void logRequest(AbstractWriteRequest request)
          Log a write request.
 void logRequest(StoredProcedure proc, boolean isRead)
          Log a call to a stored procedure.
 RecoveryTask recoverNextRequest(int previousRequestId)
          Get the next request (begin/commit/rollback or WriteRequest) from the recovery log given the id of the previously recovered request.
 void rollback(TransactionMarkerMetaData tm)
          Log a transaction rollback.
 void setCheckpointTableCreateStatement(java.lang.String checkpointTableName, java.lang.String checkpointTableCreateStatement)
          Sets the checkpoint table name and create statement.
 void setLogTableCreateStatement(java.lang.String logTableName, java.lang.String logTableCreateStatement)
          Sets the log table name and create statement.
 void storeCheckpoint(java.lang.String checkpointName)
          Store a Checkpoint using the current log state.
 void storeCheckpoint(java.lang.String checkpointName, int 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, isRecovering
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

driver

private java.lang.String driver
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.


logTable

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


logTableCreateStatement

private java.lang.String logTableCreateStatement

checkpointTable

private java.lang.String checkpointTable
Checkpoint table name.


checkpointTableCreateStatement

private java.lang.String checkpointTableCreateStatement

connection

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


pstmt

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


logTableId

private int logTableId
Current maximum value of the primary key in logTable.


timeout

private int timeout
Timeout for SQL requests.


loggerThread

private JDBCLoggerThread loggerThread
Constructor Detail

JDBCRecoveryLog

public JDBCRecoveryLog(java.lang.String driver,
                       java.lang.String url,
                       java.lang.String login,
                       java.lang.String password,
                       int requestTimeout)
Creates a new JDBCRecoveryLog instance.

Parameters:
driver - the driver 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.
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.


setLogTableCreateStatement

public void setLogTableCreateStatement(java.lang.String logTableName,
                                       java.lang.String logTableCreateStatement)
Sets the log table name and create statement.

Parameters:
logTableName - Name of the log table
logTableCreateStatement - The create statement to create the log table

setCheckpointTableCreateStatement

public void setCheckpointTableCreateStatement(java.lang.String checkpointTableName,
                                              java.lang.String checkpointTableCreateStatement)
Sets the checkpoint table name and create statement.

Parameters:
checkpointTableName - name of the checkpoint table.
checkpointTableCreateStatement - the create statement to create the checkpoint table.

getLogTableId

public int getLogTableId()
Returns the value of logTableId.

Returns:
int

incrementLogTableId

private int incrementLogTableId()
Increments the value of logTableId.


intializeDatabase

private void intializeDatabase()
                        throws java.sql.SQLException
Checks if the tables (log and checkpoint) already exist, else, it creates missing tables on the database.

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

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 class: AbstractRecoveryLog
Store a Checkpoint using the current log state.

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,
                            int requestId)
                     throws java.sql.SQLException
Description copied from class: AbstractRecoveryLog
Store a Checkpoint using the given request id.

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, int)

waitForTransactionsEnd

private void waitForTransactionsEnd(boolean forceRollback)

getCheckpointRequestId

public int getCheckpointRequestId(java.lang.String checkpointName)
                           throws java.sql.SQLException
Description copied from class: AbstractRecoveryLog
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 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(int 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(int)

cleanRecoveryLog

public void cleanRecoveryLog()
                      throws java.sql.SQLException
Removes all rollbacked transaction from the recovery log and deletes all begin/commit statements for completed transactions.

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

getXmlInformation

public java.lang.String getXmlInformation()
Description copied from class: AbstractRecoveryLog
Get xml information of the current recovery load in the system.

Specified by:
getXmlInformation in class AbstractRecoveryLog
Returns:
xml formatted string
See Also:
AbstractRecoveryLog.getXmlInformation()


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