Search in sources :

Example 21 with NodeState

use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.

the class PropertyIndexInfoProvider method getInfo.

@Override
public IndexInfo getInfo(String indexPath) throws IOException {
    NodeState idxState = NodeStateUtils.getNode(nodeStore.getRoot(), indexPath);
    checkArgument(PropertyIndexEditorProvider.TYPE.equals(idxState.getString(IndexConstants.TYPE_PROPERTY_NAME)), "Index definition at [%s] is not of type 'property'", indexPath);
    PropertyIndexInfo info = new PropertyIndexInfo(indexPath);
    computeCountEstimate(info, idxState);
    return info;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState)

Example 22 with NodeState

use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.

the class UniqueEntryStoreStrategy method query.

@Override
public Iterable<String> query(final Filter filter, final String indexName, final NodeState indexMeta, final Iterable<String> values) {
    final NodeState index = indexMeta.getChildNode(getIndexNodeName());
    return new Iterable<String>() {

        @Override
        public Iterator<String> iterator() {
            if (values == null) {
                return new Iterator<String>() {

                    Iterator<? extends ChildNodeEntry> it = index.getChildNodeEntries().iterator();

                    @Override
                    public boolean hasNext() {
                        return it.hasNext();
                    }

                    @Override
                    public String next() {
                        PropertyState s = it.next().getNodeState().getProperty("entry");
                        return s.getValue(Type.STRING, 0);
                    }

                    @Override
                    public void remove() {
                        it.remove();
                    }
                };
            }
            ArrayList<String> list = new ArrayList<String>();
            for (String p : values) {
                NodeState key = index.getChildNode(p);
                if (key.exists()) {
                    // we have an entry for this value, so use it
                    PropertyState s = key.getProperty("entry");
                    String v = s.getValue(Type.STRING, 0);
                    list.add(v);
                }
            }
            return list.iterator();
        }
    };
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) MultiStringPropertyState(org.apache.jackrabbit.oak.plugins.memory.MultiStringPropertyState) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 23 with NodeState

use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.

the class NodeCounter method collectCounts.

private void collectCounts(StringBuilder buff, String path, int level) {
    long count = getEstimatedNodeCount(path);
    if (count > 0) {
        if (buff.length() > 0) {
            buff.append(",\n");
        }
        buff.append(path).append(": ").append(count);
    }
    if (level <= 0) {
        return;
    }
    NodeState s = child(store.getRoot(), PathUtils.elements(path));
    if (!s.exists()) {
        return;
    }
    ArrayList<String> names = new ArrayList<String>();
    for (ChildNodeEntry c : s.getChildNodeEntries()) {
        names.add(c.getName());
    }
    Collections.sort(names);
    for (String cn : names) {
        s.getChildNode(cn);
        String child = PathUtils.concat(path, cn);
        collectCounts(buff, child, level - 1);
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) ArrayList(java.util.ArrayList)

Example 24 with NodeState

use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.

the class NodeTypePredicateTest method multipleNodeTypesMatch.

@Test
public void multipleNodeTypesMatch() {
    NodeState node = createNodeOfType(NT_FILE);
    TypePredicate p = new TypePredicate(node, new String[] { NT_FOLDER, NT_RESOURCE, NT_FILE });
    assertTrue(p.apply(node));
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) TypePredicate(org.apache.jackrabbit.oak.plugins.nodetype.TypePredicate) Test(org.junit.Test)

Example 25 with NodeState

use of org.apache.jackrabbit.oak.spi.state.NodeState in project jackrabbit-oak by apache.

the class NodeTypePredicateTest method multipleNodeTypesMiss.

@Test
public void multipleNodeTypesMiss() {
    NodeState node = createNodeOfType(NT_FILE);
    TypePredicate p = new TypePredicate(node, new String[] { NT_FOLDER, NT_RESOURCE, JCR_CONTENT });
    assertFalse(p.apply(node));
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) TypePredicate(org.apache.jackrabbit.oak.plugins.nodetype.TypePredicate) Test(org.junit.Test)

Aggregations

NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)779 Test (org.junit.Test)498 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)335 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)94 ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)61 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)60 FilterImpl (org.apache.jackrabbit.oak.query.index.FilterImpl)54 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)48 EditorHook (org.apache.jackrabbit.oak.spi.commit.EditorHook)46 NodeStore (org.apache.jackrabbit.oak.spi.state.NodeStore)41 MemoryNodeStore (org.apache.jackrabbit.oak.plugins.memory.MemoryNodeStore)36 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)33 Nonnull (javax.annotation.Nonnull)32 Tree (org.apache.jackrabbit.oak.api.Tree)29 ArrayList (java.util.ArrayList)25 NodeStateTestUtils.getNodeState (org.apache.jackrabbit.oak.plugins.migration.NodeStateTestUtils.getNodeState)23 NodeStateTestUtils.getNodeState (org.apache.jackrabbit.oak.upgrade.util.NodeStateTestUtils.getNodeState)23 DocumentNodeState (org.apache.jackrabbit.oak.plugins.document.DocumentNodeState)22 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)22 CommitInfo (org.apache.jackrabbit.oak.spi.commit.CommitInfo)17