Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.ValueType


        }
        FieldType fieldType = fieldTypes.getFieldType(new SchemaIdImpl(Bytes.tail(key, key.length - 1)));
        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) {
            int metadataSize = Bytes.toInt(prefixedValue, prefixedValue.length - Bytes.SIZEOF_INT, Bytes.SIZEOF_INT);
            metadataSpace = metadataSize + Bytes.SIZEOF_INT;
            metadata = MetadataSerDeser.read(
                    new DataInputImpl(prefixedValue, prefixedValue.length - metadataSpace, metadataSize));
        } else {
            throw new RuntimeException("Unsupported field metadata encoding version: " + metadataEncodingVersion);
        }

        Object value = valueType.read(new DataInputImpl(prefixedValue, FieldFlags.SIZE_OF_FIELD_FLAGS,
                prefixedValue.length - FieldFlags.SIZE_OF_FIELD_FLAGS - metadataSpace));

        return new ExtractedField(fieldType, value, metadata);
    }
View Full Code Here


            throw new JsonFormatException("Lily 1.1 format change: the valueType should now be specified as a string" +
                    " rather than a nested object with the 'primitive' property.");
        }

        String valueTypeString = getString(node, "valueType");
        ValueType valueType = typeManager.getValueType(ValueTypeNSConverter.fromJson(valueTypeString, namespaces));
        FieldType fieldType = typeManager.newFieldType(valueType, name, scope);

        String idString = getString(node, "id", null);
        SchemaId id = null;
        if (idString != null) {
View Full Code Here

public class FieldValueStringConverterTest {
    @Test
    public void testFromString() throws Exception {
        IdGenerator idGenerator = new IdGeneratorImpl();

        ValueType valueType = mock(ValueType.class);

        when(valueType.getBaseName()).thenReturn("STRING");
        assertEquals("foo", FieldValueStringConverter.fromString("foo", valueType, idGenerator));

        when(valueType.getBaseName()).thenReturn("INTEGER");
        assertEquals(new Integer(123), FieldValueStringConverter.fromString("123", valueType, idGenerator));

        when(valueType.getBaseName()).thenReturn("LONG");
        assertEquals(new Long(12345), FieldValueStringConverter.fromString("12345", valueType, idGenerator));

        when(valueType.getBaseName()).thenReturn("DOUBLE");
        assertEquals(new Double(12345.6), FieldValueStringConverter.fromString("12345.6", valueType, idGenerator));

        when(valueType.getBaseName()).thenReturn("DECIMAL");
        assertEquals(new BigDecimal("12345.12345"), FieldValueStringConverter.fromString("12345.12345", valueType, idGenerator));

        when(valueType.getBaseName()).thenReturn("URI");
        assertEquals(new URI("http://www.ngdata.com/"),
                FieldValueStringConverter.fromString("http://www.ngdata.com/", valueType, idGenerator));

        when(valueType.getBaseName()).thenReturn("BOOLEAN");
        assertEquals(Boolean.TRUE, FieldValueStringConverter.fromString("true", valueType, idGenerator));
        assertEquals(Boolean.FALSE, FieldValueStringConverter.fromString("false", valueType, idGenerator));

        when(valueType.getBaseName()).thenReturn("LINK");
        assertEquals(new Link(idGenerator.newRecordId("foobar")),
                FieldValueStringConverter.fromString("USER.foobar", valueType, idGenerator));

        when(valueType.getBaseName()).thenReturn("DATE");
        assertEquals(new LocalDate(2012, 6, 28), FieldValueStringConverter.fromString("2012-06-28", valueType, idGenerator));

        when(valueType.getBaseName()).thenReturn("DATETIME");
        assertEquals(new DateTime(2012, 6, 28, 5, 36, 0, 0, DateTimeZone.UTC),
                FieldValueStringConverter.fromString("2012-06-28T05:36Z", valueType, idGenerator));
    }
View Full Code Here

            return currentValue.equals(cond.getValue());
        } else if (cond.getOp() == CompareOp.NOT_EQUAL) {
            return !currentValue.equals(cond.getValue());
        }

        ValueType valueType = typeManager.getFieldTypeByName(cond.getField()).getValueType();
        Comparator comparator = valueType.getComparator();

        if (comparator == null) {
            throw new RepositoryException("Other than (not-)equals operator in mutation condition used for value type "
                    + "that does not support comparison: " + valueType.getName());
        }

        int result = comparator.compare(currentValue, cond.getValue());

        if (result == 0) {
View Full Code Here

        List<String> results = new ArrayList<String>();

        for (IndexValue value : filterValues(indexValues)) {
            FormatContext formatCtx = new FormatContext(repository);

            ValueType valueType = value.fieldType.getValueType();
            if (valueType.getBaseName().equals("LIST")) {
                // The values of the first list-level are supplied as individual IndexValues
                valueType = valueType.getNestedValueType();
            }

            String result = formatCtx.format(value.value, valueType, formatCtx);

            if (result != null) {
View Full Code Here

        public String format(Object record, ValueType valueType, FormatContext formatCtx) throws InterruptedException {
            StringBuilder builder = new StringBuilder();
            TypeManager typeManager = formatCtx.repository.getTypeManager();

            for (Map.Entry<QName, Object> field : ((Record)record).getFields().entrySet()) {
                ValueType fieldValueType;
                try {
                    fieldValueType = typeManager.getFieldTypeByName(field.getKey()).getValueType();
                } catch (RepositoryException e) {
                    // error loading field type: skip this field
                    continue;
View Full Code Here

            .name(new QName(ns, "rt1"))
            .field(fieldType1.getId(), false)
            .create();

        // Make a RecordValueType with the record type specified
        ValueType recordVT1 = typeManager.getValueType("RECORD<{"+ns+"}rt1>");

        // Create a fieldType with as value type a RecordValueType
        FieldType fieldType2 = typeManager.createFieldType(typeManager.newFieldType(recordVT1, new QName(ns, "field2"), Scope.NON_VERSIONED));
        // Create a recordType with a field of this field type
        RecordType rt2 = typeManager.recordTypeBuilder()
View Full Code Here

            .name(new QName(ns, "rt1"))
            .field(fieldType1.getId(), false)
            .create();

        // Make a RecordValueType with the record type specified
        ValueType recordVT1 = typeManager.getValueType("RECORD<{"+ns+"}rt1>");

        // Create a fieldType with as value type a RecordValueType
        FieldType fieldType2 = typeManager.createFieldType(typeManager.newFieldType(recordVT1, new QName(ns, "field2"), Scope.NON_VERSIONED));
        // Create a recordType with a field of this field type
        RecordType rt2 = typeManager.recordTypeBuilder()
            .name(new QName(ns, "rt2"))
            .field(fieldType2.getId(), false)
            .create();

        // Create a fieldType with as value type a 'nested' RecordValueType
        ValueType recordVT2 = typeManager.getValueType("RECORD<{"+ns+"}rt2>");
        FieldType fieldType3 = typeManager.createFieldType(typeManager.newFieldType(recordVT2, new QName(ns, "field3"), Scope.NON_VERSIONED));
        RecordType rt3 = typeManager.recordTypeBuilder()
            .name(new QName(ns, "rt3"))
            .field(fieldType3.getId(), false)
            .create();
View Full Code Here

        // Create record types to be used as versioned and versioned-mutable record types, which should be ignored
        RecordType vrt = typeManager.recordTypeBuilder().name(new QName(ns, "vrt")).field(fieldType1.getId(), false).create();
        RecordType vmrt = typeManager.recordTypeBuilder().name(new QName(ns, "vmrt")).field(fieldType1.getId(), false).create();

        // Make a RecordValueType without the record type specified
        ValueType recordVT1 = typeManager.getValueType("RECORD");

        // Create a fieldType with as value type a RecordValueType
        FieldType fieldType2 = typeManager.createFieldType(typeManager.newFieldType(recordVT1, new QName(ns, "field2"), Scope.NON_VERSIONED));
        // Create a recordType with a field of this field type
        RecordType rt2 = typeManager.recordTypeBuilder()
View Full Code Here

            .name(new QName(ns, "rt1"))
            .field(fieldType1.getId(), false)
            .create();

        // Make a RecordValueType without the record type specified
        ValueType recordVT1 = typeManager.getValueType("RECORD");

        // Create a fieldType with as value type a RecordValueType
        FieldType fieldType2 = typeManager.createFieldType(typeManager.newFieldType(recordVT1, new QName(ns, "field2"), Scope.NON_VERSIONED));

        // Create a recordType with a field of this field type
View Full Code Here

TOP

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

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.