jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1400140 - in /jackrabbit/oak/trunk/oak-jcr/src: main/java/org/apache/jackrabbit/oak/jcr/ test/java/org/apache/jackrabbit/oak/jcr/ test/java/org/apache/jackrabbit/oak/jcr/security/privilege/
Date Fri, 19 Oct 2012 15:56:35 GMT
Author: jukka
Date: Fri Oct 19 15:56:34 2012
New Revision: 1400140

URL: http://svn.apache.org/viewvc?rev=1400140&view=rev
Log:
OAK-352: Oak builder for simplified repository construction

Add a Jcr class for constructing RepositoryImpl instances with all the relevant components
included

Added:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java   (with
props)
Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/OakRepositoryFactory.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/RepositoryImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OakRepositoryStub.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/privilege/PrivilegeRegistrationTest.java

Added: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java?rev=1400140&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java (added)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/Jcr.java Fri
Oct 19 15:56:34 2012
@@ -0,0 +1,142 @@
+/*
+ * 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 com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.plugins.index.IndexConstants.DEFAULT_INDEX_HOME;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+import javax.annotation.Nonnull;
+import javax.jcr.Repository;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.oak.Oak;
+import org.apache.jackrabbit.oak.core.OrderedChildrenEditor;
+import org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler;
+import org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider;
+import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneHook;
+import org.apache.jackrabbit.oak.plugins.index.lucene.LuceneReindexHook;
+import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexHook;
+import org.apache.jackrabbit.oak.plugins.name.NameValidatorProvider;
+import org.apache.jackrabbit.oak.plugins.name.NamespaceValidatorProvider;
+import org.apache.jackrabbit.oak.plugins.nodetype.DefaultTypeEditor;
+import org.apache.jackrabbit.oak.plugins.nodetype.InitialContent;
+import org.apache.jackrabbit.oak.plugins.nodetype.TypeValidatorProvider;
+import org.apache.jackrabbit.oak.security.SecurityProviderImpl;
+import org.apache.jackrabbit.oak.spi.commit.CommitHook;
+import org.apache.jackrabbit.oak.spi.commit.ConflictHandler;
+import org.apache.jackrabbit.oak.spi.commit.Validator;
+import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
+import org.apache.jackrabbit.oak.spi.lifecycle.MicroKernelTracker;
+import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
+import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
+
+public class Jcr {
+
+    private final Oak oak;
+
+    private ScheduledExecutorService executor =
+            Executors.newScheduledThreadPool(0);
+
+    private SecurityProvider securityProvider;
+
+    private Jcr(Oak oak) {
+        this.oak = oak;
+
+        with(new InitialContent());
+
+        with(new DefaultTypeEditor());
+
+        with(new SecurityProviderImpl());
+
+        with(new NameValidatorProvider());
+        with(new NamespaceValidatorProvider());
+        with(new TypeValidatorProvider());
+        with(new ConflictValidatorProvider());
+
+        with(new PropertyIndexHook());
+        with(new LuceneReindexHook(DEFAULT_INDEX_HOME));
+        with(new LuceneHook(DEFAULT_INDEX_HOME));
+        with(new OrderedChildrenEditor());
+        with(new AnnotatingConflictHandler());
+    }
+
+    public Jcr() {
+        this(new Oak());
+    }
+
+    public Jcr(MicroKernel kernel) {
+        this(new Oak(kernel));
+    }
+
+    @Nonnull
+    public Jcr with(@Nonnull MicroKernelTracker initializer) {
+       oak.with(checkNotNull(initializer));
+       return this;
+    }
+
+    @Nonnull
+    public Jcr with(@Nonnull QueryIndexProvider provider) {
+        oak.with(checkNotNull(provider));
+        return this;
+    }
+
+    @Nonnull
+    public Jcr with(@Nonnull CommitHook hook) {
+        oak.with(checkNotNull(hook));
+        return this;
+    }
+
+    @Nonnull
+    public Jcr with(@Nonnull ValidatorProvider provider) {
+        oak.with(checkNotNull(provider));
+        return this;
+    }
+
+    @Nonnull
+    public Jcr with(@Nonnull Validator validator) {
+        oak.with(checkNotNull(validator));
+        return this;
+    }
+
+    @Nonnull
+    public Jcr with(@Nonnull SecurityProvider securityProvider) {
+        oak.with(checkNotNull(securityProvider));
+        this.securityProvider = securityProvider;
+        return this;
+    }
+
+    @Nonnull
+    public Jcr with(@Nonnull ConflictHandler conflictHandler) {
+        oak.with(checkNotNull(conflictHandler));
+        return this;
+    }
+
+    @Nonnull
+    public Jcr with(@Nonnull ScheduledExecutorService executor) {
+        this.executor = checkNotNull(executor);
+        return this;
+    }
+
+    public Repository createRepository() {
+        return new RepositoryImpl(
+                oak.createContentRepository(), executor, securityProvider);
+    }
+
+}

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

Modified: 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=1400140&r1=1400139&r2=1400140&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/OakRepositoryFactory.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/OakRepositoryFactory.java
Fri Oct 19 15:56:34 2012
@@ -19,14 +19,10 @@ package org.apache.jackrabbit.oak.jcr;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.Map;
-import java.util.concurrent.Executors;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.RepositoryFactory;
 
-import org.apache.jackrabbit.mk.core.MicroKernelImpl;
-import org.apache.jackrabbit.oak.security.SecurityProviderImpl;
-
 public class OakRepositoryFactory implements RepositoryFactory {
 
     private static final String REPOSITORY_URI = "org.apache.jackrabbit.repository.uri";
@@ -51,7 +47,7 @@ public class OakRepositoryFactory implem
             URI uri, Map<String, String> parameters)
             throws RepositoryException {
         // TODO correctly interpret uri
-        return new RepositoryImpl(new MicroKernelImpl(), Executors.newScheduledThreadPool(0),
new SecurityProviderImpl());
+        return new Jcr().createRepository();
     }
 
 }

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=1400140&r1=1400139&r2=1400140&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
Fri Oct 19 15:56:34 2012
@@ -26,24 +26,8 @@ import javax.jcr.Value;
 import javax.security.auth.login.LoginException;
 
 import org.apache.jackrabbit.commons.SimpleValueFactory;
-import org.apache.jackrabbit.mk.api.MicroKernel;
-import org.apache.jackrabbit.oak.Oak;
 import org.apache.jackrabbit.oak.api.ContentRepository;
 import org.apache.jackrabbit.oak.api.ContentSession;
-import org.apache.jackrabbit.oak.core.OrderedChildrenEditor;
-import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
-import org.apache.jackrabbit.oak.plugins.commit.AnnotatingConflictHandler;
-import org.apache.jackrabbit.oak.plugins.commit.ConflictValidatorProvider;
-import org.apache.jackrabbit.oak.plugins.index.property.PropertyIndexHook;
-import org.apache.jackrabbit.oak.plugins.name.NameValidatorProvider;
-import org.apache.jackrabbit.oak.plugins.name.NamespaceValidatorProvider;
-import org.apache.jackrabbit.oak.plugins.nodetype.InitialContent;
-import org.apache.jackrabbit.oak.plugins.nodetype.TypeValidatorProvider;
-import org.apache.jackrabbit.oak.spi.commit.CompositeHook;
-import org.apache.jackrabbit.oak.spi.commit.CompositeValidatorProvider;
-import org.apache.jackrabbit.oak.spi.commit.ConflictHandler;
-import org.apache.jackrabbit.oak.spi.commit.ValidatingHook;
-import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
 import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -58,21 +42,6 @@ public class RepositoryImpl implements R
      */
     private static final Logger log = LoggerFactory.getLogger(RepositoryImpl.class);
 
