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 SetSavepoint extends DistributedTransactionMarker 45 { 46 private static final long serialVersionUID = 1429582815473734482L; 47 48 private String savepointName; 49 private TransactionMarkerMetaData tm; 50 private Long tid; 51 private int numberOfEnabledBackends; 52 53 59 public SetSavepoint(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 drm.getScheduler().setSavepoint(tm, savepointName); 85 } 86 catch (SQLException e) 87 { 88 drm.getLogger().warn( 89 Translate 90 .get("virtualdatabase.distributed.setsavepoint.sqlexception"), e); 91 throw e; 92 } 93 catch (RuntimeException re) 94 { 95 drm.getLogger().warn( 96 Translate.get("virtualdatabase.distributed.setsavepoint.exception"), 97 re); 98 throw new SQLException (re.getMessage()); 99 } 100 } 101 102 105 public Object executeCommand(DistributedRequestManager drm) 106 throws SQLException 107 { 108 try 109 { 110 if (numberOfEnabledBackends == 0) 111 throw new NoMoreBackendException( 112 "No backend enabled on this controller"); 113 114 if (drm.getLogger().isDebugEnabled()) 115 drm.getLogger().debug( 116 Translate.get("transaction.setsavepoint", new String []{ 117 savepointName, String.valueOf(transactionId)})); 118 119 drm.getLoadBalancer().setSavepoint(tm, savepointName); 121 122 if (drm.getRecoveryLog() != null) 124 { 125 drm.getRecoveryLog().logSetSavepoint(tm, savepointName); 126 } 127 } 128 catch (NoMoreBackendException e) 129 { 130 if (drm.getRecoveryLog() != null) 133 { 134 if (drm.getLogger().isDebugEnabled()) 135 drm.getLogger().debug( 136 Translate.get( 137 "virtualdatabase.distributed.setsavepoint.logging.only", 138 new String []{savepointName, String.valueOf(transactionId)})); 139 long logId = drm.getRecoveryLog().logSetSavepoint(tm, savepointName); 140 e.setRecoveryLogId(logId); 141 e.setLogin(tm.getLogin()); 142 } 143 throw e; 144 } 145 catch (SQLException e) 146 { 147 drm.getLogger().warn( 148 Translate 149 .get("virtualdatabase.distributed.setsavepoint.sqlexception"), e); 150 return e; 151 } 152 catch (RuntimeException re) 153 { 154 drm.getLogger().warn( 155 Translate.get("virtualdatabase.distributed.setsavepoint.exception"), 156 re); 157 throw new SQLException (re.getMessage()); 158 } 159 catch (AllBackendsFailedException e) 160 { 161 AbstractRequest request = new UnknownRequest( 162 "savepoint " + savepointName, false, 0, "\n"); 163 request.setTransactionId(transactionId); 164 drm.addFailedOnAllBackends(request); 165 if (drm.getLogger().isDebugEnabled()) 166 drm 167 .getLogger() 168 .debug( 169 Translate 170 .get( 171 "virtualdatabase.distributed.setsavepoint.all.backends.locally.failed", 172 new String []{savepointName, 173 String.valueOf(transactionId)})); 174 return e; 175 } 176 finally 177 { 178 if (numberOfEnabledBackends != 0) 179 { 180 drm.getScheduler().savepointCompleted(transactionId); 182 } 183 } 184 185 drm.addSavepoint(tid, savepointName); 187 return Boolean.TRUE; 188 } 189 190 195 public String getSavepointName() 196 { 197 return savepointName; 198 } 199 200 203 public boolean equals(Object obj) 204 { 205 if (super.equals(obj)) 206 return savepointName.equals(((SetSavepoint) obj).getSavepointName()); 207 else 208 return false; 209 } 210 211 214 public String toString() 215 { 216 return "Set savepoint " + savepointName + " to transaction " 217 + transactionId; 218 } 219 } 220 | Popular Tags |