You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by re...@apache.org on 2025/12/15 17:08:43 UTC

(jackrabbit-filevault) 01/01: POC

This is an automated email from the ASF dual-hosted git repository.

reschke pushed a commit to branch JCRVLT-831-poc
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git

commit 41c73d7f4657976570402e4efcb3d0efcda196b5
Author: Julian Reschke <re...@apache.org>
AuthorDate: Mon Dec 15 18:08:23 2025 +0100

    POC
---
 .../apache/jackrabbit/vault/fs/api/FilterSet.java  |  2 +-
 .../jackrabbit/vault/fs/impl/AggregateImpl.java    | 80 ++++++----------------
 2 files changed, 23 insertions(+), 59 deletions(-)

diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/FilterSet.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/FilterSet.java
index b2a507f9..48de2c73 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/FilterSet.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/FilterSet.java
@@ -302,7 +302,7 @@ public abstract class FilterSet<E extends Filter> implements Dumpable {
             result = null;
         }
 
-        log.debug("getDirectChildNameTowardsFilterRoot(root={}, path={}) -> {}", rootMatch, pathMatch, result);
+        log.error("getDirectChildNameTowardsFilterRoot(root={}, path={}) -> {}", rootMatch, pathMatch, result);
 
         return result;
     }
diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/AggregateImpl.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/AggregateImpl.java
index 189f614d..7a88e779 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/AggregateImpl.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/AggregateImpl.java
@@ -102,7 +102,7 @@ public class AggregateImpl implements Aggregate {
 
     private List<AggregateImpl> leaves;
 
-    private String[] namespacePrefixes;
+    private Set<String> namespacePrefixes = new HashSet<>();
 
     private char state = STATE_INITIAL;
 
@@ -178,7 +178,7 @@ public class AggregateImpl implements Aggregate {
         includes = null;
         binaries = null;
         leaves = null;
-        namespacePrefixes = null;
+        namespacePrefixes = new HashSet<>();
         nodeRef = null;
         relPath = null;
         state = STATE_INITIAL;
@@ -402,10 +402,7 @@ public class AggregateImpl implements Aggregate {
     }
 
     public String[] getNamespacePrefixes() {
-        if (namespacePrefixes == null) {
-            loadNamespaces();
-        }
-        return namespacePrefixes;
+        return namespacePrefixes.toArray(new String[0]);
     }
 
     public String getNamespaceURI(String prefix) throws RepositoryException {
@@ -455,6 +452,7 @@ public class AggregateImpl implements Aggregate {
             Iterable<Property> properties = new PropertyIterable(node.getProperties());
             for (Property prop : properties) {
                 if (includes(relativePath + "/" + prop.getName())) {
+                    addNamespaceForProperty(prop);
                     aggregateWalkListener.onProperty(prop, depth + 1);
                 }
             }
@@ -525,7 +523,7 @@ public class AggregateImpl implements Aggregate {
                 log.trace("including {} -> {}", path, nodePath);
             }
             if (includes == null) {
-                includes = new HashSet<String>();
+                includes = new HashSet<>();
             }
             includes.add(relPath);
             if (!node.isSame(getNode())) {
@@ -535,28 +533,28 @@ public class AggregateImpl implements Aggregate {
         }
     }
 
-    private void addNamespace(Set<String> prefixes, Property prop) throws RepositoryException {
+    private void addNamespaceForProperty(Property prop) throws RepositoryException {
         String propName = prop.getName();
-        addNamespace(prefixes, propName);
+        addNamespaceForName(propName);
         switch (prop.getType()) {
             case PropertyType.NAME:
                 if ("jcr:mixinTypes".equals(propName) || prop.getDefinition().isMultiple()) {
                     Value[] values = prop.getValues();
                     for (Value value: values) {
-                        addNamespace(prefixes, value.getString());
+                        addNamespaceForName(value.getString());
                     }
                 } else {
-                    addNamespace(prefixes, prop.getValue().getString());
+                    addNamespaceForName(prop.getValue().getString());
                 }
                 break;
             case PropertyType.PATH:
                 if (prop.getDefinition().isMultiple()) {
                     Value[] values = prop.getValues();
                     for (Value value: values) {
-                        addNamespacePath(prefixes, value.getString());
+                        addNamespacesForPath(value.getString());
                     }
                 } else {
-                    addNamespacePath(prefixes, prop.getValue().getString());
+                    addNamespacesForPath(prop.getValue().getString());
                 }
                 break;
         }
@@ -567,7 +565,7 @@ public class AggregateImpl implements Aggregate {
         String relPath = propPath.substring(path.length());
         if (includes == null || !includes.contains(relPath)) {
             if (log.isDebugEnabled()) {
-                log.trace("including {} -> {}", path, propPath);
+                log.debug("including {} -> {}", path, propPath);
             }
             // ensure that parent node is included as well
             include(parent, null);
@@ -601,58 +599,18 @@ public class AggregateImpl implements Aggregate {
         }
     }
 
-    private void addNamespace(Set<String> prefixes, String name) throws RepositoryException {
+    private void addNamespaceForName(String name) {
         int idx = name.indexOf(':');
         if (idx > 0) {
             String pfx = name.substring(0, idx);
-            if (!prefixes.contains(pfx)) {
-                prefixes.add(pfx);
-            }
+            namespacePrefixes.add(pfx);
         }
     }
 
-    private void addNamespacePath(Set<String> prefixes, String path) throws RepositoryException {
+    private void addNamespacesForPath(String path) {
         String[] names = path.split("/");
         for (String name: names) {
-            addNamespace(prefixes, name);
-        }
-    }
-
-    private void loadNamespaces() {
-        if (namespacePrefixes == null) {
-            if (log.isDebugEnabled()) {
-                log.trace("loading namespaces of aggregate {}", path);
-            }
-            try {
-                load();
-                Set<String> prefixes = new HashSet<String>();
-                // need to traverse the nodes to get all namespaces
-                loadNamespaces(prefixes, "", getNode());
-                namespacePrefixes = prefixes.toArray(new String[prefixes.size()]);
-            } catch (RepositoryException e) {
-                throw new IllegalStateException("Internal error while loading namespaces", e);
-            }
-        }
-    }
-
-    private void loadNamespaces(Set<String> prefixes, String parentPath, Node node) throws RepositoryException {
-        String name = node.getName();
-        addNamespace(prefixes, name);
-        for (PropertyIterator iter = node.getProperties(); iter.hasNext();) {
-            Property p = iter.nextProperty();
-            String relPath = parentPath + "/" + p.getName();
-            if (includes(relPath)) {
-                addNamespace(prefixes, p);
-            }
-        }
-        for (NodeIterator iter = node.getNodes(); iter.hasNext();) {
-            Node c = iter.nextNode();
-            String relPath = parentPath + "/" + c.getName();
-            if (includes(relPath)) {
-                loadNamespaces(prefixes, relPath, c);
-            } else if (node.getPrimaryNodeType().hasOrderableChildNodes()) {
-                addNamespace(prefixes, c.getName());
-            }
+            addNamespaceForName(name);
         }
     }
 
@@ -714,12 +672,16 @@ public class AggregateImpl implements Aggregate {
         // get a node iterator suitable for the current node and the applicable filters
         NodeIterator nIter = getNodeIteratorFor(node, filter);
 
+        int visited = 0;
+
         // include "our" nodes to the include set and delegate the others to the
         // respective aggregator building sub aggregates
         while (nIter.hasNext()) {
             Node n = nIter.nextNode();
+            visited += 1;
             String path = n.getPath();
             log.trace("checking {}", path);
+            addNamespacesForPath(path);
 
             PathFilterSet coverSet = filter.getCoveringFilterSet(path);
             boolean isAncestor = filter.isAncestor(path);
@@ -777,6 +739,8 @@ public class AggregateImpl implements Aggregate {
                 }
             }
         }
+
+        log.error("In " + node.getPath() + ", visited " + visited + " siblings");
     }
 
     private static NodeIterator getNodeIteratorFor(Node node, WorkspaceFilter filter) throws RepositoryException {