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 an...@apache.org on 2015/04/14 10:35:13 UTC
svn commit: r1673387 [1/2] - in
/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr:
delegate/ lock/ query/ security/ session/ session/operation/ version/
Author: angela
Date: Tue Apr 14 08:35:12 2015
New Revision: 1673387
URL: http://svn.apache.org/r1673387
Log:
OAK-2712 : Possible null-dereference when calling ItemImpl#perform
Modified:
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/AccessControlManagerDelegator.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/AuthorizableDelegator.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/GroupDelegator.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/ImpersonationDelegator.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/JackrabbitAccessControlManagerDelegator.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PrincipalManagerDelegator.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PrivilegeManagerDelegator.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserDelegator.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserManagerDelegator.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockImpl.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockManagerImpl.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockOperation.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/AccessManager.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/ItemImpl.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/NodeImpl.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/PropertyImpl.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionImpl.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/WorkspaceImpl.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/operation/SessionOperation.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionHistoryImpl.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionImpl.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/version/VersionManagerImpl.java
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/AccessControlManagerDelegator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/AccessControlManagerDelegator.java?rev=1673387&r1=1673386&r2=1673387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/AccessControlManagerDelegator.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/AccessControlManagerDelegator.java Tue Apr 14 08:35:12 2015
@@ -19,6 +19,7 @@
package org.apache.jackrabbit.oak.jcr.delegate;
+import javax.annotation.Nonnull;
import javax.jcr.RepositoryException;
import javax.jcr.security.AccessControlManager;
import javax.jcr.security.AccessControlPolicy;
@@ -45,6 +46,7 @@ public class AccessControlManagerDelegat
@Override
public Privilege[] getSupportedPrivileges(final String absPath) throws RepositoryException {
return delegate.perform(new SessionOperation<Privilege[]>("getSupportedPrivileges") {
+ @Nonnull
@Override
public Privilege[] perform() throws RepositoryException {
return acManager.getSupportedPrivileges(absPath);
@@ -55,6 +57,7 @@ public class AccessControlManagerDelegat
@Override
public Privilege privilegeFromName(final String privilegeName) throws RepositoryException {
return delegate.perform(new SessionOperation<Privilege>("privilegeFromName") {
+ @Nonnull
@Override
public Privilege perform() throws RepositoryException {
return acManager.privilegeFromName(privilegeName);
@@ -66,6 +69,7 @@ public class AccessControlManagerDelegat
public boolean hasPrivileges(final String absPath, final Privilege[] privileges)
throws RepositoryException {
return delegate.perform(new SessionOperation<Boolean>("hasPrivileges") {
+ @Nonnull
@Override
public Boolean perform() throws RepositoryException {
return acManager.hasPrivileges(absPath, privileges);
@@ -76,6 +80,7 @@ public class AccessControlManagerDelegat
@Override
public Privilege[] getPrivileges(final String absPath) throws RepositoryException {
return delegate.perform(new SessionOperation<Privilege[]>("getPrivileges") {
+ @Nonnull
@Override
public Privilege[] perform() throws RepositoryException {
return acManager.getPrivileges(absPath);
@@ -86,6 +91,7 @@ public class AccessControlManagerDelegat
@Override
public AccessControlPolicy[] getPolicies(final String absPath) throws RepositoryException {
return delegate.perform(new SessionOperation<AccessControlPolicy[]>("getPolicies") {
+ @Nonnull
@Override
public AccessControlPolicy[] perform() throws RepositoryException {
return acManager.getPolicies(absPath);
@@ -97,6 +103,7 @@ public class AccessControlManagerDelegat
public AccessControlPolicy[] getEffectivePolicies(final String absPath)
throws RepositoryException {
return delegate.perform(new SessionOperation<AccessControlPolicy[]>("getEffectivePolicies") {
+ @Nonnull
@Override
public AccessControlPolicy[] perform() throws RepositoryException {
return acManager.getEffectivePolicies(absPath);
@@ -108,6 +115,7 @@ public class AccessControlManagerDelegat
public AccessControlPolicyIterator getApplicablePolicies(final String absPath)
throws RepositoryException {
return delegate.perform(new SessionOperation<AccessControlPolicyIterator>("getApplicablePolicies") {
+ @Nonnull
@Override
public AccessControlPolicyIterator perform() throws RepositoryException {
return acManager.getApplicablePolicies(absPath);
@@ -118,11 +126,10 @@ public class AccessControlManagerDelegat
@Override
public void setPolicy(final String absPath, final AccessControlPolicy policy)
throws RepositoryException {
- delegate.perform(new SessionOperation<Void>("setPolicy") {
+ delegate.performVoid(new SessionOperation("setPolicy") {
@Override
- public Void perform() throws RepositoryException {
+ public void performVoid() throws RepositoryException {
acManager.setPolicy(absPath, policy);
- return null;
}
});
}
@@ -130,11 +137,10 @@ public class AccessControlManagerDelegat
@Override
public void removePolicy(final String absPath, final AccessControlPolicy policy)
throws RepositoryException {
- delegate.perform(new SessionOperation<Void>("removePolicy") {
+ delegate.performVoid(new SessionOperation("removePolicy") {
@Override
- public Void perform() throws RepositoryException {
+ public void performVoid() throws RepositoryException {
acManager.removePolicy(absPath, policy);
- return null;
}
});
}
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/AuthorizableDelegator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/AuthorizableDelegator.java?rev=1673387&r1=1673386&r2=1673387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/AuthorizableDelegator.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/AuthorizableDelegator.java Tue Apr 14 08:35:12 2015
@@ -73,6 +73,7 @@ abstract class AuthorizableDelegator imp
@Override
public boolean isGroup() {
return sessionDelegate.safePerform(new SessionOperation<Boolean>("isGroup") {
+ @Nonnull
@Override
public Boolean perform() {
return delegate.isGroup();
@@ -83,6 +84,7 @@ abstract class AuthorizableDelegator imp
@Override
public String getID() throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<String>("getID") {
+ @Nonnull
@Override
public String perform() throws RepositoryException {
return delegate.getID();
@@ -95,6 +97,7 @@ abstract class AuthorizableDelegator imp
@Override
public Principal getPrincipal() throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<Principal>("getPrincipal") {
+ @Nonnull
@Override
public Principal perform() throws RepositoryException {
return delegate.getPrincipal();
@@ -105,6 +108,7 @@ abstract class AuthorizableDelegator imp
@Override
public Iterator<Group> declaredMemberOf() throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<Iterator<Group>>("declaredMemberOf") {
+ @Nonnull
@Override
public Iterator<Group> perform() throws RepositoryException {
Iterator<Group> groups = delegate.declaredMemberOf();
@@ -122,6 +126,7 @@ abstract class AuthorizableDelegator imp
@Override
public Iterator<Group> memberOf() throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<Iterator<Group>>("memberOf") {
+ @Nonnull
@Override
public Iterator<Group> perform() throws RepositoryException {
Iterator<Group> groups = delegate.memberOf();
@@ -138,11 +143,10 @@ abstract class AuthorizableDelegator imp
@Override
public void remove() throws RepositoryException {
- sessionDelegate.perform(new SessionOperation<Void>("remove") {
+ sessionDelegate.performVoid(new SessionOperation("remove") {
@Override
- public Void perform() throws RepositoryException {
+ public void performVoid() throws RepositoryException {
delegate.remove();
- return null;
}
});
}
@@ -150,6 +154,7 @@ abstract class AuthorizableDelegator imp
@Override
public Iterator<String> getPropertyNames() throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<Iterator<String>>("getPropertyNames") {
+ @Nonnull
@Override
public Iterator<String> perform() throws RepositoryException {
return delegate.getPropertyNames();
@@ -160,6 +165,7 @@ abstract class AuthorizableDelegator imp
@Override
public Iterator<String> getPropertyNames(final String relPath) throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<Iterator<String>>("getPropertyNames") {
+ @Nonnull
@Override
public Iterator<String> perform() throws RepositoryException {
return delegate.getPropertyNames(relPath);
@@ -170,6 +176,7 @@ abstract class AuthorizableDelegator imp
@Override
public boolean hasProperty(final String relPath) throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<Boolean>("hasProperty") {
+ @Nonnull
@Override
public Boolean perform() throws RepositoryException {
return delegate.hasProperty(relPath);
@@ -179,22 +186,20 @@ abstract class AuthorizableDelegator imp
@Override
public void setProperty(final String relPath, final Value value) throws RepositoryException {
- sessionDelegate.perform(new SessionOperation<Void>("setProperty") {
+ sessionDelegate.performVoid(new SessionOperation("setProperty") {
@Override
- public Void perform() throws RepositoryException {
+ public void performVoid() throws RepositoryException {
delegate.setProperty(relPath, value);
- return null;
}
});
}
@Override
public void setProperty(final String relPath, final Value[] value) throws RepositoryException {
- sessionDelegate.perform(new SessionOperation<Void>("setProperty") {
+ sessionDelegate.performVoid(new SessionOperation("setProperty") {
@Override
- public Void perform() throws RepositoryException {
+ public void performVoid() throws RepositoryException {
delegate.setProperty(relPath, value);
- return null;
}
});
}
@@ -202,6 +207,7 @@ abstract class AuthorizableDelegator imp
@Override
public Value[] getProperty(final String relPath) throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<Value[]>("getProperty") {
+ @Nonnull
@Override
public Value[] perform() throws RepositoryException {
return delegate.getProperty(relPath);
@@ -212,6 +218,7 @@ abstract class AuthorizableDelegator imp
@Override
public boolean removeProperty(final String relPath) throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<Boolean>("removeProperty") {
+ @Nonnull
@Override
public Boolean perform() throws RepositoryException {
return delegate.removeProperty(relPath);
@@ -222,6 +229,7 @@ abstract class AuthorizableDelegator imp
@Override
public String getPath() throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<String>("getPath") {
+ @Nonnull
@Override
public String perform() throws RepositoryException {
return delegate.getPath();
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/GroupDelegator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/GroupDelegator.java?rev=1673387&r1=1673386&r2=1673387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/GroupDelegator.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/GroupDelegator.java Tue Apr 14 08:35:12 2015
@@ -67,6 +67,7 @@ final class GroupDelegator extends Autho
@Override
public Iterator<Authorizable> getDeclaredMembers() throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<Iterator<Authorizable>>("getDeclaredMembers") {
+ @Nonnull
@Override
public Iterator<Authorizable> perform() throws RepositoryException {
Iterator<Authorizable> authorizables = getDelegate().getDeclaredMembers();
@@ -84,6 +85,7 @@ final class GroupDelegator extends Autho
@Override
public Iterator<Authorizable> getMembers() throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<Iterator<Authorizable>>("getMembers") {
+ @Nonnull
@Override
public Iterator<Authorizable> perform() throws RepositoryException {
Iterator<Authorizable> authorizables = getDelegate().getMembers();
@@ -101,6 +103,7 @@ final class GroupDelegator extends Autho
@Override
public boolean isDeclaredMember(final Authorizable authorizable) throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<Boolean>("isDeclaredMember") {
+ @Nonnull
@Override
public Boolean perform() throws RepositoryException {
return getDelegate().isDeclaredMember(unwrap(authorizable));
@@ -111,6 +114,7 @@ final class GroupDelegator extends Autho
@Override
public boolean isMember(final Authorizable authorizable) throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<Boolean>("isMember") {
+ @Nonnull
@Override
public Boolean perform() throws RepositoryException {
return getDelegate().isMember(unwrap(authorizable));
@@ -121,6 +125,7 @@ final class GroupDelegator extends Autho
@Override
public boolean addMember(final Authorizable authorizable) throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<Boolean>("addMember") {
+ @Nonnull
@Override
public Boolean perform() throws RepositoryException {
return getDelegate().addMember(unwrap(authorizable));
@@ -131,6 +136,7 @@ final class GroupDelegator extends Autho
@Override
public boolean removeMember(final Authorizable authorizable) throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<Boolean>("removeMember") {
+ @Nonnull
@Override
public Boolean perform() throws RepositoryException {
return getDelegate().removeMember(unwrap(authorizable));
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/ImpersonationDelegator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/ImpersonationDelegator.java?rev=1673387&r1=1673386&r2=1673387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/ImpersonationDelegator.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/ImpersonationDelegator.java Tue Apr 14 08:35:12 2015
@@ -23,6 +23,7 @@ import static com.google.common.base.Pre
import java.security.Principal;
+import javax.annotation.Nonnull;
import javax.jcr.RepositoryException;
import javax.security.auth.Subject;
@@ -57,6 +58,7 @@ final class ImpersonationDelegator imple
@Override
public PrincipalIterator getImpersonators() throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<PrincipalIterator>("getImpersonators") {
+ @Nonnull
@Override
public PrincipalIterator perform() throws RepositoryException {
return impersonationDelegate.getImpersonators();
@@ -67,6 +69,7 @@ final class ImpersonationDelegator imple
@Override
public boolean grantImpersonation(final Principal principal) throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<Boolean>("grantImpersonation") {
+ @Nonnull
@Override
public Boolean perform() throws RepositoryException {
return impersonationDelegate.grantImpersonation(principal);
@@ -77,6 +80,7 @@ final class ImpersonationDelegator imple
@Override
public boolean revokeImpersonation(final Principal principal) throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<Boolean>("revokeImpersonation") {
+ @Nonnull
@Override
public Boolean perform() throws RepositoryException {
return impersonationDelegate.revokeImpersonation(principal);
@@ -87,6 +91,7 @@ final class ImpersonationDelegator imple
@Override
public boolean allows(final Subject subject) throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<Boolean>("allows") {
+ @Nonnull
@Override
public Boolean perform() throws RepositoryException {
return impersonationDelegate.allows(subject);
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/JackrabbitAccessControlManagerDelegator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/JackrabbitAccessControlManagerDelegator.java?rev=1673387&r1=1673386&r2=1673387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/JackrabbitAccessControlManagerDelegator.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/JackrabbitAccessControlManagerDelegator.java Tue Apr 14 08:35:12 2015
@@ -22,6 +22,7 @@ package org.apache.jackrabbit.oak.jcr.de
import java.security.Principal;
import java.util.Set;
+import javax.annotation.Nonnull;
import javax.jcr.RepositoryException;
import javax.jcr.security.AccessControlPolicy;
import javax.jcr.security.AccessControlPolicyIterator;
@@ -52,8 +53,8 @@ public class JackrabbitAccessControlMana
@Override
public JackrabbitAccessControlPolicy[] getApplicablePolicies(final Principal principal)
throws RepositoryException {
- return delegate.perform(
- new SessionOperation<JackrabbitAccessControlPolicy[]>("getApplicablePolicies") {
+ return delegate.perform(new SessionOperation<JackrabbitAccessControlPolicy[]>("getApplicablePolicies") {
+ @Nonnull
@Override
public JackrabbitAccessControlPolicy[] perform() throws RepositoryException {
return jackrabbitACManager.getApplicablePolicies(principal);
@@ -64,8 +65,8 @@ public class JackrabbitAccessControlMana
@Override
public JackrabbitAccessControlPolicy[] getPolicies(final Principal principal)
throws RepositoryException {
- return delegate.perform(
- new SessionOperation<JackrabbitAccessControlPolicy[]>("getPolicies") {
+ return delegate.perform(new SessionOperation<JackrabbitAccessControlPolicy[]>("getPolicies") {
+ @Nonnull
@Override
public JackrabbitAccessControlPolicy[] perform() throws RepositoryException {
return jackrabbitACManager.getPolicies(principal);
@@ -76,8 +77,8 @@ public class JackrabbitAccessControlMana
@Override
public AccessControlPolicy[] getEffectivePolicies(final Set<Principal> principals)
throws RepositoryException {
- return delegate.perform(
- new SessionOperation<AccessControlPolicy[]>("getEffectivePolicies") {
+ return delegate.perform(new SessionOperation<AccessControlPolicy[]>("getEffectivePolicies") {
+ @Nonnull
@Override
public AccessControlPolicy[] perform() throws RepositoryException {
return jackrabbitACManager.getEffectivePolicies(principals);
@@ -88,8 +89,8 @@ public class JackrabbitAccessControlMana
@Override
public boolean hasPrivileges(final String absPath, final Set<Principal> principals,
final Privilege[] privileges) throws RepositoryException {
- return delegate.perform(
- new SessionOperation<Boolean>("hasPrivileges") {
+ return delegate.perform(new SessionOperation<Boolean>("hasPrivileges") {
+ @Nonnull
@Override
public Boolean perform() throws RepositoryException {
return jackrabbitACManager.hasPrivileges(absPath, principals, privileges);
@@ -100,8 +101,8 @@ public class JackrabbitAccessControlMana
@Override
public Privilege[] getPrivileges(final String absPath, final Set<Principal> principals)
throws RepositoryException {
- return delegate.perform(
- new SessionOperation<Privilege[]>("getPrivileges") {
+ return delegate.perform(new SessionOperation<Privilege[]>("getPrivileges") {
+ @Nonnull
@Override
public Privilege[] perform() throws RepositoryException {
return jackrabbitACManager.getPrivileges(absPath, principals);
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java?rev=1673387&r1=1673386&r2=1673387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java Tue Apr 14 08:35:12 2015
@@ -724,6 +724,7 @@ public class NodeDelegate extends ItemDe
return getLock() != null;
}
+ @CheckForNull
public NodeDelegate getLock() {
Tree lock = findLock(tree, false);
if (lock != null) {
@@ -739,7 +740,8 @@ public class NodeDelegate extends ItemDe
return null;
}
- private Tree findLock(Tree tree, boolean deep) {
+ @CheckForNull
+ private Tree findLock(@Nonnull Tree tree, boolean deep) {
if (holdsLock(tree, deep)) {
return tree;
} else if (tree.isRoot()) {
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PrincipalManagerDelegator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PrincipalManagerDelegator.java?rev=1673387&r1=1673386&r2=1673387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PrincipalManagerDelegator.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PrincipalManagerDelegator.java Tue Apr 14 08:35:12 2015
@@ -21,6 +21,9 @@ package org.apache.jackrabbit.oak.jcr.de
import java.security.Principal;
+import javax.annotation.Nonnull;
+import javax.jcr.RepositoryException;
+
import org.apache.jackrabbit.api.security.principal.PrincipalIterator;
import org.apache.jackrabbit.api.security.principal.PrincipalManager;
import org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation;
@@ -44,6 +47,7 @@ public class PrincipalManagerDelegator i
@Override
public boolean hasPrincipal(final String principalName) {
return delegate.safePerform(new SessionOperation<Boolean>("hasPrincipal") {
+ @Nonnull
@Override
public Boolean perform() {
return principalManager.hasPrincipal(principalName);
@@ -53,17 +57,22 @@ public class PrincipalManagerDelegator i
@Override
public Principal getPrincipal(final String principalName) {
- return delegate.safePerform(new SessionOperation<Principal>("getPrincipal") {
- @Override
- public Principal perform() {
- return principalManager.getPrincipal(principalName);
- }
- });
+ try {
+ return delegate.performNullable(new SessionOperation<Principal>("getPrincipal") {
+ @Override
+ public Principal performNullable() {
+ return principalManager.getPrincipal(principalName);
+ }
+ });
+ } catch (RepositoryException e) {
+ throw new RuntimeException("Unexpected exception thrown by operation 'getPrincipal'", e);
+ }
}
@Override
public PrincipalIterator findPrincipals(final String simpleFilter) {
return delegate.safePerform(new SessionOperation<PrincipalIterator>("findPrincipals") {
+ @Nonnull
@Override
public PrincipalIterator perform() {
return principalManager.findPrincipals(simpleFilter);
@@ -74,6 +83,7 @@ public class PrincipalManagerDelegator i
@Override
public PrincipalIterator findPrincipals(final String simpleFilter, final int searchType) {
return delegate.safePerform(new SessionOperation<PrincipalIterator>("findPrincipals") {
+ @Nonnull
@Override
public PrincipalIterator perform() {
return principalManager.findPrincipals(simpleFilter, searchType);
@@ -84,6 +94,7 @@ public class PrincipalManagerDelegator i
@Override
public PrincipalIterator getPrincipals(final int searchType) {
return delegate.safePerform(new SessionOperation<PrincipalIterator>("getPrincipals") {
+ @Nonnull
@Override
public PrincipalIterator perform() {
return principalManager.getPrincipals(searchType);
@@ -94,6 +105,7 @@ public class PrincipalManagerDelegator i
@Override
public PrincipalIterator getGroupMembership(final Principal principal) {
return delegate.safePerform(new SessionOperation<PrincipalIterator>("getGroupMembership") {
+ @Nonnull
@Override
public PrincipalIterator perform() {
return principalManager.getGroupMembership(principal);
@@ -104,6 +116,7 @@ public class PrincipalManagerDelegator i
@Override
public Principal getEveryone() {
return delegate.safePerform(new SessionOperation<Principal>("getEveryone") {
+ @Nonnull
@Override
public Principal perform() {
return principalManager.getEveryone();
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PrivilegeManagerDelegator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PrivilegeManagerDelegator.java?rev=1673387&r1=1673386&r2=1673387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PrivilegeManagerDelegator.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/PrivilegeManagerDelegator.java Tue Apr 14 08:35:12 2015
@@ -19,6 +19,7 @@
package org.apache.jackrabbit.oak.jcr.delegate;
+import javax.annotation.Nonnull;
import javax.jcr.AccessDeniedException;
import javax.jcr.NamespaceException;
import javax.jcr.RepositoryException;
@@ -46,6 +47,7 @@ public class PrivilegeManagerDelegator i
@Override
public Privilege[] getRegisteredPrivileges() throws RepositoryException {
return delegate.perform(new SessionOperation<Privilege[]>("getRegisteredPrivileges") {
+ @Nonnull
@Override
public Privilege[] perform() throws RepositoryException {
return pm.getRegisteredPrivileges();
@@ -56,6 +58,7 @@ public class PrivilegeManagerDelegator i
@Override
public Privilege getPrivilege(final String privilegeName) throws AccessControlException, RepositoryException {
return delegate.perform(new SessionOperation<Privilege>("getPrivilege") {
+ @Nonnull
@Override
public Privilege perform() throws RepositoryException {
return pm.getPrivilege(privilegeName);
@@ -66,6 +69,7 @@ public class PrivilegeManagerDelegator i
@Override
public Privilege registerPrivilege(final String privilegeName, final boolean isAbstract, final String[] declaredAggregateNames) throws AccessDeniedException, NamespaceException, RepositoryException {
return delegate.perform(new SessionOperation<Privilege>("registerPrivilege") {
+ @Nonnull
@Override
public Privilege perform() throws RepositoryException {
return pm.registerPrivilege(privilegeName, isAbstract, declaredAggregateNames);
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java?rev=1673387&r1=1673386&r2=1673387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java Tue Apr 14 08:35:12 2015
@@ -36,6 +36,7 @@ import java.util.concurrent.locks.Reentr
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import javax.jcr.ItemExistsException;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
@@ -186,8 +187,8 @@ public class SessionDelegate {
* @throws RepositoryException
* @see #getRoot()
*/
- public <T> T perform(SessionOperation<T> sessionOperation)
- throws RepositoryException {
+ @Nonnull
+ public <T> T perform(@Nonnull SessionOperation<T> sessionOperation) throws RepositoryException {
long t0 = clock.getTime();
// Acquire the exclusive lock for accessing session internals.
@@ -195,51 +196,79 @@ public class SessionDelegate {
// message to let the user know of such cases.
lock.lock(sessionOperation);
try {
- if (sessionOpCount == 0) {
- // Refresh and precondition checks only for non re-entrant
- // session operations. Don't refresh if this operation is a
- // refresh operation itself or a save operation, which does an
- // implicit refresh, or logout for obvious reasons.
- if (!sessionOperation.isRefresh()
- && !sessionOperation.isSave()
- && !sessionOperation.isLogout()
- && refreshStrategy.needsRefresh(
- SECONDS.convert(t0 - sessionCounters.accessTime, MILLISECONDS))) {
- refresh(true);
- refreshStrategy.refreshed();
- updateCount++;
- }
- sessionOperation.checkPreconditions();
- }
+ prePerform(sessionOperation, t0);
try {
sessionOpCount++;
T result = sessionOperation.perform();
logOperationDetails(contentSession, sessionOperation);
return result;
} finally {
- sessionCounters.accessTime = t0;
- long dt = NANOSECONDS.convert(clock.getTime() - t0, MILLISECONDS);
- sessionOpCount--;
- if (sessionOperation.isUpdate()) {
- sessionCounters.writeTime = t0;
- sessionCounters.writeCount++;
- writeCounter.incrementAndGet();
- writeDuration.addAndGet(dt);
- updateCount++;
- } else {
- sessionCounters.readTime = t0;
- sessionCounters.readCount++;
- readCounter.incrementAndGet();
- readDuration.addAndGet(dt);
- }
- if (sessionOperation.isSave()) {
- refreshAtNextAccess.refreshAtNextAccess(false);
- // Force refreshing on access through other sessions on the same thread
- saveCountRefresh.forceRefresh();
- } else if (sessionOperation.isRefresh()) {
- refreshAtNextAccess.refreshAtNextAccess(false);
- saveCountRefresh.refreshed();
- }
+ postPerform(sessionOperation, t0);
+ }
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ /**
+ * Same as {@link #perform(org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation)}
+ * but with the option to return {@code null}; thus calling
+ * {@link org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation#performNullable()}
+ *
+ * @param sessionOperation the {@code SessionOperation} to perform
+ * @param <T> return type of {@code sessionOperation}
+ * @return the result of {@code sessionOperation.performNullable()}, which
+ * might also be {@code null}.
+ * @throws RepositoryException
+ * @see #perform(org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation)
+ */
+ @Nullable
+ public <T> T performNullable(@Nonnull SessionOperation<T> sessionOperation) throws RepositoryException {
+ long t0 = clock.getTime();
+
+ // Acquire the exclusive lock for accessing session internals.
+ // No other session should be holding the lock, so we log a
+ // message to let the user know of such cases.
+ lock.lock(sessionOperation);
+ try {
+ prePerform(sessionOperation, t0);
+ try {
+ sessionOpCount++;
+ T result = sessionOperation.performNullable();
+ logOperationDetails(contentSession, sessionOperation);
+ return result;
+ } finally {
+ postPerform(sessionOperation, t0);
+ }
+ } finally {
+ lock.unlock();
+ }
+ }
+
+ /**
+ * Same as {@link #perform(org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation)}
+ * for calls that don't expect any return value; thus calling
+ * {@link org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation#performVoid()}.
+ *
+ * @param sessionOperation the {@code SessionOperation} to perform.
+ * @throws RepositoryException
+ * @see #perform(org.apache.jackrabbit.oak.jcr.session.operation.SessionOperation)
+ */
+ public void performVoid(SessionOperation sessionOperation) throws RepositoryException {
+ long t0 = clock.getTime();
+
+ // Acquire the exclusive lock for accessing session internals.
+ // No other session should be holding the lock, so we log a
+ // message to let the user know of such cases.
+ lock.lock(sessionOperation);
+ try {
+ prePerform(sessionOperation, t0);
+ try {
+ sessionOpCount++;
+ sessionOperation.performVoid();
+ logOperationDetails(contentSession, sessionOperation);
+ } finally {
+ postPerform(sessionOperation, t0);
}
} finally {
lock.unlock();
@@ -261,8 +290,7 @@ public class SessionDelegate {
try {
return perform(sessionOperation);
} catch (RepositoryException e) {
- throw new RuntimeException("Unexpected exception thrown by operation " +
- sessionOperation, e);
+ throw new RuntimeException("Unexpected exception thrown by operation " + sessionOperation, e);
}
}
@@ -564,7 +592,49 @@ public class SessionDelegate {
return contentSession.toString();
}
- //------------------------------------------------------------< internal >---
+ //-----------------------------------------------------------< internal >---
+ private void prePerform(@Nonnull SessionOperation op, long t0) throws RepositoryException {
+ if (sessionOpCount == 0) {
+ // Refresh and precondition checks only for non re-entrant
+ // session operations. Don't refresh if this operation is a
+ // refresh operation itself or a save operation, which does an
+ // implicit refresh, or logout for obvious reasons.
+ if (!op.isRefresh() && !op.isSave() && !op.isLogout() &&
+ refreshStrategy.needsRefresh(SECONDS.convert(t0 - sessionCounters.accessTime, MILLISECONDS))) {
+ refresh(true);
+ refreshStrategy.refreshed();
+ updateCount++;
+ }
+ op.checkPreconditions();
+ }
+ }
+
+ private void postPerform(@Nonnull SessionOperation op, long t0) {
+ sessionCounters.accessTime = t0;
+ long dt = NANOSECONDS.convert(clock.getTime() - t0, MILLISECONDS);
+ sessionOpCount--;
+ if (op.isUpdate()) {
+ sessionCounters.writeTime = t0;
+ sessionCounters.writeCount++;
+ writeCounter.incrementAndGet();
+ writeDuration.addAndGet(dt);
+ updateCount++;
+ } else {
+ sessionCounters.readTime = t0;
+ sessionCounters.readCount++;
+ readCounter.incrementAndGet();
+ readDuration.addAndGet(dt);
+ }
+ if (op.isSave()) {
+ refreshAtNextAccess.refreshAtNextAccess(false);
+ // Force refreshing on access through other sessions on the same thread
+ saveCountRefresh.forceRefresh();
+ } else if (op.isRefresh()) {
+ refreshAtNextAccess.refreshAtNextAccess(false);
+ saveCountRefresh.refreshed();
+ }
+ }
+
private static <T> void logOperationDetails(ContentSession session, SessionOperation<T> ops) {
if (readOperationLogger.isTraceEnabled()
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserDelegator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserDelegator.java?rev=1673387&r1=1673386&r2=1673387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserDelegator.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserDelegator.java Tue Apr 14 08:35:12 2015
@@ -64,6 +64,7 @@ final class UserDelegator extends Author
@Override
public boolean isAdmin() {
return sessionDelegate.safePerform(new SessionOperation<Boolean>("isAdmin") {
+ @Nonnull
@Override
public Boolean perform() {
return getDelegate().isAdmin();
@@ -74,6 +75,7 @@ final class UserDelegator extends Author
@Override
public boolean isSystemUser() {
return sessionDelegate.safePerform(new SessionOperation<Boolean>("isSystemUser") {
+ @Nonnull
@Override
public Boolean perform() {
return getDelegate().isSystemUser();
@@ -84,6 +86,7 @@ final class UserDelegator extends Author
@Override
public Credentials getCredentials() {
return sessionDelegate.safePerform(new SessionOperation<Credentials>("getCredentials") {
+ @Nonnull
@Override
public Credentials perform() throws RepositoryException {
return getDelegate().getCredentials();
@@ -94,6 +97,7 @@ final class UserDelegator extends Author
@Override
public Impersonation getImpersonation() {
return sessionDelegate.safePerform(new SessionOperation<Impersonation>("getImpersonation") {
+ @Nonnull
@Override
public Impersonation perform() throws RepositoryException {
Impersonation impersonation = getDelegate().getImpersonation();
@@ -104,33 +108,30 @@ final class UserDelegator extends Author
@Override
public void changePassword(final String password) throws RepositoryException {
- sessionDelegate.perform(new SessionOperation<Void>("changePassword") {
+ sessionDelegate.performVoid(new SessionOperation("changePassword") {
@Override
- public Void perform() throws RepositoryException {
+ public void performVoid() throws RepositoryException {
getDelegate().changePassword(password);
- return null;
}
});
}
@Override
public void changePassword(final String password, final String oldPassword) throws RepositoryException {
- sessionDelegate.perform(new SessionOperation<Void>("changePassword") {
+ sessionDelegate.performVoid(new SessionOperation("changePassword") {
@Override
- public Void perform() throws RepositoryException {
+ public void performVoid() throws RepositoryException {
getDelegate().changePassword(password, oldPassword);
- return null;
}
});
}
@Override
public void disable(final String reason) throws RepositoryException {
- sessionDelegate.perform(new SessionOperation<Void>("disable") {
+ sessionDelegate.performVoid(new SessionOperation("disable") {
@Override
- public Void perform() throws RepositoryException {
+ public void performVoid() throws RepositoryException {
getDelegate().disable(reason);
- return null;
}
});
}
@@ -138,6 +139,7 @@ final class UserDelegator extends Author
@Override
public boolean isDisabled() throws RepositoryException {
return sessionDelegate.perform(new SessionOperation<Boolean>("isDisabled") {
+ @Nonnull
@Override
public Boolean perform() throws RepositoryException {
return getDelegate().isDisabled();
@@ -147,9 +149,9 @@ final class UserDelegator extends Author
@Override
public String getDisabledReason() throws RepositoryException {
- return sessionDelegate.perform(new SessionOperation<String>("getDisabledReason") {
+ return sessionDelegate.performNullable(new SessionOperation<String>("getDisabledReason") {
@Override
- public String perform() throws RepositoryException {
+ public String performNullable() throws RepositoryException {
return getDelegate().getDisabledReason();
}
});
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserManagerDelegator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserManagerDelegator.java?rev=1673387&r1=1673386&r2=1673387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserManagerDelegator.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/UserManagerDelegator.java Tue Apr 14 08:35:12 2015
@@ -24,6 +24,7 @@ import static com.google.common.base.Pre
import java.security.Principal;
import java.util.Iterator;
+import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.jcr.RepositoryException;
@@ -57,10 +58,9 @@ public class UserManagerDelegator implem
@Override
public Authorizable getAuthorizable(final String id) throws RepositoryException {
- return sessionDelegate.perform(
- new UserManagerOperation<Authorizable>(sessionDelegate, "getAuthorizable") {
+ return sessionDelegate.performNullable(new UserManagerOperation<Authorizable>(sessionDelegate, "getAuthorizable") {
@Override
- public Authorizable perform() throws RepositoryException {
+ public Authorizable performNullable() throws RepositoryException {
Authorizable authorizable = userManagerDelegate.getAuthorizable(id);
return AuthorizableDelegator.wrap(sessionDelegate, authorizable);
}
@@ -69,24 +69,22 @@ public class UserManagerDelegator implem
@Override
public <T extends Authorizable> T getAuthorizable(final String id, final Class<T> authorizableClass) throws RepositoryException {
- return (T) sessionDelegate.perform(
- new UserManagerOperation<Authorizable>(sessionDelegate, "getAuthorizable") {
- @Override
- public Authorizable perform() throws RepositoryException {
- Authorizable authorizable = userManagerDelegate.getAuthorizable(id);
- return UserUtil.castAuthorizable(AuthorizableDelegator.wrap(sessionDelegate, authorizable), authorizableClass);
+ return (T) sessionDelegate.performNullable(new UserManagerOperation<Authorizable>(sessionDelegate, "getAuthorizable") {
+ @Override
+ public Authorizable performNullable() throws RepositoryException {
+ Authorizable authorizable = userManagerDelegate.getAuthorizable(id);
+ return UserUtil.castAuthorizable(AuthorizableDelegator.wrap(sessionDelegate, authorizable), authorizableClass);
- }
- }
+ }
+ }
);
}
@Override
public Authorizable getAuthorizable(final Principal principal) throws RepositoryException {
- return sessionDelegate.perform(
- new UserManagerOperation<Authorizable>(sessionDelegate, "getAuthorizable") {
+ return sessionDelegate.performNullable(new UserManagerOperation<Authorizable>(sessionDelegate, "getAuthorizable") {
@Override
- public Authorizable perform() throws RepositoryException {
+ public Authorizable performNullable() throws RepositoryException {
Authorizable authorizable = userManagerDelegate.getAuthorizable(principal);
return AuthorizableDelegator.wrap(sessionDelegate, authorizable);
}
@@ -95,10 +93,9 @@ public class UserManagerDelegator implem
@Override
public Authorizable getAuthorizableByPath(final String path) throws RepositoryException {
- return sessionDelegate.perform(
- new UserManagerOperation<Authorizable>(sessionDelegate, "getAuthorizableByPath") {
+ return sessionDelegate.performNullable(new UserManagerOperation<Authorizable>(sessionDelegate, "getAuthorizableByPath") {
@Override
- public Authorizable perform() throws RepositoryException {
+ public Authorizable performNullable() throws RepositoryException {
Authorizable authorizable = userManagerDelegate.getAuthorizableByPath(path);
return AuthorizableDelegator.wrap(sessionDelegate, authorizable);
}
@@ -107,8 +104,8 @@ public class UserManagerDelegator implem
@Override
public Iterator<Authorizable> findAuthorizables(final String relPath, final String value) throws RepositoryException {
- return sessionDelegate.perform(
- new UserManagerOperation<Iterator<Authorizable>>(sessionDelegate, "findAuthorizables") {
+ return sessionDelegate.perform(new UserManagerOperation<Iterator<Authorizable>>(sessionDelegate, "findAuthorizables") {
+ @Nonnull
@Override
public Iterator<Authorizable> perform() throws RepositoryException {
Iterator<Authorizable> authorizables = userManagerDelegate.findAuthorizables(relPath, value);
@@ -125,8 +122,8 @@ public class UserManagerDelegator implem
@Override
public Iterator<Authorizable> findAuthorizables(final String relPath, final String value, final int searchType) throws RepositoryException {
- return sessionDelegate.perform(
- new UserManagerOperation<Iterator<Authorizable>>(sessionDelegate, "findAuthorizables") {
+ return sessionDelegate.perform(new UserManagerOperation<Iterator<Authorizable>>(sessionDelegate, "findAuthorizables") {
+ @Nonnull
@Override
public Iterator<Authorizable> perform() throws RepositoryException {
Iterator<Authorizable> authorizables = userManagerDelegate.findAuthorizables(relPath, value, searchType);
@@ -143,8 +140,8 @@ public class UserManagerDelegator implem
@Override
public Iterator<Authorizable> findAuthorizables(final Query query) throws RepositoryException {
- return sessionDelegate.perform(
- new UserManagerOperation<Iterator<Authorizable>>(sessionDelegate, "findAuthorizables") {
+ return sessionDelegate.perform(new UserManagerOperation<Iterator<Authorizable>>(sessionDelegate, "findAuthorizables") {
+ @Nonnull
@Override
public Iterator<Authorizable> perform() throws RepositoryException {
Iterator<Authorizable> authorizables = userManagerDelegate.findAuthorizables(query);
@@ -161,8 +158,8 @@ public class UserManagerDelegator implem
@Override
public User createUser(final String userID, final String password) throws AuthorizableExistsException, RepositoryException {
- return sessionDelegate.perform(
- new UserManagerOperation<User>(sessionDelegate, "createUser") {
+ return sessionDelegate.perform(new UserManagerOperation<User>(sessionDelegate, "createUser") {
+ @Nonnull
@Override
public User perform() throws RepositoryException {
User user = userManagerDelegate.createUser(userID, password);
@@ -173,8 +170,8 @@ public class UserManagerDelegator implem
@Override
public User createUser(final String userID, final String password, final Principal principal, final String intermediatePath) throws RepositoryException {
- return sessionDelegate.perform(
- new UserManagerOperation<User>(sessionDelegate, "createUser") {
+ return sessionDelegate.perform(new UserManagerOperation<User>(sessionDelegate, "createUser") {
+ @Nonnull
@Override
public User perform() throws RepositoryException {
User user = userManagerDelegate.createUser(userID, password, principal, intermediatePath);
@@ -185,20 +182,20 @@ public class UserManagerDelegator implem
@Override
public User createSystemUser(final String userID, final String intermediatePath) throws RepositoryException {
- return sessionDelegate.perform(
- new UserManagerOperation<User>(sessionDelegate, "createUser") {
- @Override
- public User perform() throws RepositoryException {
- User user = userManagerDelegate.createSystemUser(userID, intermediatePath);
- return UserDelegator.wrap(sessionDelegate, user);
- }
- });
+ return sessionDelegate.perform(new UserManagerOperation<User>(sessionDelegate, "createUser") {
+ @Nonnull
+ @Override
+ public User perform() throws RepositoryException {
+ User user = userManagerDelegate.createSystemUser(userID, intermediatePath);
+ return UserDelegator.wrap(sessionDelegate, user);
+ }
+ });
}
@Override
public Group createGroup(final String groupID) throws RepositoryException {
- return sessionDelegate.perform(
- new UserManagerOperation<Group>(sessionDelegate, "createGroup") {
+ return sessionDelegate.perform(new UserManagerOperation<Group>(sessionDelegate, "createGroup") {
+ @Nonnull
@Override
public Group perform() throws RepositoryException {
Group group = userManagerDelegate.createGroup(groupID);
@@ -209,8 +206,8 @@ public class UserManagerDelegator implem
@Override
public Group createGroup(final Principal principal) throws RepositoryException {
- return sessionDelegate.perform(
- new UserManagerOperation<Group>(sessionDelegate, "createGroup") {
+ return sessionDelegate.perform(new UserManagerOperation<Group>(sessionDelegate, "createGroup") {
+ @Nonnull
@Override
public Group perform() throws RepositoryException {
Group group = userManagerDelegate.createGroup(principal);
@@ -221,8 +218,8 @@ public class UserManagerDelegator implem
@Override
public Group createGroup(final Principal principal, final String intermediatePath) throws RepositoryException {
- return sessionDelegate.perform(
- new UserManagerOperation<Group>(sessionDelegate, "createGroup") {
+ return sessionDelegate.perform(new UserManagerOperation<Group>(sessionDelegate, "createGroup") {
+ @Nonnull
@Override
public Group perform() throws RepositoryException {
Group group = userManagerDelegate.createGroup(principal, intermediatePath);
@@ -233,8 +230,8 @@ public class UserManagerDelegator implem
@Override
public Group createGroup(final String groupID, final Principal principal, final String intermediatePath) throws RepositoryException {
- return sessionDelegate.perform(
- new UserManagerOperation<Group>(sessionDelegate, "createGroup") {
+ return sessionDelegate.perform(new UserManagerOperation<Group>(sessionDelegate, "createGroup") {
+ @Nonnull
@Override
public Group perform() throws RepositoryException {
Group group = userManagerDelegate.createGroup(groupID, principal, intermediatePath);
@@ -245,8 +242,8 @@ public class UserManagerDelegator implem
@Override
public boolean isAutoSave() {
- return sessionDelegate.safePerform(
- new UserManagerOperation<Boolean>(sessionDelegate, "isAutoSave") {
+ return sessionDelegate.safePerform(new UserManagerOperation<Boolean>(sessionDelegate, "isAutoSave") {
+ @Nonnull
@Override
public Boolean perform() {
return userManagerDelegate.isAutoSave();
@@ -256,12 +253,10 @@ public class UserManagerDelegator implem
@Override
public void autoSave(final boolean enable) throws RepositoryException {
- sessionDelegate.perform(
- new UserManagerOperation<Void>(sessionDelegate, "autoSave") {
+ sessionDelegate.performVoid(new UserManagerOperation(sessionDelegate, "autoSave") {
@Override
- public Void perform() throws RepositoryException {
+ public void performVoid() throws RepositoryException {
userManagerDelegate.autoSave(enable);
- return null;
}
});
}
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockImpl.java?rev=1673387&r1=1673386&r2=1673387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockImpl.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockImpl.java Tue Apr 14 08:35:12 2015
@@ -18,13 +18,14 @@ package org.apache.jackrabbit.oak.jcr.lo
import static com.google.common.base.Preconditions.checkNotNull;
-import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
import javax.jcr.Node;
import javax.jcr.RepositoryException;
import javax.jcr.lock.Lock;
import javax.jcr.lock.LockException;
+import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
import org.apache.jackrabbit.oak.jcr.session.NodeImpl;
import org.apache.jackrabbit.oak.jcr.session.SessionContext;
import org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate;
@@ -37,8 +38,7 @@ public final class LockImpl implements L
private final NodeDelegate delegate;
- public LockImpl(
- @Nonnull SessionContext context, @Nonnull NodeDelegate delegate) {
+ public LockImpl(@Nonnull SessionContext context, @Nonnull NodeDelegate delegate) {
this.context = checkNotNull(context);
this.delegate = checkNotNull(delegate);
}
@@ -54,9 +54,9 @@ public final class LockImpl implements L
@Override
public String getLockOwner() {
- return safePerform(new NodeOperation<String>(delegate, "getLockOwner") {
+ return savePerformNullable(new NodeOperation<String>(delegate, "getLockOwner") {
@Override
- public String perform() {
+ public String performNullable() {
return node.getLockOwner();
}
});
@@ -64,7 +64,8 @@ public final class LockImpl implements L
@Override
public boolean isDeep() {
- return safePerform(new NodeOperation<Boolean>(delegate, "isDeep") {
+ return getSessionDelegate().safePerform(new NodeOperation<Boolean>(delegate, "isDeep") {
+ @Nonnull
@Override
public Boolean perform() {
return node.holdsLock(true);
@@ -74,8 +75,9 @@ public final class LockImpl implements L
@Override
public boolean isLive() {
- return context.getSession().isLive() && safePerform(
+ return context.getSession().isLive() && getSessionDelegate().safePerform(
new NodeOperation<Boolean>(delegate, "isLive") {
+ @Nonnull
@Override
public Boolean perform() {
return node.holdsLock(false);
@@ -86,9 +88,9 @@ public final class LockImpl implements L
@Override
public String getLockToken() {
- return safePerform(new NodeOperation<String>(delegate, "getLockToken") {
+ return savePerformNullable(new NodeOperation<String>(delegate, "getLockToken") {
@Override
- public String perform() {
+ public String performNullable() {
String token = node.getPath();
if (context.getOpenScopedLocks().contains(token)) {
return token;
@@ -123,7 +125,8 @@ public final class LockImpl implements L
@Override
public boolean isSessionScoped() {
- return safePerform(new NodeOperation<Boolean>(delegate, "isSessionScoped") {
+ return getSessionDelegate().safePerform(new NodeOperation<Boolean>(delegate, "isSessionScoped") {
+ @Nonnull
@Override
public Boolean perform() {
String path = node.getPath();
@@ -134,7 +137,8 @@ public final class LockImpl implements L
@Override
public boolean isLockOwningSession() {
- return safePerform(new NodeOperation<Boolean>(delegate, "isLockOwningSessions") {
+ return getSessionDelegate().safePerform(new NodeOperation<Boolean>(delegate, "isLockOwningSessions") {
+ @Nonnull
@Override
public Boolean perform() {
String path = node.getPath();
@@ -153,18 +157,16 @@ public final class LockImpl implements L
//-----------------------------------------------------------< private >--
- /**
- * Perform the passed {@link SessionOperation} assuming it does not
- * throw a {@code RepositoryException}. If it does, wrap it into and
- * throw it as a {@code RuntimeException}.
- *
- * @param op operation to perform
- * @param <U> return type of the operation
- * @return the result of {@code op.perform()}
- */
- @CheckForNull
- private final <U> U safePerform(@Nonnull SessionOperation<U> op) {
- return context.getSessionDelegate().safePerform(op);
+ private SessionDelegate getSessionDelegate() {
+ return context.getSessionDelegate();
}
+ @Nullable
+ private <U> U savePerformNullable(@Nonnull SessionOperation<U> op) {
+ try {
+ return context.getSessionDelegate().performNullable(op);
+ } catch (RepositoryException e) {
+ throw new RuntimeException("Unexpected exception thrown by operation " + op, e);
+ }
+ }
}
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockManagerImpl.java?rev=1673387&r1=1673386&r2=1673387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockManagerImpl.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockManagerImpl.java Tue Apr 14 08:35:12 2015
@@ -54,10 +54,12 @@ public class LockManagerImpl implements
this.delegate = sessionContext.getSessionDelegate();
}
- @Override @Nonnull
+ @Nonnull
+ @Override
public String[] getLockTokens() throws RepositoryException {
- return perform(new SessionOperation<String[]>("getLockTokens") {
- @Override @Nonnull
+ return delegate.perform(new SessionOperation<String[]>("getLockTokens") {
+ @Nonnull
+ @Override
public String[] perform() {
Set<String> tokens = sessionContext.getOpenScopedLocks();
return tokens.toArray(new String[tokens.size()]);
@@ -69,17 +71,14 @@ public class LockManagerImpl implements
public void addLockToken(final String lockToken)
throws RepositoryException {
try {
- perform(new LockOperation<String>(sessionContext, lockToken, "addLockToken") {
+ delegate.performVoid(new LockOperation(sessionContext, lockToken, "addLockToken") {
@Override
- protected String perform(NodeDelegate node)
- throws LockException {
+ protected void performVoid(@Nonnull NodeDelegate node) throws LockException {
if (node.holdsLock(false)) { // TODO: check ownership?
String token = node.getPath();
sessionContext.getOpenScopedLocks().add(token);
- return null;
} else {
- throw new LockException(
- "Invalid lock token: " + lockToken);
+ throw new LockException("Invalid lock token: " + lockToken);
}
}
});
@@ -89,25 +88,25 @@ public class LockManagerImpl implements
}
@Override
- public void removeLockToken(final String lockToken)
- throws RepositoryException {
- if (!perform(new SessionOperation<Boolean>("removeLockToken") {
- @Override @Nonnull
+ public void removeLockToken(final String lockToken) throws RepositoryException {
+ if (!delegate.perform(new SessionOperation<Boolean>("removeLockToken") {
+ @Nonnull
+ @Override
public Boolean perform() {
// TODO: name mapping?
return sessionContext.getOpenScopedLocks().remove(lockToken);
}
})) {
- throw new LockException(
- "Lock token " + lockToken + " is not held by this session");
+ throw new LockException("Lock token " + lockToken + " is not held by this session");
}
}
@Override
public boolean isLocked(String absPath) throws RepositoryException {
- return perform(new LockOperation<Boolean>(sessionContext, absPath, "isLocked") {
+ return delegate.perform(new LockOperation<Boolean>(sessionContext, absPath, "isLocked") {
+ @Nonnull
@Override
- protected Boolean perform(NodeDelegate node) {
+ protected Boolean perform(@Nonnull NodeDelegate node) {
return node.isLocked();
}
});
@@ -115,61 +114,64 @@ public class LockManagerImpl implements
@Override
public boolean holdsLock(String absPath) throws RepositoryException {
- return perform(new LockOperation<Boolean>(sessionContext, absPath, "holdsLock") {
+ return delegate.perform(new LockOperation<Boolean>(sessionContext, absPath, "holdsLock") {
+ @Nonnull
@Override
- protected Boolean perform(NodeDelegate node) {
+ protected Boolean perform(@Nonnull NodeDelegate node) {
return node.holdsLock(false);
}
});
}
- @Override @Nonnull
- public Lock getLock(String absPath) throws RepositoryException {
- NodeDelegate lock = perform(
- new LockOperation<NodeDelegate>(sessionContext, absPath, "getLock") {
- @Override
- protected NodeDelegate perform(NodeDelegate node) {
- return node.getLock();
- }
- });
- if (lock != null) {
- return new LockImpl(sessionContext, lock);
- } else {
- throw new LockException("Node " + absPath + " is not locked");
- }
+ @Nonnull
+ @Override
+ public Lock getLock(final String absPath) throws RepositoryException {
+ NodeDelegate lock = delegate.perform(new LockOperation<NodeDelegate>(sessionContext, absPath, "getLock") {
+ @Nonnull
+ @Override
+ protected NodeDelegate perform(@Nonnull NodeDelegate node) throws LockException {
+ NodeDelegate lock = node.getLock();
+ if (lock == null) {
+ throw new LockException("Node " + absPath + " is not locked");
+ } else {
+ return lock;
+ }
+ }
+ });
+
+ return new LockImpl(sessionContext, lock);
}
- @Override @Nonnull
- public Lock lock(
- String absPath, final boolean isDeep, final boolean isSessionScoped,
- long timeoutHint, String ownerInfo) throws RepositoryException {
- return new LockImpl(sessionContext, perform(
- new LockOperation<NodeDelegate>(sessionContext, absPath, "lock") {
- @Override
- protected NodeDelegate perform(NodeDelegate node)
- throws RepositoryException {
- if (node.getStatus() != Status.UNCHANGED) {
- throw new InvalidItemStateException(
- "Unable to lock a node with pending changes");
- }
- node.lock(isDeep);
- String path = node.getPath();
- if (isSessionScoped) {
- sessionContext.getSessionScopedLocks().add(path);
- } else {
- sessionContext.getOpenScopedLocks().add(path);
- }
- session.refresh(true);
- return node;
- }
- }));
+ @Nonnull
+ @Override
+ public Lock lock(String absPath, final boolean isDeep, final boolean isSessionScoped,
+ long timeoutHint, String ownerInfo) throws RepositoryException {
+ return new LockImpl(sessionContext, delegate.perform(new LockOperation<NodeDelegate>(sessionContext, absPath, "lock") {
+ @Nonnull
+ @Override
+ protected NodeDelegate perform(@Nonnull NodeDelegate node) throws RepositoryException {
+ if (node.getStatus() != Status.UNCHANGED) {
+ throw new InvalidItemStateException(
+ "Unable to lock a node with pending changes");
+ }
+ node.lock(isDeep);
+ String path = node.getPath();
+ if (isSessionScoped) {
+ sessionContext.getSessionScopedLocks().add(path);
+ } else {
+ sessionContext.getOpenScopedLocks().add(path);
+ }
+ session.refresh(true);
+ return node;
+ }
+ }));
}
@Override
public void unlock(String absPath) throws RepositoryException {
- perform(new LockOperation<Void>(sessionContext, absPath, "unlock") {
+ delegate.performVoid(new LockOperation(sessionContext, absPath, "unlock") {
@Override
- protected Void perform(NodeDelegate node)
+ protected void performVoid(@Nonnull NodeDelegate node)
throws RepositoryException {
String path = node.getPath();
if (canUnlock(path, node)) {
@@ -177,11 +179,11 @@ public class LockManagerImpl implements
sessionContext.getSessionScopedLocks().remove(path);
sessionContext.getOpenScopedLocks().remove(path);
session.refresh(true);
- return null;
} else {
throw new LockException("Not an owner of the lock " + path);
}
}
+
private boolean canUnlock(String path, NodeDelegate node) {
if (sessionContext.getSessionScopedLocks().contains(path)
|| sessionContext.getOpenScopedLocks().contains(path)) {
@@ -208,10 +210,4 @@ public class LockManagerImpl implements
}
return false;
}
-
- private <T> T perform(SessionOperation<T> operation)
- throws RepositoryException {
- return delegate.perform(operation);
- }
-
}
\ No newline at end of file
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockOperation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockOperation.java?rev=1673387&r1=1673386&r2=1673387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockOperation.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/lock/LockOperation.java Tue Apr 14 08:35:12 2015
@@ -16,6 +16,7 @@
*/
package org.apache.jackrabbit.oak.jcr.lock;
+import javax.annotation.Nonnull;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
@@ -32,24 +33,13 @@ import org.apache.jackrabbit.oak.jcr.ses
public abstract class LockOperation<T> extends SessionOperation<T> {
protected final SessionDelegate session;
-
- private final NodeDelegate node;
-
private final String path;
- protected LockOperation(SessionDelegate session, NodeDelegate node, String name) {
- super(name);
- this.session = session;
- this.path = null;
- this.node = node;
- }
-
protected LockOperation(SessionContext context, String absPath, String name)
throws PathNotFoundException {
super(name);
this.session = context.getSessionDelegate();
this.path = context.getOakPathOrThrowNotFound(absPath);
- this.node = null;
}
@Override
@@ -57,23 +47,38 @@ public abstract class LockOperation<T> e
return true;
}
+ @Nonnull
@Override
public T perform() throws RepositoryException {
session.refresh(true);
+
+ NodeDelegate node = session.getNode(path);
if (node != null) {
return perform(node);
} else {
- NodeDelegate node = session.getNode(path);
- if (node != null) {
- return perform(node);
- } else {
- throw new PathNotFoundException(
- "Node " + path + " not found");
- }
+ throw new PathNotFoundException("Node " + path + " not found");
}
}
- protected abstract T perform(NodeDelegate node)
- throws RepositoryException;
+ @Override
+ public void performVoid() throws RepositoryException {
+ session.refresh(true);
+
+ NodeDelegate node = session.getNode(path);
+ if (node != null) {
+ performVoid(node);
+ } else {
+ throw new PathNotFoundException("Node " + path + " not found");
+ }
+ }
+
+ @Nonnull
+ protected T perform(@Nonnull NodeDelegate node) throws RepositoryException {
+ throw new UnsupportedOperationException();
+ }
+
+ protected void performVoid(@Nonnull NodeDelegate node) throws RepositoryException {
+ throw new UnsupportedOperationException();
+ }
}
\ No newline at end of file
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java?rev=1673387&r1=1673386&r2=1673387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/query/QueryImpl.java Tue Apr 14 08:35:12 2015
@@ -21,6 +21,7 @@ package org.apache.jackrabbit.oak.jcr.qu
import java.util.HashMap;
import java.util.List;
+import javax.annotation.Nonnull;
import javax.jcr.ItemNotFoundException;
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
@@ -80,6 +81,7 @@ public class QueryImpl implements Query
}
List<String> names = sessionContext.getSessionDelegate().perform(
new SessionOperation<List<String>>("parse") {
+ @Nonnull
@Override
public List<String> perform() throws RepositoryException {
return manager.parse(statement, language);
@@ -96,6 +98,7 @@ public class QueryImpl implements Query
public QueryResult execute() throws RepositoryException {
return sessionContext.getSessionDelegate().perform(
new SessionOperation<QueryResult>("execute") {
+ @Nonnull
@Override
public QueryResult perform() throws RepositoryException {
return manager.executeQuery(statement, language, limit,
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/AccessManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/AccessManager.java?rev=1673387&r1=1673386&r2=1673387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/AccessManager.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/security/AccessManager.java Tue Apr 14 08:35:12 2015
@@ -42,6 +42,7 @@ public class AccessManager {
public boolean hasPermissions(@Nonnull final String oakPath, @Nonnull final String actions) {
return delegate.safePerform(new SessionOperation<Boolean>("hasPermissions") {
+ @Nonnull
@Override
public Boolean perform() {
return permissionProvider.isGranted(oakPath, actions);
@@ -51,6 +52,7 @@ public class AccessManager {
public boolean hasPermissions(@Nonnull final Tree tree, @Nullable final PropertyState property, final long permissions) throws RepositoryException {
return delegate.safePerform(new SessionOperation<Boolean>("hasPermissions") {
+ @Nonnull
@Override
public Boolean perform() {
return permissionProvider.isGranted(tree, property, permissions);
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/ItemImpl.java?rev=1673387&r1=1673386&r2=1673387&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/ItemImpl.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/ItemImpl.java Tue Apr 14 08:35:12 2015
@@ -28,7 +28,6 @@ import static org.apache.jackrabbit.oak.
import java.util.List;
-import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.jcr.AccessDeniedException;
import javax.jcr.InvalidItemStateException;
@@ -108,24 +107,11 @@ abstract class ItemImpl<T extends ItemDe
* @return the result of {@code op.perform()}
* @throws RepositoryException as thrown by {@code op.perform()}.
*/
- @CheckForNull
+ @Nonnull
protected final <U> U perform(@Nonnull SessionOperation<U> op) throws RepositoryException {
return sessionDelegate.perform(op);
}
- /**
- * Perform the passed {@link SessionOperation} assuming it does not throw an
- * {@code RepositoryException}. If it does, wrap it into and throw it as a
- * {@code RuntimeException}.
- * @param op operation to perform
- * @param <U> return type of the operation
- * @return the result of {@code op.perform()}
- */
- @CheckForNull
- protected final <U> U safePerform(@Nonnull SessionOperation<U> op) {
- return sessionDelegate.safePerform(op);
- }
-
//---------------------------------------------------------------< Item >---
/**
@@ -135,6 +121,7 @@ abstract class ItemImpl<T extends ItemDe
@Nonnull
public String getName() throws RepositoryException {
String oakName = perform(new ItemOperation<String>(dlg, "getName") {
+ @Nonnull
@Override
public String perform() {
return item.getName();
@@ -151,6 +138,7 @@ abstract class ItemImpl<T extends ItemDe
@Nonnull
public String getPath() throws RepositoryException {
return toJcrPath(perform(new ItemOperation<String>(dlg, "getPath") {
+ @Nonnull
@Override
public String perform() {
return item.getPath();
@@ -173,6 +161,7 @@ abstract class ItemImpl<T extends ItemDe
}
ItemDelegate ancestor = perform(new ItemOperation<ItemDelegate>(dlg, "getAncestor") {
+ @Nonnull
@Override
public ItemDelegate perform() throws RepositoryException {
String path = item.getPath();
@@ -190,7 +179,12 @@ abstract class ItemImpl<T extends ItemDe
return item;
}
- return sessionDelegate.getNode(path.substring(0, slash));
+ NodeDelegate ndlg = sessionDelegate.getNode(path.substring(0, slash));
+ if (ndlg == null) {
+ throw new ItemNotFoundException(getPath() + "Invalid ancestor depth " + depth);
+ } else {
+ return ndlg;
+ }
}
});
@@ -256,11 +250,10 @@ abstract class ItemImpl<T extends ItemDe
@Override
public void save() throws RepositoryException {
try {
- perform(new ItemWriteOperation<Void>("save") {
+ sessionDelegate.performVoid(new ItemWriteOperation("save") {
@Override
- public Void perform() throws RepositoryException {
+ public void performVoid() throws RepositoryException {
dlg.save();
- return null;
}
@Override
@@ -292,20 +285,21 @@ abstract class ItemImpl<T extends ItemDe
if (!keepChanges) {
log.warn("Item#refresh invokes Session#refresh!");
}
- perform(new SessionOperation<Void>("refresh") {
+ sessionDelegate.performVoid(new SessionOperation("refresh") {
@Override
- public Void perform() throws InvalidItemStateException {
+ public void performVoid() throws InvalidItemStateException {
sessionDelegate.refresh(keepChanges);
if (!dlg.exists()) {
throw new InvalidItemStateException(
"This item no longer exists");
}
- return null;
}
+
@Override
public boolean isUpdate() {
return true;
}
+
@Override
public boolean isRefresh() {
return true;