Package org.jboss.cache

Examples of org.jboss.cache.OptimisticTreeNode


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

        // get a hold of the node
        OptimisticTreeNode node = (OptimisticTreeNode) cache.get(fqn);
        DataVersion versionFromCache = node.getVersion();

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


        tm.resume(tx);
        tx.commit();

        assertEquals(value, cache.get("/a/b/x/y", key));

        OptimisticTreeNode n = (OptimisticTreeNode) cache.get(Fqn.ROOT);
        System.out.println(n.getVersion());
    }
View Full Code Here

   private Set childrenRemoved = new HashSet();
   private static boolean trace = log.isTraceEnabled();


    public WorkspaceNodeImpl() {
        this(new OptimisticTreeNode(), null);
    }
View Full Code Here

           workspaceNode = (WorkspaceNode) it.next();
           if (workspaceNode.isDirty())
           {
               Fqn fqn = workspaceNode.getFqn();
               if (trace) log.trace("Validating version for node [" + fqn + "]");
               OptimisticTreeNode realNode = (OptimisticTreeNode) cache._get(fqn);

               // if this is a newly created node then we expect the underlying node to be null.
               // also, if the node has been deleted in the WS and the underlying node is null, this *may* be ok ... will test again later when comparing versions
               // if not, we have a problem...
               if (realNode == null && !workspaceNode.isCreated() && !workspaceNode.isDeleted())
               {
                   throw new DataVersioningException("Real node for " + fqn + " is null, and this wasn't newly created in this tx!");
               }

              // needs to have been created AND modified - we allow concurrent creation if no data is put into the node
              if (realNode != null && workspaceNode.isCreated() && workspaceNode.isModified())
              {
                 throw new DataVersioningException("Tx attempted to create " + fqn + " anew.  It has already been created since this tx started by another (possibly remote) tx.");
              }

               if (!workspaceNode.isCreated() && (workspaceNode.isDeleted() || workspaceNode.isModified()))
               {
                  // if the real node is null, throw a DVE
                  if (realNode == null)
                  {
                     // but not if the WSN has also been deleted
                     if (!workspaceNode.isDeleted())
                        throw new DataVersioningException("Unable to compare versions since the underlying node has been deleted by a concurrent transaction!");
                     else
                        if (trace) log.trace("The data node ["+fqn+"] is null, but this is ok since the workspace node is marked as deleted as well");
                  }
                  else if (realNode.getVersion().newerThan( workspaceNode.getVersion() ))
                  {
                     // newerThan() will internally test if the DataVersion types being compared tally up, and will barf if
                     // necessary with an appropriate DataVersioningException.
                     // we have an out of date node here
                     throw new DataVersioningException("DataNode [" + fqn + "] version " + ((OptimisticTreeNode)workspaceNode.getNode()).getVersion() + " is newer than workspace node " + workspaceNode.getVersion());
View Full Code Here

            {
                // "Will somebody please think of the children!!"
                // if (wrappedNode.hasCreatedOrRemovedChildren() handleChildNodes(wrappedNode);
                //if (wrappedNode.isModified())
                //{
              OptimisticTreeNode current = (OptimisticTreeNode) wrappedNode.getNode();
              boolean updateVersion = false;

              if (wrappedNode.isChildrenModified())
              {
                 log.trace("Updating children since node has modified children");
                 // merge children.
                 List deltas = wrappedNode.getMergedChildren();

                 if (trace) log.trace("Applying children deltas to parent node " + current.getFqn());
                 for (Iterator i = ((Set) deltas.get(0)).iterator(); i.hasNext();)
                 {
                     TreeNode child = (TreeNode) i.next();
                     current.addChild(child.getName(), child);
                 }

                 for (Iterator i = ((Set) deltas.get(1)).iterator(); i.hasNext();)
                 {
                    TreeNode child = (TreeNode) i.next();
                    current.removeChild(child.getName());
                 }

                  updateVersion = cache.getLockParentForChildInsertRemove();
              }

               if (wrappedNode.isModified() || wrappedNode.isCreated())
               {
                    cache.notifyNodeModify(wrappedNode.getFqn(), true);

                    log.trace("Merging data since node is dirty");
                    Map mergedData = wrappedNode.getMergedData();
                    current.put(mergedData, true);
                    updateVersion = true;
                    cache.notifyNodeModified(wrappedNode.getFqn());
                    cache.notifyNodeModify(wrappedNode.getFqn(), false);
               }
              
               if (updateVersion)
               {
                    if (wrappedNode.isVersioningImplicit())
                    {
                        if (trace) log.trace("Versioning is implicit; incrementing.");
                        if (wrappedNode.getVersion() instanceof DefaultDataVersion)
                           current.setVersion(((DefaultDataVersion)wrappedNode.getVersion()).increment());
                       else
                           log.debug("Even though no explicit version was passed in, node has an external DataVersion impl.  Don't know how to increment, not incrementing.");
                    }
                    else
                    {
                        if (trace) log.trace("Versioning is explicit; not attempting an increment.");
                        current.setVersion(wrappedNode.getVersion());
                    }
                    if (trace) log.trace("Setting version of node from " + wrappedNode.getVersion() + " to " + current.getVersion());
                }
                else
                {
                    if (trace) log.trace("Version update on " + wrappedNode.getFqn() + " not necessary since the node is not dirty or LockParentForChildInsertRemove is set to false");
                    cache.notifyNodeVisited(wrappedNode.getFqn());
View Full Code Here

TOP

Related Classes of org.jboss.cache.OptimisticTreeNode

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.