Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.Link$LinkBuilder


    }

    @Test
    public void testLinkBuilder_WithoutTable() {
        RecordId recordId = idGenerator.newRecordId("42");
        Link link = Link.newBuilder()
                         .recordId(recordId)
                         .create();

        assertEquals(recordId, link.getMasterRecordId());
        assertEquals(null, link.getTable());
    }
View Full Code Here


        Record record = table.recordBuilder()
                .id("deref-test-main")
                .recordType(rt1.getName())
                .field(ft1.getName(), "deref test main")
                .field(ft2.getName(), new Link(linkedRecord.getId()))
                .create();

        SchemaId vtag = typeManager.getFieldTypeByName(VersionTag.LAST).getId();
        DependantRecordIdsIterator it = null;
View Full Code Here

        RecordTypeBuilder rtBuilder = typeManager.recordTypeBuilder();
        RecordType valueTypeRT = rtBuilder.name(new QName("testLinkType", "linkValueTypeRecordType"))
            .field(fieldType1.getId(), false)
            .create();

        testType("recordValueTypeId", "LINK", new Link(idGenerator.newRecordId()));
        testType("recordValueTypeId", "LINK<{testLinkType}linkValueTypeRecordType>", new Link(idGenerator.newRecordId()));
        testType("recordValueTypeId", "LIST<LINK<{testLinkType}linkValueTypeRecordType>>", Arrays.asList(new Link(idGenerator.newRecordId()), new Link(idGenerator.newRecordId())));
        testType("recordValueTypeId", "LIST<LINK>", Arrays.asList(new Link(idGenerator.newRecordId()), new Link(idGenerator.newRecordId())));
        testType("recordValueTypeId", "PATH<LINK<{testLinkType}linkValueTypeRecordType>>", new HierarchyPath(new Link(idGenerator.newRecordId()), new Link(idGenerator.newRecordId())));
        testType("recordValueTypeId", "PATH<LINK>", new HierarchyPath(new Link(idGenerator.newRecordId()), new Link(idGenerator.newRecordId())));
        testType("recordValueTypeId", "LIST<PATH<LINK<{testLinkType}linkValueTypeRecordType>>>", Arrays.asList(new HierarchyPath(new Link(idGenerator.newRecordId()), new Link(idGenerator.newRecordId())), new HierarchyPath(new Link(idGenerator.newRecordId()), new Link(idGenerator.newRecordId()))));
        testType("recordValueTypeId", "LIST<PATH<LINK>>", Arrays.asList(new HierarchyPath(new Link(idGenerator.newRecordId()), new Link(idGenerator.newRecordId())), new HierarchyPath(new Link(idGenerator.newRecordId()), new Link(idGenerator.newRecordId()))));
    }
View Full Code Here

    @Override
    public Link read(DataInput dataInput) {
        // Read the encoding version byte, but ignore it for the moment since there is only one encoding
        byte version = dataInput.readByte();
        Link link;
        switch (version) {
            case VERSION_ONE:
                link = Lily11RecordIdDecoder.decodeLink(dataInput, idGenerator);
                break;
            case VERSION_TWO:
View Full Code Here

        // (2)
        Record record2 = table.newRecord();
        record2.setRecordType(new QName(BNS, "Book"));
        record2.setField(new QName(BNS, "title"), "Fishing 2");
        record2.setField(new QName(BNS, "sequel_to"), new Link(record1.getId()));
        record2 = table.create(record2);

        // (3)
        Link sequelToLink = (Link) record2.getField(new QName(BNS, "sequel_to"));
        RecordId sequelTo = sequelToLink.resolve(record2.getId(), repository.getIdGenerator());
        Record linkedRecord = table.read(sequelTo);
        System.out.println(linkedRecord.getField(new QName(BNS, "title")));
    }
View Full Code Here

        defaultTable.recordBuilder()
                .id(repository.getIdGenerator().newRecordId(baseProductId))
                .recordType(new QName(NS, "Alpha"))
                .field(nvfield1.getName(), "29485")
                .field(nvLinkField1.getName(), new Link(linkedRecordId))
                .create();

        defaultTable.recordBuilder()
                .id(repository.getIdGenerator().newRecordId(baseProductId,
                        Collections.singletonMap("country", "france")))
View Full Code Here

        expectEvent(CREATE, Table.RECORD.name, record1.getId(), nvfield1.getId(), nvTag.getId());
        record1 = defaultTable.create(record1);

        Record record2 = defaultTable.newRecord();
        record2.setRecordType(nvRecordType1.getName());
        record2.setField(nvLinkField1.getName(), new Link(record1.getId()));
        record2.setField(nvTag.getName(), 0L);
        expectEvent(CREATE, Table.RECORD.name, record2.getId(), nvLinkField1.getId(), nvTag.getId());
        record2 = defaultTable.create(record2);

        commitIndex();
View Full Code Here

        expectEvent(CREATE, Table.RECORD.name, record1.getId(), nvfield1.getId(), nvTag.getId());
        record1 = defaultTable.create(record1);

        Record record2 = defaultTable.newRecord();
        record2.setRecordType(nvRecordType1.getName());
        record2.setField(nvLinkField1.getName(), new Link(record1.getId()));
        record2.setField(nvTag.getName(), 0L);
        expectEvent(CREATE, Table.RECORD.name, record2.getId(), nvLinkField1.getId(), nvTag.getId());
        record2 = defaultTable.create(record2);

        commitIndex();
View Full Code Here

    }

    private void linkToOtherRecord(LRepository repository) throws Exception {
        RecordId id = lilyProxy.getLilyServerProxy().getClient().getDefaultRepository()
                .getIdGenerator().fromString("USER.subRec");
        repository.getDefaultTable().recordBuilder().id("testId").field(linkField, new Link(id)).update();
    }
