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.exceptions.NoResultAvailableException; 30 import org.continuent.sequoia.common.i18n.Translate; 31 import org.continuent.sequoia.controller.recoverylog.LoggerThread; 32 import org.continuent.sequoia.controller.recoverylog.RecoveryLog; 33 34 44 public class GetUpdateCountEvent implements LogEvent 45 { 46 private Connection connection; 47 private RecoveryLog recoveryLog; 48 private long requestId; 49 private int updateCount = -1; 50 private Exception catchedException = null; 51 52 59 public GetUpdateCountEvent(Connection connection, RecoveryLog recoveryLog, 60 long requestId) 61 { 62 this.connection = connection; 63 this.recoveryLog = recoveryLog; 64 this.requestId = requestId; 65 } 66 67 70 public boolean belongToTransaction(long tid) 71 { 72 return false; 73 } 74 75 78 public void execute(LoggerThread loggerThread) 79 { 80 PreparedStatement stmt = null; 81 ResultSet rs = null; 82 try 83 { 84 stmt = connection 85 .prepareStatement("SELECT update_count, exec_status FROM " 86 + recoveryLog.getLogTableName() + " WHERE request_id=?"); 87 stmt.setLong(1, requestId); 88 rs = stmt.executeQuery(); 89 if (rs.next()) 90 { 91 updateCount = rs.getInt(1); 93 if (!LogEntry.SUCCESS.equals(rs.getString(2))) 94 throw new SQLException (Translate.get("recovery.jdbc.update.failed")); 95 } 96 else 97 { 98 String msg = Translate.get("recovery.jdbc.updatecount.not.found", 100 requestId); 101 catchedException = new NoResultAvailableException(msg); 102 } 103 } 104 catch (SQLException e) 105 { 106 catchedException = new SQLException (Translate.get( 107 "recovery.jdbc.updatecount.not.found.error", new Object []{ 108 new Long (requestId), e.getMessage()})); 109 } 110 finally 111 { 112 try 113 { 114 if (rs != null) 115 rs.close(); 116 } 117 catch (Exception ignore) 118 { 119 } 120 try 121 { 122 if (stmt != null) 123 stmt.close(); 124 } 125 catch (Exception ignore) 126 { 127 } 128 synchronized (this) 129 { 130 notify(); 131 } 132 } 133 } 134 135 142 public final Exception getCatchedException() 143 { 144 return catchedException; 145 } 146 147 152 public int getUpdateCount() 153 { 154 return updateCount; 155 } 156 157 160 public String toString() 161 { 162 return "GetUpdateCountEvent for request ID " + requestId; 163 } 164 } 165 | Popular Tags |