1 24 25 package org.objectweb.cjdbc.controller.virtualdatabase.protocol; 26 27 import java.sql.SQLException ; 28 29 import org.objectweb.cjdbc.common.exceptions.NoMoreBackendException; 30 import org.objectweb.cjdbc.common.i18n.Translate; 31 import org.objectweb.cjdbc.common.sql.AbstractRequest; 32 import org.objectweb.cjdbc.common.sql.UnknownRequest; 33 import org.objectweb.cjdbc.controller.loadbalancer.AllBackendsFailedException; 34 import org.objectweb.cjdbc.controller.requestmanager.TransactionMarkerMetaData; 35 import org.objectweb.cjdbc.controller.requestmanager.distributed.DistributedRequestManager; 36 37 44 public class ReleaseSavepoint extends DistributedTransactionMarker 45 { 46 private static final long serialVersionUID = 3025352266902951038L; 47 48 private String savepointName; 49 private TransactionMarkerMetaData tm; 50 private Long tid; 51 private int numberOfEnabledBackends; 52 53 59 public ReleaseSavepoint(long transactionId, String savepointName) 60 { 61 super(transactionId); 62 this.savepointName = savepointName; 63 } 64 65 68 public void scheduleCommand(DistributedRequestManager drm) 69 throws SQLException 70 { 71 try 72 { 73 tid = new Long (transactionId); 76 tm = drm.getTransactionMarker(tid); 77 78 numberOfEnabledBackends = drm.getLoadBalancer() 79 .getNumberOfEnabledBackends(); 80 if (numberOfEnabledBackends == 0) 81 return; 83 if (!drm.hasSavepoint(tid, savepointName)) 85 throw new SQLException (Translate.get("transaction.savepoint.not.found", 86 new String []{savepointName, String.valueOf(transactionId)})); 87 88 drm.getScheduler().releaseSavepoint(tm, savepointName); 90 } 91 catch (SQLException e) 92 { 93 drm 94 .getLogger() 95 .warn( 96 Translate 97 .get("virtualdatabase.distributed.releasesavepoint.sqlexception"), 98 e); 99 throw e; 100 } 101 catch (RuntimeException re) 102 { 103 drm.getLogger().warn( 104 Translate 105 .get("virtualdatabase.distributed.releasesavepoint.exception"), 106 re); 107 throw new SQLException (re.getMessage()); 108 } 109 } 110 111 114 public Object executeCommand(DistributedRequestManager drm) 115 throws SQLException 116 { 117 try 118 { 119 if (numberOfEnabledBackends == 0) 120 throw new NoMoreBackendException( 121 "No backend enabled on this controller"); 122 123 if (drm.getLogger().isDebugEnabled()) 124 drm.getLogger().debug( 125 Translate.get("transaction.releasesavepoint", new String []{ 126 savepointName, String.valueOf(transactionId)})); 127 128 drm.getLoadBalancer().releaseSavepoint(tm, savepointName); 130 131 if (drm.getRecoveryLog() != null) 133 { 134 drm.getRecoveryLog().logReleaseSavepoint(tm, savepointName); 135 } 136 } 137 catch (NoMoreBackendException e) 138 { 139 if (drm.getRecoveryLog() != null) 142 { 143 if (drm.getLogger().isDebugEnabled()) 144 drm.getLogger().debug( 145 Translate.get( 146 "virtualdatabase.distributed.releasesavepoint.logging.only", 147 new String []{savepointName, String.valueOf(transactionId)})); 148 long logId = drm.getRecoveryLog() 149 .logReleaseSavepoint(tm, savepointName); 150 e.setRecoveryLogId(logId); 151 e.setLogin(tm.getLogin()); 152 } 153 throw e; 154 } 155 catch (SQLException e) 156 { 157 drm 158 .getLogger() 159 .warn( 160 Translate 161 .get("virtualdatabase.distributed.releasesavepoint.sqlexception"), 162 e); 163 return e; 164 } 165 catch (RuntimeException re) 166 { 167 drm.getLogger().warn( 168 Translate 169 .get("virtualdatabase.distributed.releasesavepoint.exception"), 170 re); 171 throw new SQLException (re.getMessage()); 172 } 173 catch (AllBackendsFailedException e) 174 { 175 AbstractRequest request = new UnknownRequest("release " + savepointName, 176 false, 0, "\n"); 177 request.setTransactionId(transactionId); 178 drm.addFailedOnAllBackends(request); 179 if (drm.getLogger().isDebugEnabled()) 180 drm 181 .getLogger() 182 .debug( 183 Translate 184 .get( 185 "virtualdatabase.distributed.releasesavepoint.all.backends.locally.failed", 186 new String []{savepointName, 187 String.valueOf(transactionId)})); 188 return e; 189 } 190 finally 191 { 192 if (numberOfEnabledBackends != 0) 193 { 194 drm.getScheduler().savepointCompleted(transactionId); 196 197 drm.removeSavepoint(tid, savepointName); 199 } 200 } 201 return Boolean.TRUE; 202 } 203 204 209 public String getSavepointName() 210 { 211 return savepointName; 212 } 213 214 217 public boolean equals(Object obj) 218 { 219 if (super.equals(obj)) 220 return savepointName.equals(((ReleaseSavepoint) obj).getSavepointName()); 221 else 222 return false; 223 } 224 225 228 public String toString() 229 { 230 return "Release savepoint " + savepointName + " from transaction " 231 + transactionId; 232 } 233 } 234 | Popular Tags |