Package org.modeshape.jcr.cache

Examples of org.modeshape.jcr.cache.ChildReferences$Context


                              NodeKey key,
                              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);
View Full Code Here


    public void renameChild( SessionCache cache,
                             NodeKey key,
                             Name newName ) {
        WritableSessionCache session = writableSession(cache);
        session.assertInSession(this);
        ChildReferences references = getChildReferences(session);
        if (!references.hasChild(key)) throw new NodeNotFoundException(key);

        // We need a mutable node in the session for the child, so that we can find changes in the parent ...
        cache.mutable(key);

        // If the node was previously appended ...
View Full Code Here

        CachedNode aclNode = cache.getNode(aclNodeReference);
        if (aclNode == null) {
            return null;
        }
        Map<String, Set<String>> result = new HashMap<>();
        ChildReferences permissionsReference = aclNode.getChildReferences(cache);
        for (ChildReference permissionReference : permissionsReference) {
            CachedNode permission = cache.getNode(permissionReference);
            String name = permission.getProperty(ModeShapeLexicon.PERMISSION_PRINCIPAL_NAME, cache).getFirstValue().toString();
            Property privileges = permission.getProperty(ModeShapeLexicon.PERMISSION_PRIVILEGES_NAME, cache);
            Set<String> privilegeNames = new HashSet<>();
View Full Code Here

            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);
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) ...
            NodeKey parentKey = getParentKey(cache);
            parentRefToMe = cache.getChildReference(parentKey, key);
        }
View Full Code Here

            assert aclNodeReference != null;
            CachedNode aclNode = cache.getNode(aclNodeReference);
            assert aclNode != null;

            Map<String, Set<String>> permissions = new HashMap<>();
            ChildReferences permissionsReference = aclNode.getChildReferences(cache);
            for (ChildReference permissionReference : permissionsReference) {
                CachedNode permission = cache.getNode(permissionReference);
                String name = permission.getProperty(ModeShapeLexicon.PERMISSION_PRINCIPAL_NAME, cache).getFirstValue().toString();
                Property privileges = permission.getProperty(ModeShapeLexicon.PERMISSION_PRIVILEGES_NAME, cache);
                Set<String> privilegeNames = new HashSet<>();
View Full Code Here

                session.lockManager().lock(node, true, false, Long.MAX_VALUE, null);

                // manipulate that lock using the system cache to simulate corrupt data
                SessionCache systemSession = repository.createSystemSession(repository.runningState().context(), false);
                SystemContent systemContent = new SystemContent(systemSession);
                ChildReferences childReferences = systemContent.locksNode().getChildReferences(systemSession);
                assertFalse("No locks found", childReferences.isEmpty());
                for (ChildReference childReference : childReferences) {
                    MutableCachedNode lock = systemSession.mutable(childReference.getKey());
                    lock.setProperty(systemSession, propertyFactory.create(ModeShapeLexicon.IS_DEEP, true));
                    lock.setProperty(systemSession, propertyFactory.create(ModeShapeLexicon.LOCKED_KEY, node.key().toString()));
                    lock.setProperty(systemSession, propertyFactory.create(ModeShapeLexicon.SESSION_SCOPE, false));
                }
                systemSession.save();
                return null;
            }
        }, "config/repo-config-persistent-no-indexes.json");

        // second run should run the upgrade
        startRunStop(new RepositoryOperation() {
            @SuppressWarnings( "deprecation" )
            @Override
            public Void call() throws Exception {
                // manipulate that lock using the system cache to simulate corrupt data
                SessionCache systemSession = repository.createSystemSession(repository.runningState().context(), true);
                SystemContent systemContent = new SystemContent(systemSession);
                ChildReferences childReferences = systemContent.locksNode().getChildReferences(systemSession);
                assertFalse("No locks found", childReferences.isEmpty());
                for (ChildReference childReference : childReferences) {
                    CachedNode lock = systemSession.getNode(childReference.getKey());
                    assertNull("Property not removed", lock.getProperty(ModeShapeLexicon.IS_DEEP, systemSession));
                    assertNull("Property not removed", lock.getProperty(ModeShapeLexicon.LOCKED_KEY, systemSession));
                    assertNull("Property not removed", lock.getProperty(ModeShapeLexicon.SESSION_SCOPE, systemSession));
View Full Code Here

                Document blockDoc = cache.blockFor(nextKey);
                if (blockDoc == null) {
                    throw new DocumentNotFoundException(nextKey);
                }
                // we only need the direct children of the block to avoid nesting
                ChildReferences refs = cache.translator().getChildReferencesFromBlock(blockDoc);
                ChildReferencesInfo nextNextKey = cache.translator().getChildReferencesInfo(blockDoc);
                next = new Segment(refs, nextNextKey != null ? nextNextKey.nextKey : null);
            }
            return next;
        }
View Full Code Here

TOP

Related Classes of org.modeshape.jcr.cache.ChildReferences$Context

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.