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/02/28 21:51:13 UTC

svn commit: r1451334 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: ItemImpl.java NodeImpl.java PropertyImpl.java

Author: jukka
Date: Thu Feb 28 20:51:12 2013
New Revision: 1451334

URL: http://svn.apache.org/r1451334
Log:
OAK-662: Reduce boilerplate code in JCR impl methods

Add ItemImpl.perform() to allow adding item-specific functionality to it.
No need to explicitly pass SessionDelegate to constructors that already take an ItemDelegate.

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
    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/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java?rev=1451334&r1=1451333&r2=1451334&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/ItemImpl.java Thu Feb 28 20:51:12 2013
@@ -51,11 +51,16 @@ abstract class ItemImpl<T extends ItemDe
      */
     private static final Logger log = LoggerFactory.getLogger(ItemImpl.class);
 
-    protected ItemImpl(SessionDelegate sessionDelegate, T itemDelegate) {
-        this.sessionDelegate = sessionDelegate;
+    protected ItemImpl(T itemDelegate) {
+        this.sessionDelegate = itemDelegate.getSessionDelegate();
         this.dlg = itemDelegate;
     }
 
+    protected <X> X perform(SessionOperation<X> operation)
+            throws RepositoryException {
+        return sessionDelegate.perform(operation);
+    }
+
     //---------------------------------------------------------------< Item >---
 
     /**
@@ -64,7 +69,7 @@ abstract class ItemImpl<T extends ItemDe
     @Override
     @Nonnull
     public String getName() throws RepositoryException {
-        return sessionDelegate.perform(new SessionOperation<String>() {
+        return perform(new SessionOperation<String>() {
             @Override
             public String perform() throws RepositoryException {
                 String oakName = dlg.getName();
@@ -81,7 +86,7 @@ abstract class ItemImpl<T extends ItemDe
     @Nonnull
     public String getPath() throws RepositoryException {
         checkStatus();
-        return sessionDelegate.perform(new SessionOperation<String>() {
+        return perform(new SessionOperation<String>() {
             @Override
             public String perform() throws RepositoryException {
                 return toJcrPath(dlg.getPath());

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1451334&r1=1451333&r2=1451334&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java Thu Feb 28 20:51:12 2013
@@ -97,7 +97,7 @@ public class NodeImpl<T extends NodeDele
     private static final Logger log = LoggerFactory.getLogger(NodeImpl.class);
 
     public NodeImpl(T dlg) {
-        super(dlg.getSessionDelegate(), dlg);
+        super(dlg);
     }
 
     //---------------------------------------------------------------< Item >---
@@ -118,7 +118,7 @@ public class NodeImpl<T extends NodeDele
     public Node getParent() throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<NodeImpl<NodeDelegate>>() {
+        return perform(new SessionOperation<NodeImpl<NodeDelegate>>() {
             @Override
             public NodeImpl<NodeDelegate> perform() throws RepositoryException {
                 if (dlg.isRoot()) {
@@ -140,7 +140,7 @@ public class NodeImpl<T extends NodeDele
     @Override
     public boolean isNew() {
         try {
-            return sessionDelegate.perform(new SessionOperation<Boolean>() {
+            return perform(new SessionOperation<Boolean>() {
                 @Override
                 public Boolean perform() throws InvalidItemStateException {
                     return !dlg.isStale() && dlg.getStatus() == Status.NEW;
@@ -157,7 +157,7 @@ public class NodeImpl<T extends NodeDele
     @Override
     public boolean isModified() {
         try {
-            return sessionDelegate.perform(new SessionOperation<Boolean>() {
+            return perform(new SessionOperation<Boolean>() {
                 @Override
                 public Boolean perform() throws InvalidItemStateException {
                     return !dlg.isStale() && dlg.getStatus() == Status.MODIFIED;
@@ -176,7 +176,7 @@ public class NodeImpl<T extends NodeDele
         checkStatus();
         checkProtected();
 
-        sessionDelegate.perform(new SessionOperation<Void>() {
+        perform(new SessionOperation<Void>() {
             @Override
             public Void perform() throws RepositoryException {
                 if (dlg.isRoot()) {
@@ -216,7 +216,7 @@ public class NodeImpl<T extends NodeDele
         checkStatus();
         checkProtected();
 
-        return sessionDelegate.perform(new SessionOperation<Node>() {
+        return perform(new SessionOperation<Node>() {
             @Override
             public Node perform() throws RepositoryException {
                 String oakPath = sessionDelegate.getOakPathKeepIndexOrThrowNotFound(relPath);
@@ -289,7 +289,7 @@ public class NodeImpl<T extends NodeDele
         checkStatus();
         checkProtected();
 
-        sessionDelegate.perform(new SessionOperation<Void>() {
+        perform(new SessionOperation<Void>() {
             @Override
             public Void perform() throws RepositoryException {
                 String oakSrcChildRelPath =
@@ -476,7 +476,7 @@ public class NodeImpl<T extends NodeDele
     public Node getNode(final String relPath) throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<NodeImpl<?>>() {
+        return perform(new SessionOperation<NodeImpl<?>>() {
             @Override
             public NodeImpl<?> perform() throws RepositoryException {
                 String oakPath = sessionDelegate.getOakPathOrThrowNotFound(relPath);
@@ -496,7 +496,7 @@ public class NodeImpl<T extends NodeDele
     public NodeIterator getNodes() throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<NodeIterator>() {
+        return perform(new SessionOperation<NodeIterator>() {
             @Override
             public NodeIterator perform() throws RepositoryException {
                 Iterator<NodeDelegate> children = dlg.getChildren();
@@ -512,7 +512,7 @@ public class NodeImpl<T extends NodeDele
             throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<NodeIterator>() {
+        return perform(new SessionOperation<NodeIterator>() {
             @Override
             public NodeIterator perform() throws RepositoryException {
                 Iterator<NodeDelegate> children = Iterators.filter(dlg.getChildren(),
@@ -537,7 +537,7 @@ public class NodeImpl<T extends NodeDele
     public NodeIterator getNodes(final String[] nameGlobs) throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<NodeIterator>() {
+        return perform(new SessionOperation<NodeIterator>() {
             @Override
             public NodeIterator perform() throws RepositoryException {
                 Iterator<NodeDelegate> children = Iterators.filter(dlg.getChildren(),
@@ -562,7 +562,7 @@ public class NodeImpl<T extends NodeDele
     public Property getProperty(final String relPath) throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<PropertyImpl>() {
+        return perform(new SessionOperation<PropertyImpl>() {
             @Override
             public PropertyImpl perform() throws RepositoryException {
                 String oakPath = sessionDelegate.getOakPathOrThrowNotFound(relPath);
@@ -581,7 +581,7 @@ public class NodeImpl<T extends NodeDele
     public PropertyIterator getProperties() throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<PropertyIterator>() {
+        return perform(new SessionOperation<PropertyIterator>() {
             @Override
             public PropertyIterator perform() throws RepositoryException {
                 Iterator<PropertyDelegate> properties = dlg.getProperties();
@@ -596,7 +596,7 @@ public class NodeImpl<T extends NodeDele
     public PropertyIterator getProperties(final String namePattern) throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<PropertyIterator>() {
+        return perform(new SessionOperation<PropertyIterator>() {
             @Override
             public PropertyIterator perform() throws RepositoryException {
                 Iterator<PropertyDelegate> properties = Iterators.filter(dlg.getProperties(),
@@ -621,7 +621,7 @@ public class NodeImpl<T extends NodeDele
     public PropertyIterator getProperties(final String[] nameGlobs) throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<PropertyIterator>() {
+        return perform(new SessionOperation<PropertyIterator>() {
             @Override
             public PropertyIterator perform() throws RepositoryException {
                 Iterator<PropertyDelegate> propertyNames = Iterators.filter(dlg.getProperties(),
@@ -649,7 +649,7 @@ public class NodeImpl<T extends NodeDele
     public Item getPrimaryItem() throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<Item>() {
+        return perform(new SessionOperation<Item>() {
             @Override
             public Item perform() throws RepositoryException {
                 String name = getPrimaryNodeType().getPrimaryItemName();
@@ -675,7 +675,7 @@ public class NodeImpl<T extends NodeDele
     public String getUUID() throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<String>() {
+        return perform(new SessionOperation<String>() {
             @Override
             public String perform() throws RepositoryException {
                 if (isNodeType(NodeType.MIX_REFERENCEABLE)) {
@@ -692,7 +692,7 @@ public class NodeImpl<T extends NodeDele
     public String getIdentifier() throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<String>() {
+        return perform(new SessionOperation<String>() {
             @Override
             public String perform() throws RepositoryException {
                 return dlg.getIdentifier();
@@ -739,7 +739,7 @@ public class NodeImpl<T extends NodeDele
     }
 
     private PropertyIterator internalGetReferences(final String name, final boolean weak) throws RepositoryException {
-        return sessionDelegate.perform(new SessionOperation<PropertyIterator>() {
+        return perform(new SessionOperation<PropertyIterator>() {
             @Override
             public PropertyIterator perform() throws InvalidItemStateException {
                 IdentifierManager idManager = sessionDelegate.getIdManager();
@@ -765,7 +765,7 @@ public class NodeImpl<T extends NodeDele
     public boolean hasNode(final String relPath) throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<Boolean>() {
+        return perform(new SessionOperation<Boolean>() {
             @Override
             public Boolean perform() throws RepositoryException {
                 String oakPath = sessionDelegate.getOakPath(relPath);
@@ -778,7 +778,7 @@ public class NodeImpl<T extends NodeDele
     public boolean hasProperty(final String relPath) throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<Boolean>() {
+        return perform(new SessionOperation<Boolean>() {
             @Override
             public Boolean perform() throws RepositoryException {
                 String oakPath = sessionDelegate.getOakPath(relPath);
@@ -791,7 +791,7 @@ public class NodeImpl<T extends NodeDele
     public boolean hasNodes() throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<Boolean>() {
+        return perform(new SessionOperation<Boolean>() {
             @Override
             public Boolean perform() throws RepositoryException {
                 return dlg.getChildCount() != 0;
@@ -803,7 +803,7 @@ public class NodeImpl<T extends NodeDele
     public boolean hasProperties() throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<Boolean>() {
+        return perform(new SessionOperation<Boolean>() {
             @Override
             public Boolean perform() throws RepositoryException {
                 return dlg.getPropertyCount() != 0;
@@ -819,7 +819,7 @@ public class NodeImpl<T extends NodeDele
     public NodeType getPrimaryNodeType() throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<NodeType>() {
+        return perform(new SessionOperation<NodeType>() {
             @Override
             public NodeType perform() throws RepositoryException {
                 NodeTypeManager ntMgr = sessionDelegate.getNodeTypeManager();
@@ -842,7 +842,7 @@ public class NodeImpl<T extends NodeDele
     public NodeType[] getMixinNodeTypes() throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<NodeType[]>() {
+        return perform(new SessionOperation<NodeType[]>() {
             @Override
             public NodeType[] perform() throws RepositoryException {
                 // TODO: check if transient changes to mixin-types are reflected here
@@ -886,7 +886,7 @@ public class NodeImpl<T extends NodeDele
         checkStatus();
         checkProtected();
 
-        sessionDelegate.perform(new SessionOperation<Void>() {
+        perform(new SessionOperation<Void>() {
             @Override
             public Void perform() throws RepositoryException {
                 // TODO: figure out the right place for this check
@@ -927,7 +927,7 @@ public class NodeImpl<T extends NodeDele
         checkStatus();
         checkProtected();
 
-        sessionDelegate.perform(new SessionOperation<Void>() {
+        perform(new SessionOperation<Void>() {
             @Override
             public Void perform() throws RepositoryException {
                 if (!isNodeType(mixinName)) {
@@ -943,7 +943,7 @@ public class NodeImpl<T extends NodeDele
     public boolean canAddMixin(final String mixinName) throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<Boolean>() {
+        return perform(new SessionOperation<Boolean>() {
             @Override
             public Boolean perform() throws RepositoryException {
                 // TODO: figure out the right place for this check
@@ -1423,7 +1423,7 @@ public class NodeImpl<T extends NodeDele
     }
 
     private void internalSetPrimaryType(final String nodeTypeName) throws RepositoryException {
-        sessionDelegate.perform(new SessionOperation<Void>() {
+        perform(new SessionOperation<Void>() {
             @Override
             public Void perform() throws RepositoryException {
                 // TODO: figure out the right place for this check
@@ -1450,7 +1450,7 @@ public class NodeImpl<T extends NodeDele
         checkStatus();
         checkProtected();
 
-        return sessionDelegate.perform(new SessionOperation<Property>() {
+        return perform(new SessionOperation<Property>() {
             @Override
             public Property perform() throws RepositoryException {
                 String oakName = sessionDelegate.getOakPath(jcrName);
@@ -1495,7 +1495,7 @@ public class NodeImpl<T extends NodeDele
         checkStatus();
         checkProtected();
 
-        return sessionDelegate.perform(new SessionOperation<Property>() {
+        return perform(new SessionOperation<Property>() {
             @Override
             public Property perform() throws RepositoryException {
                 String oakName = sessionDelegate.getOakPath(jcrName);

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=1451334&r1=1451333&r2=1451334&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 Thu Feb 28 20:51:12 2013
@@ -57,7 +57,7 @@ public class PropertyImpl extends ItemIm
     private static final Logger log = LoggerFactory.getLogger(PropertyImpl.class);
 
     PropertyImpl(PropertyDelegate dlg) {
-        super(dlg.getSessionDelegate(), dlg);
+        super(dlg);
     }
 
     //---------------------------------------------------------------< Item >---
@@ -76,7 +76,7 @@ public class PropertyImpl extends ItemIm
     @Override
     @Nonnull
     public Node getParent() throws RepositoryException {
-        return sessionDelegate.perform(new SessionOperation<NodeImpl<?>>() {
+        return perform(new SessionOperation<NodeImpl<?>>() {
             @Override
             public NodeImpl<?> perform() throws RepositoryException {
                 NodeDelegate parent = dlg.getParent();
@@ -95,7 +95,7 @@ public class PropertyImpl extends ItemIm
     @Override
     public boolean isNew() {
         try {
-            return sessionDelegate.perform(new SessionOperation<Boolean>() {
+            return perform(new SessionOperation<Boolean>() {
                 @Override
                 public Boolean perform() throws RepositoryException {
                     return dlg.getStatus() == Status.NEW;
@@ -112,7 +112,7 @@ public class PropertyImpl extends ItemIm
     @Override
     public boolean isModified() {
         try {
-            return sessionDelegate.perform(new SessionOperation<Boolean>() {
+            return perform(new SessionOperation<Boolean>() {
                 @Override
                 public Boolean perform() throws RepositoryException {
                     return dlg.getStatus() == Status.MODIFIED;
@@ -131,7 +131,7 @@ public class PropertyImpl extends ItemIm
         checkStatus();
         checkProtected();
 
-        sessionDelegate.perform(new SessionOperation<Void>() {
+        perform(new SessionOperation<Void>() {
             @Override
             public Void perform() throws RepositoryException {
                 dlg.remove();
@@ -170,7 +170,7 @@ public class PropertyImpl extends ItemIm
     public void setValue(final Value[] values) throws RepositoryException {
         checkStatus();
 
-        sessionDelegate.perform(new SessionOperation<Void>() {
+        perform(new SessionOperation<Void>() {
             @Override
             public Void perform() throws RepositoryException {
                 // assert equal types for all values entries
@@ -348,7 +348,7 @@ public class PropertyImpl extends ItemIm
     public Value getValue() throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<Value>() {
+        return perform(new SessionOperation<Value>() {
             @Override
             public Value perform() throws RepositoryException {
                 if (isMultiple()) {
@@ -365,7 +365,7 @@ public class PropertyImpl extends ItemIm
     public Value[] getValues() throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<Value[]>() {
+        return perform(new SessionOperation<Value[]>() {
             @Override
             public Value[] perform() throws RepositoryException {
                 if (!isMultiple()) {
@@ -453,7 +453,7 @@ public class PropertyImpl extends ItemIm
     @Override
     @Nonnull
     public Node getNode() throws RepositoryException {
-        return sessionDelegate.perform(new SessionOperation<Node>() {
+        return perform(new SessionOperation<Node>() {
             @Override
             public Node perform() throws RepositoryException {
                 Value value = getValue();
@@ -508,7 +508,7 @@ public class PropertyImpl extends ItemIm
     @Override
     @Nonnull
     public Property getProperty() throws RepositoryException {
-        return sessionDelegate.perform(new SessionOperation<Property>() {
+        return perform(new SessionOperation<Property>() {
             @Override
             public Property perform() throws RepositoryException {
                 Value value = getValue();
@@ -557,7 +557,7 @@ public class PropertyImpl extends ItemIm
      */
     @Override
     public int getType() throws RepositoryException {
-        return sessionDelegate.perform(new SessionOperation<Integer>() {
+        return perform(new SessionOperation<Integer>() {
             @Override
             public Integer perform() throws RepositoryException {
                 if (isMultiple()) {
@@ -579,7 +579,7 @@ public class PropertyImpl extends ItemIm
     public boolean isMultiple() throws RepositoryException {
         checkStatus();
 
-        return sessionDelegate.perform(new SessionOperation<Boolean>() {
+        return perform(new SessionOperation<Boolean>() {
             @Override
             public Boolean perform() throws RepositoryException {
                 return dlg.isMultivalue();