jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1392244 - in /jackrabbit/oak/trunk: oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/ oak-core/src/main/java/org/apache/jackrabbit/oak/ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/main/java/org/apa...
Date Mon, 01 Oct 2012 09:27:16 GMT
Author: jukka
Date: Mon Oct  1 09:27:15 2012
New Revision: 1392244

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

First draft, along with improvements to the composite plugin classes

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java
Modified:
    jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/AbstractPerformanceTest.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiValidatorProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndexer.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneHook.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneReindexHook.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeHook.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidatorProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultValidator.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultValidatorProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/CompositeQueryIndexProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndexProvider.java
    jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java

Modified: jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/AbstractPerformanceTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/AbstractPerformanceTest.java?rev=1392244&r1=1392243&r2=1392244&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/AbstractPerformanceTest.java
(original)
+++ jackrabbit/oak/trunk/oak-bench/base/src/main/java/org/apache/jackrabbit/oak/performance/AbstractPerformanceTest.java
Mon Oct  1 09:27:15 2012
@@ -176,7 +176,7 @@ public abstract class AbstractPerformanc
 
         mk = new IndexWrapper(mk);
         ValidatingHook ve =  new ValidatingHook(
-                new CompositeValidatorProvider(Collections.<ValidatorProvider>emptyList()));
+                CompositeValidatorProvider.compose(Collections.<ValidatorProvider>emptyList()));
         ContentRepository contentRepository = new ContentRepositoryImpl(mk, null, ve);
         return new RepositoryImpl(contentRepository, null);
 

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java?rev=1392244&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/Oak.java Mon Oct
 1 09:27:15 2012
@@ -0,0 +1,101 @@
+/*
+ * 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;
+
+import java.util.List;
+
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.mk.api.MicroKernel;
+import org.apache.jackrabbit.mk.core.MicroKernelImpl;
+import org.apache.jackrabbit.oak.api.ContentRepository;
+import org.apache.jackrabbit.oak.core.ContentRepositoryImpl;
+import org.apache.jackrabbit.oak.spi.commit.CommitHook;
+import org.apache.jackrabbit.oak.spi.commit.CompositeHook;
+import org.apache.jackrabbit.oak.spi.commit.CompositeValidatorProvider;
+import org.apache.jackrabbit.oak.spi.commit.ValidatingHook;
+import org.apache.jackrabbit.oak.spi.commit.Validator;
+import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
+import org.apache.jackrabbit.oak.spi.query.CompositeQueryIndexProvider;
+import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
+import org.apache.jackrabbit.oak.spi.state.NodeState;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+
+public class Oak {
+
+    private final MicroKernel kernel;
+
+    private final List<QueryIndexProvider> providers = Lists.newArrayList();
+
+    private final List<CommitHook> hooks = Lists.newArrayList();
+
+    private final List<ValidatorProvider> validators = Lists.newArrayList();
+
+    public Oak(MicroKernel kernel) {
+        this.kernel = kernel;
+    }
+
+    public Oak() {
+        this(new MicroKernelImpl());
+    }
+
+    public Oak with(QueryIndexProvider provider) {
+        providers.add(provider);
+        return this;
+    }
+
+    public Oak with(CommitHook hook) {
+        hooks.add(hook);
+        return this;
+    }
+
+    public Oak with(ValidatorProvider provider) {
+        validators.add(provider);
+        return this;
+    }
+
+    public Oak with(@Nonnull final Validator validator) {
+        return with(new ValidatorProvider() {
+            @Override @Nonnull
+            public Validator getRootValidator(
+                    NodeState before, NodeState after) {
+                return validator;
+            }
+        });
+    }
+
+    public ContentRepository createContentRepository() {
+        CommitHook hook;
+        if (!validators.isEmpty()) {
+            hook = CompositeHook.compose(ImmutableList.<CommitHook>builder()
+                    .addAll(hooks)
+                    .add(new ValidatingHook(
+                            CompositeValidatorProvider.compose(validators)))
+                    .build());
+        } else {
+            hook = CompositeHook.compose(hooks);
+        }
+        return new ContentRepositoryImpl(
+                kernel,
+                CompositeQueryIndexProvider.compose(providers),
+                hook);
+    }
+
+
+}

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java?rev=1392244&r1=1392243&r2=1392244&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ContentRepositoryImpl.java
Mon Oct  1 09:27:15 2012
@@ -16,8 +16,6 @@
  */
 package org.apache.jackrabbit.oak.core;
 
