Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.FieldType


        assertEquals(0, countResults(repository.getScanner(scan)));
    }

    @Test
    public void testFieldValueFilter() throws Exception {
        FieldType fieldType =
                typeManager.createFieldType("STRING", new QName("FieldValueFilter", "field"), Scope.NON_VERSIONED);
        RecordType rt = typeManager.recordTypeBuilder()
                .defaultNamespace("FieldValueFilter")
                .name("rt1")
                .fieldEntry()
                .use(fieldType)
                .add()
                .create();

        Record record =
                repository.recordBuilder().recordType(rt.getName()).field(fieldType.getName(), "value1").create();
        repository.recordBuilder().recordType(rt.getName()).field(fieldType.getName(), "value1").create();
        repository.recordBuilder().recordType(rt.getName()).field(fieldType.getName(), "value2").create();
        repository.recordBuilder().recordType(rt.getName()).field(fieldType.getName(), "value2").create();
        repository.recordBuilder().recordType(rt.getName()).field(fieldType.getName(), "value2").create();

        RecordScan scan = new RecordScan();
        scan.setRecordFilter(new FieldValueFilter(fieldType.getName(), "value1"));
        assertEquals(2, countResults(repository.getScanner(scan)));

        scan = new RecordScan();
        scan.setRecordFilter(new FieldValueFilter(fieldType.getName(), "value2"));
        assertEquals(3, countResults(repository.getScanner(scan)));

        scan = new RecordScan();
        scan.setRecordFilter(new FieldValueFilter(fieldType.getName(), CompareOp.NOT_EQUAL, "value1"));
        assertEquals(3, countResults(repository.getScanner(scan)));

        // (At the time of this writing, ...) when non-versioned fields are deleted, a delete marker is
        // written rather than really deleting the field. This delete marker would then also be 'not equal'
        // to the value we search, and we'd get an extra result. This test verifies the implementation takes
        // care of that.
        record.getFieldsToDelete().add(fieldType.getName());
        record.setField(fieldType1.getName(), "whatever");
        record = repository.update(record);

        scan = new RecordScan();
        scan.setRecordFilter(new FieldValueFilter(fieldType.getName(), CompareOp.NOT_EQUAL, "value1"));
        assertEquals(3, countResults(repository.getScanner(scan)));
    }
View Full Code Here


        assertEquals(3, countResults(repository.getScanner(scan)));
    }

    @Test
    public void testFilterList() throws Exception {
        FieldType f1 = typeManager.createFieldType("STRING", new QName("FilterList", "field1"), Scope.NON_VERSIONED);
        FieldType f2 = typeManager.createFieldType("STRING", new QName("FilterList", "field2"), Scope.NON_VERSIONED);

        RecordType rt = typeManager.recordTypeBuilder().defaultNamespace("FilterList").name("rt")
                .fieldEntry().use(f1).add().fieldEntry().use(f2).add().create();

        repository.recordBuilder()
                .recordType(rt.getName())
                .field(f1.getName(), "A")
                .field(f2.getName(), "B")
                .create();

        repository.recordBuilder()
                .recordType(rt.getName())
                .field(f1.getName(), "A")
                .field(f2.getName(), "C")
                .create();

        repository.recordBuilder()
                .recordType(rt.getName())
                .field(f1.getName(), "D")
                .field(f2.getName(), "B")
                .create();

        repository.recordBuilder()
                .recordType(rt.getName())
                .field(f1.getName(), "F")
                .create();

        // Test f1=A and f2=B
        RecordScan scan = new RecordScan();
        RecordFilterList filterList = new RecordFilterList();
        filterList.addFilter(new FieldValueFilter(f1.getName(), "A"));
        filterList.addFilter(new FieldValueFilter(f2.getName(), "B"));
        scan.setRecordFilter(filterList);
        assertEquals(1, countResults(repository.getScanner(scan)));

        // Test f1=A or f2=B
        scan = new RecordScan();
        filterList = new RecordFilterList(RecordFilterList.Operator.MUST_PASS_ONE);
        filterList.addFilter(new FieldValueFilter(f1.getName(), "A"));
        filterList.addFilter(new FieldValueFilter(f2.getName(), "B"));
        scan.setRecordFilter(filterList);
        assertEquals(3, countResults(repository.getScanner(scan)));

        // Test f1=A and (f2=B or f2=C)
        scan = new RecordScan();
        RecordFilterList filterList2 = new RecordFilterList(RecordFilterList.Operator.MUST_PASS_ONE);
        filterList2.addFilter(new FieldValueFilter(f2.getName(), "B"));
        filterList2.addFilter(new FieldValueFilter(f2.getName(), "C"));
        filterList = new RecordFilterList();
        filterList.addFilter(new FieldValueFilter(f1.getName(), "A"));
        filterList.addFilter(filterList2);
        scan.setRecordFilter(filterList);
        assertEquals(2, countResults(repository.getScanner(scan)));

        // Test f1=F and f2=Z
        scan = new RecordScan();
        filterList = new RecordFilterList();
        filterList.addFilter(new FieldValueFilter(f1.getName(), "F"));
        filterList.addFilter(new FieldValueFilter(f2.getName(), "Z"));
        scan.setRecordFilter(filterList);
        assertEquals(0, countResults(repository.getScanner(scan)));

        // Test f1=F and (f2=Z with filterIfMissing=false)
        scan = new RecordScan();
        filterList = new RecordFilterList();
        filterList.addFilter(new FieldValueFilter(f1.getName(), "F"));
        FieldValueFilter fvf = new FieldValueFilter(f2.getName(), "Z");
        fvf.setFilterIfMissing(false);
        filterList.addFilter(fvf);
        scan.setRecordFilter(filterList);
        assertEquals(1, countResults(repository.getScanner(scan)));
    }
