jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1461088 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: ItemImpl.java SessionImpl.java delegate/SessionDelegate.java
Date Tue, 26 Mar 2013 12:36:56 GMT
Author: mduerig
Date: Tue Mar 26 12:36:56 2013
New Revision: 1461088

URL: http://svn.apache.org/r1461088
Log:
OAK-672: Avoid JCR APIs calling other JCR APIs
- consolidate pre condition checks
- avoid duplicate path resolution in move method
- remove unused members from SessionDelegate

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/SessionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.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=1461088&r1=1461087&r2=1461088&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
Tue Mar 26 12:36:56 2013
@@ -245,7 +245,7 @@ abstract class ItemImpl<T extends ItemDe
 
     protected abstract ItemDefinition getDefinition() throws RepositoryException;
 
-    public void checkProtected() throws RepositoryException {
+    void checkProtected() throws RepositoryException {
         ItemDefinition definition;
         try {
             definition = getDefinition();

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java?rev=1461088&r1=1461087&r2=1461088&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
Tue Mar 26 12:36:56 2013
@@ -105,10 +105,6 @@ public class SessionImpl implements Jack
         }
     }
 
-    public void checkProtectedNodes(String... absJcrPaths) throws RepositoryException {
-        checkProtectedNodes(this, absJcrPaths);
-    }
-
     //------------------------------------------------------------< Session >---
 
     @Override
@@ -141,7 +137,7 @@ public class SessionImpl implements Jack
     @Override
     @Nonnull
     public Session impersonate(Credentials credentials) throws RepositoryException {
-        ensureIsAlive();
+        dlg.checkAlive();
 
         ImpersonationCredentials impCreds = new ImpersonationCredentials(credentials, dlg.getAuthInfo());
         return getRepository().login(impCreds, dlg.getWorkspaceName());
@@ -150,7 +146,7 @@ public class SessionImpl implements Jack
     @Override
     @Nonnull
     public ValueFactory getValueFactory() throws RepositoryException {
-        ensureIsAlive();
+        dlg.checkAlive();
         return sessionContext.getValueFactory();
     }
 
@@ -160,7 +156,7 @@ public class SessionImpl implements Jack
         return dlg.perform(new SessionOperation<NodeImpl<?>>() {
             @Override
             protected void checkPreconditions() throws RepositoryException {
-                ensureIsAlive();
+                dlg.checkAlive();
             }
 
             @Override
@@ -187,7 +183,7 @@ public class SessionImpl implements Jack
         return dlg.perform(new SessionOperation<NodeImpl<?>>() {
             @Override
             protected void checkPreconditions() throws RepositoryException {
-                ensureIsAlive();
+                dlg.checkAlive();
             }
 
             @Override
@@ -224,7 +220,7 @@ public class SessionImpl implements Jack
         return dlg.perform(new SessionOperation<NodeImpl<?>>() {
             @Override
             protected void checkPreconditions() throws RepositoryException {
-                ensureIsAlive();
+                dlg.checkAlive();
             }
 
             @Override
@@ -244,7 +240,7 @@ public class SessionImpl implements Jack
         return dlg.perform(new SessionOperation<Boolean>() {
             @Override
             protected void checkPreconditions() throws RepositoryException {
-                ensureIsAlive();
+                dlg.checkAlive();
             }
 
             @Override
@@ -300,24 +296,20 @@ public class SessionImpl implements Jack
         dlg.perform(new SessionOperation<Void>() {
             @Override
             protected void checkPreconditions() throws RepositoryException {
-                ensureIsAlive();
-                checkProtectedNodes(Text.getRelativeParent(srcAbsPath, 1), Text.getRelativeParent(destAbsPath,
1));
+                dlg.checkAlive();
+                checkProtectedNodes(SessionImpl.this,
+                        Text.getRelativeParent(srcAbsPath, 1), Text.getRelativeParent(destAbsPath,
1));
             }
 
             @Override
             public Void perform() throws RepositoryException {
-                String oakPath = sessionContext.getOakPathKeepIndexOrThrowNotFound(destAbsPath);
-                String oakName = PathUtils.getName(oakPath);
+                String oakDestPath = sessionContext.getOakPathKeepIndexOrThrowNotFound(destAbsPath);
                 // handle index
-                if (oakName.contains("[")) {
+                if (PathUtils.getName(oakDestPath).contains("[")) {
                     throw new RepositoryException("Cannot create a new node using a name
including an index");
                 }
 
-                dlg.move(
-                        getOakPathOrThrowNotFound(srcAbsPath),
-                        getOakPathOrThrowNotFound(oakPath),
-                        true);
-
+                dlg.move(getOakPathOrThrowNotFound(srcAbsPath), oakDestPath, true);
                 return null;
             }
         });
@@ -330,21 +322,21 @@ public class SessionImpl implements Jack
 
     @Override
     public void save() throws RepositoryException {
-        ensureIsAlive();
+        dlg.checkAlive();
         dlg.save();
         sessionContext.refresh();
     }
 
     @Override
     public void refresh(boolean keepChanges) throws RepositoryException {
-        ensureIsAlive();
+        dlg.checkAlive();
         dlg.refresh(keepChanges);
         sessionContext.refresh();
     }
 
     @Override
     public boolean hasPendingChanges() throws RepositoryException {
-        ensureIsAlive();
+        dlg.checkAlive();
         return dlg.hasPendingChanges();
     }
 
@@ -504,7 +496,7 @@ public class SessionImpl implements Jack
 
     @Override
     public boolean hasPermission(String absPath, String actions) throws RepositoryException
{
-        ensureIsAlive();
+        dlg.checkAlive();
 
         String oakPath = sessionContext.getOakPathKeepIndex(absPath);
         if (oakPath == null) {
@@ -524,7 +516,7 @@ public class SessionImpl implements Jack
 
     @Override
     public boolean hasCapability(String methodName, Object target, Object[] arguments) throws
RepositoryException {
-        ensureIsAlive();
+        dlg.checkAlive();
 
         // TODO
         return TODO.unimplemented().returnValue(false);
@@ -665,18 +657,4 @@ public class SessionImpl implements Jack
         return sessionContext.getUserManager();
     }
 
-    //------------------------------------------------------------< private >---
-
-    /**
-     * Ensure that this session is alive and throw an exception otherwise.
-     *
-     * @throws RepositoryException if this session has been rendered invalid
-     *                             for some reason (e.g. if this session has been closed
explicitly by logout)
-     */
-    private void ensureIsAlive() throws RepositoryException {
-        // check session status
-        if (!dlg.isAlive()) {
-            throw new RepositoryException("This session has been closed.");
-        }
-    }
 }
\ No newline at end of file

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=1461088&r1=1461087&r2=1461088&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 Mar 26 12:36:56 2013
@@ -52,23 +52,6 @@ public class SessionDelegate {
     private int sessionOpCount;
     private int revision;
 
-    private abstract class SessionReadOperation<T> extends SessionOperation<T>
{
-        @Override
-        protected void checkPreconditions() throws RepositoryException {
-            checkAlive();
-        }
-    }
-
-    private abstract class SessionWriteOperation<T> extends SessionReadOperation<T>
{
-        @Override
-        protected void checkPreconditions() throws RepositoryException {
-            super.checkPreconditions();
-            if (isReadOnly()) {
-                throw new RepositoryException("This session is read only");
-            }
-        }
-    }
-
     public SessionDelegate(@Nonnull ContentSession contentSession) {
         this.contentSession = checkNotNull(contentSession);
         this.root = contentSession.getLatestRoot();
@@ -104,16 +87,6 @@ public class SessionDelegate {
         }
     }
 
-    public <T> T safePerform(SessionOperation<T> sessionOperation) {
-        try {
-            return perform(sessionOperation);
-        } catch (RepositoryException e) {
-            String msg = sessionOperation + "threw an unexpected exception";
-            log.error(msg, e);
-            throw new IllegalArgumentException(msg, e);
-        }
-    }
-
     @Nonnull  // FIXME this should be package private
     public Root getRoot() {
         return root;
@@ -124,20 +97,26 @@ public class SessionDelegate {
         return contentSession;
     }
 
+    /**
+     * Determine whether this session is alive and has not been logged
+     * out or become stale by other means.
+     * @return {@code true} if this session is alive, {@code false} otherwise.
+     */
     public boolean isAlive() {
         return isAlive;
     }
 
+    /**
+     * Check that this session is alive.
+     * @throws RepositoryException if this session is not alive
+     * @see #isAlive()
+     */
     public void checkAlive() throws RepositoryException {
         if (!isAlive()) {
             throw new RepositoryException("This session has been closed.");
         }
     }
 
-    public boolean isReadOnly() {
-        return false;
-    }
-
     @Nonnull
     public AuthInfo getAuthInfo() {
         return contentSession.getAuthInfo();



Mime
View raw message