You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-dev@jackrabbit.apache.org by ju...@apache.org on 2012/03/14 12:14:51 UTC

svn commit: r1300502 - in /jackrabbit/oak/trunk: ./ oak-jcr/ oak-jcr/src/ oak-jcr/src/main/ oak-jcr/src/main/java/ oak-jcr/src/main/java/org/ oak-jcr/src/main/java/org/apache/ oak-jcr/src/main/java/org/apache/jackrabbit/ oak-jcr/src/main/java/org/apach...

Author: jukka
Date: Wed Mar 14 11:14:50 2012
New Revision: 1300502

URL: http://svn.apache.org/viewvc?rev=1300502&view=rev
Log:
JCR-5: JCR bindings for Oak

Added a dummy OakRepositoryFactory class and a basic CRUD test case.

Include oak-jcr in the main Oak build.

Added:
    jackrabbit/oak/trunk/oak-jcr/src/
    jackrabbit/oak/trunk/oak-jcr/src/main/
    jackrabbit/oak/trunk/oak-jcr/src/main/java/
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/OakRepositoryFactory.java   (with props)
    jackrabbit/oak/trunk/oak-jcr/src/main/resources/
    jackrabbit/oak/trunk/oak-jcr/src/main/resources/META-INF/
    jackrabbit/oak/trunk/oak-jcr/src/main/resources/META-INF/services/
    jackrabbit/oak/trunk/oak-jcr/src/main/resources/META-INF/services/javax.jcr.RepositoryFactory
    jackrabbit/oak/trunk/oak-jcr/src/test/
    jackrabbit/oak/trunk/oak-jcr/src/test/java/
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java   (with props)
Modified:
    jackrabbit/oak/trunk/oak-jcr/pom.xml
    jackrabbit/oak/trunk/pom.xml

Modified: jackrabbit/oak/trunk/oak-jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/pom.xml?rev=1300502&r1=1300501&r2=1300502&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-jcr/pom.xml Wed Mar 14 11:14:50 2012
@@ -33,4 +33,25 @@
   <artifactId>oak-jcr</artifactId>
   <name>Oak JCR Binding</name>
 
+  <dependencies>
+    <dependency>
+      <groupId>javax.jcr</groupId>
+      <artifactId>jcr</artifactId>
+      <version>2.0</version>
+    </dependency>
+
+    <!-- Test dependencies -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.jackrabbit</groupId>
+      <artifactId>jackrabbit-jcr-commons</artifactId>
+      <version>2.4.0</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+
 </project>

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/OakRepositoryFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/OakRepositoryFactory.java?rev=1300502&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/OakRepositoryFactory.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/OakRepositoryFactory.java Wed Mar 14 11:14:50 2012
@@ -0,0 +1,56 @@
+/*
+ * 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.jcr;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Map;
+
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.RepositoryFactory;
+import javax.jcr.UnsupportedRepositoryOperationException;
+
+@SuppressWarnings("rawtypes")
+public class OakRepositoryFactory implements RepositoryFactory {
+
+    private static final String REPOSITORY_URI =
+            "org.apache.jackrabbit.repository.uri";
+
+    @Override
+    public Repository getRepository(Map parameters)
+            throws RepositoryException {
+        Object value = parameters.get(REPOSITORY_URI);
+        if (value != null) {
+            try {
+                URI uri = new URI(value.toString());
+                if (uri.getScheme().equalsIgnoreCase("jcr-oak")) {
+                    return getRepository(uri, parameters);
+                }
+            } catch (URISyntaxException ignore) {
+            }
+        }
+        return null;
+    }
+
+    private Repository getRepository(URI uri, Map parameters)
+            throws RepositoryException {
+        throw new UnsupportedRepositoryOperationException(
+                "jcr-oak repository URIs are not yet supported: " + uri);
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/OakRepositoryFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/oak/trunk/oak-jcr/src/main/resources/META-INF/services/javax.jcr.RepositoryFactory
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/resources/META-INF/services/javax.jcr.RepositoryFactory?rev=1300502&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/resources/META-INF/services/javax.jcr.RepositoryFactory (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/resources/META-INF/services/javax.jcr.RepositoryFactory Wed Mar 14 11:14:50 2012
@@ -0,0 +1,16 @@
+#  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.
+
+org.apache.jackrabbit.oak.jcr.OakRepositoryFactory

Added: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java?rev=1300502&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java Wed Mar 14 11:14:50 2012
@@ -0,0 +1,67 @@
+/*
+ * 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.jcr;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertTrue;
+
+import javax.jcr.Node;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.commons.JcrUtils;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class CRUDTest {
+
+    @Ignore
+    @Test
+    public void testCRUD() throws RepositoryException {
+        Repository repository =
+                JcrUtils.getRepository("jcr-oak://inmemory/CRUDTest");
+
+        Session session = repository.login();
+        try {
+            // Create
+            Node hello = session.getRootNode().addNode("hello");
+            hello.setProperty("world",  "hello world");
+            session.save();
+
+            // Read
+            assertEquals(
+                    "hello world",
+                    session.getProperty("/hello/world").getString());
+
+            // Update
+            session.getNode("/hello").setProperty("world", "Hello, World!");
+            session.save();
+            assertEquals(
+                    "Hello, World!",
+                    session.getProperty("/hello/world").getString());
+
+            // Delete
+            session.getNode("/hello").remove();
+            session.save();
+            assertTrue(!session.propertyExists("/hello/world"));
+        } finally {
+            session.logout();
+        }
+    }
+
+}

Propchange: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/CRUDTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/oak/trunk/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/pom.xml?rev=1300502&r1=1300501&r2=1300502&view=diff
==============================================================================
--- jackrabbit/oak/trunk/pom.xml (original)
+++ jackrabbit/oak/trunk/pom.xml Wed Mar 14 11:14:50 2012
@@ -41,6 +41,7 @@
   <modules>
     <module>oak-parent</module>
     <module>oak-core</module>
+    <module>oak-jcr</module>
     <module>oak-run</module>
     <module>oak-it</module>
     <module>oak-bench</module>