Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.MetadataBuilder


    @Test
    public void testMetadataToDelete() throws Exception {
        Record record = repository.getRecordFactory().newRecord();
        record.setMetadata(new QName("ns", "field1"),
                new MetadataBuilder()
                        .value("mfield1", "value1")
                        .delete("mfield2")
                        .delete("mfield3")
                        .build());

        record.setMetadata(new QName("ns", "field2"),
                new MetadataBuilder()
                        .delete("mfield4")
                        .build());

        WriteOptions options = new WriteOptions();
        options.setUseNamespacePrefixes(false);
View Full Code Here


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

        record = repository.newRecord(recordId);
        record.delete(fieldType1.getName(), true);
        record.setMetadata(fieldType1.getName(), new MetadataBuilder().value("field1", "value1a").build());
        record = repository.update(record);

        // validate state of returned record
        assertFalse(record.hasField(fieldType1.getName()));
        assertNull(record.getMetadata(fieldType1.getName()));
View Full Code Here

        // Record with empty Metadata object
        Record record = repository.newRecord();
        record.setRecordType(recordType1.getName());
        record.setField(fieldType1.getName(), "field value");
        record.setField(fieldType2.getName(), new Integer(1));
        record.setMetadata(fieldType1.getName(), new MetadataBuilder().build());
        record = repository.create(record);

        // validate state of read record
        record = repository.read(record.getId());
        assertNull(record.getMetadata(fieldType1.getName()));

        // Record with Metadata object containing only delets
        record = repository.newRecord();
        record.setRecordType(recordType1.getName());
        record.setField(fieldType1.getName(), "field value");
        record.setField(fieldType2.getName(), new Integer(1));
        record.setMetadata(fieldType1.getName(), new MetadataBuilder().delete("field1").build());
        record = repository.create(record);

        // validate state of read record
        record = repository.read(record.getId());
        assertNull(record.getMetadata(fieldType1.getName()));
View Full Code Here

    public void testMetadataNotSupportedOnVersionedMutableFields() throws Exception {
        Record record = repository.newRecord();
        record.setRecordType(recordType1.getName());
        record.setField(fieldType1.getName(), "field value");
        record.setField(fieldType3.getName(), Boolean.TRUE);
        record.setMetadata(fieldType3.getName(), new MetadataBuilder().value("field1", "value1").build());
        try {
            record = repository.create(record);
            fail("Expected an exception trying to set metadata on a versioned-mutable field");
        } catch (Exception e) {
            assertTrue(e.getMessage().contains("Field metadata is currently not supported for versioned-mutable fields."));
View Full Code Here

            os.close();

            Record record = repository.newRecord();
            record.setRecordType(recordType1.getName());
            record.setField(blobField.getName(), blob);
            record.setMetadata(blobField.getName(), new MetadataBuilder().value("field1", "value1").build());
            try {
                record = repository.create(record);
                fail("Expected an exception trying to set metadata on a blob field");
            } catch (Exception e) {
                assertTrue(e.getMessage().contains("Field metadata is currently not supported for BLOB fields."));
View Full Code Here

        // is metadata for the field (metadata is stored in the same cell as the value, and should be ignored
        // by the FieldValueFilter)
        Record record = repository.newRecord();
        record.setRecordType(recordType1.getName());
        record.setField(fieldType1.getName(), "stop drinking coke");
        record.setMetadata(fieldType1.getName(), new MetadataBuilder().value("field1", "foobar").build());
        repository.create(record);

        RecordScan scan = new RecordScan();
        scan.setRecordFilter(new FieldValueFilter(fieldType1.getName(), "stop drinking coke"));
        assertEquals(1, countResults(repository.getScanner(scan)));
View Full Code Here

    @Test
    public void testMetadataViaRecordBuilder() throws Exception {
        Record record = repository.recordBuilder()
                .recordType(recordType1.getName())
                .field(fieldType1.getName(), "hi")
                .metadata(fieldType1.getName(), new MetadataBuilder().value("x", "y").build())
                .create();

        record = repository.read(record.getId());
        assertEquals("y", record.getMetadata(fieldType1.getName()).get("x"));
    }
View Full Code Here

    @Test
    public void testMetadataFieldsToDeleteNotStored() throws Exception {
        Record record = repository.recordBuilder()
                .recordType(recordType1.getName())
                .field(fieldType1.getName(), "hi")
                .metadata(fieldType1.getName(), new MetadataBuilder().value("x", "y").delete("z").build())
                .create();

        record = repository.read(record.getId());
        assertEquals(0, record.getMetadata(fieldType1.getName()).getFieldsToDelete().size());
    }
View Full Code Here

            output.writeVUTF(field);
        }
    }

    public static Metadata read(DataInput input) {
        MetadataBuilder metadataBuilder = new MetadataBuilder();

        // read fields
        int size = input.readVInt();
        for (int i = 0; i < size; i++) {
            String key = input.readVUTF();
            byte valueType = input.readByte();
            ValueSerDeser serdeser = BYTE_TO_SERDESER.get(valueType);
            if (serdeser == null) {
                throw new IllegalArgumentException("Unsupported kind of metadata value: type byte " + (int)valueType);
            }
            Object value = serdeser.deserialize(input);
            metadataBuilder.object(key, value);
        }

        // read deleted fields
        size = input.readVInt();
        for (int i = 0; i < size; i++) {
            metadataBuilder.delete(input.readVUTF());
        }

        return metadataBuilder.build();
    }
View Full Code Here

            metadataBuilders = new HashMap<QName, MetadataBuilder>();
            Iterator<Map.Entry<String, JsonNode>> it = metadata.getFields();
            while (it.hasNext()) {
                Map.Entry<String, JsonNode> entry = it.next();
                QName qname = QNameConverter.fromJson(entry.getKey(), namespaces);
                MetadataBuilder builder = readMetadata(entry.getValue(), qname);
                metadataBuilders.put(qname, builder);
            }
        }

        ObjectNode metadataToDelete = getObject(node, "metadataToDelete", null);
        if (metadataToDelete != null) {
            if (metadataBuilders == null) {
                metadataBuilders = new HashMap<QName, MetadataBuilder>();
            }

            Iterator<Map.Entry<String, JsonNode>> it = metadataToDelete.getFields();
            while (it.hasNext()) {
                Map.Entry<String, JsonNode> entry = it.next();
                QName qname = QNameConverter.fromJson(entry.getKey(), namespaces);
                MetadataBuilder builder = readMetadataToDelete(entry.getValue(), metadataBuilders.get(qname), qname);
                metadataBuilders.put(qname, builder);
            }
        }

        if (metadataBuilders != null) {
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.