Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

Rollback.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2005 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Emmanuel Cecchet.
00022  * Contributor(s): ______________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.controller.virtualdatabase.protocol;
00026 
00027 import java.io.Serializable;
00028 import java.sql.SQLException;
00029 
00030 import org.objectweb.cjdbc.common.i18n.Translate;
00031 import org.objectweb.cjdbc.common.sql.AbstractRequest;
00032 import org.objectweb.cjdbc.common.sql.UnknownRequest;
00033 import org.objectweb.cjdbc.controller.loadbalancer.AllBackendsFailedException;
00034 import org.objectweb.cjdbc.controller.requestmanager.TransactionMarkerMetaData;
00035 import org.objectweb.cjdbc.controller.requestmanager.distributed.DistributedRequestManager;
00036 
00037 /**
00038  * Execute a distributed rollback.
00039  * 
00040  * @author <a href="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
00041  * @version 1.0
00042  */
00043 public class Rollback implements Serializable
00044 {
00045 
00046   private long transactionId;
00047 
00048   /**
00049    * Creates a new <code>Rollback</code> message.
00050    * 
00051    * @param transactionId id of the transaction to rollback
00052    */
00053   public Rollback(long transactionId)
00054   {
00055     this.transactionId = transactionId;
00056   }
00057 
00058   /**
00059    * Execution of a distributed rollback command on the specified
00060    * <code>DistributedRequestManager</code>
00061    * 
00062    * @param drm the DistributedRequestManager that will execute the rollback
00063    * @return Boolean.TRUE if everything went fine or a SQLException if an error
00064    *         occured
00065    * @throws SQLException if an error occurs
00066    */
00067   public Object rollback(DistributedRequestManager drm) throws SQLException
00068   {
00069     try
00070     {
00071       Long tid = new Long(transactionId);
00072       TransactionMarkerMetaData tm = drm.getTransactionMarker(tid);
00073 
00074       // Wait for the scheduler to give us the authorization to execute
00075       drm.getScheduler().rollback(tm);
00076 
00077       if (drm.getLogger().isDebugEnabled())
00078         drm.getLogger().debug(Translate.get("transaction.rollback", "" + tid));
00079 
00080       try
00081       {
00082         // Send to load balancer
00083         drm.getLoadBalancer().rollback(tm);
00084 
00085         // Notify the cache
00086         if (drm.getResultCache() != null)
00087           drm.getResultCache().rollback(tm.getTransactionId());
00088 
00089         // Notify the recovery log manager
00090         if (drm.getRecoveryLog() != null)
00091           drm.getRecoveryLog().rollback(tm);
00092       }
00093       catch (SQLException e)
00094       {
00095         return e;
00096       }
00097       catch (AllBackendsFailedException e)
00098       {
00099         AbstractRequest request = new UnknownRequest("rollback", false, 0, "\n");
00100         request.setTransactionId(transactionId);
00101         drm.addFailedOnAllBackends(request);
00102         if (drm.getLogger().isDebugEnabled())
00103           drm
00104               .getLogger()
00105               .debug(
00106                   Translate
00107                       .get(
00108                           "virtualdatabase.distributed.commit.all.backends.locally.failed",
00109                           transactionId));
00110         return e;
00111       }
00112       finally
00113       {
00114         // Notify scheduler for completion
00115         drm.getScheduler().rollbackCompleted(transactionId);
00116         drm.completeTransaction(tid);
00117       }
00118       return Boolean.TRUE;
00119     }
00120     catch (SQLException e)
00121     {
00122       drm.getLogger()
00123           .warn(
00124               Translate
00125                   .get("virtualdatabase.distributed.rollback.sqlexception"), e);
00126       throw e;
00127     }
00128     catch (RuntimeException re)
00129     {
00130       drm.getLogger().warn(
00131           Translate.get("virtualdatabase.distributed.rollback.exception"), re);
00132       throw new SQLException(re.getMessage());
00133     }
00134   }
00135 
00136 }

Generated on Mon Apr 11 22:01:34 2005 for C-JDBC by  doxygen 1.3.9.1