Search in sources :

Example 61 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)

Example 62 with ChildNodeEntry

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

the class EffectiveType method getDefinition.

/**
 * Finds a matching definition for a property with the given name and type.
 *
 * @param property modified property
 * @return matching property definition, or {@code null}
 */
@CheckForNull
NodeState getDefinition(@Nonnull PropertyState property) {
    String propertyName = property.getName();
    Type<?> propertyType = property.getType();
    String escapedName;
    if (JCR_PRIMARYTYPE.equals(propertyName)) {
        escapedName = NodeTypeConstants.REP_PRIMARY_TYPE;
    } else if (JCR_MIXINTYPES.equals(propertyName)) {
        escapedName = NodeTypeConstants.REP_MIXIN_TYPES;
    } else if (JCR_UUID.equals(propertyName)) {
        escapedName = NodeTypeConstants.REP_UUID;
    } else {
        escapedName = propertyName;
    }
    String definedType = propertyType.toString();
    String undefinedType;
    if (propertyType.isArray()) {
        undefinedType = UNDEFINEDS.toString();
    } else {
        undefinedType = UNDEFINED.toString();
    }
    // Find matching named property definition
    for (NodeState type : types) {
        NodeState definitions = type.getChildNode(REP_NAMED_PROPERTY_DEFINITIONS).getChildNode(escapedName);
        NodeState definition = definitions.getChildNode(definedType);
        if (definition.exists()) {
            return definition;
        }
        definition = definitions.getChildNode(undefinedType);
        if (definition.exists()) {
            return definition;
        }
        // TODO: unnecessary if the OAK-713 fallback wasn't needed below
        for (ChildNodeEntry entry : definitions.getChildNodeEntries()) {
            definition = entry.getNodeState();
            if (definition.getBoolean(JCR_MANDATORY)) {
                return definition;
            }
        }
    // TODO: Fall back to residual definitions until we have consensus on OAK-713
    // throw new ConstraintViolationException(
    // "No matching definition found for property " + propertyName);
    }
    // Find matching residual property definition
    for (NodeState type : types) {
        NodeState residual = type.getChildNode(REP_RESIDUAL_PROPERTY_DEFINITIONS);
        NodeState definition = residual.getChildNode(definedType);
        if (!definition.exists()) {
            definition = residual.getChildNode(undefinedType);
        }
        if (definition.exists()) {
            return definition;
        }
    }
    return null;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) CheckForNull(javax.annotation.CheckForNull)

Example 63 with ChildNodeEntry

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

the class EffectiveType method isValidChildNode.

/**
 * Finds a matching definition for a child node with the given name and
 * types.
 *
 * @param nameWithIndex child node name, possibly with an SNS index
 * @param effective effective types of the child node
 * @return {@code true} if there's a matching child node definition,
 *         {@code false} otherwise
 */
boolean isValidChildNode(@Nonnull String nameWithIndex, @Nonnull EffectiveType effective) {
    String name = dropIndexFromName(nameWithIndex);
    boolean sns = !name.equals(nameWithIndex);
    Set<String> typeNames = effective.getTypeNames();
    // Find matching named child node definition
    for (NodeState type : types) {
        NodeState definitions = type.getChildNode(REP_NAMED_CHILD_NODE_DEFINITIONS).getChildNode(name);
        for (String typeName : typeNames) {
            NodeState definition = definitions.getChildNode(typeName);
            if (definition.exists() && snsMatch(sns, definition)) {
                return true;
            }
        }
        // TODO: unnecessary if the OAK-713 fallback wasn't needed below
        for (ChildNodeEntry entry : definitions.getChildNodeEntries()) {
            NodeState definition = entry.getNodeState();
            if (definition.getBoolean(JCR_MANDATORY)) {
                return false;
            }
        }
    // TODO: Fall back to residual definitions until we have consensus on OAK-713
    // throw new ConstraintViolationException(
    // "Incorrect node type of child node " + nodeName);
    }
    // Find matching residual child node definition
    for (NodeState type : types) {
        NodeState residual = type.getChildNode(REP_RESIDUAL_CHILD_NODE_DEFINITIONS);
        for (String typeName : typeNames) {
            NodeState definition = residual.getChildNode(typeName);
            if (definition.exists() && snsMatch(sns, definition)) {
                return true;
            }
        }
    }
    return false;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)

Example 64 with ChildNodeEntry

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

the class PropertyIndexInfoProvider method computeCountEstimate.

private void computeCountEstimate(PropertyIndexInfo info, NodeState idxState) {
    long count = -1;
    for (ChildNodeEntry cne : idxState.getChildNodeEntries()) {
        // In multiplexing setups there can be multiple index nodes
        if (NodeStateUtils.isHidden(cne.getName())) {
            NodeState indexData = cne.getNodeState();
            long estimate = ApproximateCounter.getCountSync(indexData);
            if (estimate > 0) {
                if (count < 0) {
                    count = 0;
                }
                count += estimate;
            } else if (count < 0 && indexData.getChildNodeCount(1) == 0) {
                // If we cannot get estimate then at least try to see if any index data is there or not
                count = 0;
            }
        }
    }
    info.estimatedCount = count;
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)

Example 65 with ChildNodeEntry

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

the class CheckpointCompactorTest method checkGeneration.

private static void checkGeneration(NodeState node, GCGeneration gcGeneration) {
    assertTrue(node instanceof SegmentNodeState);
    assertEquals(gcGeneration, ((SegmentNodeState) node).getRecordId().getSegmentId().getGcGeneration());
    for (ChildNodeEntry cne : node.getChildNodeEntries()) {
        checkGeneration(cne.getNodeState(), gcGeneration);
    }
}
Also used : ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)

Aggregations

ChildNodeEntry (org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)80 NodeState (org.apache.jackrabbit.oak.spi.state.NodeState)58 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)23 PropertyState (org.apache.jackrabbit.oak.api.PropertyState)18 Test (org.junit.Test)17 ArrayList (java.util.ArrayList)7 MemoryDocumentStore (org.apache.jackrabbit.oak.plugins.document.memory.MemoryDocumentStore)6 EmptyNodeState (org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState)6 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 MemoryChildNodeEntry (org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry)4 AbstractNodeState (org.apache.jackrabbit.oak.spi.state.AbstractNodeState)4 Calendar (java.util.Calendar)3 VersionGCStats (org.apache.jackrabbit.oak.plugins.document.VersionGarbageCollector.VersionGCStats)3 SegmentNodeState (org.apache.jackrabbit.oak.segment.SegmentNodeState)3 Clock (org.apache.jackrabbit.oak.stats.Clock)3 Iterator (java.util.Iterator)2 Map (java.util.Map)2 UUID (java.util.UUID)2 CheckForNull (javax.annotation.CheckForNull)2 Nonnull (javax.annotation.Nonnull)2