jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1478112 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: core/ plugins/name/ plugins/nodetype/ plugins/nodetype/write/ plugins/observation2/
Date Wed, 01 May 2013 17:43:02 GMT
Author: mduerig
Date: Wed May  1 17:43:01 2013
New Revision: 1478112

URL: http://svn.apache.org/r1478112
Log:
OAK-798: Review / refactor TreeImpl and related classes
reduce usage of deprecated methods: replace Root.getTreeOrNull with Root.getTree in oak-core

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ReadWriteNamespaceRegistry.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/BuiltInNodeTypes.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/ReadWriteNodeTypeManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation2/EventCollector.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation2/EventQueueReader.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation2/ObservationManagerImpl2.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java?rev=1478112&r1=1478111&r2=1478112&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
Wed May  1 17:43:01 2013
@@ -185,8 +185,8 @@ public class RootImpl implements Root {
         boolean success = branch.move(sourcePath, destPath);
         reset();
         if (success) {
-            getTreeOrNull(getParentPath(sourcePath)).updateChildOrder();
-            getTreeOrNull(getParentPath(destPath)).updateChildOrder();
+            getTree(getParentPath(sourcePath)).updateChildOrder();
+            getTree(getParentPath(destPath)).updateChildOrder();
             lastMove = lastMove.setMove(sourcePath, destParent, getName(destPath));
         }
         return success;
@@ -199,7 +199,7 @@ public class RootImpl implements Root {
         boolean success = branch.copy(sourcePath, destPath);
         reset();
         if (success) {
-            getTreeOrNull(getParentPath(destPath)).updateChildOrder();
+            getTree(getParentPath(destPath)).updateChildOrder();
         }
         return success;
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ReadWriteNamespaceRegistry.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ReadWriteNamespaceRegistry.java?rev=1478112&r1=1478111&r2=1478112&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ReadWriteNamespaceRegistry.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ReadWriteNamespaceRegistry.java
Wed May  1 17:43:01 2013
@@ -16,6 +16,9 @@
  */
 package org.apache.jackrabbit.oak.plugins.name;
 
+import static org.apache.jackrabbit.oak.api.Type.NAME;
+import static org.apache.jackrabbit.oak.api.Type.STRING;
+
 import java.util.Map;
 
 import javax.jcr.AccessDeniedException;
@@ -28,9 +31,6 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 
-import static org.apache.jackrabbit.oak.api.Type.NAME;
-import static org.apache.jackrabbit.oak.api.Type.STRING;
-
 /**
  * Writable namespace registry. Mainly for use to implement the full JCR API.
  */
@@ -59,11 +59,11 @@ public abstract class ReadWriteNamespace
     }
 
     private static Tree getOrCreate(Root root, String... path) {
-        Tree tree = root.getTreeOrNull("/");
-        assert tree != null;
+        Tree tree = root.getTree("/");
+        assert tree.exists();
         for (String name : path) {
-            Tree child = tree.getChildOrNull(name);
-            if (child == null) {
+            Tree child = tree.getChild(name);
+            if (!child.exists()) {
                 child = tree.addChild(name);
             }
             tree = child;
@@ -115,8 +115,8 @@ public abstract class ReadWriteNamespace
     @Override
     public void unregisterNamespace(String prefix) throws RepositoryException {
         Root root = getWriteRoot();
-        Tree namespaces = root.getTreeOrNull(NAMESPACES_PATH);
-        if (namespaces == null || !namespaces.hasProperty(prefix)) {
+        Tree namespaces = root.getTree(NAMESPACES_PATH);
+        if (!namespaces.exists() || !namespaces.hasProperty(prefix)) {
             throw new NamespaceException(
                     "Namespace mapping from " + prefix + " to "
                     + getURI(prefix) + " can not be unregistered");

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java?rev=1478112&r1=1478111&r2=1478112&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
Wed May  1 17:43:01 2013
@@ -124,7 +124,7 @@ public abstract class ReadOnlyNodeTypeMa
         return new ReadOnlyNodeTypeManager() {
             @Override
             protected Tree getTypes() {
-                return root.getTreeOrNull(NODE_TYPES_PATH);
+                return root.getTree(NODE_TYPES_PATH);
             }
 
             @Nonnull
@@ -308,8 +308,8 @@ public abstract class ReadOnlyNodeTypeMa
             return true;
         }
 
-        Tree type = types.getChildOrNull(typeName);
-        if (type == null) {
+        Tree type = types.getChild(typeName);
+        if (!types.exists()) {
             return false;
         }
 
@@ -411,8 +411,8 @@ public abstract class ReadOnlyNodeTypeMa
     NodeTypeImpl internalGetNodeType(String oakName) throws NoSuchNodeTypeException {
         Tree types = getTypes();
         if (types != null) {
-            Tree type = types.getChildOrNull(oakName);
-            if (type != null) {
+            Tree type = types.getChild(oakName);
+            if (type.exists()) {
                 return new NodeTypeImpl(type, getNamePathMapper());
             }
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/BuiltInNodeTypes.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/BuiltInNodeTypes.java?rev=1478112&r1=1478111&r2=1478112&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/BuiltInNodeTypes.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/BuiltInNodeTypes.java
Wed May  1 17:43:01 2013
@@ -16,10 +16,13 @@
  */
 package org.apache.jackrabbit.oak.plugins.nodetype.write;
 
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
+
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.util.Map;
+
 import javax.annotation.Nonnull;
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.RepositoryException;
@@ -37,8 +40,6 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.name.ReadWriteNamespaceRegistry;
 import org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl;
 
-import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
-
 /**
  * {@code BuiltInNodeTypes} is a utility class that registers the built-in
  * node types required for a JCR repository running on Oak.
@@ -55,7 +56,7 @@ class BuiltInNodeTypes {
         this.ntMgr =  new ReadWriteNodeTypeManager() {
             @Override
             protected Tree getTypes() {
-                return root.getTreeOrNull(NODE_TYPES_PATH);
+                return root.getTree(NODE_TYPES_PATH);
             }
 
             @Nonnull
@@ -68,7 +69,7 @@ class BuiltInNodeTypes {
         this.nsReg = new ReadWriteNamespaceRegistry() {
             @Override
             protected Tree getReadTree() {
-                return root.getTreeOrNull("/");
+                return root.getTree("/");
             }
             @Override
             protected Root getWriteRoot() {
@@ -80,7 +81,7 @@ class BuiltInNodeTypes {
                 new GlobalNameMapper() {
                     @Override
                     protected Map<String, String> getNamespaceMap() {
-                        return Namespaces.getNamespaceMap(root.getTreeOrNull("/"));
+                        return Namespaces.getNamespaceMap(root.getTree("/"));
                     }
                 }));
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/ReadWriteNodeTypeManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/ReadWriteNodeTypeManager.java?rev=1478112&r1=1478111&r2=1478112&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/ReadWriteNodeTypeManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/ReadWriteNodeTypeManager.java
Wed May  1 17:43:01 2013
@@ -16,8 +16,13 @@
  */
 package org.apache.jackrabbit.oak.plugins.nodetype.write;
 
+import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_NODE_TYPES;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
+
 import java.util.ArrayList;
 import java.util.List;
+
 import javax.annotation.Nonnull;
 import javax.jcr.AccessDeniedException;
 import javax.jcr.RepositoryException;
@@ -36,10 +41,6 @@ import org.apache.jackrabbit.oak.api.Roo
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
 
-import static org.apache.jackrabbit.JcrConstants.JCR_SYSTEM;
-import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.JCR_NODE_TYPES;
-import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
-
 /**
  * {@code ReadWriteNodeTypeManager} extends the {@link ReadOnlyNodeTypeManager}
  * with support for operations that modify node types.
@@ -164,11 +165,11 @@ public abstract class ReadWriteNodeTypeM
     }
 
     private static Tree getOrCreateNodeTypes(Root root) {
-        Tree types = root.getTreeOrNull(NODE_TYPES_PATH);
-        if (types == null) {
-            Tree system = root.getTreeOrNull('/' + JCR_SYSTEM);
-            if (system == null) {
-                system = root.getTreeOrNull("/").addChild(JCR_SYSTEM);
+        Tree types = root.getTree(NODE_TYPES_PATH);
+        if (!types.exists()) {
+            Tree system = root.getTree('/' + JCR_SYSTEM);
+            if (!system.exists()) {
+                system = root.getTree("/").addChild(JCR_SYSTEM);
             }
             types = system.addChild(JCR_NODE_TYPES);
         }
@@ -177,13 +178,9 @@ public abstract class ReadWriteNodeTypeM
 
     @Override
     public void unregisterNodeType(String name) throws RepositoryException {
-        Tree type = null;
         Root root = getWriteRoot();
-        Tree types = root.getTreeOrNull(NODE_TYPES_PATH);
-        if (types != null) {
-            type = types.getChildOrNull(getOakName(name));
-        }
-        if (type == null) {
+        Tree type = root.getTree(NODE_TYPES_PATH).getChild(getOakName(name));
+        if (!type.exists()) {
             throw new NoSuchNodeTypeException("Node type " + name + " can not be unregistered.");
         }
 
@@ -204,15 +201,15 @@ public abstract class ReadWriteNodeTypeM
     @Override
     public void unregisterNodeTypes(String[] names) throws RepositoryException {
         Root root = getWriteRoot();
-        Tree types = root.getTreeOrNull(NODE_TYPES_PATH);
-        if (types == null) {
+        Tree types = root.getTree(NODE_TYPES_PATH);
+        if (!types.exists()) {
             throw new NoSuchNodeTypeException("Node types can not be unregistered.");
         }
 
         try {
             for (String name : names) {
-                Tree type = types.getChildOrNull(getOakName(name));
-                if (type == null) {
+                Tree type = types.getChild(getOakName(name));
+                if (!type.exists()) {
                     throw new NoSuchNodeTypeException("Node type " + name + " can not be
unregistered.");
                 }
                 type.remove();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation2/EventCollector.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation2/EventCollector.java?rev=1478112&r1=1478111&r2=1478112&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation2/EventCollector.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation2/EventCollector.java
Wed May  1 17:43:01 2013
@@ -155,7 +155,7 @@ class EventCollector implements Runnable
 
     private Tree getOrCreateListenerSpec(Root root) {
         return getOrCreate(getOrCreate(getOrCreate(
-                root.getTreeOrNull('/' + JCR_SYSTEM), REP_OBSERVATION), LISTENERS), getId());
+                root.getTree('/' + JCR_SYSTEM), REP_OBSERVATION), LISTENERS), getId());
     }
 
     private Root getLatestRoot() {
@@ -180,8 +180,8 @@ class EventCollector implements Runnable
 
     private void clearFilterSpec() throws CommitFailedException {
         Root root = getLatestRoot();
-        Tree listenerSpec = root.getTreeOrNull(LISTENER_PATH + '/' + getId());
-        if  (listenerSpec != null) {
+        Tree listenerSpec = root.getTree(LISTENER_PATH + '/' + getId());
+        if  (listenerSpec.exists()) {
             listenerSpec.remove();
             root.commit();
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation2/EventQueueReader.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation2/EventQueueReader.java?rev=1478112&r1=1478111&r2=1478112&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation2/EventQueueReader.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation2/EventQueueReader.java
Wed May  1 17:43:01 2013
@@ -73,22 +73,20 @@ public class EventQueueReader {
 
     private Iterator<Tree> getEvents(long next, final String id) {
         if (bundles == null) {
-            bundles = root.getTreeOrNull(EVENTS_PATH);
+            bundles = root.getTree(EVENTS_PATH);
         }
 
-        if (bundles != null) {
-            Tree bundle = bundles.getChildOrNull(String.valueOf(next));
-            if (bundle != null) {
-                nextBundleId++;
-                if (bundle.getChildrenCount() > 0) {
-                    return Iterators.filter(bundle.getChildren().iterator(),
-                            new Predicate<Tree>() {
-                        @Override
-                        public boolean apply(Tree tree) {
-                            return tree.hasChild(id);
-                        }
-                    });
-                }
+        Tree bundle = bundles.getChildOrNull(String.valueOf(next));
+        if (bundle != null) {
+            nextBundleId++;
+            if (bundle.getChildrenCount() > 0) {
+                return Iterators.filter(bundle.getChildren().iterator(),
+                        new Predicate<Tree>() {
+                    @Override
+                    public boolean apply(Tree tree) {
+                        return tree.hasChild(id);
+                    }
+                });
             }
         }
         return null;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation2/ObservationManagerImpl2.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation2/ObservationManagerImpl2.java?rev=1478112&r1=1478111&r2=1478112&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation2/ObservationManagerImpl2.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/observation2/ObservationManagerImpl2.java
Wed May  1 17:43:01 2013
@@ -74,8 +74,8 @@ public class ObservationManagerImpl2 imp
         if (EventQueueWriterProvider.BUNDLE_ID.get() == 0) {
             try {
                 Root root = contentSession.getLatestRoot();
-                Tree events = root.getTreeOrNull(ObservationConstants.EVENTS_PATH);
-                if (events != null) {
+                Tree events = root.getTree(ObservationConstants.EVENTS_PATH);
+                if (events.exists()) {
                     events.remove();
                     root.commit();
                 }



Mime
View raw message