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.AbstractWriteRequest; 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 ExecWriteRequestWithKeys extends DistributedRequest 43 { 44 private static final long serialVersionUID = -7075254412706395576L; 45 private int numberOfEnabledBackends; 46 47 50 public ExecWriteRequestWithKeys(AbstractWriteRequest request) 51 { 52 super(request); 53 } 54 55 58 public void scheduleRequest(DistributedRequestManager drm) 59 throws SQLException 60 { 61 numberOfEnabledBackends = drm.getLoadBalancer() 62 .getNumberOfEnabledBackends(); 63 if (numberOfEnabledBackends == 0) 64 { drm.lazyTransactionStart(request); 66 } 67 else 68 drm.scheduleExecWriteRequest((AbstractWriteRequest) request); 69 } 70 71 74 public Object executeScheduledRequest(DistributedRequestManager drm) 75 throws SQLException 76 { 77 try 78 { 79 ControllerResultSet execWriteRequestResult = null; 80 if (numberOfEnabledBackends == 0) 81 throw new NoMoreBackendException( 82 "No backend enabled on this controller"); 83 execWriteRequestResult = drm 84 .loadBalanceExecWriteRequestWithKeys((AbstractWriteRequest) request); 85 86 drm.updateAndNotifyExecWriteRequest((AbstractWriteRequest) request); 87 return execWriteRequestResult; 88 } 89 catch (NoMoreBackendException e) 90 { 91 if (drm.getLogger().isDebugEnabled()) 92 drm.getLogger().debug( 93 Translate.get("virtualdatabase.distributed.write.logging.only", 94 request.getSQLShortForm(drm.getVirtualDatabase() 95 .getSQLShortFormLength()))); 96 if (drm.getRecoveryLog() != null) 99 { 100 long logId = drm.getRecoveryLog().logRequest( 101 (AbstractWriteRequest) request); 102 e.setRecoveryLogId(logId); 103 } 104 drm.getScheduler().notifyWriteCompleted((AbstractWriteRequest) request); 106 throw e; 107 } 108 catch (AllBackendsFailedException e) 109 { 110 drm.addFailedOnAllBackends(request); 113 if (drm.getLogger().isDebugEnabled()) 114 drm 115 .getLogger() 116 .debug( 117 Translate 118 .get( 119 "virtualdatabase.distributed.write.all.backends.locally.failed", 120 request.getSQLShortForm(drm.getVirtualDatabase() 121 .getSQLShortFormLength()))); 122 return e; 123 } 124 catch (SQLException e) 125 { 126 drm.getScheduler().notifyWriteCompleted((AbstractWriteRequest) request); 129 drm.getLogger().warn( 130 Translate.get("virtualdatabase.distributed.write.sqlexception", e 131 .getMessage()), e); 132 throw e; 133 } 134 catch (RuntimeException re) 135 { 136 drm.getScheduler().notifyWriteCompleted((AbstractWriteRequest) request); 139 drm.getLogger().warn( 140 Translate.get("virtualdatabase.distributed.write.exception", re 141 .getMessage()), re); 142 throw new SQLException (re.getMessage()); 143 } 144 } 145 146 } | Popular Tags |