1 24 25 package org.objectweb.cjdbc.controller.loadbalancer.tasks; 26 27 import java.sql.Connection ; 28 import java.sql.SQLException ; 29 import java.sql.Savepoint ; 30 31 import org.objectweb.cjdbc.controller.backend.DatabaseBackend; 32 import org.objectweb.cjdbc.controller.connection.AbstractConnectionManager; 33 import org.objectweb.cjdbc.controller.loadbalancer.BackendWorkerThread; 34 35 42 public class ReleaseSavepointTask extends AbstractTask 43 { 44 45 private String login; 46 47 48 private long transactionId; 49 50 51 private long timeout; 52 53 54 private String savepointName; 55 56 66 public ReleaseSavepointTask(int nbToComplete, int totalNb, long timeout, 67 String login, long transactionId, String savepointName) 68 { 69 super(nbToComplete, totalNb); 70 this.login = login; 71 this.transactionId = transactionId; 72 this.timeout = timeout; 73 this.savepointName = savepointName; 74 } 75 76 79 public void executeTask(BackendWorkerThread backendThread) 80 throws SQLException 81 { 82 DatabaseBackend db = backendThread.getBackend(); 83 Long lTid = new Long (transactionId); 84 85 AbstractConnectionManager cm = db.getConnectionManager(login); 86 if (cm == null) 87 { 88 SQLException se = new SQLException ( 89 "No Connection Manager for Virtual Login:" + login); 90 try 91 { 92 notifyFailure(backendThread, 1, se); 93 } 94 catch (SQLException ignore) 95 { 96 97 } 98 throw se; 99 } 100 Connection c = cm.retrieveConnection(transactionId); 101 102 if (c == null) 104 { db.stopTransaction(lTid); 106 SQLException se = new SQLException ( 107 "Unable to retrieve connection for transaction " + transactionId); 108 109 try 110 { if (!notifyFailure(backendThread, timeout, se)) 112 return; 113 } 114 catch (SQLException ignore) 115 { 116 } 117 backendThread.kill(); 120 String msg = "Failed to release savepoint for transaction " 121 + transactionId + " on backend " + db.getName() + " but " 122 + getSuccess() + " succeeded (" + se + ")"; 123 backendThread.getLogger().error(msg); 124 throw new SQLException (msg); 125 } 126 127 Savepoint savepoint = null; 129 try 130 { 131 savepoint = db.getSavepoint(lTid, savepointName); 132 c.releaseSavepoint(savepoint); 133 } 134 catch (Exception e) 135 { 136 try 137 { 138 if (!notifyFailure(backendThread, timeout, new SQLException ( 139 e.getMessage()))) 140 return; 141 } 142 catch (SQLException ignore) 143 { 144 } 145 backendThread.kill(); 148 String msg = "Failed to release savepoint for transaction " 149 + transactionId + " on backend " + db.getName() + " but " 150 + getSuccess() + " succeeded (" + e + ")"; 151 backendThread.getLogger().error(msg); 152 throw new SQLException (msg); 153 } 154 finally 155 { 156 db.removeSavepoint(lTid, savepoint); 157 } 158 159 notifySuccess(); 160 } 161 162 165 public String toString() 166 { 167 return "ReleaseSavepointTask for transaction " + transactionId + " (" 168 + savepointName + ")"; 169 } 170 } 171 | Popular Tags |