Index: oak-core/src/main/java/org/apache/jackrabbit/oak/api/AuthInfo.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>MacRoman =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/api/AuthInfo.java (revision ) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/api/AuthInfo.java (revision ) @@ -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); + +} Index: oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>MacRoman =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java (revision 1306758) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/api/Connection.java (revision ) @@ -19,13 +19,35 @@ 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(); \ No newline at end of file Index: oak-core/src/main/java/org/apache/jackrabbit/oak/core/SessionInfoImpl.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/core/SessionInfoImpl.java (revision 1306758) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ConnectionImpl.java (revision ) @@ -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; } + public String getRevision() { + return revision; + } + @Override + public AuthInfo getAuthInfo() { + // todo implement getAuthInfo + return new AuthInfo() { + @Override - public String getUserID() { - return sc.getUserID(); - } + public String getUserID() { + return sc.getUserID(); + } - @Override - public String[] getAttributeNames() { - return sc.getAttributeNames(); - } + @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); + } + }; + } @Override - public String getRevision() { - return revision; + public NodeState getCurrentRoot() { + return null; // todo implement getCurrentRoot } @Override - public String getWorkspaceName() { - return workspaceName; + public NodeState commit(NodeState newRoot) throws CommitFailedException { + return null; // todo implement commit } @Override - public void dispose() { - // TODO + public NodeBuilder getNodeBuilder(NodeState state) { + return null; // todo implement getNodeBuilder + } + @Override + public void close() throws IOException { + // todo implement close } + + @Override + public String getWorkspaceName() { + return workspaceName; + } + } \ No newline at end of file Index: oak-core/src/main/java/org/apache/jackrabbit/oak/core/TmpRepositoryService.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>MacRoman =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/core/TmpRepositoryService.java (revision 1306758) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/core/TmpRepositoryService.java (revision ) @@ -19,7 +19,6 @@ 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; @@ -54,7 +53,7 @@ } @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,16 +71,10 @@ 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; } /** \ No newline at end of file Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>MacRoman =================================================================== --- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java (revision 1306758) +++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java (revision ) @@ -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 @@ 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()); } \ No newline at end of file Index: oak-core/src/main/java/org/apache/jackrabbit/oak/api/CommitFailedException.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>MacRoman =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/api/CommitFailedException.java (revision 1306758) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/api/CommitFailedException.java (revision ) @@ -16,6 +16,8 @@ */ package org.apache.jackrabbit.oak.api; +import javax.jcr.RepositoryException; + /** * Main exception thrown by methods defined on the {@code Connection} interface * indicating that committing a given set of changes failed. @@ -26,5 +28,14 @@ * - CommitFailedException extends from repository exception * - CommitFailedException transports status code that are then converted to jcr exceptions */ -public class CommitFailedException extends Exception { +public class CommitFailedException extends RuntimeException { + private final RepositoryException repositoryException; + + public CommitFailedException(RepositoryException repositoryException) { + this.repositoryException = repositoryException; + } + + public void throwRepositoryException() throws RepositoryException { + throw repositoryException; + } } Index: oak-core/src/main/java/org/apache/jackrabbit/oak/api/RepositoryService.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>MacRoman =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/api/RepositoryService.java (revision 1306758) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/api/RepositoryService.java (revision ) @@ -24,24 +24,13 @@ * 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 Index: oak-core/src/main/java/org/apache/jackrabbit/oak/api/SessionInfo.java =================================================================== --- oak-core/src/main/java/org/apache/jackrabbit/oak/api/SessionInfo.java (revision 1306758) +++ oak-core/src/main/java/org/apache/jackrabbit/oak/api/SessionInfo.java (revision 1306758) @@ -1,80 +0,0 @@ -/* - * 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 SessionInfo} TODO... describe how obtained, when disposed, used for communication with oak-api, identification, authorization.... - */ -public interface SessionInfo { - - /** - * 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); - - /** - * Returns the current revision the associated session is operating on. - * Unless otherwise specified the revision is set to the current head - * revision upon {@code SessionInfo} creation. Later on in the lifecycle - * of this {@code SessionInfo} the revision will be reset to match the - * latest state after successful commit of modifications or if the associated - * session is being refreshed. - * - * TODO: review. maybe this isn't needed any more in oak-jcr once we got rid of all mk-dependencies. - * - * @return the revision The current revision. - */ - String getRevision(); - - /** - * 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(); - - /** - * Dispose this instance of {@code SessionInfo} as the associated - * JCR Session instance was logged out. This method allows an implementation - * to free any resources that may possibly be associated with this instance. - */ - void dispose(); -} \ No newline at end of file Index: oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>MacRoman =================================================================== --- oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java (revision 1306758) +++ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java (revision ) @@ -18,7 +18,8 @@ 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.Workspace; import javax.jcr.retention.RetentionManager; import javax.jcr.security.AccessControlManager; +import java.io.IOException; import java.security.AccessControlException; /** @@ -56,7 +58,7 @@ 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 @@ private final SessionContext 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 @@ @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,8 +248,13 @@ isAlive = false; // TODO - sessionInfo.dispose(); + try { + connection.close(); - } + } + catch (IOException e) { + log.warn("Error while closing connection", e); + } + } //----------------------------------------------------< Import / Export >--- @@ -469,7 +476,7 @@ @Override public String getWorkspaceName() { - return sessionInfo.getWorkspaceName(); + return connection.getWorkspaceName(); } @Override \ No newline at end of file