View Full Code Here

        // Link extraction from a record without versions
        //
        {
            Record record = repository.newRecord();
            record.setRecordType(recordType.getName());
            record.setField(nonVersionedFt.getName(), new Link(ids.newRecordId("foo1")));
            record = repository.create(record);
            repoSetup.waitForSepProcessing();

            Set<RecordId> referrers = linkIndex.getReferrers(ids.newRecordId("foo1"), lastVTag);
            assertEquals(1, referrers.size());
            assertTrue(referrers.contains(record.getId()));

            referrers = linkIndex.getReferrers(ids.newRecordId("bar1"), lastVTag);
            assertEquals(0, referrers.size());

            // Now perform an update so that there is a version
            record.setField(versionedFt.getName(), Arrays.asList(new Link(ids.newRecordId("foo2")),
                    new Link(ids.newRecordId("foo3"))));
            record = repository.update(record);
            repoSetup.waitForSepProcessing();

            referrers = linkIndex.getReferrers(ids.newRecordId("foo1"), lastVTag);
            assertEquals(1, referrers.size());
            assertTrue(referrers.contains(record.getId()));

            referrers = linkIndex.getReferrers(ids.newRecordId("foo2"), lastVTag);
            assertEquals(1, referrers.size());
            assertTrue(referrers.contains(record.getId()));
        }

        //
        // Link extraction from nested types
        //
        {
            Record record = repository
                    .recordBuilder()
                    .defaultNamespace("ns")
                    .recordType("MyRecordType")
                    .field("nestedLinks",
                            Arrays.asList(
                                    Arrays.asList(
                                            new HierarchyPath(new Link(ids.newRecordId("nl1"))),
                                            new HierarchyPath(new Link(ids.newRecordId("nl2")))
                                    ),
                                    Arrays.asList(
                                            new HierarchyPath(new Link(ids.newRecordId("nl3"))),
                                            new HierarchyPath(new Link(ids.newRecordId("nl4")))
                                    )
                            ))
                    .create();
            repoSetup.waitForSepProcessing();

            Set<RecordId> referrers = linkIndex.getReferrers(ids.newRecordId("nl1"), lastVTag);
            assertEquals(1, referrers.size());
            assertTrue(referrers.contains(record.getId()));

            Set<RecordId> forwardLinks = linkIndex.getForwardLinks(record.getId(), lastVTag, nestedFt.getId());
            assertEquals(4, forwardLinks.size());
            assertTrue(forwardLinks.contains(ids.newRecordId("nl1")));
            assertTrue(forwardLinks.contains(ids.newRecordId("nl2")));
            assertTrue(forwardLinks.contains(ids.newRecordId("nl3")));
            assertTrue(forwardLinks.contains(ids.newRecordId("nl4")));
        }

        //
        // Link extraction from complex types
        //
        {
            Record record = repository
                    .recordBuilder()
                    .defaultNamespace("ns")
                    .recordType("MyRecordType")
                    .field("complexLinks",
                            Arrays.asList(
                                    repository
                                            .recordBuilder()
                                            .defaultNamespace("ns")
                                            .recordType("MyRecordType")
                                            .field("link1", new Link(ids.newRecordId("cl1")))
                                            .build(),
                                    repository
                                            .recordBuilder()
                                            .defaultNamespace("ns")
                                            .recordType("MyRecordType")
                                            .field("link1", new Link(ids.newRecordId("cl2")))
                                            .build()
                            ))
                    .create();
            repoSetup.waitForSepProcessing();
View Full Code Here

TOP

Related Classes of org.lilyproject.repository.api.Link$LinkBuilder

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.