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.StoredProcedure; 32 import org.objectweb.cjdbc.controller.loadbalancer.AllBackendsFailedException; 33 import org.objectweb.cjdbc.controller.requestmanager.distributed.DistributedRequestManager; 34 35 41 public class ExecWriteStoredProcedure extends DistributedRequest 42 { 43 private static final long serialVersionUID = 3550127604843949629L; 44 45 private int numberOfEnabledBackends; 46 47 52 public ExecWriteStoredProcedure(StoredProcedure proc) 53 { 54 super(proc); 55 } 56 57 60 public void scheduleRequest(DistributedRequestManager drm) 61 throws SQLException 62 { 63 drm.lazyTransactionStart(request); 65 drm.scheduleStoredProcedure((StoredProcedure) request); 66 } 67 68 71 public Object executeScheduledRequest(DistributedRequestManager drm) 72 throws SQLException 73 { 74 int execWriteStoredProcedure = 0; 75 StoredProcedure proc = (StoredProcedure) request; 76 try 77 { 78 if (numberOfEnabledBackends == 0) 79 throw new NoMoreBackendException( 80 "No backend enabled on this controller"); 81 82 if (drm.getLogger().isDebugEnabled()) 83 drm.getLogger().debug( 84 Translate.get("requestmanager.write.stored.procedure", 85 new String []{ 86 String.valueOf(request.getId()), 87 request.getSQLShortForm(drm.getVirtualDatabase() 88 .getSQLShortFormLength())})); 89 90 execWriteStoredProcedure = drm.loadBalanceWriteStoredProcedure(proc); 91 92 drm.flushCacheAndLogStoredProcedure(proc, false); 93 94 drm.getScheduler().storedProcedureCompleted(proc); 96 97 return new Integer (execWriteStoredProcedure); 98 } 99 catch (NoMoreBackendException e) 100 { 101 if (drm.getLogger().isDebugEnabled()) 102 drm.getLogger().debug( 103 Translate.get( 104 "virtualdatabase.distributed.write.procedure.logging.only", 105 request.getSQLShortForm(drm.getVirtualDatabase() 106 .getSQLShortFormLength()))); 107 if (drm.getRecoveryLog() != null) 110 { 111 if (numberOfEnabledBackends == 0) 112 { if (drm.getLoadBalancer().waitForTotalOrder(request, false)) 114 drm.getLoadBalancer().removeHeadFromAndNotifyTotalOrderQueue(); 115 } 116 long logId = drm.getRecoveryLog().logRequest(proc, true); 117 e.setRecoveryLogId(logId); 118 } 119 drm.getScheduler().storedProcedureCompleted(proc); 121 throw e; 122 } 123 catch (AllBackendsFailedException e) 124 { 125 drm.getScheduler().storedProcedureCompleted(proc); 128 drm.addFailedOnAllBackends(request); 129 if (drm.getLogger().isDebugEnabled()) 130 drm 131 .getLogger() 132 .debug( 133 Translate 134 .get( 135 "virtualdatabase.distributed.write.procedure.all.backends.locally.failed", 136 request.getSQLShortForm(drm.getVirtualDatabase() 137 .getSQLShortFormLength()))); 138 return e; 139 } 140 catch (SQLException e) 141 { 142 drm.getScheduler().storedProcedureCompleted(proc); 145 drm.getLogger().warn( 146 Translate.get( 147 "virtualdatabase.distributed.write.procedure.sqlexception", e 148 .getMessage()), e); 149 throw e; 150 } 151 catch (RuntimeException re) 152 { 153 drm.getScheduler().storedProcedureCompleted(proc); 156 drm.getLogger().warn( 157 Translate.get( 158 "virtualdatabase.distributed.write.procedure.exception", re 159 .getMessage()), re); 160 throw new SQLException (re.getMessage()); 161 } 162 } 163 164 } | Popular Tags |