Package org.modeshape.jcr.cache

Examples of org.modeshape.jcr.cache.MutableCachedNode



        SessionCache sessionCache = this.session.spawnSessionCache(false);
        String externalNodeKey = documentStore.createExternalProjection(parentNodeToBecomeFederatedKey.toString(), sourceName,
                                                                        externalPath, projectionAlias);
        MutableCachedNode node = sessionCache.mutable(parentNodeToBecomeFederatedKey);
        node.addFederatedSegment(externalNodeKey, projectionAlias);
        sessionCache.save();
    }
View Full Code Here


        NodeKey federatedNodeKey = session.getNode(path.getParent().getString()).key();
        NodeKey externalNodeKey = session.getNode(path.getString()).key();

        SessionCache sessionCache = session.spawnSessionCache(false);
        MutableCachedNode federatedNode = sessionCache.mutable(federatedNodeKey);
        federatedNode.removeFederatedSegment(externalNodeKey.toString());
        sessionCache.save();
    }
View Full Code Here

     * @param updateExisting a boolean flag denoting whether the new node type definition should be overwrite an existing node
     *        type definition
     */
    public void store( Iterable<JcrNodeType> nodeTypes,
                       boolean updateExisting ) {
        MutableCachedNode nodeTypesNode = mutableNodeTypesNode();
        Set<Name> names = new HashSet<Name>();
        Set<NodeKey> keys = new HashSet<NodeKey>();
        for (JcrNodeType nodeType : nodeTypes) {
            if (!names.add(nodeType.getInternalName())) {
                Logger.getLogger(getClass()).debug("Found duplicate node type: " + nodeType);
View Full Code Here

     * @param updateExisting a boolean flag denoting whether the new node type definition should be overwrite an existing node
     *        type definition
     */
    public void store( JcrNodeType nodeType,
                       boolean updateExisting ) {
        MutableCachedNode nodeTypesNode = mutableNodeTypesNode();
        store(nodeType, nodeTypesNode, updateExisting);
    }
View Full Code Here

        assert system != null;
        assert nodeTypes != null;

        Name name = nodeType.getInternalName();
        final NodeKey key = nodeType.key();
        MutableCachedNode nodeTypeNode = null;
        Set<NodeKey> existingChildKeys = null;
        if (nodeTypes.getChildReferences(system).hasChild(key)) {
            // The node already exists ...
            if (!updateExisting) return;
            nodeTypeNode = system.mutable(key);

            // We'll need to delete any existing child that isn't there anymore ...
            existingChildKeys = new HashSet<NodeKey>();
            for (ChildReference childRef : nodeTypeNode.getChildReferences(system)) {
                existingChildKeys.add(childRef.getKey());
            }
        }

        // Define the properties for this node type ...
        NodeType[] supertypes = nodeType.getDeclaredSupertypes();
        List<Name> supertypeNames = new ArrayList<Name>(supertypes.length);
        for (int i = 0; i < supertypes.length; i++) {
            supertypeNames.add(((JcrNodeType)supertypes[i]).getInternalName());
        }

        List<Property> properties = new ArrayList<Property>();
        properties.add(propertyFactory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.NODE_TYPE));
        properties.add(propertyFactory.create(JcrLexicon.IS_MIXIN, nodeType.isMixin()));
        properties.add(propertyFactory.create(JcrLexicon.IS_ABSTRACT, nodeType.isAbstract()));
        properties.add(propertyFactory.create(JcrLexicon.IS_QUERYABLE, nodeType.isQueryable()));

        if (nodeType.getPrimaryItemName() != null) {
            properties.add(propertyFactory.create(JcrLexicon.PRIMARY_ITEM_NAME, nodeType.getPrimaryItemName()));
        }

        properties.add(propertyFactory.create(JcrLexicon.NODE_TYPE_NAME, nodeType.getName()));
        properties.add(propertyFactory.create(JcrLexicon.HAS_ORDERABLE_CHILD_NODES, nodeType.hasOrderableChildNodes()));
        properties.add(propertyFactory.create(JcrLexicon.SUPERTYPES, supertypeNames));

        // Now make or adjust the node for the node type ...
        if (nodeTypeNode != null) {
            // Update the properties ...
            nodeTypeNode.setProperties(system, properties);
            // make sure each new supertype of the existing node is present *before* the existing node in the parent nodeTypes
            // this because node type validation is a top-down process, expecting the parents before the children
            for (NodeType superType : supertypes) {
                CachedNode superTypeNode = system.getNode(((JcrNodeType)superType).key());
                if (superTypeNode instanceof MutableCachedNode && ((MutableCachedNode)superTypeNode).isNew()) {
                    nodeTypes.reorderChild(system, superTypeNode.getKey(), nodeTypeNode.getKey());
                }
            }
        } else {
            // We have to create the node type node ...
            nodeTypeNode = nodeTypes.createChild(system, key, name, properties);
        }

        // And the property definitions ...
        for (JcrPropertyDefinition defn : nodeType.getDeclaredPropertyDefinitions()) {
            store(nodeTypeNode, defn);
            if (existingChildKeys != null) existingChildKeys.remove(defn.key());
        }

        // And the child node definitions ...
        for (JcrNodeDefinition defn : nodeType.getDeclaredChildNodeDefinitions()) {
            store(nodeTypeNode, defn);
            if (existingChildKeys != null) existingChildKeys.remove(defn.key());
        }

        // Remove any children that weren't represented by a property definition or child node definition ...
        if (existingChildKeys != null && !existingChildKeys.isEmpty()) {
            for (NodeKey childKey : existingChildKeys) {
                // Remove the child from the parent, then destrot it ...
                nodeTypeNode.removeChild(system, childKey);
                system.destroy(childKey);
            }
        }
    }
View Full Code Here

    private void store( MutableCachedNode nodeTypeNode,
                        JcrPropertyDefinition propertyDef ) {
        // Find an existing node for this property definition ...
        final NodeKey key = propertyDef.key();
        final Name name = propertyDef.getInternalName();
        MutableCachedNode propDefnNode = null;
        if (!nodeTypeNode.isNew()) {
            if (nodeTypeNode.getChildReferences(system).hasChild(key)) {
                // The node already exists ...
                propDefnNode = system.mutable(key);
            }
        }

        List<Property> properties = new ArrayList<Property>();
        properties.add(propertyFactory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.PROPERTY_DEFINITION));

        if (!JcrNodeType.RESIDUAL_ITEM_NAME.equals(propertyDef.getName())) {
            properties.add(propertyFactory.create(JcrLexicon.NAME, name));
        }
        properties.add(propertyFactory.create(JcrLexicon.AUTO_CREATED, propertyDef.isAutoCreated()));
        properties.add(propertyFactory.create(JcrLexicon.MANDATORY, propertyDef.isMandatory()));
        properties.add(propertyFactory.create(JcrLexicon.MULTIPLE, propertyDef.isMultiple()));
        properties.add(propertyFactory.create(JcrLexicon.PROTECTED, propertyDef.isProtected()));
        properties.add(propertyFactory.create(JcrLexicon.ON_PARENT_VERSION,
                                              OnParentVersionAction.nameFromValue(propertyDef.getOnParentVersion())));
        properties.add(propertyFactory.create(JcrLexicon.REQUIRED_TYPE,
                                              org.modeshape.jcr.api.PropertyType.nameFromValue(propertyDef.getRequiredType())
                                                                                .toUpperCase()));

        List<String> symbols = new ArrayList<String>();
        for (String value : propertyDef.getAvailableQueryOperators()) {
            if (value != null) symbols.add(value);
        }
        properties.add(propertyFactory.create(JcrLexicon.AVAILABLE_QUERY_OPERATORS, symbols));

        Value[] defaultValues = propertyDef.getDefaultValues();
        if (defaultValues != null && defaultValues.length > 0) {
            String[] defaultsAsString = new String[defaultValues.length];

            for (int i = 0; i < defaultValues.length; i++) {
                try {
                    defaultsAsString[i] = defaultValues[i].getString();
                } catch (RepositoryException re) {
                    // Really shouldn't get here as all values are convertible to string
                    throw new IllegalStateException(re);
                }
            }
            properties.add(propertyFactory.create(JcrLexicon.DEFAULT_VALUES, defaultsAsString));
        }

        String[] valueConstraints = propertyDef.getValueConstraints();
        if (valueConstraints.length > 0) {
            properties.add(propertyFactory.create(JcrLexicon.VALUE_CONSTRAINTS, valueConstraints));
        }

        // Now either update the existing node or create a new node ..
        if (propDefnNode != null) {
            // Update the properties ...
            propDefnNode.setProperties(system, properties);
        } else {
            // We have to create the node type node ...
            propDefnNode = nodeTypeNode.createChild(system, key, name, properties);
        }
    }
