Package org.jboss.cache.transaction

Examples of org.jboss.cache.transaction.TransactionContext


      assertNotNull("Tx should have been set up by now", cache.getInvocationContext().getTransaction());
      assertEquals("The same current transaction should be associated with this invocation ctx.", tm.getTransaction(), cache.getInvocationContext().getTransaction());
      assertNotNull("Gtx should have been set up by now", cache.getInvocationContext().getGlobalTransaction());

      Transaction tx = tm.getTransaction();
      TransactionContext transactionContext = tt.get(tt.get(tx));

      if (commit)
      {
         tm.commit();
      } else
      {
         tm.rollback();
      }

      assertNull("Tx should have been scrubbed", cache.getInvocationContext().getTransaction());
      assertNull("Gtx should have been scrubbed", cache.getInvocationContext().getGlobalTransaction());
      assertEquals("Method call should have been scrubbed", null, cache.getInvocationContext().getMethodCall());
      assertEquals("Cache command should have been scrubbed", null, cache.getInvocationContext().getCommand());

      // check that the transaction transactionContext hasn't leaked stuff.
      assert transactionContext.getModifications().isEmpty() : "Should have scrubbed modifications in transaction transactionContext";
      assert transactionContext.getLocks().isEmpty() : "Should have scrubbed modifications in transaction transactionContext";
      assert transactionContext.getOrderedSynchronizationHandler() == null : "Should have removed the ordered sync handler";
   }
View Full Code Here


   public static void manageReverseRemove(InvocationContext ctx, NodeSPI childNode, boolean reverseRemoveCheck, List createdNodes, CommandsFactory commandsFactory)
   {
      if (ctx.getGlobalTransaction() != null) //if no tx then reverse remove does not make sense
      {
         Fqn fqn = childNode.getFqn();
         TransactionContext transactionContext = ctx.getTransactionContext();
         boolean needToReverseRemove = reverseRemoveCheck && childNode.isDeleted() && transactionContext != null && transactionContext.getRemovedNodes().contains(fqn);
         if (!needToReverseRemove) return;
         childNode.markAsDeleted(false);
         //if we'll rollback the tx data should be added to the node again
         Map oldData = new HashMap(childNode.getDataDirect());
         PutDataMapCommand command = commandsFactory.buildPutDataMapCommand(ctx.getGlobalTransaction(), fqn, oldData);
         // txTable.get(gtx).addUndoOperation(command); --- now need to make sure this is added to the normal mods list instead
         transactionContext.addModification(command);
         //we're prepared for rollback, now reset the node
         childNode.clearDataDirect();
         if (createdNodes != null)
         {
            createdNodes.add(childNode);
View Full Code Here

   @Override
   public Object visitPrepareCommand(InvocationContext ctx, PrepareCommand command) throws Throwable
   {
      Object retVal = invokeNextInterceptor(ctx, command);
      TransactionContext transactionContext = ctx.getTransactionContext();
      if (transactionContext.hasLocalModifications())
      {
         PrepareCommand replicablePrepareCommand = command.copy(); // makre sure we remove any "local" transactions
         replicablePrepareCommand.removeModifications(transactionContext.getLocalModifications());
         command = replicablePrepareCommand;
      }

      if (!skipReplicationOfTransactionMethod(ctx)) runPreparePhase(command, command.getGlobalTransaction(), ctx);
      return retVal;
View Full Code Here

   }

   private void prepareCacheLoader(InvocationContext ctx) throws Throwable
   {
      GlobalTransaction gtx = ctx.getGlobalTransaction();
      TransactionContext tCtx = ctx.getTransactionContext();
      if (tCtx == null)
      {
         throw new Exception("tCtx for transaction " + gtx + " not found in transaction table");
      }
      List<Modification> cacheLoaderModifications = new ArrayList<Modification>();

      builder.visitCollection(ctx, tCtx.getModifications());
      if (cacheLoaderModifications.size() > 0)
      {
         loader.prepare(gtx, cacheLoaderModifications, false);
      }
   }
View Full Code Here

      // tx-level overrides are more important
      Transaction tx = ctx.getTransaction();
      if (tx != null)
      {
         TransactionContext transactionContext = ctx.getTransactionContext();
         if (transactionContext != null)
         {
            if (transactionContext.isForceAsyncReplication()) sync = false;
            else if (transactionContext.isForceSyncReplication()) sync = true;
         }
      }

      replicateCall(recipients, c, sync, true, useOutOfBandMessage, false, syncReplTimeout);
   }
View Full Code Here

   }

   @Override
   protected Object handleRollbackCommand(InvocationContext ctx, RollbackCommand command) throws Throwable
   {
      TransactionContext transactionContext = ctx.getTransactionContext();
      if (trace)
      {
         log.trace("called to rollback cache with GlobalTransaction=" + command.getGlobalTransaction());
      }
      if (transactionContext == null)
      {
         log.error("transactionContext for transaction " + command.getGlobalTransaction() + " not found (transaction has possibly already been rolled back)");
      }
      else
      {
         for (Fqn fqn : transactionContext.getRemovedNodes())
         {
            dataContainer.removeFromDataStructure(fqn, false);
         }
         // 1. Revert the modifications by running the undo-op list in reverse. This *cannot* throw any exceptions !

View Full Code Here

      // need to make a note of ALL nodes created here!!
      List<NodeSPI> createdNodes = new LinkedList<NodeSPI>();
      // we need to mark new nodes created as deleted since they are only created to form a path to the node being removed, to
      // create a lock.
      boolean created = lockManager.lockPessimistically(ctx, command.getFqn(), WRITE, true, false, true, true, createdNodes, true);
      TransactionContext transactionContext = null;
      if (ctx.getGlobalTransaction() != null)
      {
         transactionContext = ctx.getTransactionContext();
         transactionContext.addRemovedNode(command.getFqn());
         for (NodeSPI nodeSPI : createdNodes)
         {
            transactionContext.addRemovedNode(nodeSPI.getFqn());
            nodeSPI.markAsDeleted(true);
         }
      }

      lockAllForRemoval(dataContainer.peek(command.getFqn(), false, false), ctx, transactionContext);
View Full Code Here

   }

   private void prepareCacheLoader(InvocationContext ctx) throws Throwable
   {
      GlobalTransaction gtx = ctx.getGlobalTransaction();
      TransactionContext tCtx = ctx.getTransactionContext();
      if (tCtx == null)
      {
         throw new Exception("tCtx for transaction " + gtx + " not found in transaction table");
      }
      List<Modification> cacheLoaderModifications = new ArrayList<Modification>();

      builder.visitCollection(ctx, tCtx.getModifications());
      if (cacheLoaderModifications.size() > 0)
      {
         loader.prepare(gtx, cacheLoaderModifications, false);
      }
   }
View Full Code Here

         // Asssociate the local TX with the global TX. Create new
         // transactionContext for TX in txTable, the modifications
         // below will need this transactionContext to add their modifications
         // under the GlobalTx key
         TransactionContext transactionContext = txTable.get(gtx);
         if (transactionContext == null)
         {
            // create a new transaction transactionContext
            if (trace) log.trace("creating new tx transactionContext");
            transactionContext = contextFactory.createTransactionContext(ltx);
View Full Code Here

      }
   }

   protected void cleanupStaleLocks(InvocationContext ctx) throws Throwable
   {
      TransactionContext transactionContext = ctx.getTransactionContext();
      if (transactionContext != null) lockManager.unlock(ctx);
   }
View Full Code Here

TOP

Related Classes of org.jboss.cache.transaction.TransactionContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.