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.LoggerThread; 31 32 39 public class GetCheckpointLogIdEvent implements LogEvent 40 { 41 42 private Connection connection; 43 private String checkpointTableName; 44 private String checkpointName; 45 private long logId = -1; 46 private SQLException catchedException = null; 47 48 55 public GetCheckpointLogIdEvent(Connection connection, 56 String checkpointTableName, String checkpointName) 57 { 58 this.connection = connection; 59 this.checkpointTableName = checkpointTableName; 60 this.checkpointName = checkpointName; 61 } 62 63 66 public boolean belongToTransaction(long tid) 67 { 68 return false; 69 } 70 71 74 public void execute(LoggerThread loggerThread) 75 { 76 PreparedStatement stmt = null; 77 ResultSet rs = null; 78 try 79 { 80 stmt = connection.prepareStatement("SELECT log_id FROM " 81 + checkpointTableName + " WHERE name LIKE ?"); 82 stmt.setString(1, checkpointName); 83 rs = stmt.executeQuery(); 84 85 if (rs.next()) 86 logId = rs.getLong(1); 87 else 88 { 89 String msg = Translate.get("recovery.jdbc.checkpoint.not.found", 90 checkpointName); 91 throw new SQLException (msg); 92 } 93 } 94 catch (SQLException e) 95 { 96 catchedException = new SQLException (Translate.get( 97 "recovery.jdbc.checkpoint.not.found.error", new String []{ 98 checkpointName, e.getMessage()})); 99 } 100 finally 101 { 102 try 103 { 104 if (rs != null) 105 rs.close(); 106 } 107 catch (Exception ignore) 108 { 109 } 110 try 111 { 112 if (stmt != null) 113 stmt.close(); 114 } 115 catch (Exception ignore) 116 { 117 } 118 synchronized (this) 119 { 120 notify(); 121 } 122 } 123 } 124 125 131 public final SQLException getCatchedException() 132 { 133 return catchedException; 134 } 135 136 142 public long getCheckpointLogId() throws SQLException 143 { 144 if (logId == -1) 145 { 146 throw catchedException; 147 } 148 return logId; 149 } 150 151 154 public String toString() 155 { 156 return "GetCheckpointLogIdEvent for checkpoint " + checkpointName; 157 } 158 } 159 | Popular Tags |