Search in sources :

Example 56 with ChildNodeEntry

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

the class JsonSerializer method serialize.

public void serialize(NodeState node) {
    json.object();
    for (PropertyState property : node.getProperties()) {
        String name = property.getName();
        if (filter.includeProperty(name)) {
            json.key(name);
            serialize(property);
        }
    }
    if (filter.includeProperty(":childNodeCount")) {
        json.key(":childNodeCount");
        json.value(node.getChildNodeCount(Integer.MAX_VALUE));
    }
    int index = 0;
    int count = 0;
    for (ChildNodeEntry child : node.getChildNodeEntries()) {
        String name = child.getName();
        if (filter.includeNode(name) && index++ >= offset) {
            if (count++ >= maxChildNodes) {
                break;
            }
            json.key(name);
            if (depth > 0) {
                getChildSerializer().serialize(child.getNodeState());
            } else {
                json.object();
                json.endObject();
            }
        }
    }
    json.endObject();
}
Also used : ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 57 with ChildNodeEntry

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

the class MemoryNodeState method wrap.

static MemoryNodeState wrap(NodeState state) {
    if (state instanceof MemoryNodeState) {
        return (MemoryNodeState) state;
    }
    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(), child.getNodeState());
    }
    return new MemoryNodeState(properties, nodes);
}
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)

Example 58 with ChildNodeEntry

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

the class MemoryNodeState method compareAgainstBaseState.

/**
     * We don't keep track of a separate base node state for
     * {@link MemoryNodeState} instances, so this method will just do
     * a generic diff against the given state.
     */
@Override
public boolean compareAgainstBaseState(NodeState base, NodeStateDiff diff) {
    if (base == EMPTY_NODE || !base.exists()) {
        return EmptyNodeState.compareAgainstEmptyState(this, diff);
    }
    Map<String, PropertyState> newProperties = new HashMap<String, PropertyState>(properties);
    for (PropertyState before : base.getProperties()) {
        PropertyState after = newProperties.remove(before.getName());
        if (after == null) {
            if (!diff.propertyDeleted(before)) {
                return false;
            }
        } else if (!after.equals(before)) {
            if (!diff.propertyChanged(before, after)) {
                return false;
            }
        }
    }
    for (PropertyState after : newProperties.values()) {
        if (!diff.propertyAdded(after)) {
            return false;
        }
    }
    Map<String, NodeState> newNodes = new HashMap<String, NodeState>(nodes);
    for (ChildNodeEntry entry : base.getChildNodeEntries()) {
        String name = entry.getName();
        NodeState before = entry.getNodeState();
        NodeState after = newNodes.remove(name);
        if (after == null) {
            if (!diff.childNodeDeleted(name, before)) {
                return false;
            }
        } else if (after != before) {
            if (!diff.childNodeChanged(name, before, after)) {
                return false;
            }
        }
    }
    for (Map.Entry<String, NodeState> entry : newNodes.entrySet()) {
        if (!diff.childNodeAdded(entry.getKey(), entry.getValue())) {
            return false;
        }
    }
    return true;
}
Also used : AbstractNodeState(org.apache.jackrabbit.oak.spi.state.AbstractNodeState) NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) HashMap(java.util.HashMap) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) Map(java.util.Map) HashMap(java.util.HashMap) 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