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 SavepointTask extends AbstractTask 43 { 44 45 46 private String login; 47 48 49 private long transactionId; 50 51 52 private long timeout; 53 54 55 private String savepointName; 56 57 58 private Savepoint result; 59 60 61 71 public SavepointTask(int nbToComplete, int totalNb, long timeout, String login, 72 long transactionId, String savepointName) 73 { 74 super(nbToComplete, totalNb); 75 this.login = login; 76 this.transactionId = transactionId; 77 this.timeout = timeout; 78 this.savepointName = savepointName; 79 } 80 81 84 public void executeTask(BackendWorkerThread backendThread) 85 throws SQLException 86 { 87 DatabaseBackend db = backendThread.getBackend(); 88 Long lTid = new Long (transactionId); 89 90 AbstractConnectionManager cm = db.getConnectionManager(login); 91 if (cm == null) 92 { 93 SQLException se = new SQLException ( 94 "No Connection Manager for Virtual Login:" + login); 95 try 96 { 97 notifyFailure(backendThread, 1, se); 98 } 99 catch (SQLException ignore) 100 { 101 102 } 103 throw se; 104 } 105 Connection c = cm.retrieveConnection(transactionId); 106 107 if (c == null) 109 { db.stopTransaction(lTid); 111 SQLException se = new SQLException ( 112 "Unable to retrieve connection for transaction " + transactionId); 113 114 try 115 { if (!notifyFailure(backendThread, timeout, se)) 117 return; 118 } 119 catch (SQLException ignore) 120 { 121 } 122 backendThread.kill(); 125 String msg = "Failed to set savepoint for transaction " + transactionId 126 + " on backend " + db.getName() + " but " + getSuccess() 127 + " succeeded (" + se + ")"; 128 backendThread.getLogger().error(msg); 129 throw new SQLException (msg); 130 } 131 132 Savepoint savepoint = null; 134 try 135 { 136 savepoint = c.setSavepoint(savepointName); 137 result = savepoint; 138 } 139 catch (Exception e) 140 { 141 try 142 { 143 if (!notifyFailure(backendThread, timeout, new SQLException ( 144 e.getMessage()))) 145 return; 146 } 147 catch (SQLException ignore) 148 { 149 } 150 backendThread.kill(); 153 String msg = "Failed to set savepoint for transaction " + transactionId 154 + " on backend " + db.getName() + " but " + getSuccess() 155 + " succeeded (" + e + ")"; 156 backendThread.getLogger().error(msg); 157 throw new SQLException (msg); 158 } 159 finally 160 { 161 if (savepoint != null) 162 db.addSavepoint(lTid, savepoint); 163 } 164 165 notifySuccess(); 166 } 167 168 173 public Savepoint getResult() 174 { 175 return result; 176 } 177 178 181 public String toString() 182 { 183 return "SavepointTask for transaction " + transactionId + " (" 184 + savepointName + ")"; 185 } 186 } 187 | Popular Tags |