Package org.modeshape.jcr.cache

Examples of org.modeshape.jcr.cache.ChildReference


            }
        }

        // Now, update this node (the parent) ...
        MutableChildReferences appended = this.appended.get();
        ChildReference removed = null;
        if (appended != null) {
            removed = appended.remove(childKey); // The node may have been appended to this node but not yet persisted ...
        }
        if (removed == null) {
            changedChildren.remove(childKey);
View Full Code Here


                              NodeKey nextNode ) {
        WritableSessionCache session = writableSession(cache);
        session.assertInSession(this);

        ChildReferences references = getChildReferences(session);
        ChildReference before = null;
        if (nextNode != null) {
            before = references.getChild(nextNode);
            if (before == null) throw new NodeNotFoundException(key);
        }

        // Remove the node from where it is ...
        MutableChildReferences appended = this.appended.get();
        ChildReference toBeMoved = null;
        if (appended != null) {
            // Try to remove it from the appended nodes ...
            toBeMoved = appended.remove(key);
        }

        if (toBeMoved == null) {
            // It wasn't appended, so verify it is really a child ...
            toBeMoved = references.getChild(key);
            if (toBeMoved == null) throw new NodeNotFoundException(key);
            if (changedChildren.inserted(key) == null) {
                // And mark it as removed only if it doesn't appear as inserted
                // a node can be transient, not appended but inserted in the case of transient reorderings
                changedChildren.remove(key);
            }
        }

        if (nextNode == null) {
            // The node is to be placed at the end of the children ...
            appended(true).append(key, toBeMoved.getName());
        } else {
            // The node is to be inserted at some point in the children. Note that we do this regardless of
            // where it already is, even if it is in the correct spot already, because someone else may move
            // it between the time we check and the time our session is saved.
            changedChildren.insertBefore(before, toBeMoved);
View Full Code Here

    @Override
    public Map<String, Set<String>> getPermissions( NodeCache cache ) {
        if (!hasACL(cache)) {
            return null;
        }
        ChildReference aclNodeReference = getChildReferences(cache).getChild(ModeShapeLexicon.ACCESS_LIST_NODE_NAME);
        if (aclNodeReference  == null) {
            return null;
        }
        CachedNode aclNode = cache.getNode(aclNodeReference);
        if (aclNode == null) {
View Full Code Here

            throw new UnsupportedOperationException(JcrI18n.aclsOnExternalNodesNotAllowed.text());
        }
        if (!this.getMixinTypes(cache).contains(ModeShapeLexicon.ACCESS_CONTROLLABLE)) {
            addMixin(cache, ModeShapeLexicon.ACCESS_CONTROLLABLE);
        }
        ChildReference aclNodeRef = getChildReferences(cache).getChild(ModeShapeLexicon.ACCESS_LIST_NODE_NAME);
        MutableCachedNode aclNode = null;
        PropertyFactory propertyFactory = cache.getContext().getPropertyFactory();
        ChildReferences permissionsReferences = null;
        if (aclNodeRef != null) {
            aclNode = cache.mutable(aclNodeRef.getKey());
            permissionsReferences = aclNode.getChildReferences(cache);
            //there was a previous ACL node present so iterate it and remove all permissions which are not found in the map
            for (ChildReference permissionRef : permissionsReferences) {
                CachedNode permissionNode = cache.getNode(permissionRef);
                String principalName = permissionNode.getProperty(ModeShapeLexicon.PERMISSION_PRINCIPAL_NAME, cache)
                                                     .getFirstValue().toString();
                if (!privilegesByPrincipalName.containsKey(principalName)) {
                    permissionChanges().principalRemoved(principalName);
                    NodeKey permissionNodeKey = permissionNode.getKey();
                    aclNode.removeChild(cache, permissionNodeKey);
                    cache.destroy(permissionNodeKey);
                }
            }
        } else {
            org.modeshape.jcr.value.Property primaryType = propertyFactory.create(JcrLexicon.PRIMARY_TYPE,
                                                                                  ModeShapeLexicon.ACCESS_LIST_NODE_TYPE);
            aclNode = this.createChild(cache, null, ModeShapeLexicon.ACCESS_LIST_NODE_NAME, primaryType);
            permissionsReferences = ImmutableChildReferences.EmptyChildReferences.INSTANCE;
        }

        //go through the new map of permissions and update/create the internal nodes
        NameFactory nameFactory = cache.getContext().getValueFactories().getNameFactory();

        for (String principal : privilegesByPrincipalName.keySet()) {
            Name principalName = nameFactory.create(principal);
            ChildReference permissionRef = permissionsReferences.getChild(principalName);
            if (permissionRef == null) {
                //this is a new principal
                permissionChanges().principalAdded(principal);
                org.modeshape.jcr.value.Property primaryType = propertyFactory.create(
                        JcrLexicon.PRIMARY_TYPE, ModeShapeLexicon.PERMISSION);
                Property principalProp = propertyFactory.create(ModeShapeLexicon.PERMISSION_PRINCIPAL_NAME,
                                                                    principal);
                Property privileges = propertyFactory.create(ModeShapeLexicon.PERMISSION_PRIVILEGES_NAME,
                                                             privilegesByPrincipalName.get(principal));
                aclNode.createChild(cache, null, principalName, primaryType, principalProp, privileges);
            } else {
                //there already is a child node for this principal, so we just need to update its privileges
                MutableCachedNode permissionNode = cache.mutable(permissionRef.getKey());
                Property privileges = propertyFactory.create(ModeShapeLexicon.PERMISSION_PRIVILEGES_NAME,
                                                             privilegesByPrincipalName.get(principal));
                permissionNode.setProperty(cache, privileges);
            }
        }
View Full Code Here

        this.context = context;
        this.documentStore = documentStore;
        this.changeBus = changeBus;
        this.translator = translator;
        this.rootKey = rootKey;
        this.childReferenceForRoot = new ChildReference(rootKey, Path.ROOT_NAME, 1);
        this.repositoryKey = repositoryKey;
        this.workspaceName = workspaceName;
        this.workspaceKey = rootKey.getWorkspaceKey();
        this.sourceKey = rootKey.getSourceKey();
        this.pathFactory = context.getValueFactories().getPathFactory();
View Full Code Here

        if (!additionalParents.isEmpty()) {
            Path parentOfPath = path.getParent();
            for (NodeKey parentKey : additionalParents) {
                CachedNode parent = cache.getNode(parentKey);
                if (parent.getPath(cache).isAtOrBelow(parentOfPath)) {
                    ChildReference ref = parent.getChildReferences(cache).getChild(key);
                    if (ref != null && ref.getSegment().equals(path.getLastSegment())) return true;
                }
            }
        }
        return false;
    }
View Full Code Here

        // The rest of this logic is only for non-root nodes ...
        assert currentParent != null;

        // Get our parent's child references to find which one points to us ...
        ChildReferences currentReferences = currentParent.getChildReferences(cache);
        ChildReference parentRefToMe = null;
        if (currentReferences.supportsGetChildReferenceByKey()) {
            // Just using the node key is faster if it is supported by the implementation ...
            parentRefToMe = currentReferences.getChild(key);
        } else {
            // Directly look up the ChildReference by going to the cache (and possibly connector) ...
View Full Code Here

    public Map<String, Set<String>> getPermissions( NodeCache cache ) {
        if (!hasACL(cache)) {
            return null;
        }
        if (permissions.get() == null) {
            ChildReference aclNodeReference = getChildReferences(cache).getChild(ModeShapeLexicon.ACCESS_LIST_NODE_NAME);
            assert aclNodeReference != null;
            CachedNode aclNode = cache.getNode(aclNodeReference);
            assert aclNode != null;

            Map<String, Set<String>> permissions = new HashMap<>();
View Full Code Here

        int removedChildren = 0;
        int renamedChildren = 0;
        int appendedThenReorderedChildren = 0;

        for (Iterator<ChildReference> childReferenceIterator = persisted.iterator(name); childReferenceIterator.hasNext(); ) {
            ChildReference persistedChild = childReferenceIterator.next();
            ++persistedChildrenCount;

            if (changedChildren != null) {
                if (changedChildren.isRemoved(persistedChild)) {
                    --removedChildren;
View Full Code Here

    public ChildReference getChild( Name name,
                                    int snsIndex,
                                    Context context ) {
        if (changedChildren != null) context = new WithChanges(context, changedChildren);
        // First look in the delegate references ...
        ChildReference ref = persisted.getChild(name, snsIndex, context);
        if (ref == null) {
            if (appended != null) {
                // Look in the added ...
                ref = appended.getChild(name, snsIndex, context);
                if (ref == null && changedChildren != null && changedChildren.insertionCount() > 0) {
View Full Code Here

TOP

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

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.