1 21 22 package org.continuent.sequoia.controller.recoverylog.events; 23 24 import java.sql.Connection ; 25 import java.sql.PreparedStatement ; 26 import java.sql.ResultSet ; 27 import java.sql.SQLException ; 28 29 import org.continuent.sequoia.common.i18n.Translate; 30 import org.continuent.sequoia.controller.recoverylog.CheckpointLogEntry; 31 import org.continuent.sequoia.controller.recoverylog.LoggerThread; 32 import org.continuent.sequoia.controller.recoverylog.RecoveryLog; 33 34 41 public class GetCheckpointLogEntryEvent implements LogEvent 42 { 43 44 private Connection connection; 45 private RecoveryLog recoveryLog; 46 private String checkpointName; 47 private CheckpointLogEntry logEntry = null; 48 private SQLException catchedException = null; 49 50 57 public GetCheckpointLogEntryEvent(Connection connection, 58 RecoveryLog recoveryLog, String checkpointName) 59 { 60 this.connection = connection; 61 this.recoveryLog = recoveryLog; 62 this.checkpointName = checkpointName; 63 } 64 65 68 public boolean belongToTransaction(long tid) 69 { 70 return false; 71 } 72 73 76 public void execute(LoggerThread loggerThread) 77 { 78 PreparedStatement stmt = null; 79 ResultSet rs = null; 80 try 81 { 82 stmt = connection.prepareStatement("SELECT " 83 + recoveryLog.getLogTableSqlColumnName() 84 + ",vlogin,auto_conn_tran,transaction_id,request_id FROM " 85 + recoveryLog.getLogTableName() + "," 86 + recoveryLog.getCheckpointTableName() + " WHERE name LIKE ? and " 87 + recoveryLog.getLogTableName() + ".log_id=" 88 + recoveryLog.getCheckpointTableName() + ".log_id"); 89 stmt.setString(1, checkpointName); 90 rs = stmt.executeQuery(); 91 92 if (rs.next()) 93 { 94 logEntry = new CheckpointLogEntry(rs.getString(1), rs.getString(2), rs 95 .getString(3), rs.getLong(4), rs.getLong(5)); 96 return; 97 } 98 99 String msg = Translate.get("recovery.jdbc.checkpoint.not.found", 100 checkpointName); 101 throw new SQLException (msg); 102 } 103 catch (SQLException e) 104 { 105 catchedException = new SQLException (Translate.get( 106 "recovery.jdbc.checkpoint.not.found.error", new String []{ 107 checkpointName, e.getMessage()})); 108 } 109 finally 110 { 111 try 112 { 113 if (rs != null) 114 rs.close(); 115 } 116 catch (Exception ignore) 117 { 118 } 119 try 120 { 121 if (stmt != null) 122 stmt.close(); 123 } 124 catch (Exception ignore) 125 { 126 } 127 synchronized (this) 128 { 129 notify(); 130 } 131 } 132 } 133 134 140 public final SQLException getCatchedException() 141 { 142 return catchedException; 143 } 144 145 151 public CheckpointLogEntry getCheckpointLogEntry() throws SQLException 152 { 153 if (logEntry == null) 154 { 155 throw catchedException; 156 } 157 return logEntry; 158 } 159 160 163 public String toString() 164 { 165 return "GetCheckpointLogEntryEvent for checkpoint " + checkpointName; 166 } 167 } 168 | Popular Tags |