-    private static final ValidatorProvider DEFAULT_VALIDATOR =
-            new CompositeValidatorProvider(
-                    new NameValidatorProvider(),
-                    new NamespaceValidatorProvider(),
-                    new TypeValidatorProvider(),
-                    new ConflictValidatorProvider());
-
-    private static final CompositeHook DEFAULT_COMMIT_HOOK =
-            new CompositeHook(
-                    new ValidatingHook(DEFAULT_VALIDATOR),
-                    new PropertyIndexHook(),
-                    new OrderedChildrenEditor());
-
-    private static final ConflictHandler DEFAULT_CONFLICT_HANDLER = new AnnotatingConflictHandler();
-
     private final Descriptors descriptors = new Descriptors(new SimpleValueFactory());
     private final ContentRepository contentRepository;
 
@@ -80,16 +49,6 @@ public class RepositoryImpl implements R
 
     private final SecurityProvider securityProvider;
 
-    public RepositoryImpl(MicroKernel kernel, ScheduledExecutorService executor,
-                          SecurityProvider securityProvider) {
-        this(new Oak(setupInitialContent(kernel))
-                .with(DEFAULT_COMMIT_HOOK)
-                .with(DEFAULT_CONFLICT_HANDLER)
-                .with(securityProvider)
-                .createContentRepository(),
-                executor, securityProvider);
-    }
-
     public RepositoryImpl(
             ContentRepository contentRepository,
             ScheduledExecutorService executor,
@@ -208,8 +167,4 @@ public class RepositoryImpl implements R
         return login(null, workspace);
     }
 
