1 23 24 package org.continuent.sequoia.controller.loadbalancer.tasks; 25 26 import java.sql.SQLException ; 27 import java.sql.Savepoint ; 28 29 import org.continuent.sequoia.common.i18n.Translate; 30 import org.continuent.sequoia.common.log.Trace; 31 import org.continuent.sequoia.controller.backend.DatabaseBackend; 32 import org.continuent.sequoia.controller.connection.AbstractConnectionManager; 33 import org.continuent.sequoia.controller.connection.PooledConnection; 34 import org.continuent.sequoia.controller.loadbalancer.BackendWorkerThread; 35 import org.continuent.sequoia.controller.requestmanager.TransactionMetaData; 36 import org.continuent.sequoia.controller.requests.AbstractRequest; 37 38 45 public class ReleaseSavepointTask extends AbstractTask 46 { 47 48 private TransactionMetaData tm; 49 50 private String savepointName; 51 52 static Trace endUserLogger = Trace 53 .getLogger("org.continuent.sequoia.enduser"); 54 55 64 public ReleaseSavepointTask(int nbToComplete, int totalNb, 65 TransactionMetaData tm, String savepointName) throws NullPointerException  66 { 67 super(nbToComplete, totalNb, tm.isPersistentConnection(), tm 68 .getPersistentConnectionId()); 69 if (tm == null) 70 throw new NullPointerException ("Unexpected null metadata in BeginTask"); 71 this.tm = tm; 72 this.savepointName = savepointName; 73 } 74 75 78 public void executeTask(BackendWorkerThread backendThread) 79 throws SQLException  80 { 81 DatabaseBackend backend = backendThread.getBackend(); 82 Long lTid = new Long (tm.getTransactionId()); 83 84 AbstractConnectionManager cm = backend.getConnectionManager(tm.getLogin()); 85 if (cm == null) 86 { 87 SQLException se = new SQLException ( 88 "No Connection Manager for Virtual Login:" + tm.getLogin()); 89 try 90 { 91 notifyFailure(backendThread, -1, se); 92 } 93 catch (SQLException ignore) 94 { 95 96 } 97 throw se; 98 } 99 PooledConnection c = cm.retrieveConnectionForTransaction(tm 100 .getTransactionId()); 101 102 if (c == null) 104 { backend.stopTransaction(lTid); 106 SQLException se = new SQLException ( 107 "Unable to retrieve connection for transaction " 108 + tm.getTransactionId()); 109 110 try 111 { if (!notifyFailure(backendThread, tm.getTimeout(), se)) 113 return; 114 } 115 catch (SQLException ignore) 116 { 117 } 118 backendThread.getLoadBalancer().disableBackend(backend, true); 121 String msg = "Failed to release savepoint for transaction " 122 + tm.getTransactionId() + " on backend " + backend.getName() 123 + " but " + getSuccess() + " succeeded (" + se + ")"; 124 backendThread.getLogger().error(msg); 125 endUserLogger.error(Translate.get("loadbalancer.backend.disabling", 126 backend.getName())); 127 throw new SQLException (msg); 128 } 129 130 Savepoint savepoint = null; 132 try 133 { 134 savepoint = backend.getSavepoint(lTid, savepointName); 135 c.getConnection().releaseSavepoint(savepoint); 136 } 137 catch (Exception e) 138 { 139 try 140 { 141 if (!notifyFailure(backendThread, tm.getTimeout(), new SQLException (e 142 .getMessage()))) 143 return; 144 } 145 catch (SQLException ignore) 146 { 147 } 148 backendThread.getLoadBalancer().disableBackend(backend, true); 151 String msg = "Failed to release savepoint for transaction " 152 + tm.getTransactionId() + " on backend " + backend.getName() 153 + " but " + getSuccess() + " succeeded (" + e + ")"; 154 backendThread.getLogger().error(msg); 155 endUserLogger.error(Translate.get("loadbalancer.backend.disabling", 156 backend.getName())); 157 throw new SQLException (msg); 158 } 159 finally 160 { 161 backend.removeSavepoint(lTid, savepoint); 162 } 163 164 notifySuccess(backendThread); 165 } 166 167 170 public AbstractRequest getRequest() 171 { 172 return null; 173 } 174 175 178 public String getSavepointName() 179 { 180 return savepointName; 181 } 182 183 186 public long getTransactionId() 187 { 188 return tm.getTransactionId(); 189 } 190 191 194 public boolean isAutoCommit() 195 { 196 return false; 197 } 198 199 202 public boolean equals(Object other) 203 { 204 if ((other == null) || !(other instanceof ReleaseSavepointTask)) 205 return false; 206 207 ReleaseSavepointTask releaseSavepoint = (ReleaseSavepointTask) other; 208 return (this.getTransactionId() == releaseSavepoint.getTransactionId()) 209 && (this.savepointName.equals(releaseSavepoint.getSavepointName())); 210 } 211 212 215 public int hashCode() 216 { 217 return (int) this.getTransactionId(); 218 } 219 220 223 public String toString() 224 { 225 return "ReleaseSavepointTask for transaction " + tm.getTransactionId() 226 + " (" + savepointName + ")"; 227 } 228 } 229 | Popular Tags |