Package org.modeshape.jcr.cache

Examples of org.modeshape.jcr.cache.MutableCachedNode


        boolean wasReferenceable = isReferenceable();
        Name mixinTypeName = nameFrom(mixinName);

        // Change the mixin types property (atomically, even if some other operation snuck in and added the mixin) ...
        SessionCache cache = sessionCache();
        MutableCachedNode mutable = mutable();
        mutable.addMixin(cache, mixinTypeName);

        NodeTypes nodeTypes = session.nodeTypes();
        JcrNodeType mixinType = nodeTypes.getNodeType(mixinTypeName);
        if (!wasReferenceable && mixinType.isNodeType(JcrMixLexicon.REFERENCEABLE)) {
            // Need to add the 'jcr:uuid' reference ...
            Property uuidProp = session.propertyFactory().create(JcrLexicon.UUID, getIdentifier());
            mutable.setProperty(cache, uuidProp);
        }

        // And auto-create any properties that are defined by the new primary type ...
        autoCreateItemsFor(mixinType);
View Full Code Here


        // per JCR 2.0 10.10.3.1, the change should be reflected immediately in the property
        updateMixinsProperty();
    }

    private void updateMixinsProperty() throws RepositoryException {
        MutableCachedNode mutable = mutable();

        // as per JCR, we need to make sure the change is reflected immediately in the jcr property
        List<Name> currentMixins = new ArrayList<Name>(mutable.getMixinTypes(sessionCache()));
        Value[] mixinValues = session.valueFactory().createValues(currentMixins, PropertyType.NAME);
        AbstractJcrProperty mixinProperty = this.jcrProperties.get(JcrLexicon.MIXIN_TYPES);
        if (mixinProperty == null) {
            mixinProperty = new JcrMultiValueProperty(this, JcrLexicon.MIXIN_TYPES, PropertyType.NAME);
            // this will overwrite another property which may've appeared in the meantime
View Full Code Here

        }

        boolean wasReferenceable = isReferenceable();

        // Change the mixin types property (atomically, even if some other operation snuck in and added the mixin) ...
        MutableCachedNode mutable = mutable();
        mutable.removeMixin(cache, removedMixinName);

        // If there were protected properties or children, remove them
        if (protectedPropertiesToRemove != null) {
            for (Name protectedPropertyName : protectedPropertiesToRemove) {
                mutable.removeProperty(cache, protectedPropertyName);
            }
        }
        if (protectedChildrenToRemove != null) {
            for (AbstractJcrNode protectedChild : protectedChildrenToRemove) {
                protectedChild.remove();
            }
        }

        if (wasReferenceable && !isReferenceable()) {
            // Need to remove the 'jcr:uuid' reference ...
            mutable.removeProperty(cache, JcrLexicon.UUID);
        }

        // Since we've changed the mixins, release the cached property definition IDs for the node's properties ...
        for (AbstractJcrProperty prop : this.jcrProperties.values()) {
            prop.releasePropertyDefinitionId();
View Full Code Here

            throw new LockException(JcrI18n.lockTokenNotHeld.text(location()));
        }

        // Determine the node type based upon this node's type information ...
        SessionCache cache = sessionCache();
        MutableCachedNode node = mutable();

        // validate there is an appropriate child node definition
        JcrNodeDefinition childDefn = validateChildNodeDefinition(newNodeName, shareableNode.getPrimaryTypeName(), true);

        // See if this node is checked in. If so, then we can only create children if the child
        // node definition has an OPV of 'ignore'. See Section 15.2.2 of the JSR-283 spec for details ...
        if (!isCheckedOut() && childDefn.getOnParentVersion() != OnParentVersionAction.IGNORE) {
            // The OPV is not 'ignore', so we can't create the new node ...
            Path parentPath = path();
            String parentPathStr = readable(parentPath);
            int numExistingSns = node.getChildReferences(cache).getChildCount(newNodeName);
            int sns = numExistingSns + 1;
            String segment = readable(session.pathFactory().createSegment(newNodeName, sns));
            String opv = OnParentVersionAction.nameFromValue(childDefn.getOnParentVersion());
            I18n msg = JcrI18n.cannotCreateChildOnCheckedInNodeSinceOpvOfChildDefinitionIsNotIgnore;
            throw new VersionException(msg.text(segment, readable(parentPathStr), childDefn.getName(), opv));
        }

        // We can create the shared node ...
        NodeKey childKey = shareableNode.key();
        node.linkChild(cache, childKey, newNodeName);
    }