-    private static MicroKernel setupInitialContent(MicroKernel mk) {
-        new InitialContent().available(new KernelNodeStore(mk));
-        return mk;
-    }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java?rev=1400140&r1=1400139&r2=1400140&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/AbstractRepositoryTest.java
Fri Oct 19 15:56:34 2012
@@ -25,11 +25,7 @@ import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
 import javax.security.auth.login.Configuration;
 
-import org.apache.jackrabbit.mk.api.MicroKernel;
-import org.apache.jackrabbit.mk.core.MicroKernelImpl;
 import org.apache.jackrabbit.oak.security.OakConfiguration;
-import org.apache.jackrabbit.oak.security.SecurityProviderImpl;
-import org.apache.jackrabbit.oak.spi.security.SecurityProvider;
 import org.junit.After;
 import org.junit.Before;
 
@@ -71,10 +67,7 @@ public abstract class AbstractRepository
 
     protected Repository getRepository() throws RepositoryException {
         if (repository == null) {
-            MicroKernel mk = new MicroKernelImpl();
-            ScheduledExecutorService executorService = getExecutor();
-            SecurityProvider securityProvider = new SecurityProviderImpl();
-            repository  = new RepositoryImpl(mk, executorService, securityProvider);
+            repository  = new Jcr().with(getExecutor()).createRepository();
         }
         return repository;
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OakRepositoryStub.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OakRepositoryStub.java?rev=1400140&r1=1400139&r2=1400140&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OakRepositoryStub.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/OakRepositoryStub.java
Fri Oct 19 15:56:34 2012
@@ -29,7 +29,6 @@ import javax.security.auth.login.Configu
 
 import org.apache.jackrabbit.mk.core.MicroKernelImpl;
 import org.apache.jackrabbit.oak.security.OakConfiguration;
-import org.apache.jackrabbit.oak.security.SecurityProviderImpl;
 import org.apache.jackrabbit.test.NotExecutableException;
 import org.apache.jackrabbit.test.RepositoryStub;
 
@@ -50,10 +49,9 @@ public class OakRepositoryStub extends R
         Configuration.setConfiguration(new OakConfiguration());
 
         String dir = "target/mk-tck-" + System.currentTimeMillis();
-        repository = new RepositoryImpl(
-                new MicroKernelImpl(dir),
-                Executors.newScheduledThreadPool(1),
-                new SecurityProviderImpl());
+        repository = new Jcr(new MicroKernelImpl(dir))
+            .with(Executors.newScheduledThreadPool(1))
+            .createRepository();
 
         Session session = repository.login(superuser);
         try {

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/privilege/PrivilegeRegistrationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/privilege/PrivilegeRegistrationTest.java?rev=1400140&r1=1400139&r2=1400140&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/privilege/PrivilegeRegistrationTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/privilege/PrivilegeRegistrationTest.java
Fri Oct 19 15:56:34 2012
@@ -35,8 +35,7 @@ import javax.jcr.security.Privilege;
 
 import org.apache.jackrabbit.api.security.authorization.PrivilegeManager;
 import org.apache.jackrabbit.mk.core.MicroKernelImpl;
-import org.apache.jackrabbit.oak.jcr.RepositoryImpl;
-import org.apache.jackrabbit.oak.security.SecurityProviderImpl;
+import org.apache.jackrabbit.oak.jcr.Jcr;
 import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants;
 import org.junit.After;
 import org.junit.Before;
@@ -59,9 +58,9 @@ public class PrivilegeRegistrationTest e
 
         // create a separate repository in order to be able to remove registered privileges.
         String dir = "target/mk-tck-" + System.currentTimeMillis();
-        repository = new RepositoryImpl(new MicroKernelImpl(dir),
-                Executors.newScheduledThreadPool(1),
-                new SecurityProviderImpl());
+        repository = new Jcr(new MicroKernelImpl(dir))
+            .with(Executors.newScheduledThreadPool(1))
+            .createRepository();
         session = getAdminSession();
         privilegeManager = getPrivilegeManager(session);
 



Mime
View raw message