View Full Code Here

        assertEquals(1, countResults(repository.getScanner(scan)));
    }

    @Test
    public void testScanWithReturnFields() throws Exception {
        FieldType f1 = typeManager.createFieldType("STRING", new QName("ReturnFieldsScan", "f1"), Scope.NON_VERSIONED);
        FieldType f2 = typeManager.createFieldType("STRING", new QName("ReturnFieldsScan", "f2"), Scope.NON_VERSIONED);
        FieldType f3 = typeManager.createFieldType("STRING", new QName("ReturnFieldsScan", "f3"), Scope.NON_VERSIONED);
        FieldType f4 = typeManager.createFieldType("STRING", new QName("ReturnFieldsScan", "f4"), Scope.NON_VERSIONED);

        RecordType rt = typeManager.recordTypeBuilder().defaultNamespace("ReturnFieldsScan").name("rt")
                .fieldEntry().use(f1).add()
                .fieldEntry().use(f2).add()
                .fieldEntry().use(f3).add()
View Full Code Here

     * Tests if record type is set when different settings of returnFields is used.
     */
    @Test
    public void testScanWithReturnFieldsRecordType() throws Exception {
        String ns = "ReturnFieldsScan-RecordType";
        FieldType f1 = typeManager.createFieldType("STRING", new QName(ns, "f1"), Scope.NON_VERSIONED);
        FieldType f2 = typeManager.createFieldType("STRING", new QName(ns, "f2"), Scope.NON_VERSIONED);
        FieldType f3 = typeManager.createFieldType("STRING", new QName(ns, "f3"), Scope.NON_VERSIONED);
        FieldType f4 = typeManager.createFieldType("STRING", new QName(ns, "f4"), Scope.NON_VERSIONED);

        RecordType rt = typeManager.recordTypeBuilder().defaultNamespace(ns).name("rt")
                .fieldEntry().use(f1).add()
                .fieldEntry().use(f2).add()
                .fieldEntry().use(f3).add()
View Full Code Here

    @Test
    public void testMetadataNotSupportedOnBlobFields() throws Exception {
        String[] types = new String[]{"BLOB", "LIST<BLOB>", "LIST<PATH<BLOB>>"};

        for (int i = 0; i < types.length; i++) {
            FieldType blobField = typeManager
                    .createFieldType("BLOB", new QName("metadata-blob", "blob" + i), Scope.NON_VERSIONED);

            Blob blob = new Blob("text/plain", 5L, "foo");
            OutputStream os = repository.getOutputStream(blob);
            os.write("12345".getBytes());
            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

        Map<SchemaId, FieldType> fieldTypeIdCacheBucket = buckets.get(bucket);
        if (fieldTypeIdCacheBucket == null) {
            throw new FieldTypeNotFoundException(id);
        }
        FieldType fieldType = fieldTypeIdCacheBucket.get(id);
        if (fieldType == null) {
            throw new FieldTypeNotFoundException(id);
        }
        return fieldType.clone();
    }
View Full Code Here

    }

    @Override
    public FieldType getFieldType(QName name) throws FieldTypeNotFoundException, InterruptedException {
        ArgumentValidator.notNull(name, "name");
        FieldType fieldType = getNameCache().get(name);
        if (fieldType == null) {
            throw new FieldTypeNotFoundException(name);
        }
        return fieldType.clone();
    }
View Full Code Here

        return fieldType.clone();
    }

    public FieldType getFieldTypeByNameReturnNull(QName name) throws InterruptedException {
        ArgumentValidator.notNull(name, "name");
        FieldType fieldType = getNameCache().get(name);
        return fieldType != null ? fieldType.clone() : null;
    }
View Full Code Here

                System.err.println("A field can only be specified in combination with a vtag.");
                return -1;
            }

            String fieldParam = cmd.getOptionValue(fieldOption.getOpt());
            FieldType field = typeManager.getFieldTypeByName(QName.fromString(fieldParam));
            fieldId = field.getId();

            if (!field.getValueType().getDeepestValueType().getBaseName().equals("LINK")) {
                System.err.println("The field '" + field.getName() + "' is not a link field.");
                return -1;
            }
        }

        //
View Full Code Here

            TypeManager typeManager = repository.getTypeManager();

            if (idxSel.getFieldChanges() != null) {
                for (RecordEvent.FieldChange fieldChange : idxSel.getFieldChanges()) {
                    FieldType fieldType = typeManager.getFieldTypeById(fieldChange.getId());
                    QName name = fieldType.getName();

                    if (fieldChange.getNewValue() != null) {
                        Object value = fieldType.getValueType().read(fieldChange.getNewValue());
                        newRecord.setField(name, value);
                    }

                    if (fieldChange.getOldValue() != null) {
                        Object value = fieldType.getValueType().read(fieldChange.getOldValue());
                        oldRecord.setField(name, value);
                    }
                }
            }
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.