View Full Code Here

    @Override
    public boolean isModified() {
        try {
            CachedNode node = node();
            if (node instanceof MutableCachedNode) {
                MutableCachedNode mutable = (MutableCachedNode)node;
                return !mutable.isNew() && mutable.hasChanges();
            }
        } catch (RepositoryException e) {
            // continue by returning false, since the node probably doesn't exist anymore
        }
        return false;
View Full Code Here

        for (Iterator<NodeKey> allChangesIt = allChanges.iterator(); allChangesIt.hasNext();) {
            NodeKey changedNodeKey = allChangesIt.next();
            if (changesAtOrBelowThis.contains(changedNodeKey)) {
                continue;
            }
            MutableCachedNode changedNodeOutsideBranch = session().cache().mutable(changedNodeKey);
            AbstractJcrNode changedNode = null;
            try {
                changedNode = session().node(changedNodeKey, null);
            } catch (ItemNotFoundException e) {
                // node was deleted
                allChangesIt.remove();
                continue;
            }
            boolean isShareable = changedNode.isShareable();
            if (isShareable /* && changedNodeOutsideBranch.hasOnlyChangesToAdditionalParents() */) {
                // assume that a shared node was added/removed and is to be included ...
                allChangesIt.remove();
                continue;
            }
            boolean isReferenceable = changedNode.isReferenceable();
            if (!isReferenceable) {
                continue;
            }
            Set<NodeKey> changedReferrers = changedNodeOutsideBranch.getChangedReferrerNodes();
            for (NodeKey changedNodeInBranchKey : changesAtOrBelowThis) {
                if (changedReferrers.contains(changedNodeInBranchKey)) {
                    // one of the changes in the branch is a referrer of the node outside the branch so we won't take the outside
                    // node into account
                    allChangesIt.remove();
View Full Code Here

                ChildReferences childReferences = locksNode.getChildReferences(systemSession);
                if (childReferences.isEmpty()) {
                    return;
                }
                for (ChildReference ref : childReferences) {
                    MutableCachedNode lockNode = systemSession.mutable(ref.getKey());

                    // remove properties that belong to the old (invalid) node type
                    lockNode.removeProperty(systemSession, ModeShapeLexicon.LOCKED_KEY);
                    lockNode.removeProperty(systemSession, ModeShapeLexicon.SESSION_SCOPE);
                    lockNode.removeProperty(systemSession, ModeShapeLexicon.IS_DEEP);
                }
                systemContent.save();
            } catch (Exception e) {
                LOGGER.error(e, JcrI18n.upgrade3_6_0CannotUpdateLocks, e.getMessage());
            }
View Full Code Here

                }

                ExecutionContext context = runningState.context();
                SessionCache systemSession = runningState.createSystemSession(context, false);
                SystemContent systemContent = new SystemContent(systemSession);
                MutableCachedNode systemNode = systemContent.mutableSystemNode();
                systemNode.setProperty(systemSession, context.getPropertyFactory().create(ModeShapeLexicon.ACL_COUNT, nodesWithAccessControl));
                systemSession.save();
            } catch (RepositoryException e) {
               LOGGER.error(e, JcrI18n.upgrade4_0_0_Alpha1_Failed, e.getMessage());
            }
        }
View Full Code Here

        // Sometimes, a shareable and shared node is represented by a JcrNode rather than a JcrSharedNode. Therefore,
        // the share-related logic needs to be done here ...

        SessionCache cache = sessionCache();
        NodeKey key = key();
        MutableCachedNode parent = mutableParent();
        if (!isShareable()) {
            // It's not shareable, so we will always destroy the node immediately ...
            parent.removeChild(cache, key);
            cache.destroy(key);
            return;
        }

        // It is shareable, so we need to check how many shares there are before we remove this node from its parent ...
        JcrSharedNodeCache shareableNodeCache = session().shareableNodeCache();
        SharedSet sharedSet = shareableNodeCache.getSharedSet(this);
        if (sharedSet.getSize() <= 1) {
            // There are no shares, so destroy the node and the shared set ...
            parent.removeChild(cache, key);
            cache.destroy(key);
            shareableNodeCache.destroyed(key);
            return;
        }

        // The node being removed is shared to at least two places, so we should remove it from the primary parent,
        // NOT destroy the node, and adjust the SharedSet ...
        parent.removeChild(cache, key);
        shareableNodeCache.removed(this);
    }