View Full Code Here

    private void store( MutableCachedNode nodeTypeNode,
                        JcrNodeDefinition childNodeDef ) {
        // Find an existing node for this property definition ...
        final NodeKey key = childNodeDef.key();
        final Name name = childNodeDef.getInternalName();
        MutableCachedNode nodeDefnNode = null;
        if (!nodeTypeNode.isNew()) {
            if (nodeTypeNode.getChildReferences(system).hasChild(key)) {
                // The node already exists ...
                nodeDefnNode = system.mutable(key);
            }
        }

        List<Property> props = new ArrayList<Property>();
        props.add(propertyFactory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.CHILD_NODE_DEFINITION));

        if (!JcrNodeType.RESIDUAL_ITEM_NAME.equals(childNodeDef.getName())) {
            props.add(propertyFactory.create(JcrLexicon.NAME, name));
        }

        if (childNodeDef.defaultPrimaryTypeName() != null) {
            props.add(propertyFactory.create(JcrLexicon.DEFAULT_PRIMARY_TYPE, childNodeDef.defaultPrimaryTypeName()));
        }

        props.add(propertyFactory.create(JcrLexicon.REQUIRED_PRIMARY_TYPES, childNodeDef.requiredPrimaryTypeNames()));
        props.add(propertyFactory.create(JcrLexicon.SAME_NAME_SIBLINGS, childNodeDef.allowsSameNameSiblings()));
        props.add(propertyFactory.create(JcrLexicon.ON_PARENT_VERSION,
                                         OnParentVersionAction.nameFromValue(childNodeDef.getOnParentVersion())));
        props.add(propertyFactory.create(JcrLexicon.AUTO_CREATED, childNodeDef.isAutoCreated()));
        props.add(propertyFactory.create(JcrLexicon.MANDATORY, childNodeDef.isMandatory()));
        props.add(propertyFactory.create(JcrLexicon.PROTECTED, childNodeDef.isProtected()));

        // Now either update the existing node or create a new node ..
        if (nodeDefnNode != null) {
            // Update the properties ...
            nodeDefnNode.setProperties(system, props);
        } else {
            // We have to create the node type node ...
            nodeDefnNode = nodeTypeNode.createChild(system, key, name, props);
        }
    }
