jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1306779 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/
Date Thu, 29 Mar 2012 10:21:33 GMT
Author: mduerig
Date: Thu Mar 29 10:21:33 2012
New Revision: 1306779

URL: http://svn.apache.org/viewvc?rev=1306779&view=rev
Log:
OAK-18: Define Oak API
apply slightly modified version of OAK-18.patch which:
- Merges SessionInfo and Connection into Connection
- Provides access to AuthInfo from Connection

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/AuthInfo.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java
      - copied, changed from r1306758, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SessionInfoImpl.java
Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/SessionInfo.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SessionInfoImpl.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/RepositoryService.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TmpRepositoryService.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/AuthInfo.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/AuthInfo.java?rev=1306779&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/AuthInfo.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/AuthInfo.java
Thu Mar 29 10:21:33 2012
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.api;
+
+/**
+ * The {@code AuthInfo} TODO... used for identification, authorization....
+ */
+public interface AuthInfo {
+
+    /**
+     * Return the user ID to be exposed on the JCR Session object. It refers
+     * to the ID of the user associated with the Credentials passed to the
+     * repository login.
+     *
+     * @return the user ID such as exposed on the JCR Session object.
+     */
+    String getUserID();
+
+    /**
+     * Returns the attribute names associated with this instance.
+     *
+     * @return The attribute names with that instance or an empty array if
+     * no attributes are present.
+     */
+    String[] getAttributeNames();
+
+    /**
+     * Returns the attribute with the given name or {@code null} if no attribute
+     * with that {@code attributeName} exists.
+     *
+     * @param attributeName The attribute name.
+     * @return The attribute or {@code null}.
+     */
+    Object getAttribute(String attributeName);
+
+}

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java?rev=1306779&r1=1306778&r2=1306779&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java
Thu Mar 29 10:21:33 2012
@@ -19,13 +19,35 @@ package org.apache.jackrabbit.oak.api;
 import org.apache.jackrabbit.mk.model.NodeBuilder;
 import org.apache.jackrabbit.mk.model.NodeState;
 
+import java.io.Closeable;
+
 /**
  * The {@code Connection} interface ...
  *
+ * - retrieving information from persistent layer (MK) that are accessible to
+ *   a given session
+ *
+ * - validate information being written back to the persistent layer. this includes
+ *   permission evaluation, node type and name constraints etc.
+ *
+ * - update the revision ID a given session is operating on.
+ *
  * TODO: define whether this is a repository-level connection or just bound to a single workspace.
  * TODO: describe how this interface is intended to handle validation: nt, names, ac, constraints...
  */
