Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.Metadata


        if (context != null) {
            context.addFieldType(fieldType);
        }
        ValueType valueType = fieldType.getValueType();

        Metadata metadata = null;
        int metadataSpace = 0; // space taken up by metadata (= metadata itself + length suffix)
        int metadataEncodingVersion = FieldFlags.getFieldMetadataVersion(flags);
        if (metadataEncodingVersion == 0) {
            // there is no metadata
        } else if (metadataEncodingVersion == 1) {
View Full Code Here


    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);

        // Check state of returned record object
        Metadata returnedMetadata = record.getMetadata(fieldType1.getName());
        assertNotNull(returnedMetadata);
        assertEquals(2, returnedMetadata.getMap().size());
        assertEquals("value1", returnedMetadata.get("field1"));
        assertEquals("value2", returnedMetadata.get("field2"));

        // Check state when freshly reading record
        record = repository.read(record.getId());

        assertEquals(1, record.getMetadataMap().size());
        Metadata readMetadata = record.getMetadataMap().get(fieldType1.getName());
        assertNotNull(readMetadata);
        assertEquals(2, readMetadata.getMap().size());
        assertEquals("value1", readMetadata.get("field1"));
        assertEquals("value2", readMetadata.get("field2"));
    }
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);
        record.setMetadata(fieldType1.getName(), metadata);
        record = repository.update(record);

        // Check state of returned record object
        Metadata returnedMetadata = record.getMetadata(fieldType1.getName());
        assertNotNull(returnedMetadata);
        assertEquals(2, returnedMetadata.getMap().size());
        assertEquals("value2a", returnedMetadata.get("field2"));
        assertEquals("value4", returnedMetadata.get("field4"));
        assertEquals(0, returnedMetadata.getFieldsToDelete().size());

        // Check state when freshly reading record
        record = repository.read(record.getId());

        Metadata readMetadata = record.getMetadataMap().get(fieldType1.getName());
        assertNotNull(readMetadata);
        assertEquals(3, readMetadata.getMap().size());
        assertEquals("value1", readMetadata.get("field1"));
        assertEquals("value2a", readMetadata.get("field2"));
        assertEquals("value4", readMetadata.get("field4"));
    }
View Full Code Here

        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());
        assertNotNull(readMetadata);
        assertEquals(1, readMetadata.getMap().size());
        assertEquals("value1", readMetadata.get("field1"));
    }
View Full Code Here

        // validate state of returned record object
        assertEquals(2L, record.getVersion().longValue());
        assertEquals(new Integer(6), record.getField(fieldType2.getName()));

        Metadata metadata = record.getMetadataMap().get(fieldType2.getName());
        assertNotNull(metadata);
        assertEquals(2, metadata.getMap().size());
        assertEquals("value1a", metadata.get("field1"));
        assertEquals("value3", metadata.get("field3"));

        // validate state of read record
        record = repository.read(record.getId());
        assertEquals(2L, record.getVersion().longValue());
        assertEquals(new Integer(6), record.getField(fieldType2.getName()));

        metadata = record.getMetadataMap().get(fieldType2.getName());
        assertNotNull(metadata);
        assertEquals(3, metadata.getMap().size());
        assertEquals("value1a", metadata.get("field1"));
        assertEquals("value2", metadata.get("field2"));
        assertEquals("value3", metadata.get("field3"));
    }
View Full Code Here

        // validate state of read record
        record = repository.read(record.getId());
        assertEquals(2L, record.getVersion().longValue());
        assertEquals(new Integer(7), record.getField(fieldType2.getName()));

        Metadata readMetadata = record.getMetadataMap().get(fieldType2.getName());
        assertNotNull(readMetadata);
        assertEquals(1, readMetadata.getMap().size());
        assertEquals("value1", readMetadata.get("field1"));
    }
View Full Code Here

        // Now parse json again to API objects
        record = RecordReader.INSTANCE.fromJson(recordNode, repository);
        assertEquals(2, record.getMetadataMap().size());

        Metadata metadata = record.getMetadata(new QName("ns", "field1"));
        assertEquals("string", metadata.get("stringfield"));
        assertEquals(55, metadata.getInt("intfield", null).intValue());
        assertEquals(999999999999L, metadata.getLong("longfield", null).longValue());
        assertEquals(Boolean.TRUE, metadata.getBoolean("booleanfield", null));
        assertEquals(33.33f, metadata.getFloat("floatfield", null), 0.001);
        assertEquals(66.66d, metadata.getDouble("doublefield", null), 0.001);
        assertEquals(new ByteArray("foo".getBytes()), metadata.getBytes("binaryfield"));

        metadata = record.getMetadata(new QName("ns", "field2"));
        assertEquals(1, metadata.getMap().size());
        assertEquals(0, metadata.getFieldsToDelete().size());
    }
View Full Code Here

        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
        assertEquals(2L, record.getVersion().longValue());
        metadata = record.getMetadataMap().get(fieldType2.getName());
        assertNotNull(metadata);
        assertEquals(1, metadata.getMap().size());
        assertEquals("value1a", metadata.get("field1"));

        // validate state of read record
        record = repository.read(record.getId());
        assertEquals(2L, record.getVersion().longValue());
        metadata = record.getMetadataMap().get(fieldType2.getName());
        assertNotNull(metadata);
        assertEquals(2, metadata.getMap().size());
        assertEquals("value1a", metadata.get("field1"));
        assertEquals("value2", metadata.get("field2"));
    }
View Full Code Here

        // Now parse json again to API objects
        record = RecordReader.INSTANCE.fromJson(recordNode, repository);
        assertEquals(2, record.getMetadataMap().size());

        Metadata metadata = record.getMetadata(new QName("ns", "field1"));
        assertTrue(metadata.getFieldsToDelete().contains("mfield2"));
        assertTrue(metadata.getFieldsToDelete().contains("mfield3"));
        assertEquals("value1", metadata.get("mfield1"));

        metadata = record.getMetadata(new QName("ns", "field2"));
        assertTrue(metadata.getFieldsToDelete().contains("mfield4"));
        assertEquals(1, metadata.getFieldsToDelete().size());
    }
View Full Code Here

                    metadataOnlyUpdate = true;
                    newValue = originalFields.get(fieldName);
                }

                // Either use new or inherit old metadata (newMetadata map contains the merged metadata)
                Metadata metadata = newMetadata.get(fieldName);
                if (metadata == null) {
                    metadata = originalFieldMetadata.get(fieldName);
                }

                if (!metadataOnlyUpdate) {
View Full Code Here

TOP

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

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.