Search in sources :

Example 41 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 42 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 43 with ChildNodeEntry

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

the class BlobMigrator method migrateNode.

private void migrateNode(NodeBuilder rootBuilder, DepthFirstNodeIterator iterator) throws IOException {
    ChildNodeEntry node = iterator.next();
    NodeState state = node.getNodeState();
    for (PropertyState property : state.getProperties()) {
        PropertyState newProperty;
        if (property.getType() == Type.BINARY) {
            newProperty = migrateProperty(property);
        } else if (property.getType() == Type.BINARIES) {
            newProperty = migrateMultiProperty(property);
        } else {
            newProperty = null;
        }
        if (newProperty != null) {
            NodeBuilder builder = iterator.getBuilder(rootBuilder);
            if (builder.exists()) {
                builder.setProperty(newProperty);
                migratedNodes++;
                log.debug("Migrated property {}/{}", lastPath, property.getName());
            } else {
                log.warn("Can't migrate blobs for a non-existing node: {}", lastPath);
            }
        }
    }
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) NodeBuilder(org.apache.jackrabbit.oak.spi.state.NodeBuilder) PropertyState(org.apache.jackrabbit.oak.api.PropertyState)

Example 44 with ChildNodeEntry

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

the class DepthFirstNodeIterator method computeNext.

@Override
protected ChildNodeEntry computeNext() {
    if (itQueue.isEmpty()) {
        return endOfData();
    }
    if (itQueue.peekLast().hasNext()) {
        ChildNodeEntry next = itQueue.peekLast().next();
        itQueue.add(next.getNodeState().getChildNodeEntries().iterator());
        nameQueue.add(next.getName());
        return next;
    } else {
        itQueue.pollLast();
        if (!nameQueue.isEmpty()) {
            nameQueue.pollLast();
        }
        return computeNext();
    }
}
Also used : ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry)

Example 45 with ChildNodeEntry

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

the class ConflictValidator method getConflictMessage.

private String getConflictMessage() {
    StringBuilder sb = new StringBuilder("Commit failed due to unresolved conflicts in ");
    sb.append(path);
    sb.append(" = {");
    for (ChildNodeEntry conflict : after.getChildNode(NodeTypeConstants.REP_OURS).getChildNodeEntries()) {
        ConflictType ct = ConflictType.fromName(conflict.getName());
        NodeState node = conflict.getNodeState();
        sb.append(ct.getName()).append(" = {");
        if (ct.effectsNode()) {
            sb.append(getChildNodeNamesAsString(node));
        } else {
            for (PropertyState ps : node.getProperties()) {
                PropertyState ours = null, theirs = null;
                switch(ct) {
                    case DELETE_CHANGED_PROPERTY:
                        ours = null;
                        theirs = ps;
                        break;
                    case ADD_EXISTING_PROPERTY:
                    case CHANGE_CHANGED_PROPERTY:
                        ours = ps;
                        theirs = after.getProperty(ps.getName());
                        break;
                    case CHANGE_DELETED_PROPERTY:
                        ours = ps;
                        theirs = null;
                        break;
                }
                sb.append(ps.getName()).append(" = {").append(toString(ours)).append(',').append(toString(theirs)).append('}');
                sb.append(',');
            }
            sb.deleteCharAt(sb.length() - 1);
        }
        sb.append("},");
    }
    sb.deleteCharAt(sb.length() - 1);
    sb.append('}');
    return sb.toString();
}
Also used : NodeState(org.apache.jackrabbit.oak.spi.state.NodeState) ChildNodeEntry(org.apache.jackrabbit.oak.spi.state.ChildNodeEntry) ConflictType(org.apache.jackrabbit.oak.spi.state.ConflictType) 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