Package org.apache.jackrabbit.oak.spi.state

Examples of org.apache.jackrabbit.oak.spi.state.NodeState


        boolean sns = !name.equals(nameWithIndex);
        Set<String> typeNames = effective.getTypeNames();

        // Find matching named child node definition
        for (NodeState type : types) {
            NodeState definitions = type
                    .getChildNode(OAK_NAMED_CHILD_NODE_DEFINITIONS)
                    .getChildNode(name);

            for (String typeName : typeNames) {
                NodeState definition = definitions.getChildNode(typeName);
                if (definition.exists() && snsMatch(sns, definition)) {
                    return true;
                }
            }

            // OAK-822: a mandatory definition always overrides alternatives
            // 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(OAK_RESIDUAL_CHILD_NODE_DEFINITIONS);
            for (String typeName : typeNames) {
                NodeState definition = residual.getChildNode(typeName);
                if (definition.exists() && snsMatch(sns, definition)) {
                    return true;
                }
            }
        }
View Full Code Here


    String getDefaultType(String nameWithIndex) {
        String name = dropIndexFromName(nameWithIndex);
        boolean sns = !name.equals(nameWithIndex);

        for (NodeState type : types) {
            NodeState named = type
                    .getChildNode(OAK_NAMED_CHILD_NODE_DEFINITIONS)
                    .getChildNode(name);
            NodeState residual = type
                    .getChildNode(OAK_RESIDUAL_CHILD_NODE_DEFINITIONS);

            for (ChildNodeEntry entry : concat(
                    named.getChildNodeEntries(),
                    residual.getChildNodeEntries())) {
                NodeState definition = entry.getNodeState();
                String defaultType = definition.getName(JCR_DEFAULTPRIMARYTYPE);
                if (defaultType != null && snsMatch(sns, definition)) {
                    return defaultType;
                }
            }
        }
View Full Code Here

            NodeState types, String path,
            String name, String primary, Iterable<String> mixins)
            throws CommitFailedException {
        List<NodeState> list = Lists.newArrayList();

        NodeState type = types.getChildNode(primary);
        if (!type.exists()) {
            throw constraintViolation(
                    1, path, "The primary type " + primary
                    + " of child node " + name + " does not exist");
        } else if (type.getBoolean(JCR_ISMIXIN)) {
            throw constraintViolation(
                    2, path, "Mixin type " + primary
                    + " used as the primary type of child node " + name);
        } else if (type.getBoolean(JCR_IS_ABSTRACT)) {
            throw constraintViolation(
                    3, path, "Abstract type " + primary
                    + " used as the primary type of child node " + name);
        } else {
            list.add(type);
        }

        // mixin types
        for (String mixin : mixins) {
            type = types.getChildNode(mixin);
            if (!type.exists()) {
                throw constraintViolation(
                        5, path, "The mixin type " + mixin
                        + " of child node " + name + " does not exist");
            } else if (!type.getBoolean(JCR_ISMIXIN)) {
                throw constraintViolation(
                        6, path, "Primary type " + mixin
                        + " used as a mixin type of child node " + name);
            } else if (type.getBoolean(JCR_IS_ABSTRACT)) {
                throw constraintViolation(
                        7, path, "Abstract type " + mixin
                        + " used as a mixin type of child node " + name);
            } else {
                list.add(type);
View Full Code Here

    }

    @Override
    public Iterable<String> query(final Filter filter, final String indexName,
            final NodeState indexMeta, final Iterable<String> values) {
        final NodeState index = indexMeta.getChildNode(INDEX_CONTENT_NODE_NAME);
        return new Iterable<String>() {
            @Override
            public Iterator<String> iterator() {
                PathIterator it = new PathIterator(filter, indexName);
                if (values == null) {
                    it.setPathContainsValue(true);
                    it.enqueue(index.getChildNodeEntries().iterator());
                } else {
                    for (String p : values) {
                        NodeState property = index.getChildNode(p);
                        if (property.exists()) {
                            // we have an entry for this value, so use it
                            it.enqueue(Iterators.singletonIterator(
                                    new MemoryChildNodeEntry("", property)));
                        }
                    }
View Full Code Here

        };
    }

    @Override
    public long count(NodeState indexMeta, Set<String> values, int max) {
        NodeState index = indexMeta.getChildNode(INDEX_CONTENT_NODE_NAME);
        int count = 0;
        if (values == null) {
            PropertyState ec = indexMeta.getProperty(ENTRY_COUNT_PROPERTY_NAME);
            if (ec != null) {
                return ec.getValue(Type.LONG);
            }
            CountingNodeVisitor v = new CountingNodeVisitor(max);
            v.visit(index);
            count = v.getEstimatedCount();
            // "is not null" queries typically read more data
            count *= 10;
        } else {
            int size = values.size();
            if (size == 0) {
                return 0;
            }
            max = Math.max(10, max / size);
            int i = 0;
            for (String p : values) {
                if (count > max && i > 3) {
                    // the total count is extrapolated from the the number
                    // of values counted so far to the total number of values
                    count = count * size / i;
                    break;
                }
                NodeState s = index.getChildNode(p);
                if (s.exists()) {
                    CountingNodeVisitor v = new CountingNodeVisitor(max);
                    v.visit(s);
                    count += v.getEstimatedCount();
                }
                i++;
View Full Code Here

                    readCount++;
                    if (readCount % 1000 == 0) {
                        LOG.warn("Traversed " + readCount + " nodes using index " + indexName + " with filter " + filter);
                    }

                    NodeState node = entry.getNodeState();

                    String name = entry.getName();
                    if (NodeStateUtils.isHidden(name)) {
                        continue;
                    }
                    currentPath = PathUtils.concat(parentPath, name);

                    nodeIterators.addLast(node.getChildNodeEntries().iterator());
                    parentPath = currentPath;

                    if (node.getBoolean("match")) {
                        return;
                    }
                   
                } else {
                    nodeIterators.removeLast();
View Full Code Here

        // get declaring types, and all their subtypes
        // TODO: should we reindex when type definitions change?
        if (definition.hasProperty(DECLARING_NODE_TYPES)) {
            this.primaryTypes = newHashSet();
            this.mixinTypes = newHashSet();
            NodeState types =
                    root.getChildNode(JCR_SYSTEM).getChildNode(JCR_NODE_TYPES);
            for (String name : definition.getNames(DECLARING_NODE_TYPES)) {
                NodeState type = types.getChildNode(name);
                if (type.getBoolean(JCR_ISMIXIN)) {
                    mixinTypes.add(name);
                } else {
                    primaryTypes.add(name);
                }
                addAll(mixinTypes, type.getNames(OAK_MIXIN_SUBTYPES));
                addAll(primaryTypes, type.getNames(OAK_PRIMARY_SUBTYPES));
            }
        } else {
            this.primaryTypes = null;
            this.mixinTypes = null;
        }
View Full Code Here

            // make sure that the index node exist, even with no content
            definition.child(INDEX_CONTENT_NODE_NAME);

            // check uniqueness constraints when leaving the root
            if (unique && !keysToCheckForUniqueness.isEmpty()) {
                NodeState indexMeta = definition.getNodeState();
                IndexStoreStrategy s = getStrategy(unique);
                for (String key : keysToCheckForUniqueness) {
                    if (s.count(indexMeta, singleton(key), 2) > 1) {
                        throw new CommitFailedException(
                                CONSTRAINT, 30,
View Full Code Here

        addFile(root, "file-1");

        store.merge(root, new EditorHook(new IndexUpdateProvider(
                new PropertyIndexEditorProvider())), PostCommitHook.EMPTY);

        NodeState rootState = store.getRoot();
        NodeTypeIndex index = new NodeTypeIndex();
        FilterImpl filter;

        filter = createFilter(rootState, JcrConstants.NT_FOLDER);
        assertEquals(2.0, index.getCost(filter, rootState), 0.0);
View Full Code Here

        assertEquals(3.0, index.getCost(filter, rootState), 0.0);
        checkCursor(index.query(filter, rootState), "/folder-1", "/folder-2", "/file-1");
    }

    private static FilterImpl createFilter(NodeState root, String nodeTypeName) {
        NodeState system = root.getChildNode(JCR_SYSTEM);
        NodeState types = system.getChildNode(JCR_NODE_TYPES);
        NodeState type = types.getChildNode(nodeTypeName);
        SelectorImpl selector = new SelectorImpl(type, nodeTypeName);
        return new FilterImpl(selector, "SELECT * FROM [" + nodeTypeName + "]", null);
    }
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.oak.spi.state.NodeState

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.