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 import org.objectweb.cjdbc.controller.virtualdatabase.ControllerResultSet; 35 36 42 public class ExecReadStoredProcedure extends DistributedRequest 43 { 44 private static final long serialVersionUID = 8634424524848530342L; 45 46 private int numberOfEnabledBackends; 47 48 54 public ExecReadStoredProcedure(StoredProcedure proc) 55 { 56 super(proc); 57 } 58 59 62 public void scheduleRequest(DistributedRequestManager drm) 63 throws SQLException 64 { 65 drm.lazyTransactionStart(request); 67 drm.scheduleStoredProcedure((StoredProcedure) request); 68 } 69 70 73 public Object executeScheduledRequest(DistributedRequestManager drm) 74 throws SQLException 75 { 76 ControllerResultSet result = null; 77 StoredProcedure proc = (StoredProcedure) request; 78 numberOfEnabledBackends = drm.getLoadBalancer() 79 .getNumberOfEnabledBackends(); 80 try 81 { 82 if (numberOfEnabledBackends == 0) 83 throw new NoMoreBackendException( 84 "No backend enabled on this controller"); 85 86 if (drm.getLogger().isDebugEnabled()) 87 drm.getLogger().debug( 88 Translate.get("requestmanager.read.stored.procedure", new String []{ 89 String.valueOf(request.getId()), 90 request.getSQLShortForm(drm.getVirtualDatabase() 91 .getSQLShortFormLength())})); 92 93 result = drm.loadBalanceReadStoredProcedure(proc); 94 95 drm.flushCacheAndLogStoredProcedure(proc, true); 96 97 drm.getScheduler().storedProcedureCompleted(proc); 99 100 return result; 101 } 102 catch (NoMoreBackendException e) 103 { 104 if (drm.getLogger().isDebugEnabled()) 105 drm.getLogger().debug( 106 Translate.get( 107 "virtualdatabase.distributed.read.procedure.logging.only", 108 request.getSQLShortForm(drm.getVirtualDatabase() 109 .getSQLShortFormLength()))); 110 if (drm.getRecoveryLog() != null) 113 { 114 if (numberOfEnabledBackends == 0) 115 { if (drm.getLoadBalancer().waitForTotalOrder(request, false)) 117 drm.getLoadBalancer().removeHeadFromAndNotifyTotalOrderQueue(); 118 } 119 long logId = drm.getRecoveryLog().logRequest(proc, true); 120 e.setRecoveryLogId(logId); 121 } 122 drm.getScheduler().storedProcedureCompleted(proc); 124 throw e; 125 } 126 catch (AllBackendsFailedException e) 127 { 128 drm.getScheduler().storedProcedureCompleted(proc); 131 drm.addFailedOnAllBackends(request); 132 if (drm.getLogger().isDebugEnabled()) 133 drm 134 .getLogger() 135 .debug( 136 Translate 137 .get( 138 "virtualdatabase.distributed.read.procedure.all.backends.locally.failed", 139 request.getSQLShortForm(drm.getVirtualDatabase() 140 .getSQLShortFormLength()))); 141 return e; 142 } 143 catch (SQLException e) 144 { 145 drm.getScheduler().storedProcedureCompleted(proc); 148 drm.getLogger().warn( 149 Translate.get( 150 "virtualdatabase.distributed.read.procedure.sqlexception", e 151 .getMessage()), e); 152 throw e; 153 } 154 catch (RuntimeException re) 155 { 156 drm.getScheduler().storedProcedureCompleted(proc); 159 drm.getLogger().warn( 160 Translate.get("virtualdatabase.distributed.read.procedure.exception", 161 re.getMessage()), re); 162 throw new SQLException (re.getMessage()); 163 } 164 } 165 } | Popular Tags |