1 21 22 package org.continuent.sequoia.controller.recoverylog.events; 23 24 import java.sql.PreparedStatement ; 25 import java.sql.SQLException ; 26 27 import org.continuent.sequoia.common.i18n.Translate; 28 import org.continuent.sequoia.common.log.Trace; 29 import org.continuent.sequoia.controller.recoverylog.LoggerThread; 30 import org.continuent.sequoia.controller.recoverylog.RecoveryLog; 31 32 38 public class LogRequestEvent implements LogEvent 39 { 40 protected LogEntry logEntry; 41 42 47 public LogRequestEvent(LogEntry entry) 48 { 49 if (entry == null) 50 throw new RuntimeException ( 51 "Invalid null entry in LogRequestEvent constructor"); 52 this.logEntry = entry; 53 } 54 55 58 public boolean belongToTransaction(long tid) 59 { 60 return logEntry.getTid() == tid; 61 } 62 63 66 public void execute(LoggerThread loggerThread) 67 { 68 Trace logger = loggerThread.getLogger(); 69 try 70 { 71 if (logger.isDebugEnabled()) 72 logger.debug(Translate.get("recovery.jdbc.loggerthread.log.info", 73 logEntry.getLogId())); 74 75 PreparedStatement pstmt = loggerThread.getLogPreparedStatement(); 76 pstmt.setLong(RecoveryLog.COLUMN_INDEX_LOG_ID, logEntry.getLogId()); 77 pstmt.setString(RecoveryLog.COLUMN_INDEX_VLOGIN, logEntry.getLogin()); 78 pstmt.setString(RecoveryLog.COLUMN_INDEX_SQL, logEntry.getQuery()); 79 pstmt.setString(RecoveryLog.COLUMN_INDEX_SQL_PARAMS, logEntry 80 .getQueryParams()); 81 pstmt.setString(RecoveryLog.COLUMN_INDEX_AUTO_CONN_TRAN, logEntry 82 .getAutoConnTrans()); 83 pstmt.setLong(RecoveryLog.COLUMN_INDEX_TRANSACTION_ID, logEntry.getTid()); 84 pstmt.setLong(RecoveryLog.COLUMN_INDEX_REQUEST_ID, logEntry 85 .getRequestId()); 86 pstmt.setString(RecoveryLog.COLUMN_INDEX_EXEC_STATUS, logEntry 87 .getExecutionStatus()); 88 pstmt.setLong(RecoveryLog.COLUMN_INDEX_EXEC_TIME, logEntry 89 .getExecutionTimeInMs()); 90 pstmt.setLong(RecoveryLog.COLUMN_INDEX_UPDATE_COUNT, logEntry 91 .getUpdateCountResult()); 92 pstmt.setLong(RecoveryLog.COLUMN_INDEX_COMPLETION_LOG_ID, logEntry 93 .getCompletionLogId()); 94 if (logger.isDebugEnabled()) 95 logger.debug(pstmt.toString()); 96 try 97 { 98 pstmt.setEscapeProcessing(logEntry.getEscapeProcessing()); 99 } 100 catch (Exception ignore) 101 { 102 } 103 int updatedRows = pstmt.executeUpdate(); 104 if ((updatedRows != 1) && logger.isWarnEnabled()) 105 logger 106 .warn("Recovery log did not update a single entry while executing: " 107 + pstmt.toString()); 108 } 109 catch (SQLException e) 110 { 111 loggerThread.invalidateLogStatements(); 112 if ("T".equals(logEntry.getAutoConnTrans())) 113 logger.error(Translate.get( 114 "recovery.jdbc.loggerthread.log.failed.transaction", new String []{ 115 logEntry.getQuery(), String.valueOf(logEntry.getTid())}), e); 116 else 117 logger.error(Translate.get("recovery.jdbc.loggerthread.log.failed", 118 logEntry.getQuery()), e); 119 loggerThread.putBackAtHeadOfQueue(this, e); 121 } 122 } 123 124 127 public String toString() 128 { 129 return "LogRequestEvent: " + logEntry; 130 } 131 132 } 133 | Popular Tags |