Package org.lilyproject.linkindex

Examples of org.lilyproject.linkindex.FieldedLink


    @Test
    public void testLinkIndex() throws Exception {
        SchemaId liveTag = repository.getIdGenerator().getSchemaId(UUID.randomUUID());

        Set<FieldedLink> links1 = new HashSet<FieldedLink>();
        links1.add(new FieldedLink(createAbsoluteId("id1"), field1));
        links1.add(new FieldedLink(createAbsoluteId("id2"), field1));

        Set<FieldedLink> links2 = new HashSet<FieldedLink>();
        links2.add(new FieldedLink(createAbsoluteId("id3"), field1));
        links2.add(new FieldedLink(createAbsoluteId("id4"), field1));

        linkIndex.updateLinks(ids.newRecordId("idA"), liveTag, links1);
        linkIndex.updateLinks(ids.newRecordId("idB"), liveTag, links1);
        linkIndex.updateLinks(ids.newRecordId("idC"), liveTag, links2);

        // Test forward link retrieval
        Set<FieldedLink> links = linkIndex.getFieldedForwardLinks(ids.newRecordId("idA"), liveTag);
        assertTrue(links.contains(new FieldedLink(createAbsoluteId("id1"), field1)));
        assertTrue(links.contains(new FieldedLink(createAbsoluteId("id2"), field1)));
        assertEquals(2, links.size());

        // Test backward link retrieval
        Set<RecordId> referrers = linkIndex.getReferrers(ids.newRecordId("id1"), liveTag);
        assertTrue(referrers.contains(ids.newRecordId("idA")));
        assertTrue(referrers.contains(ids.newRecordId("idB")));
        assertEquals(2, referrers.size());

        // Update the links for record idA and re-check
        links1.add(new FieldedLink(createAbsoluteId("id2a"), field1));
        linkIndex.updateLinks(ids.newRecordId("idA"), liveTag, links1);

        links = linkIndex.getFieldedForwardLinks(ids.newRecordId("idA"), liveTag);
        assertTrue(links.contains(new FieldedLink(createAbsoluteId("id1"), field1)));
        assertTrue(links.contains(new FieldedLink(createAbsoluteId("id2"), field1)));
        assertTrue(links.contains(new FieldedLink(createAbsoluteId("id2a"), field1)));
        assertEquals(3, links.size());

        referrers = linkIndex.getReferrers(ids.newRecordId("id1"), liveTag);
        assertTrue(referrers.contains(ids.newRecordId("idA")));
        assertTrue(referrers.contains(ids.newRecordId("idB")));
View Full Code Here


    @Test
    public void testLinkIndex_AcrossTables() throws Exception {
        SchemaId liveTag = repository.getIdGenerator().getSchemaId(UUID.randomUUID());

        Set<FieldedLink> links1 = new HashSet<FieldedLink>();
        links1.add(new FieldedLink(ids.newAbsoluteRecordId(TABLE_A, "id1"), field1));
        links1.add(new FieldedLink(ids.newAbsoluteRecordId(TABLE_A, "id2"), field1));

        Set<FieldedLink> links2 = new HashSet<FieldedLink>();
        links2.add(new FieldedLink(ids.newAbsoluteRecordId(TABLE_B, "id3"), field1));
        links2.add(new FieldedLink(ids.newAbsoluteRecordId(TABLE_B, "id4"), field1));

        linkIndex.updateLinks(ids.newAbsoluteRecordId(TABLE_A, "idA"), liveTag, links1);
        linkIndex.updateLinks(ids.newAbsoluteRecordId(TABLE_B, "idB"), liveTag, links1);
        linkIndex.updateLinks(ids.newAbsoluteRecordId(TABLE_C, "idC"), liveTag, links2);

        // Test forward link retrieval
        Set<FieldedLink> links = linkIndex.getFieldedForwardLinks(ids.newAbsoluteRecordId(TABLE_A, "idA"), liveTag);
        assertEquals(2, links.size());
        assertEquals(
                Sets.newHashSet(
                        new FieldedLink(ids.newAbsoluteRecordId(TABLE_A, "id1"), field1),
                        new FieldedLink(ids.newAbsoluteRecordId(TABLE_A, "id2"), field1)),
                links);

        // Test backward link retrieval - non-absolute ids
        Set<AbsoluteRecordId> referrers = linkIndex.getAbsoluteReferrers(ids.newAbsoluteRecordId(TABLE_A, "id1"), liveTag);
        assertEquals(2, referrers.size());
View Full Code Here

    private void testLinkIndexRetrievalWithProvidedIds(RecordId id1, RecordId id2, RecordId id3, RecordId id4) throws Exception {
        SchemaId liveTag = repository.getIdGenerator().getSchemaId(UUID.randomUUID());

        Set<FieldedLink> links1 = new HashSet<FieldedLink>();
        links1.add(new FieldedLink(createAbsoluteId(id1), field1));
        links1.add(new FieldedLink(createAbsoluteId(id2), field1));

        Set<FieldedLink> links2 = new HashSet<FieldedLink>();
        links2.add(new FieldedLink(createAbsoluteId(id3), field1));
        links2.add(new FieldedLink(createAbsoluteId(id4), field1));

        linkIndex.updateLinks(ids.newRecordId("idA"), liveTag, links1);
        linkIndex.updateLinks(ids.newRecordId("idB"), liveTag, links2);

        // Test forward link retrieval
        Set<FieldedLink> linksFromA = linkIndex.getFieldedForwardLinks(ids.newRecordId("idA"), liveTag);
        assertTrue(linksFromA.contains(new FieldedLink(createAbsoluteId(id1), field1)));
        assertTrue(linksFromA.contains(new FieldedLink(createAbsoluteId(id2), field1)));
        assertEquals(2, linksFromA.size());

        Set<FieldedLink> linksFromB = linkIndex.getFieldedForwardLinks(ids.newRecordId("idB"), liveTag);
        assertTrue(linksFromB.contains(new FieldedLink(createAbsoluteId(id3), field1)));
        assertTrue(linksFromB.contains(new FieldedLink(createAbsoluteId(id4), field1)));
        assertEquals(2, linksFromB.size());

        // Test backward link retrieval
        Set<RecordId> referrers1 = linkIndex.getReferrers(id1, liveTag);
        assertTrue(referrers1.contains(ids.newRecordId("idA")));
View Full Code Here

TOP

Related Classes of org.lilyproject.linkindex.FieldedLink

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.