Public Member Functions | |
JDBCRecoveryLog (String driverName, String driverClassName, String url, String login, String password, int requestTimeout) throws NotCompliantMBeanException | |
void | logRequest (AbstractWriteRequest request) throws SQLException |
void | logRequest (StoredProcedure proc, boolean isRead) throws SQLException |
long | getLastTransactionId () throws SQLException |
void | begin (TransactionMarkerMetaData tm) throws SQLException |
void | abort (TransactionMarkerMetaData tm) throws SQLException |
void | commit (TransactionMarkerMetaData tm) throws SQLException |
void | rollback (TransactionMarkerMetaData tm) throws SQLException |
long | getCheckpointRequestId (String checkpointName) throws SQLException |
RecoveryTask | recoverNextRequest (long previousRequestId) throws SQLException |
void | cleanRecoveryLog () throws SQLException |
ArrayList | getCheckpointNames () throws SQLException |
void | storeCheckpoint (String checkpointName) throws SQLException |
void | storeCheckpoint (String checkpointName, long requestId) throws SQLException |
void | removeCheckpoint (String checkpointName) throws SQLException |
BackendRecoveryInfo | getBackendRecoveryInfo (String databaseName, String backendName) |
void | storeBackendRecoveryInfo (String databaseName, BackendRecoveryInfo backendRecoveryInfo) throws SQLException |
void | checkRecoveryLogTables () |
String | getBackendTableName () |
String | getCheckpointTableName () |
String | getLogTableName () |
void | setBackendTableCreateStatement (String tableName, String checkpointNameType, String backendNameType, String backendStateType, String databaseNameType, String extraStatement) |
void | setCheckpointTableCreateStatement (String tableName, String nameType, String requestIdType, String extraStatement) |
void | setLogTableCreateStatement (String tableName, String idType, String vloginType, String sqlName, String sqlType, String transactionIdType, String extraStatement) |
String[][] | getData () |
String | getAssociatedString () |
String | getXmlImpl () |
Definition at line 67 of file JDBCRecoveryLog.java.
|
Creates a new
Definition at line 141 of file JDBCRecoveryLog.java. 00144 { 00145 super(AbstractRecoveryLogMBean.class); 00146 this.driverName = driverName; 00147 this.driverClassName = driverClassName; 00148 this.url = url; 00149 this.login = login; 00150 this.password = password; 00151 this.timeout = requestTimeout; 00152 00153 // Connect to the database 00154 try 00155 { 00156 connectToDatabase(); 00157 } 00158 catch (SQLException e) 00159 { 00160 throw new RuntimeException("Unable to connect to the database: " + e); 00161 } 00162 00163 // Logger thread will be created in checkRecoveryLogTables() 00164 // after database has been initialized 00165 }
|
|
Implements org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog. Definition at line 482 of file JDBCRecoveryLog.java. 00483 { 00484 // We have to perform exactly the same job as a rollback 00485 rollback(tm); 00486 }
|
|
Implements org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog. Definition at line 472 of file JDBCRecoveryLog.java. 00473 { 00474 // Store the begin in the database 00475 loggerThread.log(incrementLogTableId(), tm.getLogin(), "begin", tm 00476 .getTransactionId(), false); 00477 }
|
|
Checks if the recovery log and checkpoint tables exist, and create them if they do not exist. This method also starts the logger thread. Definition at line 1352 of file JDBCRecoveryLog.java. 01353 { 01354 try 01355 { 01356 intializeDatabase(); 01357 pstmt = connection.prepareStatement("INSERT INTO " + logTableName 01358 + " VALUES(?,?,?,?)"); 01359 } 01360 catch (SQLException e) 01361 { 01362 throw new RuntimeException("Unable to initialize the database: " + e); 01363 } 01364 01365 // Start the logger thread 01366 loggerThread = new JDBCLoggerThread(pstmt, logger); 01367 loggerThread.start(); 01368 }
|
|
Removes all rollbacked transaction from the recovery log.
Implements org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog. Definition at line 896 of file JDBCRecoveryLog.java. 00897 { 00898 PreparedStatement stmt = null; 00899 00900 // Remove the rollback statements and associated requests from the database 00901 ResultSet rs = null; 00902 try 00903 { 00904 // Get the list of transaction ids on which a rollback occurred 00905 stmt = connection.prepareStatement("SELECT transaction_id FROM " 00906 + logTableName + " WHERE sql LIKE ?"); 00907 stmt.setString(1, "rollback"); 00908 rs = stmt.executeQuery(); 00909 } 00910 catch (SQLException e) 00911 { 00912 try 00913 { 00914 if (stmt != null) 00915 stmt.close(); 00916 } 00917 catch (Exception ignore) 00918 { 00919 } 00920 throw new SQLException("Unable get rollback statements : " + e); 00921 } 00922 PreparedStatement pstmt = null; 00923 long transactionId = -1; 00924 try 00925 { 00926 // remove the rollbacked transaction from the database 00927 while (rs.next()) 00928 { 00929 transactionId = rs.getLong("transaction_Id"); 00930 pstmt = connection.prepareStatement("DELETE FROM " + logTableName 00931 + " WHERE transaction_id=?"); 00932 pstmt.setLong(1, transactionId); 00933 pstmt.executeUpdate(); 00934 pstmt.close(); 00935 } 00936 rs.close(); 00937 stmt.close(); 00938 } 00939 catch (SQLException e) 00940 { 00941 throw new SQLException(Translate.get( 00942 "recovery.jdbc.transaction.remove.failed", new String[]{ 00943 String.valueOf(transactionId), e.getMessage()})); 00944 } 00945 finally 00946 { 00947 try 00948 { 00949 if (stmt != null) 00950 stmt.close(); 00951 } 00952 catch (Exception ignore) 00953 { 00954 } 00955 try 00956 { 00957 if (pstmt != null) 00958 pstmt.close(); 00959 } 00960 catch (Exception ignore) 00961 { 00962 } 00963 00964 } 00965 }
|
|
Implements org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog. Definition at line 491 of file JDBCRecoveryLog.java. 00492 { 00493 // Some backends started a recovery process, log the commit 00494 loggerThread.log(incrementLogTableId(), tm.getLogin(), "commit", tm 00495 .getTransactionId(), false); 00496 }
|
|
Definition at line 1543 of file JDBCRecoveryLog.java. 01544 { 01545 return "jdbcrecoverylog"; 01546 }
|
|
Implements org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog. Definition at line 1218 of file JDBCRecoveryLog.java. 01220 { 01221 PreparedStatement stmt = null; 01222 String checkpoint = null; 01223 int backendState = BackendState.UNKNOWN; 01224 try 01225 { 01226 // 1. Get the reference point to delete 01227 stmt = connection.prepareStatement("SELECT * FROM " + backendTableName 01228 + " WHERE backendName LIKE ? AND databaseName LIKE ?"); 01229 stmt.setString(1, backendName); 01230 stmt.setString(2, databaseName); 01231 ResultSet rs = stmt.executeQuery(); 01232 01233 if (rs.next()) 01234 { 01235 checkpoint = rs.getString("checkpointName"); 01236 backendState = rs.getInt("backendState"); 01237 } 01238 rs.close(); 01239 } 01240 catch (SQLException e) 01241 { 01242 logger.info( 01243 "An error occured while retrieving backend recovery information", e); 01244 } 01245 finally 01246 { 01247 try 01248 { 01249 if (stmt != null) 01250 stmt.close(); 01251 } 01252 catch (Exception ignore) 01253 { 01254 } 01255 } 01256 return new BackendRecoveryInfo(backendName, checkpoint, backendState, 01257 databaseName); 01258 }
|
|
Returns the backendTableName value.
Definition at line 1375 of file JDBCRecoveryLog.java. Referenced by org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase.getDatabaseSchemaFromActiveBackendsAndRefreshDatabaseProductNames(). 01376 {
01377 return backendTableName;
01378 }
|
|
Implements org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog. Definition at line 976 of file JDBCRecoveryLog.java. References org.objectweb.cjdbc.common.sql.AbstractRequest.debug(). 00977 { 00978 PreparedStatement stmt = null; 00979 00980 // Wait for transaction to finish 00981 waitForTransactionsEnd(true); 00982 00983 try 00984 { 00985 if (logger.isDebugEnabled()) 00986 logger.debug("Retrieving checkpoint names list"); 00987 stmt = connection.prepareStatement("SELECT name from " 00988 + checkpointTableName); 00989 ResultSet rs = stmt.executeQuery(); 00990 ArrayList list = new ArrayList(); 00991 while (rs.next()) 00992 { 00993 list.add(rs.getString(1)); 00994 } 00995 rs.close(); 00996 return list; 00997 } 00998 catch (Exception e) 00999 { 01000 throw new SQLException(Translate.get( 01001 "recovery.jdbc.checkpoint.list.failed", e)); 01002 } 01003 finally 01004 { 01005 try 01006 { 01007 if (stmt != null) 01008 stmt.close(); 01009 } 01010 catch (SQLException ignore) 01011 { 01012 } 01013 } 01014 }
|
|
Implements org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog. Definition at line 552 of file JDBCRecoveryLog.java. References java.sql.Statement.executeQuery(). 00553 { 00554 long requestId = -1; 00555 PreparedStatement stmt = null; 00556 ResultSet rs = null; 00557 try 00558 { 00559 stmt = connection.prepareStatement("SELECT request_id FROM " 00560 + checkpointTableName + " WHERE name LIKE ?"); 00561 stmt.setString(1, checkpointName); 00562 rs = stmt.executeQuery(); 00563 00564 if (rs.next()) 00565 requestId = rs.getInt("request_id"); 00566 else 00567 { 00568 String msg = Translate.get("recovery.jdbc.checkpoint.not.found", 00569 checkpointName); 00570 logger.info(msg); 00571 throw new SQLException(msg); 00572 } 00573 } 00574 catch (SQLException e) 00575 { 00576 throw new SQLException(Translate.get( 00577 "recovery.jdbc.checkpoint.not.found.error", new String[]{ 00578 checkpointName, e.getMessage()})); 00579 } 00580 finally 00581 { 00582 try 00583 { 00584 if (rs != null) 00585 rs.close(); 00586 } 00587 catch (Exception ignore) 00588 { 00589 } 00590 try 00591 { 00592 if (stmt != null) 00593 stmt.close(); 00594 } 00595 catch (Exception ignore) 00596 { 00597 } 00598 } 00599 return requestId; 00600 }
|
|
Returns the checkpointTableName value.
Definition at line 1385 of file JDBCRecoveryLog.java. Referenced by org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase.getDatabaseSchemaFromActiveBackendsAndRefreshDatabaseProductNames(). 01386 {
01387 return checkpointTableName;
01388 }
|
|
Implements org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog. Definition at line 1497 of file JDBCRecoveryLog.java. References java.sql.Statement.executeQuery(). 01498 { 01499 Statement stmt = null; 01500 ResultSet rs = null; 01501 try 01502 { 01503 stmt = connection.createStatement(); 01504 rs = stmt.executeQuery("select * from " + logTableName); 01505 ArrayList list = new ArrayList(); 01506 while (rs.next()) 01507 { 01508 // 3: Query 2: User 1: ID 4: TID 01509 list.add(new String[]{rs.getString(3), rs.getString(2), 01510 rs.getString(1), rs.getString(4)}); 01511 } 01512 String[][] result = new String[list.size()][4]; 01513 for (int i = 0; i < list.size(); i++) 01514 result[i] = (String[]) list.get(i); 01515 return result; 01516 } 01517 catch (SQLException e) 01518 { 01519 return null; 01520 } 01521 finally 01522 { 01523 try 01524 { 01525 rs.close(); 01526 } 01527 catch (SQLException ignore) 01528 { 01529 } 01530 try 01531 { 01532 stmt.close(); 01533 } 01534 catch (SQLException ignore) 01535 { 01536 } 01537 } 01538 }
|
|
Implements org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog. Definition at line 422 of file JDBCRecoveryLog.java. References java.sql.Statement.close(), and java.sql.Statement.executeQuery(). 00423 { 00424 Statement stmt = null; 00425 ResultSet rs = null; 00426 try 00427 { 00428 stmt = connection.createStatement(); 00429 rs = stmt.executeQuery("select max(transaction_id) from " + logTableName); 00430 if (rs.next()) 00431 return rs.getInt(1); 00432 else 00433 return 0; 00434 } 00435 catch (SQLException e) 00436 { 00437 throw e; 00438 } 00439 finally 00440 { 00441 try 00442 { 00443 if (rs != null) 00444 rs.close(); 00445 } 00446 catch (Exception ignore) 00447 { 00448 } 00449 try 00450 { 00451 if (stmt != null) 00452 stmt.close(); 00453 } 00454 catch (Exception ignore) 00455 { 00456 } 00457 } 00458 }
|
|
Returns the logTableName value.
Definition at line 1395 of file JDBCRecoveryLog.java. Referenced by org.objectweb.cjdbc.controller.virtualdatabase.VirtualDatabase.getDatabaseSchemaFromActiveBackendsAndRefreshDatabaseProductNames(). 01396 {
01397 return logTableName;
01398 }
|
|
Implements org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog. Definition at line 1551 of file JDBCRecoveryLog.java. 01552 { 01553 StringBuffer info = new StringBuffer(); 01554 info.append("<" + DatabasesXmlTags.ELT_JDBCRecoveryLog + " " 01555 + DatabasesXmlTags.ATT_driver + "=\"" + driverClassName + "\" " 01556 + DatabasesXmlTags.ATT_url + "=\"" + url + "\" "); 01557 if (driverName != null) 01558 { 01559 info.append(DatabasesXmlTags.ATT_driverPath + "=\"" + driverName + "\" "); 01560 } 01561 info.append(DatabasesXmlTags.ATT_login + "=\"" + login + "\" " 01562 + DatabasesXmlTags.ATT_password + "=\"" + password + "\" " 01563 + DatabasesXmlTags.ATT_requestTimeout + "=\"" + (timeout / 1000) 01564 + "\">"); 01565 // Recovery Log table 01566 info.append("<" + DatabasesXmlTags.ELT_RecoveryLogTable + " " 01567 + DatabasesXmlTags.ATT_tableName + "=\"" + logTableName + "\"" + " " 01568 + DatabasesXmlTags.ATT_idColumnType + "=\"" + idType + "\"" + " " 01569 + DatabasesXmlTags.ATT_vloginColumnType + "=\"" + vloginType + "\"" 01570 + " " + DatabasesXmlTags.ATT_sqlColumnType + "=\"" + sqlType + "\"" 01571 + " " + DatabasesXmlTags.ATT_transactionIdColumnType + "=\"" 01572 + transactionIdType + "\"" + " " 01573 + DatabasesXmlTags.ATT_extraStatementDefinition + "=\"" 01574 + logextraStatement + "\"/>"); 01575 // Checkpoint table 01576 info.append("<" + DatabasesXmlTags.ELT_CheckpointTable + " " 01577 + DatabasesXmlTags.ATT_tableName + "=\"" + checkpointTableName + "\"" 01578 + " " + DatabasesXmlTags.ATT_checkpointNameColumnType + "=\"" 01579 + nameType + "\"" + " " + DatabasesXmlTags.ATT_requestIdColumnType 01580 + "=\"" + requestIdType + "\"" + " " 01581 + DatabasesXmlTags.ATT_extraStatementDefinition + "=\"" 01582 + checkextraStatement + "\"" + "/>"); 01583 // BackendLog table 01584 info.append("<" + DatabasesXmlTags.ELT_BackendTable + " " 01585 + DatabasesXmlTags.ATT_tableName + "=\"" + backendTableName + "\"" 01586 + "/>"); 01587 01588 info.append("</" + DatabasesXmlTags.ELT_JDBCRecoveryLog + ">"); 01589 01590 return info.toString(); 01591 }
|
|
Implements org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog. Definition at line 404 of file JDBCRecoveryLog.java. 00406 { 00407 if (isRead) 00408 loggerThread.log(incrementLogTableId(), proc.getLogin(), proc.getSQL(), 00409 proc.getTransactionId(), proc.getEscapeProcessing()); 00410 else 00411 { // Reverse the first bracket so that we can identify a write call 00412 StringBuffer writeCall = new StringBuffer(proc.getSQL()); 00413 writeCall.setCharAt(0, '}'); 00414 loggerThread.log(incrementLogTableId(), proc.getLogin(), writeCall 00415 .toString(), proc.getTransactionId(), proc.getEscapeProcessing()); 00416 } 00417 }
|
|
Implements org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog. Definition at line 395 of file JDBCRecoveryLog.java. 00396 { 00397 loggerThread.log(incrementLogTableId(), request.getLogin(), request 00398 .getSQL(), request.getTransactionId(), request.getEscapeProcessing()); 00399 }
|
|
Implements org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog. Definition at line 605 of file JDBCRecoveryLog.java. References java.sql.Statement.close(), org.objectweb.cjdbc.common.sql.AbstractRequest.debug(), java.sql.Statement.executeQuery(), org.objectweb.cjdbc.common.sql.AbstractRequest.setIsAutoCommit(), org.objectweb.cjdbc.common.sql.AbstractRequest.setLogin(), and org.objectweb.cjdbc.common.sql.AbstractRequest.setTransactionId(). 00607 { 00608 RecoveryTask task = null; 00609 00610 // Get the request with the id after previousRequestId. 00611 PreparedStatement stmt = null; 00612 try 00613 { 00614 ResultSet rs = null; 00615 boolean emptyResult; 00616 00617 stmt = connection.prepareStatement("SELECT * FROM " + logTableName 00618 + " WHERE id>? AND id<=? ORDER BY id"); 00619 // Note that the statement is closed in the finally block 00620 do 00621 { 00622 // Take a window of 2 requests if there is a small hole 00623 // induced by a removed begin/commit/rollback command. 00624 stmt.setLong(1, previousRequestId); 00625 stmt.setLong(2, previousRequestId + 2); 00626 // Close ResultSet of previous loop step to free resources. 00627 if (rs != null) 00628 rs.close(); 00629 rs = stmt.executeQuery(); 00630 previousRequestId += 2; // Shift the window 00631 emptyResult = !rs.next(); 00632 } 00633 while (emptyResult && (previousRequestId <= logTableId)); 00634 00635 // No more request after this one 00636 if (emptyResult) 00637 { 00638 rs.close(); 00639 return null; 00640 } 00641 00642 String sql = rs.getString(sqlColumnName); 00643 String user = rs.getString("vlogin"); 00644 int transactionId = rs.getInt("transaction_id"); 00645 int id = rs.getInt("id"); 00646 rs.close(); 00647 00648 // Construct the request object according to its type 00649 boolean escapeProcessing = true; 00650 sql = sql.trim(); 00651 // Check that the command starts with (only 2 letters are needed) 00652 // in[sert]/up[date]/de[lete]/cr[eate]/dr[op]/be[gin]/co[mmit]/ro[llback]/{c[all]/}c[all] 00653 // (write stored procedure call) 00654 String lower = sql.substring(0, 2).toLowerCase(); 00655 if (lower.equals("in")) 00656 { // insert 00657 AbstractWriteRequest wr = new InsertRequest(sql, escapeProcessing, 00658 timeout, "\n"); 00659 wr.setLogin(user); 00660 if (logger.isDebugEnabled()) 00661 logger.debug("insert request: " + sql); 00662 setDriverProcessedAndSkeleton(wr); 00663 if (transactionId != 0) 00664 { 00665 wr.setIsAutoCommit(false); 00666 wr.setTransactionId(transactionId); 00667 } 00668 else 00669 wr.setIsAutoCommit(true); 00670 task = new RecoveryTask(transactionId, id, new WriteRequestTask(1, 1, 00671 wr)); 00672 } 00673 else if (lower.equals("up")) 00674 { // update 00675 AbstractWriteRequest wr = new UpdateRequest(sql, escapeProcessing, 00676 timeout, "\n"); 00677 wr.setLogin(user); 00678 setDriverProcessedAndSkeleton(wr); 00679 if (logger.isDebugEnabled()) 00680 logger.debug("update request: " + sql); 00681 if (transactionId != 0) 00682 { 00683 wr.setIsAutoCommit(false); 00684 wr.setTransactionId(transactionId); 00685 } 00686 else 00687 wr.setIsAutoCommit(true); 00688 task = new RecoveryTask(transactionId, id, new WriteRequestTask(1, 1, 00689 wr)); 00690 } 00691 else if (lower.equals("de")) 00692 { // delete 00693 AbstractWriteRequest wr = new DeleteRequest(sql, escapeProcessing, 00694 timeout, "\n"); 00695 wr.setLogin(user); 00696 setDriverProcessedAndSkeleton(wr); 00697 if (logger.isDebugEnabled()) 00698 logger.debug("delete request: " + sql); 00699 if (transactionId != 0) 00700 { 00701 wr.setIsAutoCommit(false); 00702 wr.setTransactionId(transactionId); 00703 } 00704 else 00705 wr.setIsAutoCommit(true); 00706 task = new RecoveryTask(transactionId, id, new WriteRequestTask(1, 1, 00707 wr)); 00708 } 00709 else if (lower.equals("cr")) 00710 { // create 00711 AbstractWriteRequest wr = new CreateRequest(sql, escapeProcessing, 00712 timeout, "\n"); 00713 wr.setLogin(user); 00714 setDriverProcessedAndSkeleton(wr); 00715 if (logger.isDebugEnabled()) 00716 logger.debug("create request: " + sql); 00717 if (transactionId != 0) 00718 { 00719 wr.setIsAutoCommit(false); 00720 wr.setTransactionId(transactionId); 00721 } 00722 else 00723 wr.setIsAutoCommit(true); 00724 task = new RecoveryTask(transactionId, id, new WriteRequestTask(1, 1, 00725 wr)); 00726 } 00727 else if (lower.equals("al")) 00728 { // alter 00729 AbstractWriteRequest wr = new AlterRequest(sql, escapeProcessing, 00730 timeout, "\n"); 00731 wr.setLogin(user); 00732 setDriverProcessedAndSkeleton(wr); 00733 if (logger.isDebugEnabled()) 00734 logger.debug("alter request: " + sql); 00735 if (transactionId != 0) 00736 { 00737 wr.setIsAutoCommit(false); 00738 wr.setTransactionId(transactionId); 00739 } 00740 else 00741 wr.setIsAutoCommit(true); 00742 task = new RecoveryTask(transactionId, id, new WriteRequestTask(1, 1, 00743 wr)); 00744 } 00745 else if (lower.equals("dr")) 00746 { // drop 00747 AbstractWriteRequest wr = new DropRequest(sql, escapeProcessing, 00748 timeout, "\n"); 00749 wr.setLogin(user); 00750 setDriverProcessedAndSkeleton(wr); 00751 if (logger.isDebugEnabled()) 00752 logger.debug("drop request: " + sql); 00753 if (transactionId != 0) 00754 { 00755 wr.setIsAutoCommit(false); 00756 wr.setTransactionId(transactionId); 00757 } 00758 else 00759 wr.setIsAutoCommit(true); 00760 task = new RecoveryTask(transactionId, id, new WriteRequestTask(1, 1, 00761 wr)); 00762 } 00763 else if (lower.equals("be")) 00764 { // begin 00765 task = new RecoveryTask(transactionId, id, new BeginTask(1, 1, 00766 (long) timeout * 1000, user, transactionId)); 00767 if (logger.isDebugEnabled()) 00768 logger.debug("begin transaction: " + transactionId); 00769 } 00770 else if (lower.equals("co")) 00771 { // commit 00772 task = new RecoveryTask(transactionId, id, new CommitTask(1, 1, 00773 (long) timeout * 1000, user, transactionId)); 00774 if (logger.isDebugEnabled()) 00775 logger.debug("commit transaction: " + transactionId); 00776 } 00777 else if (lower.equals("ro")) 00778 { // rollback 00779 task = new RecoveryTask(transactionId, id, new RollbackTask(1, 1, 00780 (long) timeout * 1000, user, transactionId)); 00781 if (logger.isDebugEnabled()) 00782 logger.debug("rollback transaction: " + transactionId); 00783 } 00784 else if (lower.equals("{c")) 00785 { // read stored procedure call "{call ...}" 00786 StoredProcedure proc = new StoredProcedure(sql, escapeProcessing, 00787 timeout, "\n"); 00788 proc.setLogin(user); 00789 setDriverProcessedAndSkeleton(proc); 00790 if (logger.isDebugEnabled()) 00791 logger.debug("read stored procedure call: " + sql); 00792 if (transactionId != 0) 00793 { 00794 proc.setIsAutoCommit(false); 00795 proc.setTransactionId(transactionId); 00796 } 00797 else 00798 proc.setIsAutoCommit(true); 00799 task = new RecoveryTask(transactionId, id, new ReadStoredProcedureTask( 00800 1, 1, proc, null)); 00801 } 00802 else if (lower.equals("}c")) 00803 { // write stored procedure call, 00804 // we must replace "}call ...}" with "{call ...}" 00805 StringBuffer writeCall = new StringBuffer(sql); 00806 writeCall.setCharAt(0, '{'); 00807 StoredProcedure proc = new StoredProcedure(writeCall.toString(), 00808 escapeProcessing, timeout, "\n"); 00809 proc.setLogin(user); 00810 setDriverProcessedAndSkeleton(proc); 00811 if (logger.isDebugEnabled()) 00812 logger.debug("write stored procedure call: " + sql); 00813 if (transactionId != 0) 00814 { 00815 proc.setIsAutoCommit(false); 00816 proc.setTransactionId(transactionId); 00817 } 00818 else 00819 proc.setIsAutoCommit(true); 00820 task = new RecoveryTask(transactionId, id, 00821 new WriteStoredProcedureTask(1, 1, proc)); 00822 } 00823 else 00824 throw new SQLException(Translate.get("recovery.jdbc.sql.unkwown", sql)); 00825 } 00826 catch (SQLException e) 00827 { 00828 throw new SQLException(Translate.get("recovery.jdbc.recover.failed", e)); 00829 } 00830 finally 00831 { 00832 try 00833 { 00834 if (stmt != null) 00835 stmt.close(); 00836 } 00837 catch (Exception ignore) 00838 { 00839 } 00840 } 00841 return task; 00842 }
|
|
Implements org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog. Definition at line 1119 of file JDBCRecoveryLog.java. 01120 { 01121 PreparedStatement stmt = null; 01122 01123 // Wait for transaction to finish 01124 waitForTransactionsEnd(true); 01125 01126 try 01127 { 01128 // 1. Get the reference point to delete 01129 stmt = connection.prepareStatement("SELECT * FROM " + checkpointTableName 01130 + " WHERE name LIKE ?"); 01131 stmt.setString(1, checkpointName); 01132 ResultSet rs = stmt.executeQuery(); 01133 boolean checkpointExists = rs.next(); 01134 if (!checkpointExists) 01135 { 01136 rs.close(); 01137 stmt.close(); 01138 throw new SQLException("Checkpoint " + checkpointName 01139 + " does not exist"); 01140 } 01141 01142 int requestId = rs.getInt("request_id"); 01143 rs.close(); 01144 stmt.close(); 01145 01146 // Delete all entries below 01147 stmt = connection.prepareStatement("DELETE FROM " + logTableName 01148 + " WHERE ID <= ?"); 01149 stmt.setInt(1, requestId); 01150 stmt.executeUpdate(); 01151 stmt.close(); 01152 01153 // Delete checkpoint name 01154 stmt = connection.prepareStatement("DELETE FROM " + checkpointTableName 01155 + " WHERE name like ?"); 01156 stmt.setString(1, checkpointName); 01157 stmt.executeUpdate(); 01158 stmt.close(); 01159 } 01160 catch (SQLException e) 01161 { 01162 throw new SQLException(Translate.get( 01163 "recovery.jdbc.checkpoint.remove.failed", new String[]{ 01164 checkpointName, e.getMessage()})); 01165 } 01166 finally 01167 { 01168 try 01169 { 01170 if (stmt != null) 01171 stmt.close(); 01172 } 01173 catch (Exception ignore) 01174 { 01175 } 01176 01177 } 01178 01179 }
|
|
Implements org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog. Definition at line 501 of file JDBCRecoveryLog.java. References java.sql.Statement.close(), and java.sql.Statement.executeUpdate(). 00502 { 00503 long transactionId = tm.getTransactionId(); 00504 if (isRecovering()) 00505 { 00506 // Some backends started a recovery process, log the rollback 00507 loggerThread.log(incrementLogTableId(), tm.getLogin(), "rollback", 00508 transactionId, false); 00509 } 00510 else 00511 { 00512 // The transaction failed 00513 // Remove the requests with this transactionId from the database 00514 loggerThread.removeQueriesOfTransactionFromQueue(transactionId); 00515 PreparedStatement stmt = null; 00516 try 00517 { 00518 stmt = connection.prepareStatement("DELETE FROM " + logTableName 00519 + " WHERE transaction_id=?"); 00520 stmt.setLong(1, transactionId); 00521 stmt.executeUpdate(); 00522 } 00523 catch (SQLException e) 00524 { 00525 throw new SQLException(Translate.get( 00526 "recovery.jdbc.transaction.remove.failed", new String[]{ 00527 String.valueOf(transactionId), e.getMessage()})); 00528 } 00529 finally 00530 { 00531 try 00532 { 00533 if (stmt != null) 00534 stmt.close(); 00535 } 00536 catch (Exception ignore) 00537 { 00538 } 00539 } 00540 } 00541 }
|
|
Sets the backend table create statement
Definition at line 1410 of file JDBCRecoveryLog.java. References org.objectweb.cjdbc.common.sql.AbstractRequest.debug(). 01413 { 01414 this.backendTableName = tableName; 01415 this.backendTableCreateStatement = "CREATE TABLE " + backendTableName 01416 + " (databaseName " + databaseNameType + ", backendName " 01417 + backendNameType + ",backendState " + backendStateType 01418 + ", checkpointName " + checkpointNameType + " " + extraStatement + ")"; 01419 01420 if (logger.isDebugEnabled()) 01421 logger.debug(Translate.get("recovery.jdbc.backendtable.statement", 01422 backendTableCreateStatement)); 01423 }
|
|
Sets the checkpoint table name and create statement.
Definition at line 1433 of file JDBCRecoveryLog.java. References org.objectweb.cjdbc.common.sql.AbstractRequest.debug(). 01435 { 01436 this.checkpointTableName = tableName; 01437 this.nameType = nameType; 01438 this.requestIdType = requestIdType; 01439 this.checkextraStatement = extraStatement; 01440 // CREATE TABLE tableName ( 01441 // name checkpointNameColumnType, 01442 // request_id requestIdColumnType, 01443 // extraStatement) 01444 01445 String checkpointTableCreateStatement = "CREATE TABLE " + tableName 01446 + " (name " + nameType + ",request_id " + requestIdType 01447 + extraStatement + ")"; 01448 if (logger.isDebugEnabled()) 01449 logger.debug(Translate.get("recovery.jdbc.checkpointtable.statement", 01450 checkpointTableCreateStatement)); 01451 01452 this.checkpointTableCreateStatement = checkpointTableCreateStatement; 01453 }
|
|
Sets the log table name and create statement.
Definition at line 1466 of file JDBCRecoveryLog.java. References org.objectweb.cjdbc.common.sql.AbstractRequest.debug(). 01469 { 01470 this.logTableName = tableName; 01471 this.idType = idType; 01472 this.vloginType = vloginType; 01473 this.sqlColumnName = sqlName; 01474 this.sqlType = sqlType; 01475 this.transactionIdType = transactionIdType; 01476 this.logextraStatement = extraStatement; 01477 String logTableCreateStatement = "CREATE TABLE " + tableName + " (id " 01478 + idType + ",vlogin " + vloginType + "," + sqlColumnName + " " 01479 + sqlType + ",transaction_id " + transactionIdType + extraStatement 01480 + ")"; 01481 if (logger.isDebugEnabled()) 01482 logger.debug(Translate.get("recovery.jdbc.logtable.statement", 01483 logTableCreateStatement)); 01484 01485 this.logTableCreateStatement = logTableCreateStatement; 01486 }
|
|
Implements org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog. Definition at line 1264 of file JDBCRecoveryLog.java. 01266 { 01267 PreparedStatement stmt = null; 01268 PreparedStatement stmt2 = null; 01269 if ((backendRecoveryInfo.getCheckpoint() == null) 01270 || ((backendRecoveryInfo.getBackendState() != BackendState.DISABLED) && (backendRecoveryInfo 01271 .getBackendState() != BackendState.UNKNOWN))) 01272 backendRecoveryInfo.setCheckpoint(""); // No checkpoint 01273 else 01274 { // Check checkpoint name validity 01275 getCheckpointRequestId(backendRecoveryInfo.getCheckpoint()); 01276 } 01277 01278 try 01279 { 01280 // 1. Get the reference point to delete 01281 stmt = connection.prepareStatement("SELECT * FROM " + backendTableName 01282 + " WHERE backendName LIKE ? and databaseName LIKE ?"); 01283 stmt.setString(1, backendRecoveryInfo.getBackendName()); 01284 stmt.setString(2, databaseName); 01285 ResultSet rs = stmt.executeQuery(); 01286 boolean mustUpdate = rs.next(); 01287 rs.close(); 01288 if (!mustUpdate) 01289 { 01290 stmt2 = connection.prepareStatement("INSERT INTO " + backendTableName 01291 + " values(?,?,?,?)"); 01292 stmt2.setString(1, databaseName); 01293 stmt2.setString(2, backendRecoveryInfo.getBackendName()); 01294 stmt2.setInt(3, backendRecoveryInfo.getBackendState()); 01295 stmt2.setString(4, backendRecoveryInfo.getCheckpoint()); 01296 if (stmt2.executeUpdate() != 1) 01297 throw new SQLException( 01298 "Error while inserting new backend reference. Incorrect number of rows"); 01299 } 01300 else 01301 { 01302 stmt2 = connection 01303 .prepareStatement("UPDATE " 01304 + backendTableName 01305 + " set backendState=?,checkpointName=? where backendName=? and databaseName=?"); 01306 stmt2.setInt(1, backendRecoveryInfo.getBackendState()); 01307 stmt2.setString(2, backendRecoveryInfo.getCheckpoint()); 01308 stmt2.setString(3, backendRecoveryInfo.getBackendName()); 01309 stmt2.setString(4, databaseName); 01310 if (stmt2.executeUpdate() != 1) 01311 throw new SQLException( 01312 "Error while updating backend reference. Incorrect number of rows"); 01313 } 01314 } 01315 catch (SQLException e) 01316 { 01317 throw new SQLException("Unable to update checkpoint '" 01318 + backendRecoveryInfo.getCheckpoint() + "' for backend:" 01319 + backendRecoveryInfo.getBackendName()); 01320 } 01321 finally 01322 { 01323 try 01324 { 01325 if (stmt != null) 01326 stmt.close(); 01327 } 01328 catch (Exception ignore) 01329 { 01330 } 01331 try 01332 { 01333 if (stmt2 != null) 01334 stmt2.close(); 01335 } 01336 catch (Exception ignore) 01337 { 01338 } 01339 } 01340 }
|
|
Implements org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog. Definition at line 1071 of file JDBCRecoveryLog.java. References org.objectweb.cjdbc.common.sql.AbstractRequest.debug(). 01073 { 01074 PreparedStatement stmt = null; 01075 01076 // Check if a checkpoint with the name checkpointName already exists 01077 if (!validCheckpointName(checkpointName)) 01078 { 01079 throw new SQLException(Translate.get( 01080 "recovery.jdbc.checkpoint.duplicate", checkpointName)); 01081 } 01082 01083 // Wait for transaction to finish 01084 waitForTransactionsEnd(true); 01085 01086 try 01087 { 01088 if (logger.isDebugEnabled()) 01089 logger.debug("Storing checkpoint " + checkpointName + " at request id " 01090 + requestId); 01091 stmt = connection.prepareStatement("INSERT INTO " + checkpointTableName 01092 + " VALUES(?,?)"); 01093 stmt.setString(1, checkpointName); 01094 stmt.setLong(2, requestId); 01095 stmt.executeUpdate(); 01096 } 01097 catch (SQLException e) 01098 { 01099 throw new SQLException(Translate.get( 01100 "recovery.jdbc.checkpoint.store.failed", new String[]{checkpointName, 01101 e.getMessage()})); 01102 } 01103 finally 01104 { 01105 try 01106 { 01107 if (stmt != null) 01108 stmt.close(); 01109 } 01110 catch (Exception ignore) 01111 { 01112 } 01113 } 01114 }
|
|
Implements org.objectweb.cjdbc.controller.recoverylog.AbstractRecoveryLog. Definition at line 1062 of file JDBCRecoveryLog.java. 01063 { 01064 storeCheckpoint(checkpointName, logTableId); 01065 }
|