Package org.jboss.cache.optimistic

Examples of org.jboss.cache.optimistic.DataVersion


      WorkspaceNode workspaceNode;

      List<Fqn> nodesCreated = new ArrayList<Fqn>();

      DataVersion version = null;
      if (ctx.getOptionOverrides() != null && ctx.getOptionOverrides().getDataVersion() != null)
      {
         version = ctx.getOptionOverrides().getDataVersion();
         workspace.setVersioningImplicit(false);
      }

      // start with the ROOT node and then work our way down to the node necessary, creating nodes along the way.
      workspaceNode = workspace.getNode(Fqn.ROOT);
      if (debug) log.debug("GlobalTransaction: " + gtx + "; Root: " + workspaceNode);

      // we do not have the root in the workspace!  Put it into thr workspace now.
      if (workspaceNode == null)
      {
         NodeSPI node = cache.getRoot();
         workspaceNode = lockAndCreateWorkspaceNode(nodeFactory, node, workspace, gtx, lockAcquisitionTimeout);
         //workspaceNode = nodeFactory.createWorkspaceNode(node, workspace);
         workspace.addNode(workspaceNode);
         log.debug("Created root node in workspace.");
      }
      else
      {
         log.debug("Found root node in workspace.");
      }

      // iterate through the target Fqn's elements.
      int targetFqnSize = targetFqn.size(), currentDepth = 1;
      for (Object childName : targetFqn.peekElements())
      {
         boolean isTargetFqn = (currentDepth == targetFqnSize);
         currentDepth++;

         // current workspace node canot be null.
         // try and get the child of current node

         if (debug) log.debug("Attempting to get child " + childName);
         NodeSPI currentNode = workspaceNode.getNode().getChildDirect(childName);

         if (currentNode == null)
         {
            // first test that it exists in the workspace and has been created in thix tx!
            WorkspaceNode peekInWorkspace = workspace.getNode(new Fqn(workspaceNode.getFqn(), childName));
            if (peekInWorkspace != null && peekInWorkspace.isCreated())
            {
               // exists in workspace and has just been created.
               currentNode = peekInWorkspace.getNode();
               if (peekInWorkspace.isDeleted()) undeleteWorkspaceNode(peekInWorkspace, workspaceNode);
            }
         }

         if (currentNode == null)
         {
            // no child exists with this name; create it in the underlying data structure and then add it to the workspace.
            if (trace) log.trace("Creating new child, since it doesn't exist in the cache.");
            // we put the parent node into the workspace as we are changing it's children.
            // at this point "workspaceNode" refers to the parent of the current node.  It should never be null if
            // you got this far!
            if (workspaceNode.isDeleted())
            {
               //add a new one or overwrite an existing one that has been deleted
               if (trace)
                  log.trace("Parent node doesn't exist in workspace or has been deleted.  Adding to workspace.");
               workspace.addNode(workspaceNode);
               if (!(workspaceNode.getVersion() instanceof DefaultDataVersion))
                  workspaceNode.setVersioningImplicit(false);
            }
            else
            {
               if (trace) log.trace("Parent node exists: " + workspaceNode);
            }

            // get the version passed in, if we need to use explicit versioning.
            DataVersion versionToPassIn = null;
            if (isTargetFqn && !workspace.isVersioningImplicit()) versionToPassIn = version;

            NodeSPI newUnderlyingChildNode = workspaceNode.createChild(childName, workspaceNode.getNode(), cache, versionToPassIn);

            // now assign "workspaceNode" to the new child created.
View Full Code Here


      NodeSPI toReturn = peek(fqn, false, includeInvalidNodes);

      if (toReturn != null && version != null && configuration.isNodeLockingOptimistic())
      {
         // we need to check the version of the data node...
         DataVersion nodeVersion = toReturn.getVersion();
         if (trace)
         {
            log.trace("looking for optimistic node [" + fqn + "] with version [" + version + "].  My version is [" + nodeVersion + "]");
         }
         if (nodeVersion.newerThan(version))
         {
            // we have a versioning problem; throw an exception!
            throw new CacheException("Unable to validate versions.");
         }
      }
View Full Code Here

            // get the data version associated with this orig call.

            // since these are all crud methods the Fqn is at arg subscript 1.
            Fqn fqn = (Fqn) origArgs[origCall.getMethodId() == MethodDeclarations.moveMethodLocal_id ? 0 : 1];
            // now get a hold of the data version for this specific modification
            DataVersion versionToBroadcast = getVersionToBroadcast(w, fqn);

            // build up the new arguments list for the new call.  Identical to the original lis except that it has the
            // data version tacked on to the end.
            Object[] newArgs = new Object[origArgs.length + 1];
            System.arraycopy(origArgs, 0, newArgs, 0, origArgs.length);
View Full Code Here

   protected DataVersion getNodeVersion(TransactionWorkspace w, Fqn f)
   {
      if (w == null) return null;
      WorkspaceNode wn = w.getNode(f);
      if (wn == null) return null; // JBCACHE-1297
      DataVersion v = wn.getVersion();

      if (wn.isVersioningImplicit())
      {
         // then send back an incremented version
         v = ((DefaultDataVersion) v).increment();
View Full Code Here

               // if the method call is a move() then barf.  Note that remove calls will set data versions explicitly, regardless.
               if (ctx.isOriginLocal() && m.getMethodId() == MethodDeclarations.moveMethodLocal_id)
                  throw new CacheException("Setting a data version while performing a move() is not supported!!");

               workspace.setVersioningImplicit(false);
               DataVersion version = ctx.getOptionOverrides().getDataVersion();

               workspaceNode.setVersion(version);
               if (trace) log.trace("Setting versioning for node " + workspaceNode.getFqn() + " to explicit");

               workspaceNode.setVersioningImplicit(false);
View Full Code Here

      }
   }

   public void testSimplePut() throws Exception
   {
      DataVersion version = new TestVersion("99");
      cache.getInvocationContext().getOptionOverrides().setDataVersion(version);
      cache.put(fqn, key, "value");

      //now retrieve the data from the cache.
      assertEquals("value", cache.get(fqn, key));

      // get a hold of the node
      NodeSPI<String, String> node = (NodeSPI<String, String>) cache.getNode(fqn);
      DataVersion versionFromCache = node.getVersion();

      assertEquals(TestVersion.class, versionFromCache.getClass());
      assertEquals("99", ((TestVersion) versionFromCache).getInternalVersion());
   }
View Full Code Here

      assertEquals("99", ((TestVersion) versionFromCache).getInternalVersion());
   }

   public void testFailingPut() throws Exception
   {
      DataVersion version = new TestVersion("99");
      cache.getInvocationContext().getOptionOverrides().setDataVersion(version);
      cache.put(fqn, key, "value");

      version = new TestVersion("25");
      cache.getInvocationContext().getOptionOverrides().setDataVersion(version);
View Full Code Here

      }
   }

   public void testIncompatibleVersionTypes() throws Exception
   {
      DataVersion version = new TestVersion("99");
      cache.getInvocationContext().getOptionOverrides().setDataVersion(version);
      cache.put(fqn, key, "value");
      TransactionManager mgr = cache.getTransactionManager();
      mgr.begin();
      cache.getInvocationContext().getOptionOverrides().setDataVersion(new DefaultDataVersion(777));
View Full Code Here

   public void setInternalState(Map state)
   {
      if (state != null)
      {
         DataVersion dv = (DataVersion) state.remove(DATA_VERSION_INTERNAL_KEY);
         if (dv != null) version = dv;
      }
      super.setInternalState(state);
   }
View Full Code Here

    *
    * @throws Exception
    */
   public void testIncompatibleVersionTypes1() throws Exception
   {
      DataVersion version = new TestVersion("99");
      cache[0].getInvocationContext().getOptionOverrides().setDataVersion(version);
      cache[0].put(fqn, key, "value");// TestVersion-99 should be on both caches now

      TransactionManager mgr = cache[0].getTransactionManager();
      mgr.begin();
View Full Code Here

TOP

Related Classes of org.jboss.cache.optimistic.DataVersion

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.