View Full Code Here

    }

    protected void postProcessNodes() throws SAXException {
        try {
            for (AbstractJcrNode node : nodesForPostProcessing) {
                MutableCachedNode mutable = node.mutable();

                // ---------------
                // mix:versionable
                // ---------------
                if (node.isNodeType(JcrMixLexicon.VERSIONABLE)) {

                    // Does the versionable node already have a reference to the version history?
                    // If so, then we ignore it because we'll use our own key ...

                    // Does the versionable node already have a base version?
                    AbstractJcrProperty baseVersionProp = node.getProperty(JcrLexicon.BASE_VERSION);
                    if (baseVersionProp != null) {
                        // we rely on the fact that the base version ref is exported with full key
                        NodeKeyReference baseVersionRef = (NodeKeyReference)baseVersionProp.getValue().value();
                        String workspaceKey = baseVersionRef.getNodeKey().getWorkspaceKey();
                        //we only register the base version if it comes from the system workspace (if it doesn't come from the
                        //system workspace, it's not valid - e.g. could be coming from an older version of ModeShape)
                        if (systemWorkspaceKey.equals(workspaceKey)) {
                            session.setDesiredBaseVersionKey(node.key(), baseVersionRef.getNodeKey());
                        }
                    }
                }

                // ---------------
                // mix:lockable
                // ---------------
                if (node.isNodeType(JcrMixLexicon.LOCKABLE) && node.isLocked()) {
                    // Nodes should not be locked upon import ...
                    node.unlock();
                }

                // ---------------
                // mix:lifecycle
                // ---------------
                if (node.isNodeType(JcrMixLexicon.LIFECYCLE)) {
                    if (lifecycleInfoRetained && !isValidReference(node, JcrLexicon.LIFECYCLE_POLICY, false)) {
                        // The 'jcr:lifecyclePolicy' REFERENCE values is not valid or does not reference an existing node,
                        // so the 'jcr:lifecyclePolicy' and 'jcr:currentLifecycleState' properties should be removed...
                        mutable.removeProperty(cache, JcrLexicon.LIFECYCLE_POLICY);
                        mutable.removeProperty(cache, JcrLexicon.CURRENT_LIFECYCLE_STATE);
                    }
                }

                // --------------------
                // mix:managedRetention
                // --------------------
                if (node.isNodeType(JcrMixLexicon.MANAGED_RETENTION)) {
                    if (retentionInfoRetained && !isValidReference(node, JcrLexicon.RETENTION_POLICY, false)) {
                        // The 'jcr:retentionPolicy' REFERENCE values is not valid or does not reference an existing node,
                        // so the 'jcr:retentionPolicy', 'jcr:hold' and 'jcr:isDeep' properties should be removed ...
                        mutable.removeProperty(cache, JcrLexicon.HOLD);
                        mutable.removeProperty(cache, JcrLexicon.IS_DEEP);
                        mutable.removeProperty(cache, JcrLexicon.RETENTION_POLICY);
                    }

                }

                // --------------------
                // mix:share
                // --------------------
                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());
                }
            }

            // Restore the back references ...
            if (!referrersByNodeKey.isEmpty()) {
                for (Map.Entry<NodeKey, ReferrerCounts> entry : referrersByNodeKey.entrySet()) {
                    PropertyFactory propFactory = context.getPropertyFactory();
                    MutableCachedNode referred = cache.mutable(entry.getKey());
                    ReferrerCounts counts = entry.getValue();
                    if (referred != null && counts != null) {
                        // Add in the strong and weak referrers (that are outside the import scope) that used to be in the node
                        // before it was replaced ...
                        for (NodeKey key : counts.getStrongReferrers()) {
                            int count = counts.countStrongReferencesFrom(key);
                            for (int i = 0; i != count; ++i) {
                                Property prop = propFactory.create(nameFor(key.toString() + i));
                                referred.addReferrer(cache, prop, key, ReferenceType.STRONG);
                            }
                        }
                        for (NodeKey key : counts.getWeakReferrers()) {
                            int count = counts.countWeakReferencesFrom(key);
                            for (int i = 0; i != count; ++i) {
                                Property prop = propFactory.create(nameFor(key.toString() + i));
                                referred.addReferrer(cache, prop, key, ReferenceType.WEAK);
                            }
                        }
                    }
                }
            }
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.