-public interface Connection {
+public interface Connection extends Closeable {
+
+    AuthInfo getAuthInfo();
+
+    /**
+     * The immutable name of the workspace this {@code SessionInfo} instance has
+     * been created for. If no workspace name has been specified during
+     * repository login this method will return the name of the default
+     * workspace.
+     *
+     * @return name of the workspace this instance has been created for.
+     */
+    String getWorkspaceName();
 
     NodeState getCurrentRoot();
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/RepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/RepositoryService.java?rev=1306779&r1=1306778&r2=1306779&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/RepositoryService.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/RepositoryService.java
Thu Mar 29 10:21:33 2012
@@ -24,24 +24,13 @@ import javax.security.auth.login.LoginEx
  * The {@code RepositoryService} is the main access point of the oak-api. It
  * serves the following purposes:
  *
- * - validating a given login request and providing SessionInfo object
+ * - validating a given login request and providing a connection
  *   that is used for further communication with the persistent layer (MK).
  *
- * - retrieving information from persistent layer (MK) that are accessible to
- *   a given session
- *
- * - validate information being written back to the persistent layer. this includes
- *   permission evaluation, node type and name constraints etc.
- *
- * - update the revision ID a given session is operating on.
- *
  * The implementation of this and all related interfaces are intended to only
  * hold the state of the persistent layer at a given revision without any
  * session-related state modifications.
  */
 public interface RepositoryService {
-
-    SessionInfo login(Object credentials, String workspaceName) throws LoginException, NoSuchWorkspaceException;
-
-    Connection getConnection(SessionInfo sessionInfo);
+    Connection login(Object credentials, String workspaceName) throws LoginException, NoSuchWorkspaceException;
 }
\ No newline at end of file

Copied: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java
(from r1306758, jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SessionInfoImpl.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java?p2=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java&p1=jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SessionInfoImpl.java&r1=1306758&r2=1306779&rev=1306779&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SessionInfoImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java
Thu Mar 29 10:21:33 2012
@@ -16,61 +16,86 @@
  */
 package org.apache.jackrabbit.oak.core;
 
-import org.apache.jackrabbit.oak.api.SessionInfo;
+import org.apache.jackrabbit.mk.model.NodeBuilder;
+import org.apache.jackrabbit.mk.model.NodeState;
+import org.apache.jackrabbit.oak.api.AuthInfo;
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.Connection;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import javax.jcr.SimpleCredentials;
+import java.io.IOException;
 
 /**
- * SessionInfoImpl...
+ * ConnectionImpl...
  */
-public class SessionInfoImpl implements SessionInfo {
+public class ConnectionImpl implements Connection {
 
     /**
      * logger instance
      */
-    private static final Logger log = LoggerFactory.getLogger(SessionInfoImpl.class);
+    private static final Logger log = LoggerFactory.getLogger(ConnectionImpl.class);
 
     private final SimpleCredentials sc;
     private final String workspaceName;
 
     private String revision;
 
-    SessionInfoImpl(SimpleCredentials sc, String workspaceName, String revision) {
+    ConnectionImpl(SimpleCredentials sc, String workspaceName, String revision) {
         this.sc = sc;
         this.workspaceName = workspaceName;
         this.revision = revision;
     }
 
-    @Override
-    public String getUserID() {
-        return sc.getUserID();
+    public String getRevision() {
+        return revision;
     }
 
     @Override
-    public String[] getAttributeNames() {
-        return sc.getAttributeNames();
+    public AuthInfo getAuthInfo() {
+        // todo implement getAuthInfo
+        return new AuthInfo() {
+            @Override
+            public String getUserID() {
+                return sc.getUserID();
+            }
+
+            @Override
+            public String[] getAttributeNames() {
+                return sc.getAttributeNames();
+            }
+
+            @Override
+            public Object getAttribute(String attributeName) {
+                return sc.getAttribute(attributeName);
+            }
+        };
     }
 
     @Override
-    public Object getAttribute(String attributeName) {
-        return sc.getAttribute(attributeName);
+    public NodeState getCurrentRoot() {
+        return null; // todo implement getCurrentRoot
     }
 
     @Override
-    public String getRevision() {
-        return revision;
+    public NodeState commit(NodeState newRoot) throws CommitFailedException {
+        return null; // todo implement commit
     }
 
     @Override
-    public String getWorkspaceName() {
-        return workspaceName;
+    public NodeBuilder getNodeBuilder(NodeState state) {
+        return null; // todo implement getNodeBuilder
     }
 
     @Override
-    public void dispose() {
-        // TODO
+    public void close() throws IOException {
+        // todo implement close
+    }
 
+    @Override
+    public String getWorkspaceName() {
+        return workspaceName;
     }
+
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TmpRepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TmpRepositoryService.java?rev=1306779&r1=1306778&r2=1306779&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TmpRepositoryService.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TmpRepositoryService.java
Thu Mar 29 10:21:33 2012
@@ -19,7 +19,6 @@ package org.apache.jackrabbit.oak.core;
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.oak.api.Connection;
 import org.apache.jackrabbit.oak.api.RepositoryService;
-import org.apache.jackrabbit.oak.api.SessionInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -48,13 +47,13 @@ public class TmpRepositoryService implem
 
         // FIXME: default mk-setup must be done elsewhere...
         String headRev = mk.getHeadRevision();
-        if (!mk.nodeExists("/" + DEFAULT_WORKSPACE_NAME, headRev)) {
+        if (!mk.nodeExists('/' + DEFAULT_WORKSPACE_NAME, headRev)) {
             mk.commit("/", "+ \"" + DEFAULT_WORKSPACE_NAME + "\" : {}", headRev, null);
         }
     }
 
     @Override
-    public SessionInfo login(Object credentials, String workspaceName) throws LoginException,
NoSuchWorkspaceException {
+    public Connection login(Object credentials, String workspaceName) throws LoginException,
NoSuchWorkspaceException {
         // TODO: add proper implementation
         // TODO  - authentication against configurable spi-authentication
         // TODO  - validation of workspace name (including access rights for the given 'user')
@@ -72,18 +71,12 @@ public class TmpRepositoryService implem
         final String revision = getRevision(credentials);
 
         if (sc != null) {
-            return new SessionInfoImpl(sc, wspName, revision);
+            return new ConnectionImpl(sc, wspName, revision);
         } else {
             throw new LoginException("login failed...");
         }
     }
 
-    @Override
-    public Connection getConnection(SessionInfo sessionInfo) {
-        // TODO
-        return null;
-    }
-
     /**
      * @param credentials The credentials object used for authentication.
      * @return The microkernal revision. If the give credentials don't specify

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java?rev=1306779&r1=1306778&r2=1306779&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
Thu Mar 29 10:21:33 2012
@@ -16,8 +16,8 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
+import org.apache.jackrabbit.oak.api.Connection;
 import org.apache.jackrabbit.oak.api.RepositoryService;
-import org.apache.jackrabbit.oak.api.SessionInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -90,8 +90,8 @@ public class RepositoryImpl implements R
 
         RepositoryService service = context.getInstance(RepositoryService.class);
         try {
-            SessionInfo sessionInfo = service.login(credentials, workspaceName);
-            return new SessionImpl(context, sessionInfo);
+            Connection connection = service.login(credentials, workspaceName);
+            return new SessionImpl(context, connection);
         } catch (LoginException e) {
             throw new javax.jcr.LoginException(e.getMessage());
         }

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=1306779&r1=1306778&r2=1306779&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 Mar 29 10:21:33 2012
@@ -18,7 +18,8 @@ package org.apache.jackrabbit.oak.jcr;
 
 import org.apache.jackrabbit.commons.AbstractSession;
 import org.apache.jackrabbit.mk.api.MicroKernel;
-import org.apache.jackrabbit.oak.api.SessionInfo;
+import org.apache.jackrabbit.oak.api.Connection;
+import org.apache.jackrabbit.oak.core.ConnectionImpl;
 import org.apache.jackrabbit.oak.jcr.state.NodeStateProvider;
 import org.apache.jackrabbit.oak.jcr.state.TransientNodeState;
 import org.apache.jackrabbit.oak.jcr.state.TransientSpace;
@@ -42,6 +43,7 @@ import javax.jcr.ValueFactory;
 import javax.jcr.Workspace;
 import javax.jcr.retention.RetentionManager;
 import javax.jcr.security.AccessControlManager;
+import java.io.IOException;
 import java.security.AccessControlException;
 
 /**
@@ -56,7 +58,7 @@ public class SessionImpl extends Abstrac
 
     private final Repository repository;
     private final Workspace workspace;
-    private final SessionInfo sessionInfo;
+    private final Connection connection;
     private final ValueFactory valueFactory;
 
     private final GlobalContext globalContext;
@@ -68,11 +70,11 @@ public class SessionImpl extends Abstrac
 
     private final SessionContext<SessionImpl> sessionContext = new Context();
 
-    SessionImpl(GlobalContext globalContext, SessionInfo sessionInfo) {
+    SessionImpl(GlobalContext globalContext, Connection connection) {
 
         this.globalContext = globalContext;
-        this.sessionInfo = sessionInfo;
-        this.revision = sessionInfo.getRevision();
+        this.connection = connection;
+        this.revision = ((ConnectionImpl) connection).getRevision();
 
         valueFactory = new ValueFactoryImpl();
         repository = new RepositoryAdaptor(globalContext.getInstance(Repository.class), valueFactory);
@@ -92,17 +94,17 @@ public class SessionImpl extends Abstrac
 
     @Override
     public String getUserID() {
-        return sessionInfo.getUserID();
+        return connection.getAuthInfo().getUserID();
     }
 
     @Override
     public String[] getAttributeNames() {
-        return sessionInfo.getAttributeNames();
+        return connection.getAuthInfo().getAttributeNames();
     }
 
     @Override
     public Object getAttribute(String name) {
-        return sessionInfo.getAttribute(name);
+        return connection.getAuthInfo().getAttribute(name);
     }
 
     @Override
@@ -246,7 +248,12 @@ public class SessionImpl extends Abstrac
         isAlive = false;
         // TODO
 
-        sessionInfo.dispose();
+        try {
+            connection.close();
+        }
+        catch (IOException e) {
+            log.warn("Error while closing connection", e);
+        }
     }
 
     //----------------------------------------------------< Import / Export >---
@@ -469,7 +476,7 @@ public class SessionImpl extends Abstrac
 
         @Override
         public String getWorkspaceName() {
-            return sessionInfo.getWorkspaceName();
+            return connection.getWorkspaceName();
         }
 
         @Override



Mime
View raw message