View Full Code Here

    }

    public void remove( IndexDefinition indexDefn ) {
        assert indexDefn != null;
        assert system != null;
        MutableCachedNode indexes = mutableIndexesNode();
        final NodeKey providerKey = nodeKey(indexes.getKey(), indexDefn.getProviderName());
        if (indexes.getChildReferences(system).hasChild(providerKey)) {
            // Find the provider node ...
            MutableCachedNode providerNode = system.mutable(providerKey);

            // And remove the index defn from the provider ...
            final NodeKey key = nodeKey(providerNode.getKey(), indexDefn);
            providerNode.removeChild(system, key);
            system.destroy(key);

            // If there are no more children under the provider, remove it, too...
            if (providerNode.getChildReferences(system).isEmpty()) {
                indexes.removeChild(system, providerKey);
                system.destroy(providerKey);
            }
        }
    }
View Full Code Here

        }
    }

    public void store( IndexDefinition indexDefn,
                       boolean updateExisting ) {
        MutableCachedNode indexesNode = mutableIndexesNode();
        store(indexDefn, indexesNode, updateExisting);
    }
View Full Code Here

        assert system != null;
        assert indexes != null;
        assert indexDefn.getName() != null;

        // First find or create the provider node ...
        MutableCachedNode providerNode = null;
        final NodeKey providerKey = nodeKey(indexes.getKey(), indexDefn.getProviderName());
        if (indexes.getChildReferences(system).hasChild(providerKey)) {
            // The node already exists ...
            providerNode = system.mutable(providerKey);
        } else {
            // Create the new provider node ...
            Property primaryType = propertyFactory.create(JcrLexicon.PRIMARY_TYPE, ModeShapeLexicon.INDEX_PROVIDER);
            Name providerName = names.create(indexDefn.getProviderName());
            providerNode = indexes.createChild(system, providerKey, providerName, primaryType);
        }
        assert providerNode != null;

        Name name = names.create(indexDefn.getName());
        final NodeKey key = nodeKey(indexes.getKey(), indexDefn);
        MutableCachedNode indexNode = null;
        Set<NodeKey> existingChildKeys = null;

        if (providerNode.getChildReferences(system).hasChild(key)) {
            // The node already exists ...
            if (!updateExisting) return;
            indexNode = system.mutable(key);

            // We'll need to delete any existing column that isn't there anymore ...
            existingChildKeys = new HashSet<NodeKey>();
            for (ChildReference childRef : indexNode.getChildReferences(system)) {
                existingChildKeys.add(childRef.getKey());
            }
        }

        // Define the properties for this index definition ...
        List<Property> properties = new ArrayList<Property>();
        // Add the extended properties first, in case the standard ones overwrite them ...
        for (Map.Entry<String, Object> entry : indexDefn.getIndexProperties().entrySet()) {
            Property prop = createProperty(entry.getKey(), entry.getValue());
            if (prop != null) properties.add(prop);
        }

        // Now do the standard properties ...
        properties.add(propertyFactory.create(JcrLexicon.PRIMARY_TYPE, ModeShapeLexicon.INDEX));
        properties.add(propertyFactory.create(JcrLexicon.DESCRIPTION, indexDefn.getDescription()));
        properties.add(propertyFactory.create(ModeShapeLexicon.KIND, indexDefn.getKind().name()));
        properties.add(propertyFactory.create(ModeShapeLexicon.NODE_TYPE_NAME, indexDefn.getNodeTypeName()));
        properties.add(propertyFactory.create(ModeShapeLexicon.SYNCHRONOUS, indexDefn.isSynchronous()));

        // Now make or adjust the node for the index definition ...
        if (indexNode != null) {
            // Update the properties ...
            indexNode.setProperties(system, properties);
        } else {
            // We have to create the index definition node ...
            indexNode = providerNode.createChild(system, key, name, properties);
        }

        // And the column definitions ...
        for (IndexColumnDefinition columnDefn : indexDefn) {
            NodeKey columnDefnKey = store(indexNode, columnDefn);
            if (existingChildKeys != null) existingChildKeys.remove(columnDefnKey);
        }

        // Remove any column defns that weren't represented in the index definition ...
        if (existingChildKeys != null && !existingChildKeys.isEmpty()) {
            for (NodeKey childKey : existingChildKeys) {
                // Remove the child from the parent, then destroy it ...
                indexNode.removeChild(system, childKey);
                system.destroy(childKey);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.cache.MutableCachedNode

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.