1 24 25 package org.objectweb.cjdbc.controller.loadbalancer.tasks; 26 27 import java.sql.Connection ; 28 import java.sql.SQLException ; 29 30 import org.objectweb.cjdbc.controller.backend.DatabaseBackend; 31 import org.objectweb.cjdbc.controller.connection.AbstractConnectionManager; 32 import org.objectweb.cjdbc.controller.loadbalancer.BackendWorkerThread; 33 34 41 public class RollbackTask extends AbstractTask 42 { 43 44 private String login; 45 46 47 private long transactionId; 48 49 50 private long timeout; 51 52 61 public RollbackTask(int nbToComplete, int totalNb, long timeout, 62 String login, long transactionId) 63 { 64 super(nbToComplete, totalNb); 65 this.login = login; 66 this.transactionId = transactionId; 67 this.timeout = timeout; 68 } 69 70 76 public void executeTask(BackendWorkerThread backendThread) 77 throws SQLException 78 { 79 DatabaseBackend db = backendThread.getBackend(); 80 Long lTid = new Long (transactionId); 81 82 AbstractConnectionManager cm = db.getConnectionManager(login); 83 if (cm == null) 84 { 85 SQLException se = new SQLException ( 86 "No Connection Manager for Virtual Login:" + login); 87 try 88 { 89 notifyFailure(backendThread, 1, se); 90 } 91 catch (SQLException ignore) 92 { 93 94 } 95 throw se; 96 } 97 98 Connection c = cm.retrieveConnection(transactionId); 99 100 if (c == null) 102 { db.stopTransaction(lTid); 104 SQLException se = new SQLException ( 105 "Unable to retrieve connection for transaction " + transactionId); 106 try 107 { if (!notifyFailure(backendThread, timeout, se)) 109 return; 110 } 111 catch (SQLException ignore) 112 { 113 } 114 backendThread.kill(); 117 String msg = "Failed to rollback transaction " + transactionId 118 + " on backend " + db.getName() + " but " + getSuccess() 119 + " succeeded (" + se + ")"; 120 backendThread.getLogger().error(msg); 121 throw new SQLException (msg); 122 } 123 124 try 126 { 127 c.rollback(); 128 backendThread.getBackend().setSchemaIsDirty(true); 130 c.setAutoCommit(true); 131 } 132 catch (Exception e) 133 { 134 try 135 { 136 if (!notifyFailure(backendThread, timeout, new SQLException (e 137 .getMessage()))) 138 return; 139 } 140 catch (SQLException ignore) 141 { 142 } 143 backendThread.kill(); 146 String msg = "Failed to rollback transaction " + transactionId 147 + " on backend " + db.getName() + " but " + getSuccess() 148 + " succeeded (" + e + ")"; 149 backendThread.getLogger().error(msg); 150 throw new SQLException (msg); 151 } 152 finally 153 { 154 cm.releaseConnection(transactionId); 155 db.stopTransaction(lTid); 156 } 157 notifySuccess(); 158 } 159 160 163 public String toString() 164 { 165 return "RollbackTask (" + transactionId + ")"; 166 } 167 } | Popular Tags |