@Override @NotNull public List<QueryIndex> getQueryIndexes(NodeState state) { return ImmutableList.<QueryIndex> of(new ReferenceIndex(mountInfoProvider)); }
@Override public Cursor query(Filter filter, NodeState root) { for (PropertyRestriction pr : filter.getPropertyRestrictions()) { if (isEqualityRestrictionOnType(pr, REFERENCE)) { String uuid = pr.first.getValue(STRING); String name = pr.propertyName; return lookup(root, uuid, name, REF_NAME, filter); } if (isEqualityRestrictionOnType(pr, WEAKREFERENCE)) { String uuid = pr.first.getValue(STRING); String name = pr.propertyName; return lookup(root, uuid, name, WEAK_REF_NAME, filter); } } return newPathCursor(new ArrayList<String>(), filter.getQueryLimits()); }
@Override public double getCost(Filter filter, NodeState root) { // TODO don't call getCost for such queries if (filter.getFullTextConstraint() != null) { // not an appropriate index for full-text search return POSITIVE_INFINITY; } if (filter.containsNativeConstraint()) { // not an appropriate index for native search return Double.POSITIVE_INFINITY; } for (PropertyRestriction pr : filter.getPropertyRestrictions()) { if (isEqualityRestrictionOnType(pr, REFERENCE) || isEqualityRestrictionOnType(pr, WEAKREFERENCE)) { return COST; } } // not an appropriate index return POSITIVE_INFINITY; }
private Cursor lookup(NodeState root, String uuid, final String name, String index, Filter filter) { NodeState indexRoot = root.getChildNode(INDEX_DEFINITIONS_NAME) .getChildNode(NAME); if (!indexRoot.exists()) { return newPathCursor(new ArrayList<String>(), filter.getQueryLimits()); } List<Iterable<String>> iterables = Lists.newArrayList(); for (IndexStoreStrategy s : getStrategies(indexRoot, mountInfoProvider, index)) { iterables.add(s.query(filter, index + "(" + uuid + ")", indexRoot, ImmutableSet.of(uuid))); } Iterable<String> paths = Iterables.concat(iterables); if (!"*".equals(name)) { paths = filter(paths, new Predicate<String>() { @Override public boolean apply(String path) { return name.equals(getName(path)); } }); } paths = transform(paths, new Function<String, String>() { @Override public String apply(String path) { return getParentPath(path); } }); return newPathCursor(paths, filter.getQueryLimits()); }
@Override public double getCost(Filter filter, NodeState root) { // TODO don't call getCost for such queries if (filter.getFullTextConstraint() != null) { // not an appropriate index for full-text search return POSITIVE_INFINITY; } if (filter.containsNativeConstraint()) { // not an appropriate index for native search return Double.POSITIVE_INFINITY; } for (PropertyRestriction pr : filter.getPropertyRestrictions()) { if (isEqualityRestrictionOnType(pr, REFERENCE) || isEqualityRestrictionOnType(pr, WEAKREFERENCE)) { return COST; } } // not an appropriate index return POSITIVE_INFINITY; }
private Cursor lookup(NodeState root, String uuid, final String name, String index, Filter filter) { NodeState indexRoot = root.getChildNode(INDEX_DEFINITIONS_NAME) .getChildNode(NAME); if (!indexRoot.exists()) { return newPathCursor(new ArrayList<String>(), filter.getQueryLimits()); } List<Iterable<String>> iterables = Lists.newArrayList(); for (IndexStoreStrategy s : getStrategies(indexRoot, mountInfoProvider, index)) { iterables.add(s.query(filter, index + "(" + uuid + ")", indexRoot, ImmutableSet.of(uuid))); } Iterable<String> paths = Iterables.concat(iterables); if (!"*".equals(name)) { paths = filter(paths, new Predicate<String>() { @Override public boolean apply(String path) { return name.equals(getName(path)); } }); } paths = transform(paths, new Function<String, String>() { @Override public String apply(String path) { return getParentPath(path); } }); return newPathCursor(paths, filter.getQueryLimits()); }
@Override public Cursor query(Filter filter, NodeState root) { for (PropertyRestriction pr : filter.getPropertyRestrictions()) { if (isEqualityRestrictionOnType(pr, REFERENCE)) { String uuid = pr.first.getValue(STRING); String name = pr.propertyName; return lookup(root, uuid, name, REF_NAME, filter); } if (isEqualityRestrictionOnType(pr, WEAKREFERENCE)) { String uuid = pr.first.getValue(STRING); String name = pr.propertyName; return lookup(root, uuid, name, WEAK_REF_NAME, filter); } } return newPathCursor(new ArrayList<String>(), filter.getQueryLimits()); }
@Override @Nonnull public List<QueryIndex> getQueryIndexes(NodeState state) { return ImmutableList.<QueryIndex> of(new ReferenceIndex(mountInfoProvider)); }
@Override public double getCost(Filter filter, NodeState root) { // TODO don't call getCost for such queries if (filter.getFullTextConstraint() != null) { // not an appropriate index for full-text search return POSITIVE_INFINITY; } if (filter.containsNativeConstraint()) { // not an appropriate index for native search return Double.POSITIVE_INFINITY; } for (PropertyRestriction pr : filter.getPropertyRestrictions()) { if (isEqualityRestrictionOnType(pr, REFERENCE) || isEqualityRestrictionOnType(pr, WEAKREFERENCE)) { return COST; } } // not an appropriate index return POSITIVE_INFINITY; }
private Cursor lookup(NodeState root, String uuid, final String name, String index, Filter filter) { NodeState indexRoot = root.getChildNode(INDEX_DEFINITIONS_NAME) .getChildNode(NAME); if (!indexRoot.exists()) { return newPathCursor(new ArrayList<String>(), filter.getQueryLimits()); } List<Iterable<String>> iterables = Lists.newArrayList(); for (IndexStoreStrategy s : getStrategies(indexRoot, mountInfoProvider, index)) { iterables.add(s.query(filter, index + "(" + uuid + ")", indexRoot, ImmutableSet.of(uuid))); } Iterable<String> paths = Iterables.concat(iterables); if (!"*".equals(name)) { paths = filter(paths, new Predicate<String>() { @Override public boolean apply(String path) { return name.equals(getName(path)); } }); } paths = transform(paths, new Function<String, String>() { @Override public String apply(String path) { return getParentPath(path); } }); return newPathCursor(paths, filter.getQueryLimits()); }
@Override public Cursor query(Filter filter, NodeState root) { for (PropertyRestriction pr : filter.getPropertyRestrictions()) { if (isEqualityRestrictionOnType(pr, REFERENCE)) { String uuid = pr.first.getValue(STRING); String name = pr.propertyName; return lookup(root, uuid, name, REF_NAME, filter); } if (isEqualityRestrictionOnType(pr, WEAKREFERENCE)) { String uuid = pr.first.getValue(STRING); String name = pr.propertyName; return lookup(root, uuid, name, WEAK_REF_NAME, filter); } } return newPathCursor(new ArrayList<String>(), filter.getQueryLimits()); }
@Override @NotNull public List<QueryIndex> getQueryIndexes(NodeState state) { return ImmutableList.<QueryIndex> of(new ReferenceIndex(mountInfoProvider)); }
@Test public void basicReferenceHandling() throws Exception{ NodeState root = INITIAL_CONTENT; NodeBuilder builder = root.builder(); NodeState before = builder.getNodeState(); builder.child("a").setProperty(createProperty("foo", "u1", Type.REFERENCE)); builder.child("b").setProperty(createProperty("foo", "u1", Type.REFERENCE)); builder.child("c").setProperty(createProperty("foo", "u2", Type.WEAKREFERENCE)); NodeState after = builder.getNodeState(); EditorHook hook = new EditorHook( new IndexUpdateProvider(new ReferenceEditorProvider())); NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY); FilterImpl f = createFilter(indexed, NT_BASE); f.restrictProperty("*", Operator.EQUAL, newReference("u1"), PropertyType.REFERENCE); assertFilter(f, new ReferenceIndex(), indexed, of("/a", "/b")); FilterImpl f2 = createFilter(indexed, NT_BASE); f2.restrictProperty("*", Operator.EQUAL, newReference("u2"), PropertyType.WEAKREFERENCE); assertFilter(f2, new ReferenceIndex(), indexed, of("/c")); }
@Test public void referenceHandlingWithMounts() throws Exception{ NodeState root = INITIAL_CONTENT; NodeBuilder builder = root.builder(); NodeState before = builder.getNodeState(); builder.child("a").child("x").setProperty(createProperty("foo", "u1", Type.REFERENCE)); builder.child("b").setProperty(createProperty("foo", "u1", Type.REFERENCE)); builder.child("c").setProperty(createProperty("foo", "u1", Type.WEAKREFERENCE)); builder.child("d").setProperty(createProperty("foo", "u2", Type.WEAKREFERENCE)); builder.child("a").child("y").setProperty(createProperty("foo", "u1", Type.WEAKREFERENCE)); NodeState after = builder.getNodeState(); MountInfoProvider mip = Mounts.newBuilder() .mount("foo", "/a") .build(); EditorHook hook = new EditorHook( new IndexUpdateProvider(new ReferenceEditorProvider().with(mip))); ReferenceIndex referenceIndex = new ReferenceIndex(mip); NodeState indexed = hook.processCommit(before, after, CommitInfo.EMPTY); FilterImpl f = createFilter(indexed, NT_BASE); f.restrictProperty("*", Operator.EQUAL, newReference("u1"), PropertyType.REFERENCE); // System.out.println(NodeStateUtils.toString(NodeStateUtils.getNode(indexed, "/oak:index/reference"))); assertFilter(f, referenceIndex, indexed, of("/a/x", "/b")); FilterImpl f2 = createFilter(indexed, NT_BASE); f2.restrictProperty("*", Operator.EQUAL, newReference("u1"), PropertyType.WEAKREFERENCE); assertFilter(f2, referenceIndex, indexed, of("/c", "/a/y")); }