-import java.util.Collections;
-
 import javax.annotation.Nonnull;
 import javax.jcr.Credentials;
 import javax.jcr.NoSuchWorkspaceException;
@@ -34,8 +32,8 @@ import org.apache.jackrabbit.oak.query.Q
 import org.apache.jackrabbit.oak.security.authentication.LoginContextProviderImpl;
 import org.apache.jackrabbit.oak.spi.commit.CommitHook;
 import org.apache.jackrabbit.oak.spi.commit.CompositeHook;
-import org.apache.jackrabbit.oak.spi.commit.CompositeValidatorProvider;
 import org.apache.jackrabbit.oak.spi.commit.ConflictHandlerProvider;
+import org.apache.jackrabbit.oak.spi.commit.DefaultValidatorProvider;
 import org.apache.jackrabbit.oak.spi.commit.ValidatingHook;
 import org.apache.jackrabbit.oak.spi.commit.ValidatorProvider;
 import org.apache.jackrabbit.oak.spi.query.CompositeQueryIndexProvider;
@@ -95,8 +93,7 @@ public class ContentRepositoryImpl imple
             ValidatorProvider validatorProvider) {
         this(microKernel, indexProvider, new ValidatingHook(
                 validatorProvider != null ? validatorProvider
-                        : new CompositeValidatorProvider(
-                                Collections.<ValidatorProvider> emptyList())));
+                        : DefaultValidatorProvider.INSTANCE));
     }
 
     public ContentRepositoryImpl(

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java?rev=1392244&r1=1392243&r2=1392244&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/Activator.java
Mon Oct  1 09:27:15 2012
@@ -16,9 +16,7 @@
  */
 package org.apache.jackrabbit.oak.osgi;
 
-import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
@@ -77,16 +75,15 @@ public class Activator implements Bundle
     public Object addingService(ServiceReference reference) {
         Object service = context.getService(reference);
         if (service instanceof MicroKernel) {
-            List<CommitHook> hooks = new ArrayList<CommitHook>();
-            hooks.add(new DefaultTypeEditor());
-            hooks.add(new ValidatingHook(validatorProvider));
-            // hooks.add(new LuceneEditor());
+            CommitHook hook = new CompositeHook(
+                    new DefaultTypeEditor(),
+                    new ValidatingHook(validatorProvider));
+                    // new LuceneEditor());
 
             MicroKernel kernel = (MicroKernel) service;
             services.put(reference, context.registerService(
                     ContentRepository.class.getName(),
-                    new ContentRepositoryImpl(
-                            kernel, indexProvider, new CompositeHook(hooks)),
+                    new ContentRepositoryImpl(kernel, indexProvider, hook),
                     new Properties()));
             return service;
         } else {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexProvider.java?rev=1392244&r1=1392243&r2=1392244&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiIndexProvider.java
Mon Oct  1 09:27:15 2012
@@ -18,11 +18,13 @@
  */
 package org.apache.jackrabbit.oak.osgi;
 
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import javax.annotation.Nonnull;
+
+import org.apache.jackrabbit.oak.spi.query.CompositeQueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.query.QueryIndex;
 import org.apache.jackrabbit.oak.spi.query.QueryIndexProvider;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
@@ -79,16 +81,11 @@ public class OsgiIndexProvider implement
         context.ungetService(reference);
     }
 
-    @Override
+    @Override @Nonnull
     public List<? extends QueryIndex> getQueryIndexes(NodeStore nodeStore) {
-        if (providers.isEmpty()) {
-            return Collections.emptyList();
-        } else if (providers.size() == 1) {
-            return providers.entrySet().iterator().next().getValue().getQueryIndexes(nodeStore);
-        } else {
-            // TODO combine indexes
-            return null;
-        }
+        QueryIndexProvider composite =
+                CompositeQueryIndexProvider.compose(providers.values());
+        return composite.getQueryIndexes(nodeStore);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiValidatorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiValidatorProvider.java?rev=1392244&r1=1392243&r2=1392244&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiValidatorProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/osgi/OsgiValidatorProvider.java
Mon Oct  1 09:27:15 2012
@@ -84,7 +84,7 @@ public class OsgiValidatorProvider imple
 
     @Override
     public Validator getRootValidator(NodeState before, NodeState after) {
-        return new CompositeValidatorProvider(providers.values())
+        return CompositeValidatorProvider.compose(providers.values())
                 .getRootValidator(before, after);
     }
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndexer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndexer.java?rev=1392244&r1=1392243&r2=1392244&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndexer.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/PropertyIndexer.java
Mon Oct  1 09:27:15 2012
@@ -19,6 +19,8 @@ package org.apache.jackrabbit.oak.plugin
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.annotation.Nonnull;
+
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.plugins.unique.UniqueIndex;
 import org.apache.jackrabbit.oak.query.index.PrefixContentIndex;
@@ -50,7 +52,7 @@ public class PropertyIndexer implements 
         return after;
     }
 
-    @Override
+    @Override @Nonnull
     public List<? extends QueryIndex> getQueryIndexes(NodeStore store) {
         List<QueryIndex> queryIndexList = new ArrayList<QueryIndex>();
         NodeBuilder rootBuilder = IndexUtils.getChildBuilder(store,

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneHook.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneHook.java?rev=1392244&r1=1392243&r2=1392244&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneHook.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneHook.java
Mon Oct  1 09:27:15 2012
@@ -50,7 +50,7 @@ public class LuceneHook implements Commi
         for (IndexDefinition def : indexDefinitions) {
             hooks.add(new LuceneEditor(def));
         }
-        return new CompositeHook(hooks).processCommit(before, after);
+        return CompositeHook.compose(hooks).processCommit(before, after);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexProvider.java?rev=1392244&r1=1392243&r2=1392244&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneIndexProvider.java
Mon Oct  1 09:27:15 2012
@@ -20,6 +20,8 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
+import javax.annotation.Nonnull;
+
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.spi.query.IndexDefinition;
 import org.apache.jackrabbit.oak.spi.query.IndexUtils;
@@ -44,7 +46,7 @@ public class LuceneIndexProvider impleme
         this.indexPath = indexPath;
     }
 
-    @Override
+    @Override @Nonnull
     public List<QueryIndex> getQueryIndexes(NodeStore store) {
         if (!PathUtils.isValid(indexPath)) {
             LOG.warn("index path is not valid {}", indexPath);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneReindexHook.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneReindexHook.java?rev=1392244&r1=1392243&r2=1392244&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneReindexHook.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/lucene/LuceneReindexHook.java
Mon Oct  1 09:27:15 2012
@@ -91,10 +91,7 @@ public class LuceneReindexHook implement
         for (IndexDefinition def : defsChanged) {
             hooks.add(new LuceneEditor(def));
         }
-        if (hooks.isEmpty()) {
-            return after;
-        }
-        NodeState done = new CompositeHook(hooks).processCommit(null, after);
+        NodeState done = CompositeHook.compose(hooks).processCommit(null, after);
         LOG.debug("done reindexing repository content in {} ms.",
                 System.currentTimeMillis() - t);
         return done;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeHook.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeHook.java?rev=1392244&r1=1392243&r2=1392244&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeHook.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeHook.java
Mon Oct  1 09:27:15 2012
@@ -17,7 +17,9 @@
 package org.apache.jackrabbit.oak.spi.commit;
 
 import java.util.Arrays;
-import java.util.List;
+import java.util.Collection;
+
+import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
@@ -28,9 +30,20 @@ import org.apache.jackrabbit.oak.spi.sta
  */
 public class CompositeHook implements CommitHook {
 
-    private final List<CommitHook> hooks;
+    public static CommitHook compose(@Nonnull Collection<CommitHook> hooks) {
+        switch (hooks.size()) {
+        case 0:
+            return EmptyHook.INSTANCE;
+        case 1:
+            return hooks.iterator().next();
+        default:
+            return new CompositeHook(hooks);
+        }
+    }
+
+    private final Collection<CommitHook> hooks;
 
-    public CompositeHook(List<CommitHook> hooks) {
+    private CompositeHook(@Nonnull Collection<CommitHook> hooks) {
         this.hooks = hooks;
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidatorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidatorProvider.java?rev=1392244&r1=1392243&r2=1392244&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidatorProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/CompositeValidatorProvider.java
Mon Oct  1 09:27:15 2012
@@ -23,14 +23,29 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
 
+import javax.annotation.Nonnull;
+
 /**
  * This {@code ValidatorProvider} aggregates a list of validator providers into
  * a single validator provider.
  */
 public class CompositeValidatorProvider implements ValidatorProvider {
+
+    public static ValidatorProvider compose(
+            @Nonnull Collection<ValidatorProvider> providers) {
+        switch (providers.size()) {
+        case 0:
+            return DefaultValidatorProvider.INSTANCE;
+        case 1:
+            return providers.iterator().next();
+        default:
+            return new CompositeValidatorProvider(providers);
+        }
+    }
+
     private final Collection<ValidatorProvider> providers;
 
-    public CompositeValidatorProvider(Collection<ValidatorProvider> providers) {
+    private CompositeValidatorProvider(Collection<ValidatorProvider> providers) {
         this.providers = providers;
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultValidator.java?rev=1392244&r1=1392243&r2=1392244&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultValidator.java
Mon Oct  1 09:27:15 2012
@@ -28,6 +28,8 @@ import org.apache.jackrabbit.oak.spi.sta
  */
 public class DefaultValidator implements Validator {
 
+    public static final Validator INSTANCE = new DefaultValidator();
+
     @Override
     public void propertyAdded(PropertyState after)
             throws CommitFailedException {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultValidatorProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultValidatorProvider.java?rev=1392244&r1=1392243&r2=1392244&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultValidatorProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/commit/DefaultValidatorProvider.java
Mon Oct  1 09:27:15 2012
@@ -25,9 +25,12 @@ import org.apache.jackrabbit.oak.spi.sta
  */
 public class DefaultValidatorProvider implements ValidatorProvider {
 
-    @Nonnull
-    @Override
+    public static final ValidatorProvider INSTANCE =
+            new DefaultValidatorProvider();
+
+    @Override @Nonnull
     public Validator getRootValidator(NodeState before, NodeState after) {
-        return new DefaultValidator();
+        return DefaultValidator.INSTANCE;
     }
+
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/CompositeQueryIndexProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/CompositeQueryIndexProvider.java?rev=1392244&r1=1392243&r2=1392244&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/CompositeQueryIndexProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/CompositeQueryIndexProvider.java
Mon Oct  1 09:27:15 2012
@@ -16,42 +16,56 @@
  */
 package org.apache.jackrabbit.oak.spi.query;
 
-import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.List;
-import java.util.concurrent.CopyOnWriteArrayList;
+
+import javax.annotation.Nonnull;
 
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
+
 /**
  * This {@code QueryIndexProvider} aggregates a list of query index providers
  * into a single query index provider.
  */
 public class CompositeQueryIndexProvider implements QueryIndexProvider {
 
-    private final Collection<QueryIndexProvider> providers = new CopyOnWriteArrayList<QueryIndexProvider>();
+    @Nonnull
+    public static QueryIndexProvider compose(
+            @Nonnull Collection<QueryIndexProvider> providers) {
+        if (providers.isEmpty()) {
+            return new QueryIndexProvider() {
+                @Override
+                public List<QueryIndex> getQueryIndexes(NodeStore nodeStore) {
+                    return ImmutableList.of();
+                }
+            };
+        } else if (providers.size() == 1) {
+            return providers.iterator().next();
+        } else {
+            return new CompositeQueryIndexProvider(
+                    ImmutableList.copyOf(providers));
+        }
+    }
 
-    public CompositeQueryIndexProvider(QueryIndexProvider... providers) {
-        add(providers);
+    private final List<QueryIndexProvider> providers;
+
+    private CompositeQueryIndexProvider(List<QueryIndexProvider> providers) {
+        this.providers = providers;
     }
 
-    public void add(QueryIndexProvider... provider) {
-        if (provider == null) {
-            return;
-        }
-        for (QueryIndexProvider qip : provider) {
-            providers.add(qip);
-        }
+    public CompositeQueryIndexProvider(QueryIndexProvider... providers) {
+        this(Arrays.asList(providers));
     }
 
-    @Override
+    @Override @Nonnull
     public List<? extends QueryIndex> getQueryIndexes(NodeStore nodeStore) {
-        List<QueryIndex> indexes = new ArrayList<QueryIndex>();
-        for (QueryIndexProvider qip : providers) {
-            List<? extends QueryIndex> t = qip.getQueryIndexes(nodeStore);
-            if (t != null) {
-                indexes.addAll(t);
-            }
+        List<QueryIndex> indexes = Lists.newArrayList();
+        for (QueryIndexProvider provider : providers) {
+            indexes.addAll(provider.getQueryIndexes(nodeStore));
         }
         return indexes;
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndexProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndexProvider.java?rev=1392244&r1=1392243&r2=1392244&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndexProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndexProvider.java
Mon Oct  1 09:27:15 2012
@@ -20,6 +20,8 @@ package org.apache.jackrabbit.oak.spi.qu
 
 import java.util.List;
 
+import javax.annotation.Nonnull;
+
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 
 /**
@@ -34,6 +36,7 @@ public interface QueryIndexProvider {
      * 
      * @return the list of indexes
      */
+    @Nonnull
     List<? extends QueryIndex> getQueryIndexes(NodeStore nodeStore);
 
 }

Modified: jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java?rev=1392244&r1=1392243&r2=1392244&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java (original)
+++ jackrabbit/oak/trunk/oak-run/src/main/java/org/apache/jackrabbit/oak/run/Main.java Mon
Oct  1 09:27:15 2012
@@ -17,8 +17,6 @@
 package org.apache.jackrabbit.oak.run;
 
 import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
 import java.util.Properties;
 import java.util.concurrent.Executors;
 
@@ -199,25 +197,23 @@ public class Main {
         }
 
         private static CommitHook buildDefaultCommitHook() {
-            List<CommitHook> hooks = new ArrayList<CommitHook>();
-            hooks.add(new DefaultTypeEditor());
-            hooks.add(new ValidatingHook(createDefaultValidatorProvider()));
-            hooks.add(new LuceneHook());
-            return new CompositeHook(hooks);
+            return new CompositeHook(
+                    new DefaultTypeEditor(),
+                    new ValidatingHook(createDefaultValidatorProvider()),
+                    new LuceneHook());
         }
 
         private static ValidatorProvider createDefaultValidatorProvider() {
-            List<ValidatorProvider> providers = new ArrayList<ValidatorProvider>();
-            providers.add(new NameValidatorProvider());
-            providers.add(new NamespaceValidatorProvider());
-            providers.add(new TypeValidatorProvider());
-            providers.add(new ConflictValidatorProvider());
-            providers.add(new PermissionValidatorProvider());
-            providers.add(new AccessControlValidatorProvider());
-            // FIXME: retrieve from user context
-            providers.add(new UserValidatorProvider(new UserConfig("admin")));
-            providers.add(new PrivilegeValidatorProvider());
-            return new CompositeValidatorProvider(providers);
+            return new CompositeValidatorProvider(
+                    new NameValidatorProvider(),
+                    new NamespaceValidatorProvider(),
+                    new TypeValidatorProvider(),
+                    new ConflictValidatorProvider(),
+                    new PermissionValidatorProvider(),
+                    new AccessControlValidatorProvider(),
+                    // FIXME: retrieve from user context
+                    new UserValidatorProvider(new UserConfig("admin")),
+                    new PrivilegeValidatorProvider());
         }
 
     }



Mime
View raw message