jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1333615 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: SessionDelegate.java SessionImpl.java
Date Thu, 03 May 2012 20:47:44 GMT
Author: mduerig
Date: Thu May  3 20:47:43 2012
New Revision: 1333615

URL: http://svn.apache.org/viewvc?rev=1333615&view=rev
Log:
OAK-84: Delegates for Session, Node, Property and Item
- clean up SessionImpl and SessionDelegate 

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java?rev=1333615&r1=1333614&r2=1333615&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
Thu May  3 20:47:43 2012
@@ -73,28 +73,75 @@ public class SessionDelegate {
         return context.getInstance(Repository.class);
     }
 
+    public Session getSession() {
+        return session;
+    }
+
+    public Workspace getWorkspace() {
+        return workspace;
+    }
+
+    public String getWorkspaceName() {
+        return contentSession.getWorkspaceName();
+    }
+
+    public boolean isAlive() {
+        return isAlive;
+    }
+
     public AuthInfo getAuthInfo() {
         return contentSession.getAuthInfo();
     }
 
-    public ValueFactoryImpl getValueFactory() {
-        return valueFactory;
+    public void logout() {
+        if (!isAlive) {
+            // ignore
+            return;
+        }
+
+        isAlive = false;
+        // TODO
+
+        try {
+            contentSession.close();
+        } catch (IOException e) {
+            log.warn("Error while closing connection", e);
+        }
     }
 
-    public Tree getTree(String path) {
-        return root.getTree(path);
+    public ValueFactoryImpl getValueFactory() {
+        return valueFactory;
     }
 
     public NamePathMapper getNamePathMapper() {
         return namePathMapper;
     }
 
+    public NodeTypeManager getNodeTypeManager() throws RepositoryException {
+        return workspace.getNodeTypeManager();
+    }
+
+    public VersionManager getVersionManager() throws RepositoryException {
+        return workspace.getVersionManager();
+    }
+
+    public LockManager getLockManager() throws RepositoryException {
+        return workspace.getLockManager();
+    }
+
+    public QueryEngine getQueryEngine() {
+        return contentSession.getQueryEngine();
+    }
+
+    public Tree getTree(String path) {
+        return root.getTree(path);
+    }
+
     public void move(String srcAbsPath, String destAbsPath, boolean transientOp)
             throws RepositoryException {
 
         String srcPath = PathUtils.relativize("/", srcAbsPath);  // TODO: is this needed?
         String destPath = PathUtils.relativize("/", destAbsPath);
-
         try {
             if (transientOp) {
                 root.move(srcPath, destPath);
@@ -111,10 +158,10 @@ public class SessionDelegate {
     }
 
     public void copy(String srcAbsPath, String destAbsPath) throws RepositoryException {
+        String srcPath = PathUtils.relativize("/", srcAbsPath);
+        String destPath = PathUtils.relativize("/", destAbsPath);
         try {
             Root currentRoot = contentSession.getCurrentRoot();
-            String srcPath = PathUtils.relativize("/", srcAbsPath);
-            String destPath = PathUtils.relativize("/", destAbsPath);
             currentRoot.copy(srcPath, destPath);
             currentRoot.commit();
         }
@@ -123,6 +170,10 @@ public class SessionDelegate {
         }
     }
 
+    public boolean hasPendingChanges() {
+        return root.hasPendingChanges();
+    }
+
     public void save() throws RepositoryException {
         try {
             root.commit();
@@ -141,58 +192,6 @@ public class SessionDelegate {
         }
     }
 
-    public boolean hasPendingChanges() {
-        return root.hasPendingChanges();
-    }
-
-    public boolean isAlive() {
-        return isAlive;
-    }
-
-    public void logout() {
-        if (!isAlive) {
-            // ignore
-            return;
-        }
-
-        isAlive = false;
-        // TODO
-
-        try {
-            contentSession.close();
-        } catch (IOException e) {
-            log.warn("Error while closing connection", e);
-        }
-    }
-
-    public Workspace getWorkspace() {
-        return workspace;
-    }
-
-    public Session getSession() {
-        return session;
-    }
-
-    public String getWorkspaceName() {
-        return contentSession.getWorkspaceName();
-    }
-
-    public QueryEngine getQueryEngine() {
-        return contentSession.getQueryEngine();
-    }
-
-    public NodeTypeManager getNodeTypeManager() throws RepositoryException {
-        return workspace.getNodeTypeManager();
-    }
-
-    public VersionManager getVersionManager() throws RepositoryException {
-        return workspace.getVersionManager();
-    }
-
-    public LockManager getLockManager() throws RepositoryException {
-        return workspace.getLockManager();
-    }
-
     //-------------------------------------------< SessionNamespaceResolver >---
 
     private class SessionNameMapper extends AbstractNameMapper {
@@ -201,7 +200,7 @@ public class SessionDelegate {
         protected String getJcrPrefix(String oakPrefix) {
             try {
                 String ns = nsRegistry.getURI(oakPrefix);
-                return getSession().getNamespacePrefix(ns);
+                return session.getNamespacePrefix(ns);
             } catch (RepositoryException e) {
                 // TODO
                 return null;

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=1333615&r1=1333614&r2=1333615&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
Thu May  3 20:47:43 2012
@@ -25,7 +25,6 @@ import org.slf4j.LoggerFactory;
 import org.xml.sax.ContentHandler;
 
 import javax.jcr.Credentials;
-import javax.jcr.InvalidItemStateException;
 import javax.jcr.Node;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
@@ -182,7 +181,7 @@ public class SessionImpl extends Abstrac
     @Override
     public void addLockToken(String lt) {
         try {
-            getWorkspace().getLockManager().addLockToken(lt);
+            dlg.getLockManager().addLockToken(lt);
         } catch (RepositoryException e) {
             log.warn("Unable to add lock token '{}' to this session: {}", lt, e.getMessage());
         }
@@ -194,7 +193,7 @@ public class SessionImpl extends Abstrac
     @Override
     public String[] getLockTokens() {
         try {
-            return getWorkspace().getLockManager().getLockTokens();
+            return dlg.getLockManager().getLockTokens();
         } catch (RepositoryException e) {
             log.warn("Unable to retrieve lock tokens for this session: {}", e.getMessage());
             return new String[0];        }
@@ -206,7 +205,7 @@ public class SessionImpl extends Abstrac
     @Override
     public void removeLockToken(String lt) {
         try {
-            getWorkspace().getLockManager().addLockToken(lt);
+            dlg.getLockManager().addLockToken(lt);
         } catch (RepositoryException e) {
             log.warn("Unable to add lock token '{}' to this session: {}", lt, e.getMessage());
         }
@@ -271,119 +270,19 @@ public class SessionImpl extends Abstrac
         throw new UnsupportedOperationException("Implementation missing");
     }
 
-    //--------------------------------------------------------------------------
-
+    //------------------------------------------------------------< 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)
      */
-    void ensureIsAlive() throws RepositoryException {
+    private void ensureIsAlive() throws RepositoryException {
         // check session status
         if (!dlg.isAlive()) {
             throw new RepositoryException("This session has been closed.");
         }
     }
 
-    /**
-     * Returns true if the repository supports the given option. False otherwise.
-     *
-     * @param option Any of the option constants defined by {@link Repository}
-     * that either returns 'true' or 'false'. I.e.
-     * <ul>
-     * <li>{@link Repository#LEVEL_1_SUPPORTED}</li>
-     * <li>{@link Repository#LEVEL_2_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_ACCESS_CONTROL_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_ACTIVITIES_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_BASELINES_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_JOURNALED_OBSERVATION_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_LIFECYCLE_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_LOCKING_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_NODE_AND_PROPERTY_WITH_SAME_NAME_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_NODE_TYPE_MANAGEMENT_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_OBSERVATION_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_QUERY_SQL_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_RETENTION_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_SHAREABLE_NODES_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_SIMPLE_VERSIONING_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_TRANSACTIONS_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_UNFILED_CONTENT_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_UPDATE_MIXIN_NODE_TYPES_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_UPDATE_PRIMARY_NODE_TYPE_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_VERSIONING_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_WORKSPACE_MANAGEMENT_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_XML_EXPORT_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_XML_IMPORT_SUPPORTED}</li>
-     * <li>{@link Repository#WRITE_SUPPORTED}</li>
-     * </ul>
-     * @return true if the repository supports the given option. False otherwise.
-     */
-    boolean isSupportedOption(String option) {
-        String desc = getRepository().getDescriptor(option);
-        // if the descriptors are not available return true. the missing
-        // functionality of the given SPI impl will in this case be detected
-        // upon the corresponding SPI call (see JCR-3143).
-        return (desc == null) ? true : Boolean.valueOf(desc);
-    }
-
-    /**
-     * Make sure the repository supports the option indicated by the given string
-     * and throw an exception otherwise.
-     *
-     * @param option Any of the option constants defined by {@link Repository}
-     * that either returns 'true' or 'false'. I.e.
-     * <ul>
-     * <li>{@link Repository#LEVEL_1_SUPPORTED}</li>
-     * <li>{@link Repository#LEVEL_2_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_ACCESS_CONTROL_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_ACTIVITIES_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_BASELINES_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_JOURNALED_OBSERVATION_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_LIFECYCLE_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_LOCKING_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_NODE_AND_PROPERTY_WITH_SAME_NAME_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_NODE_TYPE_MANAGEMENT_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_OBSERVATION_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_QUERY_SQL_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_RETENTION_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_SHAREABLE_NODES_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_SIMPLE_VERSIONING_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_TRANSACTIONS_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_UNFILED_CONTENT_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_UPDATE_MIXIN_NODE_TYPES_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_UPDATE_PRIMARY_NODE_TYPE_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_VERSIONING_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_WORKSPACE_MANAGEMENT_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_XML_EXPORT_SUPPORTED}</li>
-     * <li>{@link Repository#OPTION_XML_IMPORT_SUPPORTED}</li>
-     * <li>{@link Repository#WRITE_SUPPORTED}</li>
-     * </ul>
-     * @throws UnsupportedRepositoryOperationException If the given option is
-     * not supported.
-     * @throws RepositoryException If another error occurs.
-     * @see javax.jcr.Repository#getDescriptorKeys()
-     */
-    void ensureSupportsOption(String option) throws RepositoryException {
-        if (!isSupportedOption(option)) {
-            throw new UnsupportedRepositoryOperationException(option + " is not supported
by this repository.");
-        }
-    }
-
-    /**
-     * Ensure that this session has no pending changes and throw an exception
-     * otherwise.
-     *
-     * @throws InvalidItemStateException if this nodes session has pending changes
-     * @throws RepositoryException
-     */
-    void ensureNoPendingChanges() throws RepositoryException {
-        // check for pending changes
-        if (hasPendingChanges()) {
-            String msg = "Unable to perform operation. Session has pending changes.";
-            log.debug(msg);
-            throw new InvalidItemStateException(msg);
-        }
-    }
-
 }
\ No newline at end of file



Mime
View raw message