Package org.modeshape.jcr.cache

Examples of org.modeshape.jcr.cache.ChildReference


        // we need to store the projection mappings so that we don't loose that information
        SessionCache systemSession = repository.createSystemSession(repository.context(), false);
        NodeKey systemNodeKey = getSystemNode(systemSession).getKey();
        MutableCachedNode systemNode = systemSession.mutable(systemNodeKey);
        ChildReference federationNodeRef = systemNode.getChildReferences(systemSession).getChild(ModeShapeLexicon.FEDERATION);

        if (federationNodeRef == null) {
            // there isn't a federation node present, so we need to add it
            try {
                Property primaryType = propertyFactory.create(JcrLexicon.PRIMARY_TYPE, ModeShapeLexicon.FEDERATION);
                systemNode.createChild(systemSession, systemNodeKey.withId("mode:federation"), ModeShapeLexicon.FEDERATION,
                                       primaryType);
                systemSession.save();
                federationNodeRef = systemNode.getChildReferences(systemSession).getChild(ModeShapeLexicon.FEDERATION);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        NodeKey federationNodeKey = federationNodeRef.getKey();
        MutableCachedNode federationNode = systemSession.mutable(federationNodeKey);

        Property primaryType = propertyFactory.create(JcrLexicon.PRIMARY_TYPE, ModeShapeLexicon.PROJECTION);
        Property externalNodeKeyProp = propertyFactory.create(ModeShapeLexicon.EXTERNAL_NODE_KEY, projection.getExternalNodeKey());
View Full Code Here


     */
    private void removeStoredProjection( String externalNodeKey ) {
        SessionCache systemSession = repository.createSystemSession(repository.context(), false);
        NodeKey systemNodeKey = getSystemNode(systemSession).getKey();
        MutableCachedNode systemNode = systemSession.mutable(systemNodeKey);
        ChildReference federationNodeRef = systemNode.getChildReferences(systemSession).getChild(ModeShapeLexicon.FEDERATION);

        // if we're removing a projection, one had to be stored previously, so there should be a federation node present
        assert federationNodeRef != null;

        NodeKey federationNodeKey = federationNodeRef.getKey();
        MutableCachedNode federationNode = systemSession.mutable(federationNodeKey);
        ChildReferences federationChildRefs = federationNode.getChildReferences(systemSession);

        int projectionsCount = federationChildRefs.getChildCount(ModeShapeLexicon.PROJECTION);

        for (int i = 1; i <= projectionsCount; i++) {
            ChildReference projectionRef = federationChildRefs.getChild(ModeShapeLexicon.PROJECTION, i);
            NodeKey projectionRefKey = projectionRef.getKey();
            CachedNode storedProjection = systemSession.getNode(projectionRefKey);
            String storedProjectionExternalNodeKey = storedProjection.getProperty(ModeShapeLexicon.EXTERNAL_NODE_KEY,
                                                                                  systemSession).getFirstValue().toString();
            assert storedProjectionExternalNodeKey != null;
            if (storedProjectionExternalNodeKey.equals(externalNodeKey)) {
View Full Code Here

        ChildReferences refs = node.getChildReferences(cache);
        assertThat(refs, is(notNullValue()));
        assertThat(refs.size(), is(3L));
        Iterator<ChildReference> iter = refs.iterator();

        ChildReference system = refs.getChild(JcrLexicon.SYSTEM);
        ChildReference childA = refs.getChild(name("childA"));
        ChildReference childB = refs.getChild(name("childB"));

        assertThat(system.getKey().toString(), is("source1system-jcrsystem"));
        assertThat(childA.getKey().toString(), is("source1works1-childA"));
        assertThat(childB.getKey().toString(), is("source1works1-childB"));

        assertThat(system.getName(), is(JcrLexicon.SYSTEM));
        assertThat(childA.getName(), is(name("childA")));
        assertThat(childB.getName(), is(name("childB")));
        assertThat(childA.getSnsIndex(), is(1));
        assertThat(childB.getSnsIndex(), is(1));

        assertThat(iter.next(), is(system));
        assertThat(iter.next(), is(childA));
        assertThat(iter.next(), is(childB));
        assertThat(iter.hasNext(), is(false));
View Full Code Here

    }

    @Test
    public void shouldNavigateFromRootToSystemNode() {
        CachedNode node = cache.getNode(cache.getRootKey());
        ChildReference systemRef = node.getChildReferences(cache).getChild(JcrLexicon.SYSTEM);

        // print = true;

        long nanos = System.nanoTime();
        CachedNode system = cache.getNode(systemRef);
        print("Time (load): " + millis(Math.abs(System.nanoTime() - nanos)) + " ms");

        for (int i = 0; i != 10; ++i) {
            cache.clear();
            nanos = System.nanoTime();
            system.getKey();
            system.getPath(cache);
            system.getName(cache);
            system.getProperty(JcrLexicon.UUID, cache);
            system.getProperty(JcrLexicon.PRIMARY_TYPE, cache);
            print("Time (read): " + millis(Math.abs(System.nanoTime() - nanos)) + " ms");
        }

        nanos = System.nanoTime();
        system.getKey();
        system.getPath(cache);
        system.getName(cache);
        system.getProperty(JcrLexicon.UUID, cache);
        system.getProperty(JcrLexicon.PRIMARY_TYPE, cache);
        print("Time (read): " + millis(Math.abs(System.nanoTime() - nanos)) + " ms");

        assertThat(system, is(notNullValue()));
        assertThat(system.getKey(), is(systemRef.getKey()));
        assertThat(system.getPath(cache).isRoot(), is(false));
        assertThat(system.getName(cache), is(JcrLexicon.SYSTEM));
        assertThat(system.getProperty(JcrLexicon.UUID, cache).getFirstValue().toString(),
                   is("56b3feae-3def-44f7-a433-586413f312e4"));
        assertThat(system.getProperty(JcrLexicon.PRIMARY_TYPE, cache).getFirstValue(), is((Object)ModeShapeLexicon.SYSTEM));

        // Check the child references ...
        ChildReferences refs = system.getChildReferences(cache);
        assertThat(refs, is(notNullValue()));
        assertThat(refs.size(), is(1L));
        Iterator<ChildReference> iter = refs.iterator();

        ChildReference namespaces = refs.getChild(ModeShapeLexicon.NAMESPACES);
        assertThat(namespaces.getKey().toString(), is("source1system-jcrnamespaces"));
        assertThat(namespaces.getName(), is(ModeShapeLexicon.NAMESPACES));

        assertThat(iter.next(), is(namespaces));
        assertThat(iter.hasNext(), is(false));

        nanos = System.nanoTime();
View Full Code Here

        ChildReferences refs = childB.getChildReferences(cache);
        assertThat(refs, is(notNullValue()));
        assertThat(refs.size(), is(2L));
        Iterator<ChildReference> iter = refs.iterator();

        ChildReference childC = refs.getChild(name("childC"));
        ChildReference childD = refs.getChild(name("childD"));

        assertThat(childC.getKey().toString(), is("source1works1-childC"));
        assertThat(childD.getKey().toString(), is("source1works1-childD"));

        assertThat(iter.next(), is(childC)); // from first block
        assertThat(iter.next(), is(childD)); // from second block
        assertThat(iter.hasNext(), is(false));
    }
View Full Code Here

        public CachedNode node( Path path ) {
            CachedNode node = rootNode();
            for (Segment segment : path) {
                ChildReferences children = node.getChildReferences(cache);
                ChildReference child = children.getChild(segment);
                if (child == null) {
                    throw new PathNotFoundException(path, node.getKey(), node.getPath(cache));
                }
                NodeKey childKey = child.getKey();
                CachedNode childNode = cache.getNode(childKey);
                if (childNode == null) {
                    throw new PathNotFoundException(path, node.getKey(), node.getPath(cache));
                }
                node = childNode;
View Full Code Here

                                   Segment... children ) {
        List<?> childReferences = doc.getArray(DocumentTranslator.CHILDREN);
        Iterator<?> actualIter = childReferences.iterator();
        Iterator<Segment> expectedIter = Arrays.asList(children).iterator();
        while (actualIter.hasNext()) {
            ChildReference childRef = workspaceCache.translator().childReferenceFrom(actualIter.next());
            if (!expectedIter.hasNext()) {
                fail("Found \"" + childRef + "\" but not expecting any children");
            }
            Segment expectedName = expectedIter.next();
            assertThat("Expecting child \"" + expectedName + "\" but found \"" + childRef.toString() + "\"",
                       childRef.getSegment(), is(expectedName));
        }
        if (expectedIter.hasNext()) {
            fail("Expected \"" + expectedIter.next() + "\" but found no such child");
        }
    }
View Full Code Here

                                   Name... children ) {
        List<?> childReferences = doc.getArray(DocumentTranslator.CHILDREN);
        Iterator<?> actualIter = childReferences.iterator();
        Iterator<Name> expectedIter = Arrays.asList(children).iterator();
        while (actualIter.hasNext()) {
            ChildReference childRef = workspaceCache.translator().childReferenceFrom(actualIter.next());
            if (!expectedIter.hasNext()) {
                fail("Found \"" + childRef + "\" but not expecting any children");
            }
            Name expectedName = expectedIter.next();
            assertThat("Expecting child \"" + expectedName + "[1]\" but found \"" + childRef.toString() + "\"",
                       childRef.getSegment(), is(segment(expectedName, 1)));
        }
        if (expectedIter.hasNext()) {
            fail("Expected \"" + expectedIter.next() + "\" but found no such child");
        }
    }
View Full Code Here

        public boolean remove( NodeKey key ) {
            Lock lock = this.lock.writeLock();
            try {
                lock.lock();
                ChildReference removed = null;
                if (this.inserted.remove(key)) {
                    for (Insertions insertions : insertedBefore.values()) {
                        removed = insertions.remove(key);
                        if (removed != null) {
                            insertedBefore.remove(insertions.insertedBefore(), new Insertions(insertions.insertedBefore()));
                            break;
                        }
                    }
                    if (removed != null) {
                        Name name = removed.getName();
                        AtomicInteger count = this.insertedNames.get(name);
                        if (count != null) {
                            if (count.decrementAndGet() == 0) {
                                this.insertedNames.remove(name);
                            }
View Full Code Here

                    } else {
                        // The child is a normal child of this node ...

                        // check if there is a child with the same segment in the target which was not processed yet
                        ChildReferences targetNodeChildReferences = targetNode.getChildReferences(targetCache);
                        ChildReference targetChildSameSegment = targetNodeChildReferences.getChild(sourceChildReference.getSegment());
                        if (targetChildSameSegment != null && !sourceToTargetKeys.containsValue(targetChildSameSegment.getKey())) {
                            // we found a child of the target node which has the same segment and has not been processed yet
                            // meaning it was present in the target before the deep copy/clone started (e.g. an autocreated node)
                            childCopy = targetCache.mutable(targetChildSameSegment.getKey());
                            if (!isExternal) {
                                // if the child is not external, we should remove it because the new child needs to be identical
                                // to the source child
                                targetNode.removeChild(targetCache, targetChildSameSegment.getKey());
                                targetCache.destroy(targetChildSameSegment.getKey());
                                childCopy = null;
                            }
                        }

                        if (childCopy == null) {
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.