Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.MetadataBuilder


    public void testMetadataSimpleStoreLoad() throws Exception {
        Record record = repository.newRecord();
        record.setRecordType(recordType1.getName());
        record.setField(fieldType1.getName(), "field value");

        Metadata metadata = new MetadataBuilder().value("field1", "value1").value("field2", "value2").build();

        record.setMetadata(fieldType1.getName(), metadata);
        assertEquals(2, record.getMetadataMap().get(fieldType1.getName()).getMap().size());

        record = repository.create(record);
View Full Code Here


            String ctx = "testing " + testValue.getV1() + " of type " + testValue.getV1().getClass().getName();

            Record record = repository.newRecord();
            record.setRecordType(recordType1.getName());
            record.setField(fieldType2.getName(), new Integer(1));
            record.setMetadata(fieldType2.getName(), new MetadataBuilder()
                    .object("somefield", testValue.getV1())
                    .build());
            record = repository.create(record);

            // test the type of the metadata has been retained
            assertEquals(ctx, testValue.getV1().getClass(),
                    record.getMetadata(fieldType2.getName()).getMap().get("somefield").getClass());

            // do dummy update, should not create new version
            //  (apparently, this also works fine for the float & double tests)
            record.setMetadata(fieldType2.getName(), new MetadataBuilder()
                    .object("somefield", testValue.getV1())
                    .build());
            record = repository.update(record);
            assertEquals(ctx, 1L, record.getVersion().longValue());

            // do update, should create new version
            record.setMetadata(fieldType2.getName(), new MetadataBuilder()
                    .object("somefield", testValue.getV2())
                    .build());
            record = repository.update(record);
            assertEquals(ctx, 2L, record.getVersion().longValue());
View Full Code Here

    public void testMetadataPartialUpdate() throws Exception {
        Record record = repository.newRecord();
        record.setRecordType(recordType1.getName());
        record.setField(fieldType1.getName(), "field value");

        Metadata metadata = new MetadataBuilder()
                .value("field1", "value1")
                .value("field2", "value2")
                .value("field3", "value3").build();

        record.setMetadata(fieldType1.getName(), metadata);
        record = repository.create(record);
        RecordId recordId = record.getId();

        // Now update metadata:
        //   - field1 is left unchanged and not specified
        //   - field2 is updated
        //   - field3 is deleted
        //   - a new field4 is added
        metadata = new MetadataBuilder()
                .value("field2", "value2a")
                .delete("field3")
                .value("field4", "value4").build();

        record = repository.newRecord(recordId);
View Full Code Here

    public void testMetadataOnUndefinedField() throws Exception {
        Record record = repository.newRecord();
        record.setRecordType(recordType1.getName());
        record.setField(fieldType1.getName(), "field value");
        // Set metadata on a field which does not have a value, such metadata should be ignored
        record.setMetadata(fieldType2.getName(), new MetadataBuilder().value("field1", "value1").build());

        record = repository.create(record);

        // Check state of returned record object
        assertNull(record.getMetadata(fieldType1.getName()));
View Full Code Here

    public void testMetadataVersionedField() throws Exception {
        Record record = repository.newRecord();
        record.setRecordType(recordType1.getName());
        record.setField(fieldType2.getName(), new Integer(5));

        record.setMetadata(fieldType2.getName(), new MetadataBuilder().value("field1", "value1").build());
        record = repository.create(record);

        record = repository.read(record.getId());

        Metadata readMetadata = record.getMetadataMap().get(fieldType2.getName());
View Full Code Here

    @Test
    public void testMetadataUpdateFieldAndMetadata() throws Exception {
        Record record = repository.newRecord();
        record.setRecordType(recordType1.getName());
        record.setField(fieldType2.getName(), new Integer(5));
        record.setMetadata(fieldType2.getName(), new MetadataBuilder()
                .value("field1", "value1")
                .value("field2", "value2").build());
        record = repository.create(record);

        // do update to field and metadata
        record.setField(fieldType2.getName(), new Integer(6));
        record.setMetadata(fieldType2.getName(), new MetadataBuilder()
                .value("field1", "value1a")
                .value("field3", "value3").build()); // note that we leave field2 unchanged, this tests the merging
        // of old and new metadata
        record = repository.update(record);
View Full Code Here

    @Test
    public void testMetadataUpdateFieldOnly() throws Exception {
        Record record = repository.newRecord();
        record.setRecordType(recordType1.getName());
        record.setField(fieldType2.getName(), new Integer(5));
        record.setMetadata(fieldType2.getName(), new MetadataBuilder().value("field1", "value1").build());
        record = repository.create(record);
        RecordId recordId = record.getId();

        // update only field value, metadata should not be lost be inherited from previous record state
        record = repository.newRecord();
View Full Code Here

    @Test
    public void testMetadataUpdateMetadataOnly() throws Exception {
        Record record = repository.newRecord();
        record.setRecordType(recordType1.getName());
        record.setField(fieldType2.getName(), new Integer(5));
        record.setMetadata(fieldType2.getName(), new MetadataBuilder()
                .value("field1", "value1")
                .value("field2", "value2").build());
        record = repository.create(record);
        RecordId recordId = record.getId();

        // Update only metadata -- should create new version
        record = repository.newRecord();
        record.setId(recordId);
        record.setMetadata(fieldType2.getName(), new MetadataBuilder().value("field1", "value1a").build());
        record = repository.update(record);

        Metadata metadata;

        // validate state of returned record
View Full Code Here

    @Test
    public void testMetadata() throws Exception {
        Record record = repository.getRecordFactory().newRecord();
        record.setMetadata(new QName("ns", "field1"),
                new MetadataBuilder()
                        .value("stringfield", "string")
                        .value("intfield", 55)
                        .value("longfield", 999999999999L)
                        .value("booleanfield", Boolean.TRUE)
                        .value("floatfield", 33.33f)
                        .value("doublefield", 66.66d)
                        .value("binaryfield", new ByteArray("foo".getBytes()))
                        .build());

        record.setMetadata(new QName("ns", "field2"),
                new MetadataBuilder()
                        .value("stringfield", "another_string")
                        .build());

        ObjectNode recordNode = RecordWriter.INSTANCE.toJson(record, null, repository);
View Full Code Here

    @Test
    public void testMetadataNoUpdate() throws Exception {
        Record record = repository.newRecord();
        record.setRecordType(recordType1.getName());
        record.setField(fieldType2.getName(), new Integer(1));
        record.setMetadata(fieldType2.getName(), new MetadataBuilder().value("field1", "value1").build());
        record = repository.create(record);

        assertEquals(1, record.getVersion().longValue());
        assertEquals(1, record.getMetadata(fieldType2.getName()).getMap().size());

        // resubmit the same record object, this should not cause an update
        record = repository.update(record);
        assertEquals(1, record.getVersion().longValue());

        // Delete a non-existing field from the metadata, this should also not cause an update
        record.setMetadata(fieldType2.getName(), new MetadataBuilder().delete("field2").build());
        record = repository.update(record);
        assertEquals(1, record.getVersion().longValue());

        // Once more with an empty metadata object
        record.setMetadata(fieldType2.getName(), new MetadataBuilder().build());
        record = repository.update(record);
        assertEquals(1, record.getVersion().longValue());

        // But if we do a real update, we should get a new version
        record.setMetadata(fieldType2.getName(), new MetadataBuilder().value("field1", "value1a").build());
        record = repository.update(record);
        assertEquals(2, record.getVersion().longValue());
    }
View Full Code Here

TOP

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

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.