Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.FieldType


    @Test
    public void testInvalidReadRequests() throws Exception {
        ValueType stringType = typeManager.getValueType("STRING");
        ValueType blobType = typeManager.getValueType("BLOB");

        FieldType nonBlobField = typeManager.newFieldType(stringType, new QName(namespace, "NonBlobField"),
                Scope.VERSIONED);
        nonBlobField = typeManager.createFieldType(nonBlobField);

        FieldType absentField = typeManager
                .newFieldType(blobType, new QName(namespace, "AbsentField"), Scope.VERSIONED);
        absentField = typeManager.createFieldType(absentField);

        RecordType rt = typeManager.newRecordType(new QName(namespace, "NoBlobsRT"));
        rt.addFieldTypeEntry(nonBlobField.getId(), false);
        rt = typeManager.createRecordType(rt);

        Record record = repository.newRecord();
        record.setRecordType(rt.getName());
        record.setField(nonBlobField.getName(), "This is not a blob");
        record = repository.create(record);

        try {
            repository.getInputStream(record.getId(), record.getVersion(), nonBlobField.getName(), null, null);
            fail("Expected exception");
        } catch (BlobException e) {
            // ok
        }

        try {
            repository.getInputStream(record.getId(), record.getVersion(), absentField.getName(), null, null);
            fail("Expected exception");
        } catch (FieldNotFoundException e) {
            // ok
        }

        try {
            repository.getInputStream(record.getId(), record.getVersion(),
                    new QName(namespace, "nonExistingFieldType"),
                    null, null);
            fail("Expected exception");
        } catch (FieldTypeNotFoundException e) {
            // ok
        }

        try {
            repository.getInputStream(record.getId(), record.getVersion(), null, null, null);
            fail("Expected exception");
        } catch (IllegalArgumentException e) {
            // ok
        }

        try {
            repository.getInputStream(repoSetup.getIdGenerator().fromString("USER.nonexistingrecord"), null,
                    absentField.getName());
            fail("Expected exception");
        } catch (RecordNotFoundException e) {
            // ok
        }
    }
View Full Code Here


        String NS = "org.lilyproject.client.test";

        // Create a blob field type and record type
        TypeManager typeManager = repository.getTypeManager();
        ValueType blobType = typeManager.getValueType("BLOB");
        FieldType blobFieldType = typeManager.newFieldType(blobType, new QName(NS, "data"), Scope.VERSIONED);
        blobFieldType = typeManager.createFieldType(blobFieldType);

        RecordType recordType = typeManager.newRecordType(new QName(NS, "file"));
        recordType.addFieldTypeEntry(blobFieldType.getId(), true);
        recordType = typeManager.createRecordType(recordType);


        // Upload a blob that, based upon the current default config, should end up in HBase
        //  (> 5000 bytes and < 200000 bytes)
