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 CommitTask extends AbstractTask 42 { 43 44 private String login; 45 46 47 private long transactionId; 48 49 50 private long timeout; 51 52 61 public CommitTask(int nbToComplete, int totalNb, long timeout, String login, 62 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) throws SQLException 77 { 78 DatabaseBackend db = backendThread.getBackend(); 79 Long lTid = new Long (transactionId); 80 81 AbstractConnectionManager cm = db.getConnectionManager(login); 82 if (cm == null) 83 { 84 SQLException se = new SQLException ( 85 "No Connection Manager for Virtual Login:" + login); 86 try 87 { 88 notifyFailure(backendThread, 1, se); 89 } 90 catch (SQLException ignore) 91 { 92 93 } 94 throw se; 95 } 96 Connection c = cm.retrieveConnection(transactionId); 97 98 if (c == null) 100 { db.stopTransaction(lTid); 102 SQLException se = new SQLException ( 103 "Unable to retrieve connection for transaction " + transactionId); 104 105 try 106 { if (!notifyFailure(backendThread, timeout, se)) 108 return; 109 } 110 catch (SQLException ignore) 111 { 112 } 113 backendThread.kill(); 116 String msg = "Failed to commit transaction " + transactionId 117 + " on backend " + db.getName() + " but " + getSuccess() 118 + " succeeded (" + se + ")"; 119 backendThread.getLogger().error(msg); 120 throw new SQLException (msg); 121 } 122 123 try 125 { 126 c.commit(); 127 c.setAutoCommit(true); 128 } 129 catch (Exception e) 130 { 131 try 132 { 133 if (!notifyFailure(backendThread, timeout, new SQLException (e 134 .getMessage()))) 135 return; 136 } 137 catch (SQLException ignore) 138 { 139 } 140 backendThread.kill(); 143 String msg = "Failed to commit transaction " + transactionId 144 + " on backend " + db.getName() + " but " + getSuccess() 145 + " succeeded (" + e + ")"; 146 backendThread.getLogger().error(msg); 147 throw new SQLException (msg); 148 } 149 finally 150 { 151 cm.releaseConnection(transactionId); 152 db.stopTransaction(lTid); 153 } 154 notifySuccess(); 155 } 156 157 160 public String toString() 161 { 162 return "CommitTask (" + transactionId + ")"; 163 } 164 } | Popular Tags |