Package org.modeshape.jcr.cache

Examples of org.modeshape.jcr.cache.CachedNode


            Batch batch = null;
            boolean shouldAdd = true;
            while ((batch = seq.nextBatch()) != null) {
                while (batch.hasNext()) {
                    batch.nextRow();
                    CachedNode node = batch.getNode();
                    NodeKey key = node != null ? node.getKey() : null;
                    if (keys.contains(key) && shouldAdd) shouldAdd = false;
                    if (shouldAdd) {
                        boolean added = keys.add(key);
                        print("Adding " + key);
                        assertTrue("Failed to add " + key, added);
View Full Code Here


            // Iterate over the batches ...
            Batch batch = null;
            while ((batch = seq.nextBatch()) != null) {
                while (batch.hasNext()) {
                    batch.nextRow();
                    CachedNode node = batch.getNode();
                    if (node != null) {
                        Path path = node.getPath(cache);
                        boolean isSystem = path.getSegment(0).getName().equals(JcrLexicon.SYSTEM);
                        assertTrue(path.isRoot() || !isSystem);
                    }
                }
            }
View Full Code Here

        assertThat(schematicDb.get("source1works2-childX"), is(notNullValue()));
    }

    @Test
    public void shouldLoadRootNodeIntoCache() {
        CachedNode node = cache.getNode(cache.getRootKey());
        assertThat(node, is(notNullValue()));
        assertThat(node.getKey(), is(cache.getRootKey()));
        assertThat(node.getPath(cache).isRoot(), is(true));
        assertThat(node.getName(cache).getLocalName().length(), is(0));
        assertThat(node.getName(cache).getNamespaceUri().length(), is(0));

        // Check the properties ...
        assertThat(node.getProperty(JcrLexicon.UUID, cache).getFirstValue().toString(), is(node.getKey().getIdentifier()));
        assertThat(node.getProperty(JcrLexicon.PRIMARY_TYPE, cache).getFirstValue(), is((Object)ModeShapeLexicon.ROOT));

        // Check the child references ...
        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);
View Full Code Here

        assertThat(iter.hasNext(), is(false));
    }

    @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();
        CachedNode namespacesNode = cache.getNode(namespaces);
        print("Time (load): " + millis(Math.abs(System.nanoTime() - nanos)) + " ms");
        nanos = System.nanoTime();
        assertThat(namespacesNode.getPath(cache), is(path("/jcr:system/mode:namespaces")));
        assertThat(namespacesNode.getChildReferences(cache).isEmpty(), is(true));
        print("Time (read): " + millis(Math.abs(System.nanoTime() - nanos)) + " ms");
    }
View Full Code Here

        print("Time (read): " + millis(Math.abs(System.nanoTime() - nanos)) + " ms");
    }

    @Test
    public void shouldLoadChildrenReferencesWhenBackedByMultipleBlocks() {
        CachedNode root = cache.getNode(cache.getRootKey());
        CachedNode childB = cache.getNode(root.getChildReferences(cache).getChild(name("childB")));

        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"));
View Full Code Here

        public CachedNode rootNode() {
            return node(cache.getRootKey());
        }

        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

            return node(key, path(path));
        }

        public CachedNode node( NodeKey key,
                                Path path ) {
            CachedNode byKey = node(key);
            CachedNode byPath = node(path);
            assertThat(byKey, is(byPath));
            return byKey;
        }
View Full Code Here

            assertThat(byKey, is(byPath));
            return byKey;
        }

        public CachedNode node( NodeKey key ) {
            CachedNode node = cache.getNode(key);
            if (node == null) {
                throw new NodeNotFoundException(key);
            }
            return node;
        }
View Full Code Here

            return mutableNode(key, path(path));
        }

        public MutableCachedNode mutableNode( NodeKey key,
                                              Path path ) {
            CachedNode byKey = node(key);
            CachedNode byPath = node(path);
            assertThat(byKey, is(byPath));
            return mutableNode(byKey);
        }
View Full Code Here

        public MutableCachedNode mutableNode( String path ) {
            return mutableNode(path(path));
        }

        public MutableCachedNode mutableNode( Path path ) {
            CachedNode node = node(path);
            return mutableNode(node);
        }
View Full Code Here

TOP

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

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.