Search in sources :

Example 11 with ChildNodeEntry

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

the class DocumentNodeStoreTest method childNodeEntries.

@Test
public void childNodeEntries() throws Exception {
    final AtomicInteger counter = new AtomicInteger();
    DocumentStore docStore = new MemoryDocumentStore() {

        @Nonnull
        @Override
        public <T extends Document> List<T> query(Collection<T> collection, String fromKey, String toKey, int limit) {
            counter.incrementAndGet();
            return super.query(collection, fromKey, toKey, limit);
        }
    };
    DocumentNodeStore store = builderProvider.newBuilder().setDocumentStore(docStore).getNodeStore();
    NodeBuilder root = store.getRoot().builder();
    for (int i = 0; i < 10; i++) {
        root.child("node-" + i);
    }
    store.merge(root, EmptyHook.INSTANCE, CommitInfo.EMPTY);
    counter.set(0);
    // the commit and not use a query on the document store (OAK-1322)
    for (ChildNodeEntry e : store.getRoot().getChildNodeEntries()) {
        e.getNodeState();
    }
    assertEquals(0, counter.get());
}
Also used : MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) MemoryDocumentStore(org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore) CONSTRAINT(org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) Test(org.junit.Test)

Example 12 with ChildNodeEntry

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

the class TypePredicate method isOrderable.

@Nonnull
public static TypePredicate isOrderable(@Nonnull NodeState root) {
    Set<String> orderable = newHashSet();
    NodeState types = checkNotNull(root).getChildNode(JCR_SYSTEM).getChildNode(JCR_NODE_TYPES);
    for (ChildNodeEntry entry : types.getChildNodeEntries()) {
        NodeState type = entry.getNodeState();
        if (type.getBoolean(JCR_HASORDERABLECHILDNODES)) {
            orderable.add(entry.getName());
        }
    }
    return new TypePredicate(root, orderable);
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) Nonnull(javax.annotation.Nonnull)

Example 13 with ChildNodeEntry

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

the class ReadWriteVersionManager method isEmptyHistory.

/**
     * Checks whether the passed node history hasn't been modified since its
     * creation. It means that: (1) there's just one version, called jcr:rootVersion
     * and (2) there are no custom labels.
     *
     * @param versionHistory to test
     * @return {@code true} if the version history hasn't been changed yet
     */
private boolean isEmptyHistory(NodeState versionHistory) {
    for (ChildNodeEntry entry : versionHistory.getChildNodeEntries()) {
        String name = entry.getName();
        NodeState node = entry.getNodeState();
        if (!JCR_ROOTVERSION.equals(name) && isVersion.apply(node)) {
            // a checked-in version
            return false;
        }
    }
    NodeState labels = versionHistory.getChildNode(JCR_VERSIONLABELS);
    for (PropertyState prop : labels.getProperties()) {
        if (prop.getType() == Type.REFERENCE) {
            // custom label
            return false;
        }
    }
    return true;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 14 with ChildNodeEntry

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

the class NodeStoreTree method filterNodeStates.

private static void filterNodeStates(Set<UUID> uuids, List<String> paths, NodeState state, String path, ExplorerBackend store) {
    Set<String> localPaths = newTreeSet();
    for (PropertyState ps : state.getProperties()) {
        if (store.isPersisted(ps)) {
            String recordId = store.getRecordId(ps);
            UUID id = store.getSegmentId(ps);
            if (uuids.contains(id)) {
                if (ps.getType().tag() == STRING) {
                    String val = "";
                    if (ps.count() > 0) {
                        // only shows the first value, do we need more?
                        val = displayString(ps.getValue(Type.STRING, 0));
                    }
                    localPaths.add(path + ps.getName() + " = " + val + " [SegmentPropertyState<" + ps.getType() + ">@" + recordId + "]");
                } else {
                    localPaths.add(path + ps + " [SegmentPropertyState<" + ps.getType() + ">@" + recordId + "]");
                }
            }
            if (ps.getType().tag() == BINARY) {
                // look for extra segment references
                for (int i = 0; i < ps.count(); i++) {
                    Blob b = ps.getValue(Type.BINARY, i);
                    for (Entry<UUID, String> e : store.getBulkSegmentIds(b).entrySet()) {
                        if (!e.getKey().equals(id) && uuids.contains(e.getKey())) {
                            localPaths.add(path + ps + " [SegmentPropertyState<" + ps.getType() + ">@" + recordId + "]");
                        }
                    }
                }
            }
        }
    }
    String stateId = store.getRecordId(state);
    if (uuids.contains(store.getSegmentId(state))) {
        localPaths.add(path + " [SegmentNodeState@" + stateId + "]");
    }
    String templateId = store.getTemplateRecordId(state);
    if (uuids.contains(store.getTemplateSegmentId(state))) {
        localPaths.add(path + "[Template@" + templateId + "]");
    }
    paths.addAll(localPaths);
    for (ChildNodeEntry ce : state.getChildNodeEntries()) {
        filterNodeStates(uuids, paths, ce.getNodeState(), path + ce.getName() + "/", store);
    }
}
Also used : Blob(org.apache.jackrabbit.oak.api.Blob) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) UUID(java.util.UUID) JsopBuilder.prettyPrint(org.apache.jackrabbit.oak.commons.json.JsopBuilder.prettyPrint) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 15 with ChildNodeEntry

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

the class ModifiedNodeState method squeeze.

/**
     * "Squeezes" {@link ModifiedNodeState} instances into equivalent
     * {@link MemoryNodeState}s. Other kinds of states are returned as-is.
     */
public static NodeState squeeze(NodeState state) {
    if (state instanceof ModifiedNodeState) {
        Map<String, PropertyState> properties = newHashMap();
        for (PropertyState property : state.getProperties()) {
            properties.put(property.getName(), property);
        }
        Map<String, NodeState> nodes = newHashMap();
        for (ChildNodeEntry child : state.getChildNodeEntries()) {
            nodes.put(child.getName(), squeeze(child.getNodeState()));
        }
        state = new MemoryNodeState(properties, nodes);
    }
    return state;
}
Also used : AbstractNodeState(org.apache.jackrabbit.oak.spi.state.AbstractNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Aggregations

ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)58 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)43 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)19 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)16 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)6 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)6 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)4 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 VersionGCStats (org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats)3 Clock (org.apache.jackrabbit.oak.stats.Clock)3 Map (java.util.Map)2 UUID (java.util.UUID)2 CheckForNull (javax.annotation.CheckForNull)2 Blob (org.apache.jackrabbit.oak.api.Blob)2 CommitFailedException (org.apache.jackrabbit.oak.api.CommitFailedException)2 CONSTRAINT (org.apache.jackrabbit.oak.api.CommitFailedException.CONSTRAINT)2 JsopBuilder.prettyPrint (org.apache.jackrabbit.oak.commons.json.JsopBuilder.prettyPrint)2 MemoryChildNodeEntry (org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry)2