Package org.modeshape.jcr.cache

Examples of org.modeshape.jcr.cache.NodeKey


                // --------------------
                if (node.isNodeType(ModeShapeLexicon.SHARE)) {
                    // get the actual key of the shareable node
                    String shareableNodeUUID = shareIdsToUUIDMap.get(node.key());
                    assert shareableNodeUUID != null;
                    NodeKey shareableNodeKey = uuidToNodeKeyMapping.get(shareableNodeUUID);
                    assert shareableNodeKey != null;

                    // unlink the current key from its parent references
                    NodeKey parentKey = mutable.getParentKey(cache);
                    MutableCachedNode parent = cache.mutable(parentKey);
                    parent.removeChild(cache, node.key());

                    // re-link it with the correct key - that of the shareable node
                    parent.linkChild(cache, shareableNodeKey, node.name());
View Full Code Here


        }

        protected void create() throws SAXException {
            try {
                AbstractJcrNode parent = parentHandler.node();
                final NodeKey parentKey = parent.key();
                assert parent != null;

                // Figure out the key for the node ...
                NodeKey key = null;
                List<Value> rawUuid = properties.get(JcrLexicon.UUID);
                String uuid = null;
                boolean shareableNodeAlreadyExists = false;
                if (rawUuid != null) {
                    assert rawUuid.size() == 1;
                    uuid = rawUuid.get(0).getString();
                    key = parentKey.withId(uuid);

                    try {
                        // Deal with any existing node ...
                        AbstractJcrNode existingNode = session().node(key, null, parentKey);
                        switch (uuidBehavior) {
                            case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING:
                                parent = existingNode.getParent();
                                // Attention: this *does not* remove the entry from the DB (ISPN). Therefore, it's always
                                // accessible
                                // to the workspace cache and thus to the current session !!!.
                                // Therefore, *old properties, mixins etc* will be accessible on the new child created later on
                                // until a session.save() is performed.
                                preRemoveNode(existingNode);
                                existingNode.remove();
                                break;
                            case ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW:
                                key = cache().getRootKey().withRandomId();
                                break;
                            case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING:
                                if (existingNode.path().isAtOrAbove(parent.path())) {
                                    String text = JcrI18n.cannotRemoveParentNodeOfTarget.text(existingNode.getPath(),
                                                                                              key,
                                                                                              parent.getPath());
                                    throw new ConstraintViolationException(text);
                                }
                                // Attention: this *does not* remove the entry from the DB (ISPN). Therefore, it's always
                                // accessible
                                // to the workspace cache and thus to the current session !!!.
                                // Therefore, *old properties, mixins etc* will be accessible on the new child created later on
                                // until a session.save() is performed.
                                preRemoveNode(existingNode);
                                existingNode.remove();
                                break;
                            case ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW:
                                if (existingNode.isShareable()) {
                                    shareableNodeAlreadyExists = true;
                                } else {
                                    throw new ItemExistsException(JcrI18n.itemAlreadyExistsWithUuid.text(key,
                                                                                                         session().workspace()
                                                                                                                  .getName(),
                                                                                                         existingNode.getPath()));
                                }
                        }
                    } catch (ItemNotFoundException e) {
                        // there wasn't an existing item, so just continue
                    }

                }

                // See if the node was already autocreated by the parent
                AbstractJcrNode existingNode = parent.getNodeIfExists(nodeName);
                boolean nodeAlreadyExists = existingNode != null && existingNode.getDefinition().isAutoCreated();

                // Create the new node ...
                AbstractJcrNode child;
                if (!nodeAlreadyExists) {
                    List<Value> primaryTypeValueList = properties.get(JcrLexicon.PRIMARY_TYPE);
                    String typeName = primaryTypeValueList != null ? primaryTypeValueList.get(0).getString() : null;
                    Name primaryTypeName = nameFor(typeName);

                    if (JcrNtLexicon.SHARE.equals(primaryTypeName)) {
                        assert key != null;
                        assert uuid != null;

                        // check if we already have the key of the shareable node
                        NodeKey shareableNodeKey = uuidToNodeKeyMapping.get(uuid);
                        if (shareableNodeKey != null) {
                            // we already know the key of the shareable node, so we need to just link it and return
                            parent.mutable().linkChild(cache, shareableNodeKey, nodeName);
                            node = session().node(shareableNodeKey, null, parentKey);
                        } else {
View Full Code Here

    @Override
    public void createProjection( String absNodePath,
                                  String sourceName,
                                  String externalPath,
                                  String alias ) throws RepositoryException {
        NodeKey parentNodeToBecomeFederatedKey = session.getNode(absNodePath).key();

        String projectionAlias = !StringUtil.isBlank(alias) ? alias : externalPath;
        if (projectionAlias.endsWith("/")) {
            projectionAlias = projectionAlias.substring(0, projectionAlias.length() - 1);
        }
        if (projectionAlias.contains("/")) {
            projectionAlias = projectionAlias.substring(projectionAlias.lastIndexOf("/") + 1);
        }

        if (StringUtil.isBlank(projectionAlias)) {
            // we cannot create an external projection without a valid alias
            return;
        }


        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

        Path path = session.pathFactory().create(projectionPath);
        if (path.isRoot()) {
            throw new IllegalArgumentException(JcrI18n.invalidProjectionPath.text(projectionPath));
        }

        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

    protected static Calendar calendar() throws ValueFormatException {
        return date().toCalendar();
    }

    protected static Reference reference( Object value ) throws ValueFormatException {
        return context.getValueFactories().getReferenceFactory().create(new NodeKey(value.toString()));
    }
View Full Code Here

    protected static Reference reference( Object value ) throws ValueFormatException {
        return context.getValueFactories().getReferenceFactory().create(new NodeKey(value.toString()));
    }

    protected static Reference weakReference( Object value ) throws ValueFormatException {
        return context.getValueFactories().getWeakReferenceFactory().create(new NodeKey(value.toString()));
    }
View Full Code Here

    protected static Reference weakReference( Object value ) throws ValueFormatException {
        return context.getValueFactories().getWeakReferenceFactory().create(new NodeKey(value.toString()));
    }

    protected static Reference simpleReference( Object value ) throws ValueFormatException {
        return context.getValueFactories().getSimpleReferenceFactory().create(new NodeKey(value.toString()));
    }
View Full Code Here

    private NodeKey keyTemplate;

    @Before
    public void beforeEach() throws Exception {
        MockitoAnnotations.initMocks(this);
        keyTemplate = new NodeKey("source1", "workspa", "1");
        children = new ArrayList<AbstractJcrNode>();
        refs = new ArrayList<ChildReference>();
        childNodesByRef = new HashMap<ChildReference, AbstractJcrNode>();
        for (int i = 0; i != 10; ++i) {
            // Create a child reference ...
            String name = "node" + (i + 1);
            NodeKey key = keyTemplate.withId(name);
            ChildReference ref = new ChildReference(key, new BasicName("http://foo", name), 1);
            refs.add(ref);
            // Create a mock child node ...
            AbstractJcrNode childJcrNode = mock(AbstractJcrNode.class);
            children.add(childJcrNode);
View Full Code Here

        assert nodeType != null;
        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;
View Full Code Here

     * @param propertyDef the property definition to be projected
     */
    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 ...
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.