jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1333504 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/mk/index/ main/java/org/apache/jackrabbit/oak/api/ main/java/org/apache/jackrabbit/oak/core/ main/java/org/apache/jackrabbit/oak/osgi/ main/java/org/apache/ja...
Date Thu, 03 May 2012 15:29:43 GMT
Author: thomasm
Date: Thu May  3 15:29:42 2012
New Revision: 1333504

URL: http://svn.apache.org/viewvc?rev=1333504&view=rev
Log:
OAK-28 Query implementation (removed QueryIndexProvider.init(); and implementation)

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/PropertyIndex.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.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/OsgiIndexProvider.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/PropertyValueImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/PropertyContentIndex.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingCursor.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/QueryIndexProvider.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/IndexWrapperTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java
    jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryTest.txt

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java?rev=1333504&r1=1333503&r2=1333504&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/IndexWrapper.java
Thu May  3 15:29:42 2012
@@ -29,13 +29,13 @@ import org.apache.jackrabbit.mk.util.Exc
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.mk.wrapper.MicroKernelWrapper;
 import org.apache.jackrabbit.mk.wrapper.MicroKernelWrapperBase;
+import org.apache.jackrabbit.oak.spi.QueryIndexProvider;
 
 /**
  * The index mechanism, as a wrapper.
  */
 public class IndexWrapper extends MicroKernelWrapperBase implements MicroKernel {
 
-    private static final String INDEX_PATH = "/index";
     private static final String TYPE_PREFIX = "prefix:";
     private static final String TYPE_PROPERTY = "property:";
     private static final String UNIQUE = "unique";
@@ -48,10 +48,14 @@ public class IndexWrapper extends MicroK
 
     public IndexWrapper(MicroKernel mk) {
         this.mk = MicroKernelWrapperBase.wrap(mk);
-        this.indexer = new Indexer(mk);
+        this.indexer = new Indexer(this, mk, Indexer.INDEX_CONFIG_ROOT);
         indexer.init();
     }
 
+    public QueryIndexProvider getIndexer() {
+        return indexer;
+    }
+
     @Override
     public String getHeadRevision() {
         return mk.getHeadRevision();
@@ -64,6 +68,10 @@ public class IndexWrapper extends MicroK
 
     @Override
     public boolean nodeExists(String path, String revisionId) {
+        String indexRoot = indexer.getIndexRootNode();
+        if (path.startsWith(indexRoot)) {
+            return false;
+        }
         return mk.nodeExists(path, revisionId);
     }
 
@@ -99,7 +107,8 @@ public class IndexWrapper extends MicroK
 
     @Override
     public String commitStream(String rootPath, JsopReader jsonDiff, String revisionId, String
message) {
-        if (!rootPath.startsWith(INDEX_PATH)) {
+        String indexRoot = indexer.getIndexRootNode();
+        if (!rootPath.startsWith(indexRoot)) {
             String rev = mk.commitStream(rootPath, jsonDiff, revisionId, message);
             jsonDiff.resetReader();
             indexer.updateIndex(rootPath, jsonDiff, rev);
@@ -125,7 +134,7 @@ public class IndexWrapper extends MicroK
                 t.read('{');
                 // parse but ignore
                 NodeImpl.parse(map, t, 0);
-                path = PathUtils.relativize(INDEX_PATH, path);
+                path = PathUtils.relativize(indexRoot, path);
                 if (path.startsWith(TYPE_PREFIX)) {
                     String prefix = path.substring(TYPE_PREFIX.length());
                     PrefixIndex idx = indexer.createPrefixIndex(prefix);
@@ -144,7 +153,20 @@ public class IndexWrapper extends MicroK
                 }
                 break;
             case '-':
-                throw ExceptionFactory.get("Removing indexes is not yet implemented");
+                path = PathUtils.relativize(indexRoot, path);
+                if (path.startsWith(TYPE_PREFIX)) {
+                    String prefix = path.substring(TYPE_PREFIX.length());
+                    indexer.removePrefixIndex(prefix);
+                } else if (path.startsWith(TYPE_PROPERTY)) {
+                    String property = path.substring(TYPE_PROPERTY.length());
+                    boolean unique = false;
+                    if (property.endsWith("," + UNIQUE)) {
+                        unique = true;
+                        property = property.substring(0, property.length() - UNIQUE.length()
- 1);
+                    }
+                    indexer.removePropertyIndex(property, unique);
+                }
+                break;
             default:
                 throw ExceptionFactory.get("token: " + (char) t.getTokenType());
             }
@@ -154,10 +176,11 @@ public class IndexWrapper extends MicroK
 
     @Override
     public JsopReader getNodesStream(String path, String revisionId, int depth, long offset,
int count, String filter) {
-        if (!path.startsWith(INDEX_PATH)) {
+        String indexRoot = indexer.getIndexRootNode();
+        if (!path.startsWith(indexRoot)) {
             return mk.getNodesStream(path, revisionId, depth, offset, count, filter);
         }
-        String index = PathUtils.relativize(INDEX_PATH, path);
+        String index = PathUtils.relativize(indexRoot, path);
         int idx = index.indexOf('?');
         if (idx < 0) {
             // invalid query - expected: /index/prefix:x?y

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java?rev=1333504&r1=1333503&r2=1333504&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/Indexer.java
Thu May  3 15:29:42 2012
@@ -44,30 +44,41 @@ import java.util.Map.Entry;
 public class Indexer implements QueryIndexProvider {
 
     // TODO discuss where to store index config data
-    private static final String INDEX_CONFIG_ROOT = "/jcr:system/indexes";
+    static final String INDEX_CONFIG_ROOT = "/jcr:system/indexes";
 
     private static final boolean DISABLED = Boolean.getBoolean("mk.indexDisabled");
 
     private MicroKernel mk;
+    private MicroKernel mkWrapper;
     private String revision;
     private String indexRootNode;
     private StringBuilder buffer;
     private HashMap<String, Index> indexes = new HashMap<String, Index>();
+    private ArrayList<QueryIndex> queryIndexList;
     private HashMap<String, BTreePage> modified = new HashMap<String, BTreePage>();
     private SimpleLRUCache<String, BTreePage> cache = SimpleLRUCache.newInstance(100);
     private String readRevision;
+    private boolean init;
 
-    public Indexer(MicroKernel mk, String indexRootNode) {
+    public Indexer(MicroKernel mkWrapper, MicroKernel mk, String indexRootNode) {
+        this.mkWrapper = mkWrapper;
         this.mk = mk;
         this.indexRootNode = indexRootNode;
     }
 
     public Indexer(MicroKernel mk) {
-        this(mk, INDEX_CONFIG_ROOT);
+        this(mk, mk, INDEX_CONFIG_ROOT);
+    }
+
+    public String getIndexRootNode() {
+        return indexRootNode;
     }
 
-    @Override
     public void init() {
+        if (init) {
+            return;
+        }
+        init = true;
         if (!PathUtils.isAbsolute(indexRootNode)) {
             indexRootNode = "/" + indexRootNode;
         }
@@ -106,11 +117,18 @@ public class Indexer implements QueryInd
                 }
                 if (p != null) {
                     indexes.put(p.getName(), p);
+                    queryIndexList = null;
                 }
             }
         }
     }
 
+    public void removePropertyIndex(String property, boolean unique) {
+        PropertyIndex index = new PropertyIndex(this, property, unique);
+        indexes.remove(index.getName());
+        queryIndexList = null;
+    }
+
     public PropertyIndex createPropertyIndex(String property, boolean unique) {
         PropertyIndex index = new PropertyIndex(this, property, unique);
         PropertyIndex existing = (PropertyIndex) indexes.get(index.getName());
@@ -121,6 +139,12 @@ public class Indexer implements QueryInd
         return index;
     }
 
+    public void removePrefixIndex(String prefix) {
+        PrefixIndex index = new PrefixIndex(this, prefix);
+        indexes.remove(index.getName());
+        queryIndexList = null;
+    }
+
     public PrefixIndex createPrefixIndex(String prefix) {
         PrefixIndex index = new PrefixIndex(this, prefix);
         PrefixIndex existing = (PrefixIndex) indexes.get(index.getName());
@@ -490,6 +514,7 @@ public class Indexer implements QueryInd
     private void buildAndAddIndex(Index index) {
         addRecursive(index, "/");
         indexes.put(index.getName(), index);
+        queryIndexList = null;
     }
 
     private void addRecursive(Index index, String path) {
@@ -510,20 +535,23 @@ public class Indexer implements QueryInd
 
     @Override
     public List<QueryIndex> getQueryIndexes(MicroKernel mk) {
-        if (mk != this.mk) {
+        init();
+        if (mk != this.mkWrapper) {
             return Collections.emptyList();
         }
-        ArrayList<QueryIndex> list = new ArrayList<QueryIndex>();
-        for (Index index : indexes.values()) {
-            QueryIndex qi = null;
-            if (index instanceof PropertyIndex) {
-                qi = new PropertyContentIndex(mk, (PropertyIndex) index);
-            } else if (index instanceof PrefixIndex) {
-                // TODO support prefix indexes?
+        if (queryIndexList == null) {
+            queryIndexList = new ArrayList<QueryIndex>();
+            for (Index index : indexes.values()) {
+                QueryIndex qi = null;
+                if (index instanceof PropertyIndex) {
+                    qi = new PropertyContentIndex(mk, (PropertyIndex) index);
+                } else if (index instanceof PrefixIndex) {
+                    // TODO support prefix indexes?
+                }
+                queryIndexList.add(qi);
             }
-            list.add(qi);
         }
-        return list;
+        return queryIndexList;
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/PropertyIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/PropertyIndex.java?rev=1333504&r1=1333503&r2=1333504&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/PropertyIndex.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/mk/index/PropertyIndex.java
Thu May  3 15:29:42 2012
@@ -53,6 +53,10 @@ public class PropertyIndex implements In
         return new PropertyIndex(indexer, propertyName, unique);
     }
 
+    public String getPropertyName() {
+        return propertyName;
+    }
+
     @Override
     public String getName() {
         return tree.getName();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java?rev=1333504&r1=1333503&r2=1333504&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/QueryEngine.java
Thu May  3 15:29:42 2012
@@ -28,11 +28,6 @@ import java.util.Map;
 public interface QueryEngine {
 
     /**
-     * Initialize the query engine. This includes reading the list of indexes.
-     */
-    void init();
-
-    /**
      * Parse the query (check if it's valid) and get the list of bind variable names.
      *
      * @param statement

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=1333504&r1=1333503&r2=1333504&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
Thu May  3 15:29:42 2012
@@ -42,7 +42,7 @@ import javax.security.auth.login.LoginEx
 public class ContentRepositoryImpl implements ContentRepository {
 
     /** Logger instance */
-    private static final Logger log =
+    private static final Logger LOG =
             LoggerFactory.getLogger(ContentRepositoryImpl.class);
 
     // TODO: retrieve default wsp-name from configuration
@@ -64,12 +64,6 @@ public class ContentRepositoryImpl imple
         this(mk, getDefaultIndexProvider(mk));
     }
 
-    private static QueryIndexProvider getDefaultIndexProvider(MicroKernel mk) {
-        QueryIndexProvider provider = new Indexer(mk);
-        provider.init();
-        return provider;
-    }
-
     /**
      * Creates an Oak repository instance based on the given, already
      * initialized components.
@@ -83,7 +77,6 @@ public class ContentRepositoryImpl imple
         queryEngine = new QueryEngineImpl(nodeStore, microKernel, indexProvider);
 
         // FIXME: workspace setup must be done elsewhere...
-        queryEngine.init();
         NodeState root = nodeStore.getRoot();
 
         NodeState wspNode = root.getChildNode(DEFAULT_WORKSPACE_NAME);
@@ -97,6 +90,10 @@ public class ContentRepositoryImpl imple
         }
     }
 
+    private static QueryIndexProvider getDefaultIndexProvider(MicroKernel mk) {
+        return new Indexer(mk);
+    }
+
     @Override
     public ContentSession login(Object credentials, String workspaceName)
             throws LoginException, NoSuchWorkspaceException {

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=1333504&r1=1333503&r2=1333504&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
Thu May  3 15:29:42 2012
@@ -80,11 +80,6 @@ public class OsgiIndexProvider implement
     }
 
     @Override
-    public void init() {
-        // nothing to do
-    }
-
-    @Override
     public List<QueryIndex> getQueryIndexes(MicroKernel mk) {
         if (providers.isEmpty()) {
             return Collections.emptyList();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java?rev=1333504&r1=1333503&r2=1333504&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/QueryEngineImpl.java
Thu May  3 15:29:42 2012
@@ -47,12 +47,6 @@ public class QueryEngineImpl implements 
         parserSQL2 = new SQL2Parser(vf);
     }
 
-    @Override
-    public void init() {
-        // TODO the list of index providers should be configurable as well
-        indexProvider.init();
-    }
-
     /**
      * Parse the query (check if it's valid) and get the list of bind variable names.
      *

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/PropertyValueImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/PropertyValueImpl.java?rev=1333504&r1=1333503&r2=1333504&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/PropertyValueImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/ast/PropertyValueImpl.java
Thu May  3 15:29:42 2012
@@ -63,6 +63,9 @@ public class PropertyValueImpl extends D
         NodeImpl n = selector.currentNode();
         String[] elements = PathUtils.split(propertyName);
         for (int i = 0; i < elements.length - 1; i++) {
+            if (n == null) {
+                return null;
+            }
             String p = elements[i];
             if (!n.exists(p)) {
                 return null;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/PropertyContentIndex.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/PropertyContentIndex.java?rev=1333504&r1=1333503&r2=1333504&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/PropertyContentIndex.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/PropertyContentIndex.java
Thu May  3 15:29:42 2012
@@ -42,39 +42,29 @@ public class PropertyContentIndex implem
 
     @Override
     public double getCost(Filter filter) {
-        String propertyName = index.getName();
+        String propertyName = index.getPropertyName();
         Filter.PropertyRestriction restriction = filter.getPropertyRestriction(propertyName);
         if (restriction == null) {
             return Double.MAX_VALUE;
         }
-        boolean unique = index.isUnique();
-        if (restriction.first == restriction.last) {
-            return unique ? 2 : 20;
-        }
-        int estimatedMatches = 1000000;
-        if (restriction.first != null) {
-            estimatedMatches /= 10;
-        }
-        if (restriction.last != null) {
-            estimatedMatches /= 10;
-        }
-        if (unique) {
-            estimatedMatches /= 100;
+        if (restriction.first != restriction.last) {
+            // only support equality matches (for now)
+            return Double.MAX_VALUE;
         }
-        return estimatedMatches;
+        boolean unique = index.isUnique();
+        return unique ? 2 : 20;
     }
 
     @Override
     public String getPlan(Filter filter) {
-        String propertyName = index.getName();
+        String propertyName = index.getPropertyName();
         Filter.PropertyRestriction restriction = filter.getPropertyRestriction(propertyName);
-
         return "propertyIndex \"" + restriction.propertyName + " " + restriction.toString()
+ '"';
     }
 
     @Override
     public Cursor query(Filter filter, String revisionId) {
-        String propertyName = index.getName();
+        String propertyName = index.getPropertyName();
         Filter.PropertyRestriction restriction = filter.getPropertyRestriction(propertyName);
         if (restriction == null) {
             throw new IllegalArgumentException("No restriction for " + propertyName);
@@ -131,6 +121,7 @@ public class PropertyContentIndex implem
         public boolean next() {
             if (it.hasNext()) {
                 currentPath = it.next();
+                return true;
             }
             return false;
         }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingCursor.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingCursor.java?rev=1333504&r1=1333503&r2=1333504&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingCursor.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/index/TraversingCursor.java
Thu May  3 15:29:42 2012
@@ -41,6 +41,9 @@ public class TraversingCursor implements
 
     private boolean loadChildren(String path, long offset) {
         String s = mk.getNodes(path, revisionId, 0, offset, childBlockSize, null);
+        if (s == null) {
+            return false;
+        }
         NodeCursor c = new NodeCursor();
         c.node = NodeImpl.parse(s);
         c.node.setPath(path);
@@ -56,7 +59,11 @@ public class TraversingCursor implements
             if (currentPath == null) {
                 return null;
             }
-            currentNode = NodeImpl.parse(mk.getNodes(currentPath, revisionId));
+            String s = mk.getNodes(currentPath, revisionId);
+            if (s == null) {
+                return null;
+            }
+            currentNode = NodeImpl.parse(s);
             currentNode.setPath(currentPath);
         }
         return currentNode;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/QueryIndexProvider.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/QueryIndexProvider.java?rev=1333504&r1=1333503&r2=1333504&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/QueryIndexProvider.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/QueryIndexProvider.java
Thu May  3 15:29:42 2012
@@ -23,18 +23,12 @@ import org.apache.jackrabbit.mk.api.Micr
 
 /**
  * A mechanism to index data. Indexes might be added or removed at runtime,
- * possibly by changing content in the repository. The provider knows about
- * indexes, and informs the query engine about indexes that where added or
- * removed at runtime.
+ * possibly by changing content in the repository. The provider knows about the
+ * indexes available at a given time.
  */
 public interface QueryIndexProvider {
 
     /**
-     * Initialize the instance.
-     */
-    void init();
-
-    /**
      * Get the currently configured indexes for the given MicroKernel instance.
      *
      * @param mk the MicroKernel instance

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java?rev=1333504&r1=1333503&r2=1333504&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PrefixIndexTest.java
Thu May  3 15:29:42 2012
@@ -30,7 +30,7 @@ public class PrefixIndexTest {
     @Test
     public void test() {
         MicroKernel mk = new MicroKernelImpl();
-        Indexer indexer = new Indexer(mk, "index");
+        Indexer indexer = new Indexer(mk, mk, "index");
         indexer.init();
         PrefixIndex index = indexer.createPrefixIndex("d:");
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java?rev=1333504&r1=1333503&r2=1333504&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/index/PropertyIndexTest.java
Thu May  3 15:29:42 2012
@@ -29,7 +29,7 @@ public class PropertyIndexTest {
     @Test
     public void test() {
         MicroKernel mk = new MicroKernelImpl();
-        Indexer indexer = new Indexer(mk, "index");
+        Indexer indexer = new Indexer(mk, mk, "index");
         indexer.init();
         PropertyIndex index = indexer.createPropertyIndex("id", true);
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/IndexWrapperTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/IndexWrapperTest.java?rev=1333504&r1=1333503&r2=1333504&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/IndexWrapperTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/mk/wrapper/IndexWrapperTest.java
Thu May  3 15:29:42 2012
@@ -36,47 +36,47 @@ public class IndexWrapperTest {
 
     @Test
     public void getNodes() {
-        assertNull(mk.getNodes("/index/unknown", head));
+        assertNull(mk.getNodes("/jcr:system/indexes/unknown", head));
         assertNull(mk.getNodes("/unknown", head));
     }
 
     @Test
     public void prefix() {
-        head = mk.commit("/index", "+ \"prefix:x\": {}", head, "");
+        head = mk.commit("/jcr:system/indexes", "+ \"prefix:x\": {}", head, "");
         head = mk.commit("/", "+ \"n1\": { \"value\":\"a:no\" }", head, "");
         head = mk.commit("/", "+ \"n2\": { \"value\":\"x:yes\" }", head, "");
         head = mk.commit("/", "+ \"n3\": { \"value\":\"x:a\" }", head, "");
         head = mk.commit("/", "+ \"n4\": { \"value\":\"x:a\" }", head, "");
-        String empty = mk.getNodes("/index/prefix:x?x:no", head);
+        String empty = mk.getNodes("/jcr:system/indexes/prefix:x?x:no", head);
         assertEquals("[]", empty);
-        String yes = mk.getNodes("/index/prefix:x?x:yes", head);
+        String yes = mk.getNodes("/jcr:system/indexes/prefix:x?x:yes", head);
         assertEquals("[\"/n2/value\"]", yes);
-        String a = mk.getNodes("/index/prefix:x?x:a", head);
+        String a = mk.getNodes("/jcr:system/indexes/prefix:x?x:a", head);
         assertEquals("[\"/n3/value\",\"/n4/value\"]", a);
     }
 
     @Test
     public void propertyUnique() {
-        head = mk.commit("/index", "+ \"property:id,unique\": {}", head, "");
+        head = mk.commit("/jcr:system/indexes", "+ \"property:id,unique\": {}", head, "");
         head = mk.commit("/", "+ \"n1\": { \"value\":\"empty\" }", head, "");
         head = mk.commit("/", "+ \"n2\": { \"id\":\"1\" }", head, "");
-        String empty = mk.getNodes("/index/property:id,unique?0", head);
+        String empty = mk.getNodes("/jcr:system/indexes/property:id,unique?0", head);
         assertEquals("[]", empty);
-        String one = mk.getNodes("/index/property:id,unique?1", head);
+        String one = mk.getNodes("/jcr:system/indexes/property:id,unique?1", head);
         assertEquals("[\"/n2\"]", one);
     }
 
     @Test
     public void propertyNonUnique() {
-        head = mk.commit("/index", "+ \"property:ref\": {}", head, "");
+        head = mk.commit("/jcr:system/indexes", "+ \"property:ref\": {}", head, "");
         head = mk.commit("/", "+ \"n1\": { \"ref\":\"a\" }", head, "");
         head = mk.commit("/", "+ \"n2\": { \"ref\":\"b\" }", head, "");
         head = mk.commit("/", "+ \"n3\": { \"ref\":\"b\" }", head, "");
-        String empty = mk.getNodes("/index/property:ref?no", head);
+        String empty = mk.getNodes("/jcr:system/indexes/property:ref?no", head);
         assertEquals("[]", empty);
-        String one = mk.getNodes("/index/property:ref?a", head);
+        String one = mk.getNodes("/jcr:system/indexes/property:ref?a", head);
         assertEquals("[\"/n1\"]", one);
-        String two = mk.getNodes("/index/property:ref?b", head);
+        String two = mk.getNodes("/jcr:system/indexes/property:ref?b", head);
         assertEquals("[\"/n2\",\"/n3\"]", two);
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java?rev=1333504&r1=1333503&r2=1333504&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/AbstractQueryTest.java
Thu May  3 15:29:42 2012
@@ -16,8 +16,8 @@
  */
 package org.apache.jackrabbit.oak.query;
 
-import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.core.MicroKernelImpl;
+import org.apache.jackrabbit.mk.index.IndexWrapper;
 import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.kernel.KernelNodeStore;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
@@ -28,7 +28,7 @@ import org.apache.jackrabbit.oak.spi.sta
 public abstract class AbstractQueryTest {
 
     // TODO improve: use ContentRepository here instead of creating mk instance.
-    protected final MicroKernel mk = new MicroKernelImpl();
+    protected final IndexWrapper mk = new IndexWrapper(new MicroKernelImpl());
 
     protected final NodeStore store = new KernelNodeStore(mk);
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java?rev=1333504&r1=1333503&r2=1333504&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/query/QueryTest.java
Thu May  3 15:29:42 2012
@@ -27,12 +27,10 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import org.apache.jackrabbit.mk.index.Indexer;
 import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.Result;
 import org.apache.jackrabbit.oak.api.ResultRow;
 import org.apache.jackrabbit.oak.spi.QueryIndexProvider;
-import org.junit.Before;
 import org.junit.Test;
 
 /**
@@ -40,14 +38,9 @@ import org.junit.Test;
  */
 public class QueryTest extends AbstractQueryTest {
 
-    private QueryIndexProvider ip = new Indexer(mk);
+    private QueryIndexProvider ip = mk.getIndexer();
     private QueryEngineImpl qe = new QueryEngineImpl(store, mk, ip);
 
-    @Before
-    public void setup() {
-        qe.init();
-    }
-
     @Test
     public void script() throws Exception {
         test("queryTest.txt");
@@ -151,9 +144,13 @@ public class QueryTest extends AbstractQ
                             errors = true;
                         }
                     }
-                } else {
+                } else if (line.startsWith("commit")) {
                     w.println(line);
-                    mk.commit("/", line, mk.getHeadRevision(), "");
+                    line = line.substring("commit".length()).trim();
+                    int spaceIndex = line.indexOf(' ');
+                    String path = line.substring(0, spaceIndex).trim();
+                    String diff = line.substring(spaceIndex).trim();
+                    mk.commit(path, diff, mk.getHeadRevision(), "");
                 }
             }
         } finally {

Modified: jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryTest.txt
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryTest.txt?rev=1333504&r1=1333503&r2=1333504&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryTest.txt
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/resources/org/apache/jackrabbit/oak/query/queryTest.txt
Thu May  3 15:29:42 2012
@@ -21,7 +21,24 @@
 # * new tests are typically be added on top, after the syntax docs
 # * use ascii character only
 
-+ "test": { "jcr:resource": {}, "resource": { "x" : {}}}
+# test the property content index
+
+commit / + "test": { "a": { "id": "10" }, "b": { "id" : "20" }}
+commit /jcr:system/indexes + "property:id": {}
+
+explain select * from [nt:base] where id = '10'
+nt:base AS nt:base /* propertyIndex "id [10..10]" */
+
+select * from [nt:base] where id = '10'
+/test/a
+
+explain select * from [nt:base] where id > '10'
+nt:base AS nt:base /* traverse "//*" */
+
+commit / - "test"
+commit /jcr:system/indexes - "property:id"
+
+commit / + "test": { "jcr:resource": {}, "resource": { "x" : {}}}
 
 select * from [nt:base] where id = -1
 
@@ -54,10 +71,10 @@ select * from [nt:base] as x where isdes
 /test/resource
 /test/resource/x
 
-- "test"
+commit / - "test"
 
-+ "parents": { "p0": {"id": "0"}, "p1": {"id": "1"}, "p2": {"id": "2"}}
-+ "children": { "c1": {"p": "1"}, "c2": {"p": "1"}, "c3": {"p": "2"}, "c4": {"p": "3"}}
+commit / + "parents": { "p0": {"id": "0"}, "p1": {"id": "1"}, "p2": {"id": "2"}}
+commit / + "children": { "c1": {"p": "1"}, "c2": {"p": "1"}, "c3": {"p": "2"}, "c4": {"p":
"3"}}
 
 # relative property
 select * from [nt:base] where [c1/p] = '1'
@@ -117,11 +134,11 @@ select * from [nt:base] as p inner join 
 explain select * from [nt:base] as p inner join [nt:base] as c on p.id = c.p
 nt:base AS p /* traverse "//*" */ INNER JOIN nt:base AS c /* traverse "//*" */
 
-- "parents"
-- "children"
+commit / - "parents"
+commit / - "children"
 
-+ "test": { "hello": { "x": "1" }, "world": { "x": "2" } }
-+ "test2": { "id":"1", "x": "2" }
+commit / + "test": { "hello": { "x": "1" }, "world": { "x": "2" } }
+commit / + "test2": { "id":"1", "x": "2" }
 
 select * from [nt:base]
 /
@@ -155,14 +172,14 @@ select * from [nt:base] where x is null
 /jcr:system/indexes
 /test
 
-- "test"
-- "test2"
+commit / - "test"
+commit / - "test2"
 
-+ "test": { "name": "hello" }
-+ "test2": { "name": "World!" }
-+ "test3": { "name": "Hallo" }
-+ "test4": { "name": "10%" }
-+ "test5": { "name": "10 percent" }
+commit / + "test": { "name": "hello" }
+commit / + "test2": { "name": "World!" }
+commit / + "test3": { "name": "Hallo" }
+commit / + "test4": { "name": "10%" }
+commit / + "test5": { "name": "10 percent" }
 
 select name from [nt:base] order by upper(name)
 10 percent



Mime
View raw message