You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ju...@apache.org on 2013/07/24 19:49:59 UTC

svn commit: r1506642 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: PropertyImpl.java operation/PropertyOperation.java

Author: jukka
Date: Wed Jul 24 17:49:59 2013
New Revision: 1506642

URL: http://svn.apache.org/r1506642
Log:
OAK-672: Avoid JCR APIs calling other JCR APIs

Add PropertyOperation and adjust code accordingly.
Add TODOs on places that still need work.

Added:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/operation/PropertyOperation.java   (with props)
Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java?rev=1506642&r1=1506641&r2=1506642&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/PropertyImpl.java Wed Jul 24 17:49:59 2013
@@ -42,7 +42,7 @@ import org.apache.jackrabbit.oak.api.Tre
 import org.apache.jackrabbit.oak.api.Type;
 import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
 import org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate;
-import org.apache.jackrabbit.oak.jcr.operation.ItemOperation;
+import org.apache.jackrabbit.oak.jcr.operation.PropertyOperation;
 import org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl;
 import org.apache.jackrabbit.value.ValueHelper;
 
@@ -67,14 +67,14 @@ public class PropertyImpl extends ItemIm
     @Override
     @Nonnull
     public Node getParent() throws RepositoryException {
-        return perform(new ItemOperation<Node>(dlg) {
+        return perform(new PropertyOperation<Node>(dlg) {
             @Override
             public Node perform() throws RepositoryException {
-                NodeDelegate parent = dlg.getParent();
+                NodeDelegate parent = property.getParent();
                 if (parent == null) {
                     throw new AccessDeniedException();
                 } else {
-                    return sessionContext.createNodeOrNull(dlg.getParent());
+                    return sessionContext.createNodeOrNull(parent);
                 }
             }
         });
@@ -82,20 +82,20 @@ public class PropertyImpl extends ItemIm
 
     @Override
     public boolean isNew() {
-        return safePerform(new ItemOperation<Boolean>(dlg) {
+        return safePerform(new PropertyOperation<Boolean>(dlg) {
             @Override
             public Boolean perform() {
-                return dlg.getStatus() == Status.NEW;
+                return property.getStatus() == Status.NEW;
             }
         });
     }
 
     @Override
     public boolean isModified() {
-        return safePerform(new ItemOperation<Boolean>(dlg) {
+        return safePerform(new PropertyOperation<Boolean>(dlg) {
             @Override
             public Boolean perform() {
-                return dlg.getStatus() == Status.MODIFIED;
+                return property.getStatus() == Status.MODIFIED;
             }
         });
     }
@@ -224,10 +224,11 @@ public class PropertyImpl extends ItemIm
     @Override
     @Nonnull
     public Value getValue() throws RepositoryException {
-        return perform(new ItemOperation<Value>(dlg) {
+        return perform(new PropertyOperation<Value>(dlg) {
             @Override
             public Value perform() throws RepositoryException {
-                return ValueFactoryImpl.createValue(dlg.getSingleState(), sessionContext);
+                return ValueFactoryImpl.createValue(
+                        property.getSingleState(), sessionContext);
             }
         });
     }
@@ -235,10 +236,11 @@ public class PropertyImpl extends ItemIm
     @Override
     @Nonnull
     public Value[] getValues() throws RepositoryException {
-        return perform(new ItemOperation<List<Value>>(dlg) {
+        return perform(new PropertyOperation<List<Value>>(dlg) {
             @Override
             public List<Value> perform() throws RepositoryException {
-                return ValueFactoryImpl.createValues(dlg.getMultiState(), sessionContext);
+                return ValueFactoryImpl.createValues(
+                        property.getMultiState(), sessionContext);
             }
         }).toArray(NO_VALUES);
     }
@@ -292,9 +294,10 @@ public class PropertyImpl extends ItemIm
     @Override
     @Nonnull
     public Node getNode() throws RepositoryException {
-        return perform(new ItemOperation<Node>(dlg) {
+        return perform(new PropertyOperation<Node>(dlg) {
             @Override
             public Node perform() throws RepositoryException {
+                // TODO: avoid nested calls
                 Value value = getValue();
                 switch (value.getType()) {
                     case PropertyType.REFERENCE:
@@ -344,9 +347,10 @@ public class PropertyImpl extends ItemIm
     @Override
     @Nonnull
     public Property getProperty() throws RepositoryException {
-        return perform(new ItemOperation<Property>(dlg) {
+        return perform(new PropertyOperation<Property>(dlg) {
             @Override
             public Property perform() throws RepositoryException {
+                // TODO: avoid nested calls
                 Value value = getValue();
                 Value pathValue = ValueHelper.convert(value, PropertyType.PATH, getValueFactory());
                 String path = pathValue.getString();
@@ -379,31 +383,32 @@ public class PropertyImpl extends ItemIm
     @Override
     @Nonnull
     public PropertyDefinition getDefinition() throws RepositoryException {
-        return perform(new ItemOperation<PropertyDefinition>(dlg) {
+        return perform(new PropertyOperation<PropertyDefinition>(dlg) {
             @Override
             public PropertyDefinition perform() throws RepositoryException {
                 return getDefinitionProvider().getDefinition(
-                        dlg.getParent().getTree(), dlg.getPropertyState(), true);
+                        property.getParent().getTree(),
+                        property.getPropertyState(), true);
             }
         });
     }
 
     @Override
     public int getType() throws RepositoryException {
-        return perform(new ItemOperation<Integer>(dlg) {
+        return perform(new PropertyOperation<Integer>(dlg) {
             @Override
             public Integer perform() throws RepositoryException {
-                return dlg.getPropertyState().getType().tag();
+                return property.getPropertyState().getType().tag();
             }
         });
     }
 
     @Override
     public boolean isMultiple() throws RepositoryException {
-        return perform(new ItemOperation<Boolean>(dlg) {
+        return perform(new PropertyOperation<Boolean>(dlg) {
             @Override
             public Boolean perform() throws RepositoryException {
-                return dlg.getPropertyState().isArray();
+                return property.getPropertyState().isArray();
             }
         });
     }

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/operation/PropertyOperation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/operation/PropertyOperation.java?rev=1506642&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/operation/PropertyOperation.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/operation/PropertyOperation.java Wed Jul 24 17:49:59 2013
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.jcr.operation;
+
+import org.apache.jackrabbit.oak.jcr.delegate.PropertyDelegate;
+
+public abstract class PropertyOperation<U> extends ItemOperation<U> {
+
+    protected final PropertyDelegate property;
+
+    protected PropertyOperation(PropertyDelegate property) {
+        super(property);
+        this.property = property;
+    }
+
+}
\ No newline at end of file

Propchange: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/operation/PropertyOperation.java
------------------------------------------------------------------------------
    svn:eol-style = native