View Full Code Here

        String NS = "org.lilyproject.client.test";

        // Create a field type and record type
        TypeManager typeManager = repository.getTypeManager();
        FieldType fieldType = typeManager.newFieldType("STRING", new QName(NS, "scanfield"), Scope.VERSIONED);
        fieldType = typeManager.createFieldType(fieldType);

        RecordType recordType = typeManager.newRecordType(new QName(NS, "scanrt"));
        recordType.addFieldTypeEntry(fieldType.getId(), true);
        recordType = typeManager.createRecordType(recordType);

        // Create some records
        for (int i = 0; i < 10; i++) {
            Record record = repository.newRecord();
View Full Code Here

public class HierarchicalFacetPrefixFormatterTest {
    @Test
    public void testSingValue() throws Exception {
        ValueType valueType = new StringValueType();
        FieldType fieldType = mock(FieldType.class);
        when(fieldType.getValueType()).thenReturn(valueType);

        HierarchicalFacetPrefixFormatter formatter = new HierarchicalFacetPrefixFormatter();
        IndexValue value = new IndexValue(null, fieldType, "foo/bar");
        List<String> result = formatter.format(Lists.newArrayList(value), null);
View Full Code Here

    public void testMultiValue() throws Exception {
        TypeManager typeManager = mock(TypeManager.class);
        when(typeManager.getValueType("STRING")).thenReturn(new StringValueType());

        ValueType valueType = new ListValueType(typeManager, "STRING");
        FieldType fieldType = mock(FieldType.class);
        when(fieldType.getValueType()).thenReturn(valueType);

        HierarchicalFacetPrefixFormatter formatter = new HierarchicalFacetPrefixFormatter();
        List<String> result = formatter.format(Lists.newArrayList(
                new IndexValue(null, fieldType, "foo/bar"),
                new IndexValue(null, fieldType, "bar/foo")), null);
View Full Code Here

     * be "fully loaded" (= contain all fields).
     */
    public static void extract(IdRecord record, LinkCollector collector, LRepository repository)
            throws RepositoryException, InterruptedException {
        for (Map.Entry<SchemaId, Object> field : record.getFieldsById().entrySet()) {
            FieldType fieldType;
            try {
                fieldType = repository.getTypeManager().getFieldTypeById(field.getKey());
            } catch (FieldTypeNotFoundException e) {
                // Can not do anything with a field if we cannot load its type
                continue;
View Full Code Here

     */
    private static void extractRecord(Record record, LinkCollector collector, FieldType ctxField, RecordId ctxRecord,
            LRepository repository)
            throws RepositoryException, InterruptedException {
        for (Map.Entry<QName, Object> field : record.getFields().entrySet()) {
            FieldType fieldType;
            try {
                fieldType = repository.getTypeManager().getFieldTypeByName(field.getKey());
            } catch (FieldTypeNotFoundException e) {
                // Can not do anything with a field if we cannot load its type
                continue;
View Full Code Here

        SystemFields systemFields = SystemFields.getInstance(repository.getTypeManager(), repository.getIdGenerator());

        IdentityRecordStack parentRecords = new IdentityRecordStack(parentRecord);

        for (MutationCondition condition : conditions) {
            FieldType fieldType;
            try {
                if (systemFields.isSystemField(condition.getField())) {
                    fieldType = systemFields.get(condition.getField());
                } else {
                    fieldType = repository.getTypeManager().getFieldTypeByName(condition.getField());
                }

                AvroMutationCondition avroCond = new AvroMutationCondition();

                avroCond.setName(convert(condition.getField()));

                if (condition.getValue() != null) {
                    ValueType valueType = fieldType.getValueType();
                    avroCond.setValueType(valueType.getName());

                    byte[] value = valueType.toBytes(condition.getValue(), parentRecords);
                    avroCond.setValue(ByteBuffer.wrap(value));
                }
View Full Code Here

        // Check mandatory fields
        Collection<FieldTypeEntry> fieldTypeEntries = recordType.getFieldTypeEntries();
        List<QName> fieldsToDelete = record.getFieldsToDelete();
        for (FieldTypeEntry fieldTypeEntry : fieldTypeEntries) {
            if (fieldTypeEntry.isMandatory()) {
                FieldType fieldType = getTypeManager().getFieldTypeById(fieldTypeEntry.getFieldTypeId());
                QName fieldName = fieldType.getName();
                if (fieldsToDelete.contains(fieldName)) {
                    throw new InvalidRecordException("Field: '" + fieldName + "' is mandatory.", record.getId());
                }
                if (!record.hasField(fieldName) && !originalRecord.hasField(fieldName)) {
                    throw new InvalidRecordException("Field: '" + fieldName + "' is mandatory.", record.getId());
View Full Code Here

        bos.close();
    }

    @Test
    public void testRecordType() throws Exception {
        FieldType fieldType1 = typeManager.createFieldType(typeManager.newFieldType(typeManager.getValueType("STRING"), new QName("testRecordType", "field1"), Scope.NON_VERSIONED));
        FieldType fieldType2 = typeManager.createFieldType(typeManager.newFieldType(typeManager.getValueType("INTEGER"), new QName("testRecordType", "field2"), Scope.NON_VERSIONED));
        RecordTypeBuilder rtBuilder = typeManager.recordTypeBuilder();
        RecordType valueTypeRT = rtBuilder.name(new QName("testRecordType", "recordValueTypeRecordType"))
            .field(fieldType1.getId(), false)
            .field(fieldType2.getId(), true)
            .create();

        Record recordField1 = repository.recordBuilder()
            .recordType(valueTypeRT.getName(), 1L)
            .field(fieldType1.getName(), "abc")
            .field(fieldType2.getName(), 123)
            .build();
        Record recordField2 = repository.recordBuilder()
            .recordType(valueTypeRT.getName(), 1L)
            .field(fieldType1.getName(), "def")
            .field(fieldType2.getName(), 456)
            .build();
        Record recordField3 = repository.recordBuilder()
            .recordType(valueTypeRT.getName(), 1L)
            .field(fieldType1.getName(), "xyz")
            .field(fieldType2.getName(), 888)
            .build();

        testType("recordValueTypeId", "RECORD<{testRecordType}recordValueTypeRecordType>", recordField1);
        testType("recordValueTypeId", "LIST<RECORD<{testRecordType}recordValueTypeRecordType>>", Arrays.asList(recordField1, recordField2));
        testType("recordValueTypeId", "PATH<RECORD<{testRecordType}recordValueTypeRecordType>>", new HierarchyPath(recordField1, recordField2));
View Full Code Here

TOP

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

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.