Package org.modeshape.jcr.cache

Examples of org.modeshape.jcr.cache.NodeKey


                                               AtomicReference<MutableCachedNode> frozenNodeOutput ) {
        assert versionHistoryPath != null;
        assert versionHistoryPath.size() == 6;

        // Get the information from this node ...
        NodeKey versionableNodeKey = versionableNode.getKey();
        Name primaryTypeName = versionableNode.getPrimaryType(cacheForVersionableNode);
        Set<Name> mixinTypeNames = versionableNode.getMixinTypes(cacheForVersionableNode);
        NodeKey versionHistoryKey = versionHistoryNodeKeyFor(versionableNodeKey);

        // Find the existing version history for this node (if it exists) ...
        Name versionName = null;
        MutableCachedNode historyNode = system.mutable(versionHistoryKey);
        Property predecessors = null;
        NodeKey versionKey = versionHistoryKey.withRandomId();
        if (historyNode == null) {
            // Initialize the version history ...
            historyNode = initializeVersionStorage(versionableNodeKey, versionHistoryKey, null, primaryTypeName, mixinTypeNames,
                                                   versionHistoryPath, originalVersionKey, now);
            // Overwrite the predecessor's property ...
            NodeKey rootVersionKey = historyNode.getChildReferences(system).getChild(JcrLexicon.ROOT_VERSION).getKey();
            Reference rootVersionRef = referenceFactory.create(rootVersionKey, true);
            predecessors = propertyFactory.create(JcrLexicon.PREDECESSORS, new Object[] {rootVersionRef});
            versionName = names.create("1.0");
        } else {
            ChildReferences historyChildren = historyNode.getChildReferences(system);
            predecessors = versionableNode.getProperty(JcrLexicon.PREDECESSORS, cacheForVersionableNode);
            versionName = nextNameForVersionNode(predecessors, historyChildren);
        }

        // Create a 'nt:version' node under the version history node ...
        List<Property> props = new ArrayList<Property>();
        props.add(propertyFactory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.VERSION));
        props.add(predecessors);
        props.add(propertyFactory.create(JcrLexicon.CREATED, now));
        props.add(propertyFactory.create(JcrLexicon.UUID, versionKey.getIdentifier()));
        MutableCachedNode versionNode = historyNode.createChild(system, versionKey, versionName, props);

        // Create a 'nt:frozenNode' node under the 'nt:version' node ...
        NodeKey frozenNodeKey = systemKey().withRandomId();

        props = new ArrayList<Property>();
        props.add(propertyFactory.create(JcrLexicon.PRIMARY_TYPE, JcrNtLexicon.FROZEN_NODE));
        props.add(propertyFactory.create(JcrLexicon.FROZEN_UUID, versionableNodeKey.getIdentifier()));
        props.add(propertyFactory.create(JcrLexicon.FROZEN_PRIMARY_TYPE, primaryTypeName));
        props.add(propertyFactory.create(JcrLexicon.FROZEN_MIXIN_TYPES, mixinTypeNames));
        props.add(propertyFactory.create(JcrLexicon.UUID, frozenNodeKey));

        if (versionableProperties != null) props.addAll(versionableProperties);
        MutableCachedNode frozenNode = versionNode.createChild(system, frozenNodeKey, JcrLexicon.FROZEN_NODE, props);
        assert frozenNode != null;
        frozenNodeOutput.set(frozenNode);

        // Now update the predecessor nodes to have the new version node be included as one of their successors ...
        Property successors = null;
        final Set<Reference> successorReferences = new HashSet<Reference>();
        for (Object value : predecessors) {
            NodeKey predecessorKey = ((NodeKeyReference)value).getNodeKey();
            CachedNode predecessor = system.getNode(predecessorKey);

            // Look up the 'jcr:successors' property on the predecessor ...
            successors = predecessor.getProperty(JcrLexicon.SUCCESSORS, system);
            if (successors != null) {
                // There were already successors, so we need to add our new version node the list ...
                successorReferences.clear();
                for (Object successorValue : successors) {
                    NodeKey successorKey = ((NodeKeyReference)successorValue).getNodeKey();
                    successorReferences.add(referenceFactory.create(successorKey, true));
                }
            }

            // Now add the uuid of the versionable node ...
View Full Code Here


        // Try to find the versions in the history that are considered predecessors ...
        if (predecessors != null) {
            for (Object predecessor : predecessors) {
                if (predecessor == null) continue;
                NodeKey key = ((NodeKeyReference)predecessor).getNodeKey();
                CachedNode predecessorNode = system.getNode(key);
                Name predecessorName = predecessorNode.getName(system);
                if (proposedName == null || predecessorName.getLocalName().length() < proposedName.length()) {
                    proposedName = predecessorName.getLocalName();
                    versionNode = predecessorNode;
View Full Code Here

        Map<String, Set<String>> permissions = startingNode.getPermissions(sessionCache);
        CachedNode node = startingNode;
        if (permissions == null && searchParents) {
            // walk up the hierarchy until we get a set of permissions or we reach the root or a missing parent
            while (permissions == null) {
                NodeKey parentKey = node.getParentKey(sessionCache);
                if (parentKey == null) {
                    break;
                }
                node = sessionCache.getNode(parentKey);
                if (node == null) {
View Full Code Here

        }

        @Override
        public NodeKey create( String value ) throws ValueFormatException {
            if (NodeKey.isValidFormat(value)) {
                return new NodeKey(value);
            }
            throw new ValueFormatException(value, PropertyType.OBJECT, "Unable to convert " + value.getClass() + " to a NodeKey");
        }
View Full Code Here

        if (reindexSystemContent) {
            // We need to look for the system node, and index it differently ...
            ChildReferences childRefs = node.getChildReferences(cache);
            ChildReference systemRef = childRefs.getChild(JcrLexicon.SYSTEM);
            NodeKey systemKey = systemRef != null ? systemRef.getKey() : null;
            for (ChildReference childRef : node.getChildReferences(cache)) {
                NodeKey childKey = childRef.getKey();
                if (childKey.equals(systemKey)) {
                    // This is the "/jcr:system" node ...
                    node = cache.getNode(childKey);
                    reindexSystemContent(node, depth - 1, indexes);
                } else {
                    queue.add(childKey);
                }
            }
        } else {
            // Add all children to the queue ...
            for (ChildReference childRef : node.getChildReferences(cache)) {
                NodeKey childKey = childRef.getKey();
                // we should not reindex anything which is in the system area
                if (!childKey.getWorkspaceKey().equals(runningState.systemWorkspaceKey())) {
                    queue.add(childKey);
                }
            }
        }

        // Now, process the queue until empty ...
        while (true) {
            NodeKey key = queue.poll();
            if (key == null) break;

            // Look up the node and find the path ...
            node = cache.getNode(key);
            if (node == null || !node.isQueryable(cache)) {
View Full Code Here

            throw new ValueFormatException(value, getPropertyType(),
                                           GraphI18n.unableToCreateValue.text(getPropertyType().getName(),
                                                                              String.class.getSimpleName(),
                                                                              value));
        }
        return new NodeKeyReference(new NodeKey(value), weak, false, simple);
    }
View Full Code Here

                        // Iterate through the projections ...
                        for (Projection projection : this.projections.values()) {
                            final String alias = projection.getAlias();

                            String externalKeyStr = projection.getExternalNodeKey(); // contains the source & workspace keys ...
                            final NodeKey externalKey = new NodeKey(externalKeyStr);
                            final String externalDocId = externalKey.getIdentifier();

                            // Find the connector that serves up this external key ...
                            Connector conn = getConnectorForSourceKey(externalKey.getSourceKey());
                            if (conn == null) {
                                // should never happen
                                throw new IllegalStateException("External source key: " + externalKey.getSourceKey()
                                                                + " has no matching connector");
                            }
                            if (conn != connector) {
                                // since projections are stored in bulk (not on a per-connector basis), we only care about the
                                // projection
                                // if it belongs to this connector
                                continue;
                            }
                            // Find the path mappings ...
                            BasicPathMappings mappings = mappingsByConnectorSourceName.get(connectorSourceName);
                            if (mappings == null) {
                                mappings = new BasicPathMappings(connectorSourceName, pathFactory);
                                mappingsByConnectorSourceName.put(connectorSourceName, mappings);
                            }
                            // Now add the path mapping for this projection. First, find the path of the one projected node ...
                            String projectedKeyStr = projection.getProjectedNodeKey();
                            NodeKey projectedKey = new NodeKey(projectedKeyStr);
                            String workspaceName = workspaceNamesByKey.get(projectedKey.getWorkspaceKey());
                            if (workspaceName == null) continue;
                            try {
                                WorkspaceCache cache = repository.repositoryCache().getWorkspaceCache(workspaceName);
                                AllPathsCache allPathsCache = new AllPathsCache(cache, null, pathFactory);
                                CachedNode node = cache.getNode(projectedKey);
View Full Code Here

    }

    @Override
    public Reference create( String value ) {
        if (value == null) return null;
        NodeKey key = JcrSession.createNodeKeyFromIdentifier(value, rootKey);
        boolean isForeign = !(key.getSourceKey().equals(rootKey.getSourceKey()) && key.getWorkspaceKey()
                                                                                      .equals(rootKey.getWorkspaceKey()));
        return new NodeKeyReference(key, weak, isForeign, simple);
    }
View Full Code Here

    }

    static NodeKey documentIdToNodeKey( String sourceName,
                                        String documentId ) {
        String sourceKey = NodeKey.keyForSourceName(sourceName);
        return new NodeKey(sourceKey, EXTERNAL_WORKSPACE_KEY, documentId);
    }
View Full Code Here

        String sourceKey = NodeKey.keyForSourceName(sourceName);
        return new NodeKey(sourceKey, EXTERNAL_WORKSPACE_KEY, documentId);
    }

    private String documentIdFromNodeKey( String nodeKey ) {
        return new NodeKey(nodeKey).getIdentifier();
    }
View Full Code Here

TOP

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

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.