Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.Link


            defaultTable
                    .recordBuilder()
                    .recordType(recordType.getName())
                    .field(linkField.getName(),
                            new Link(defaultTable
                                    .recordBuilder()
                                    .id(recordId)
                                    .recordType(recordType.getName())
                                    .field(recordField.getName(),
                                            defaultTable
                                                    .recordBuilder()
                                                    .recordType(recordType.getName())
                                                    .field(stringField.getName(), "bordeaux")
                                                    .build())
                                    .create()
                                    .getId()))
                    .create();

            commitIndex();

            verifyResultCount("+cfd_case1:bordeaux", 1);

            // perform update
            log.debug("Begin test V611");

            defaultTable
                    .recordBuilder()
                    .id(recordId)
                    .field(recordField.getName(),
                            defaultTable
                                    .recordBuilder()
                                    .recordType(recordType.getName())
                                    .field(stringField.getName(), "bordooo")
                                    .build())
                    .update();

            commitIndex();

            verifyResultCount("+cfd_case1:bordooo", 1);
            verifyResultCount("+cfd_case1:bordeaux", 0);
        }

        //
        // Case 2: link field => record field => link field => string field
        //
        {
            log.debug("Begin test V620");

            RecordId recordId1 = idGenerator.newRecordId();
            RecordId recordId2 = idGenerator.newRecordId();

            defaultTable
                    .recordBuilder()
                    .recordType(recordType.getName())
                    .field(linkField.getName(),
                            new Link(defaultTable
                                    .recordBuilder()
                                    .id(recordId1)
                                    .recordType(recordType.getName())
                                    .field(recordField.getName(),
                                            defaultTable
                                                    .recordBuilder()
                                                    .recordType(recordType.getName())
                                                    .field(linkField.getName(),
                                                            new Link(defaultTable
                                                                    .recordBuilder()
                                                                    .id(recordId2)
                                                                    .recordType(recordType.getName())
                                                                    .field(stringField.getName(), "beaujolais")
                                                                    .create()
                                                                    .getId()))
                                                    .build())
                                    .create()
                                    .getId()))
                    .create();

            commitIndex();

            verifyResultCount("+cfd_case2:beaujolais", 1);

            // perform update
            log.debug("Begin test V621");

            defaultTable
                    .recordBuilder()
                    .id(recordId2)
                    .field(stringField.getName(), "booojolais")
                    .update();

            commitIndex();

            verifyResultCount("+cfd_case2:booojolais", 1);
            verifyResultCount("+cfd_case2:beaujolais", 0);
        }

        //
        // Case 3: record field => link field => string field
        //
        {
            log.debug("Begin test V630");

            RecordId recordId = idGenerator.newRecordId();

            defaultTable
                    .recordBuilder()
                    .recordType(recordType.getName())
                    .field(record2Field.getName(),
                            defaultTable
                                    .recordBuilder()
                                    .recordType(recordType.getName())
                                    .field(linkField.getName(),
                                            new Link(defaultTable
                                                    .recordBuilder()
                                                    .id(recordId)
                                                    .recordType(recordType.getName())
                                                    .field(stringField.getName(), "bourgogne")
                                                    .create()
                                                    .getId()))
                                    .build())
                    .create();

            commitIndex();

            verifyResultCount("+cfd_case3:bourgogne", 1);

            // perform an update
            log.debug("Begin test V631");

            defaultTable
                    .recordBuilder()
                    .id(recordId)
                    .field(stringField.getName(), "boerhonje")
                    .update();

            commitIndex();

            verifyResultCount("+cfd_case3:boerhonje", 1);
            verifyResultCount("+cfd_case3:bourgogne", 0);
        }

        //
        // Case 4: link field => list<record> field => link field => string field
        //
        {
            log.debug("Begin test V640");

            RecordId recordId1 = idGenerator.newRecordId();
            RecordId recordId2 = idGenerator.newRecordId();
            RecordId recordId3 = idGenerator.newRecordId();
            RecordId recordId4 = idGenerator.newRecordId();

            defaultTable
                    .recordBuilder()
                    .recordType(recordType.getName())
                    .id(recordId1)
                    .field(linkField.getName(),
                            new Link(defaultTable
                                    .recordBuilder()
                                    .id(recordId2)
                                    .recordType(recordType.getName())
                                    .field(recordListField.getName(),
                                            Arrays.asList(
                                                    defaultTable
                                                            .recordBuilder()
                                                            .id(recordId3)
                                                            .recordType(recordType.getName())
                                                            .field(linkField.getName(),
                                                                    new Link(defaultTable
                                                                            .recordBuilder()
                                                                            .id(recordId3)
                                                                            .recordType(recordType.getName())
                                                                            .field(stringField.getName(), "champagne")
                                                                            .create()
                                                                            .getId()))
                                                            .build(),
                                                    defaultTable
                                                            .recordBuilder()
                                                            .id(recordId4)
                                                            .recordType(recordType.getName())
                                                            .field(linkField.getName(),
                                                                    new Link(defaultTable
                                                                            .recordBuilder()
                                                                            .id(recordId4)
                                                                            .recordType(recordType.getName())
                                                                            .field(stringField.getName(), "languedoc")
                                                                            .create()
                                                                            .getId()))
                                                            .build()
                                            ))
                                    .create()
                                    .getId()))
                    .create();

            commitIndex();

            verifyResultCount("+cfd_case4:champagne", 1);
            verifyResultCount("+cfd_case4:languedoc", 1);

            // perform an update
            log.debug("Begin test V640");

            defaultTable
                    .recordBuilder()
                    .id(recordId3)
                    .field(stringField.getName(), "sampanje")
                    .update();

            commitIndex();

            verifyResultCount("+cfd_case4:sampanje", 1);
            verifyResultCount("+cfd_case4:languedoc", 1);
            verifyResultCount("+cfd_case4:champagne", 0);

            // perform another update */
            log.debug("Begin test V641");

            defaultTable
                    .recordBuilder()
                    .id(recordId2)
                    .recordType(recordType.getName())
                    .field(recordListField.getName(),
                            Arrays.asList(defaultTable
                                    .recordBuilder()
                                    .recordType(recordType.getName())
                                    .field(linkField.getName(), new Link(recordId3))
                                    .build()))
                    .update();

            commitIndex();

            verifyResultCount("+cfd_case4:sampanje", 1);
            verifyResultCount("+cfd_case4:languedoc", 0);
        }

        //
        // Case 5: link field => record field => record field => string field
        //
        {
            log.debug("Begin test V650");

            RecordId recordId1 = idGenerator.newRecordId();
            RecordId recordId2 = idGenerator.newRecordId();

            defaultTable
                    .recordBuilder()
                    .id(recordId1)
                    .recordType(recordType.getName())
                    .field(linkField.getName(),
                            new Link(defaultTable
                                    .recordBuilder()
                                    .id(recordId2)
                                    .recordType(recordType.getName())
                                    .field(recordField.getName(),
                                            defaultTable
View Full Code Here


        if (linkedRecordSource != null) {
            TestRecord record = testActionContext.records.getRecord(linkedRecordSource);
            if (record == null) {
                return new ActionResult(false, null, 0);
            }
            return new ActionResult(true, new Link(record.getRecordId()), 0);
        }
        // Create a record of the specified RecordType
        String linkedRecordTypeName = testFieldType.getLinkedRecordTypeName();
        if (linkedRecordTypeName != null) {
            TestRecordType linkedRecordType;
            try {
                linkedRecordType = testActionContext.recordTypes.get(QNameConverter.fromJson(linkedRecordTypeName,
                        testActionContext.nameSpaces));
            } catch (org.lilyproject.tools.import_.json.JsonFormatException e) {
                throw new RuntimeException("Error creating link field", e);
            }
            ActionResult result = createRecord(linkedRecordType);
            report(result.success, result.duration,
                    "linkCreate." + linkedRecordType.getRecordType().getName().getName());
            if (!result.success) {
                return new ActionResult(false, null, 0);
            }
            return new ActionResult(true, new Link(((Record) result.object).getId()), result.duration);
        }
        // Generate a link that possibly (most likely) points to a non-existing record
        return new ActionResult(true, testFieldType.generateLink(), 0);
    }
View Full Code Here

            recordIdBytes = dataInput.readBytes(recordIdLength);
        }
        String args = dataInput.readUTF();

        if (recordIdLength == 0 && args == null) {
            return new Link();
        }

        Link.LinkBuilder builder = Link.newBuilder();
        if (recordIdLength > 0) {
            RecordId id = decode(new DataInputImpl(recordIdBytes), idGenerator);
View Full Code Here

            recordIdBytes = dataInput.readBytes(recordIdLength);
        }
        String args = dataInput.readUTF();

        if (recordIdLength == 0 && args == null) {
            return new Link();
        }

        LinkBuilder builder = Link.newBuilder();
        if (recordIdLength > 0) {
            RecordId id = idGenerator.fromBytes(recordIdBytes);
View Full Code Here

            return;
        }

        List<Link> partLinks = new ArrayList<Link>(message.parts.size());
        for (RecordId recordId : partRecordIds) {
            partLinks.add(new Link(recordId));
        }
        messageRecord.setField(new QName(NS, "parts"), partLinks);

        long startTime = System.nanoTime();
        messageRecord = table.createOrUpdate(messageRecord);
        double duration = System.nanoTime() - startTime;
        metrics.increment("Message record", "Create", duration / 1e6d);

        for (int i = 0; i < message.parts.size(); i++) {
            Part part = message.parts.get(i);
            Record partRecord = table.newRecord(partRecordIds.get(i));
            partRecord.setRecordType(new QName(NS, "Part"));
            partRecord.setField(new QName(NS, "mediaType"), part.blob.getMediaType());
            partRecord.setField(new QName(NS, "content"), part.blob);
            partRecord.setField(new QName(NS, "message"), new Link(messageRecord.getId()));

            startTime = System.nanoTime();
            partRecord = table.createOrUpdate(partRecord);
            duration = System.nanoTime() - startTime;
            metrics.increment("Part record", "Create", duration / 1e6d);
View Full Code Here

        for (int i = 0; i < 300; i++) {
            repository.recordBuilder()
                    .recordType(rt1.getName())
                    .field(ft1.getName(), "foo bar bar")
                    .field(ft2.getName(), new Link(idGenerator.newRecordId()))
                    .create();
        }

        Assert.assertTrue("Processing messages took too long", lilyProxy.waitSepEventsProcessed(60000L));
View Full Code Here

    @Test
    public void testPlainRecordId() {
        RecordId recordId = idGenerator.newRecordId("123");

        Link link = Link.newBuilder().recordId(recordId).create();
        assertTrue(link.copyAll());
        assertEquals(recordId, link.getMasterRecordId());

        assertEquals("USER.123", link.toString());
        assertEquals(link, Link.fromString(link.toString(), idGenerator));
        DataOutput dataOutput = new DataOutputImpl();
        link.write(dataOutput);
        assertEquals(link, Link.read(new DataInputImpl(dataOutput.toByteArray()), idGenerator));

        RecordId ctx = idGenerator.newRecordId("0");
        RecordId resolved = link.resolve(ctx, idGenerator);
        assertEquals(recordId, resolved);

        // test the copy all
        Map<String, String> varProps = new HashMap<String, String>();
        varProps.put("a", "1");
        varProps.put("b", "2");

        ctx = idGenerator.newRecordId(ctx, varProps);
        resolved = link.resolve(ctx, idGenerator);
        assertEquals(recordId, resolved.getMaster());
        assertEquals(2, resolved.getVariantProperties().size());
    }
View Full Code Here

        assertEquals(2, resolved.getVariantProperties().size());
    }

    @Test public void testFromStringWithDots() {
        String idStr = "USER.AB\\.CD";
        Link link = Link.fromString(idStr, idGenerator);
        assertEquals("USER.AB\\.CD", link.toString());

        String variantStr = ".foo\\.com=bar\\.com";
        Link variantLink = Link.fromString(variantStr, idGenerator);

        String fullStr = "USER.AB\\.CD.foo\\.com=bar\\.com";
        Link fullLink = Link.fromString(fullStr, idGenerator);


    }
View Full Code Here

    }

    @Test
    public void testFromString_WithTable() {
        String idString = "mytable:USER.1234";
        Link link = Link.fromString(idString, idGenerator);

        assertEquals("mytable", link.getTable());
        assertEquals("USER.1234", link.getMasterRecordId().toString());
    }
View Full Code Here

    }

    @Test
    public void testFromString_NoTable() {
        String idString = "USER.1234";
        Link link = Link.fromString(idString, idGenerator);

        assertNull(link.getTable());
        assertEquals("USER.1234", link.getMasterRecordId().toString());
    }
View Full Code Here

TOP

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

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.