Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.Record


        ValueType rvt = typeManager.getValueType("RECORD");
        FieldType ft1 = typeManager.createFieldType(typeManager.newFieldType(rvt, ft1Name, Scope.NON_VERSIONED));
        FieldType ft2 = typeManager.createFieldType(typeManager.newFieldType(rvt, ft2Name, Scope.VERSIONED));
        typeManager.recordTypeBuilder().name(rtName).field(ft1.getId(), false).field(ft2.getId(), false).create();

        Record ft1Value1 = repository.recordBuilder().recordType(rvtRTName).field(fieldType1.getName(), "ft1abc")
                .build();

        // Create nested record

        Record record = repository.recordBuilder().recordType(rtName).field(ft1Name, ft1Value1).build();
        record.setField(ft2Name, record);
        try {
            repository.create(record);
            fail("Expecting a Record Exception since a record may not be nested in itself");
        } catch (RecordException expected) {
        }

        // Create with deep nesting

        Record ft2Value2 = repository.recordBuilder().recordType(rvtRTName).field(ft1Name, record).build();
        record.setField(ft2Name, ft2Value2);
        try {
            repository.create(record);
            fail("Expecting a Record Exception since a record may not be nested in itself");
        } catch (RecordException expected) {
View Full Code Here


        FieldType byteArrayValueType = typeManager.createFieldType("BYTEARRAY", new QName("testByteArrayValueType",
                "field1"), Scope.NON_VERSIONED);
        RecordType recordType = typeManager.recordTypeBuilder().defaultNamespace("testByteArrayValueType")
                .name("recordType1")
                .field(byteArrayValueType.getId(), false).create();
        Record record = repository.recordBuilder().defaultNamespace("testByteArrayValueType").recordType("recordType1")
                .field("field1", new ByteArray(Bytes.toBytes("some bytes"))).create();
        Record readRecord = repository.read(record.getId());
        ByteArray readValue = readRecord.getField(new QName("testByteArrayValueType", "field1"));
        assertEquals("some bytes", Bytes.toString(readValue.getBytesUnsafe()));
    }
View Full Code Here

    @Test
    public void testScannerBasics() throws Exception {
        List<String> fieldValues = new ArrayList<String>();
        for (int i = 'A'; i <= 'Z'; i++) {
            RecordId id = idGenerator.newRecordId("Z" + (char) i);
            Record record = repository.newRecord(id);
            record.setRecordType(recordType1.getName());
            String value = "field 1 - " + (char) i;
            fieldValues.add(value);
            record.setField(fieldType1.getName(), value);
            repository.create(record);
        }

        RecordScan scan = new RecordScan();
        scan.setStartRecordId(idGenerator.newRecordId("ZA"));
        scan.setStopRecordId(idGenerator.newRecordId("ZZ")); // stop row is exclusive

        RecordScanner scanner = repository.getScanner(scan);

        int i = 0;
        Record record;
        while ((record = scanner.next()) != null) {
            assertEquals(record.getField(fieldType1.getName()), fieldValues.get(i));
            i++;
        }
        scanner.close();
        assertEquals("Found 25 records", 25, i);
View Full Code Here

    }

    @Test
    public void testScannerWithIdRecords() throws Exception {
        RecordId id = idGenerator.newRecordId();
        Record record = repository.newRecord(id);
        record.setRecordType(recordType1.getName());
        record.setField(fieldType1.getName(), "dummy value");
        repository.create(record);

        RecordScan scan = new RecordScan();

        IdRecordScanner scanner = repository.getScannerWithIds(scan);
View Full Code Here

    }

    @Test(expected = ClassCastException.class)
    public void testScannerWithoutIdRecords() throws Exception {
        RecordId id = idGenerator.newRecordId();
        Record record = repository.newRecord(id);
        record.setRecordType(recordType1.getName());
        record.setField(fieldType1.getName(), "dummy value");
        repository.create(record);

        RecordScan scan = new RecordScan();

        // normal Record scanner!
        RecordScanner scanner = repository.getScanner(scan);
        final Record next = scanner.next();
        assertNotNull(next);

        // this cast will fail
        final IdRecord casted = (IdRecord) next;
    }
View Full Code Here

                .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

        // Test ALL filter
        RecordScan scan = new RecordScan();
        scan.setRecordFilter(new RecordTypeFilter(rt.getName()));
        scan.setReturnFields(new ReturnFields(ReturnFields.Type.ALL));
        Record record = repository.getScanner(scan).next();
        assertEquals(3, record.getFields().size());

        // Test NONE filter
        scan = new RecordScan();
        scan.setRecordFilter(new RecordTypeFilter(rt.getName()));
        scan.setReturnFields(new ReturnFields(ReturnFields.Type.NONE));
        record = repository.getScanner(scan).next();
        assertEquals(0, record.getFields().size());

        // Test ENUM filter
        scan = new RecordScan();
        scan.setRecordFilter(new RecordTypeFilter(rt.getName()));
        scan.setReturnFields(new ReturnFields(f1.getName(), f2.getName()));
        record = repository.getScanner(scan).next();
        assertEquals(2, record.getFields().size());
        assertTrue(record.hasField(f1.getName()));
        assertTrue(record.hasField(f2.getName()));
        assertFalse(record.hasField(f3.getName()));

        // Test scanning on filtered field, should not work
        scan = new RecordScan();
        RecordFilterList filterList = new RecordFilterList();
        filterList.addFilter(new RecordTypeFilter(rt.getName()));
View Full Code Here

                break;
            }
        }

        if (!allSatisfied) {
            Record responseRecord = record.cloneRecord();
            if (newRecord != null) {
                // reduce the fields to return to those that were submitted
                reduceFields(responseRecord, newRecord.getFields().keySet());
            } else {
                // reduce the fields to those on which conditions were put
                reduceFields(responseRecord, extractFields(conditions));
            }
            responseRecord.setResponseStatus(ResponseStatus.CONFLICT);
            return responseRecord;
        }

        return null;
    }
View Full Code Here

        // Test ALL filter
        RecordScan scan = new RecordScan();
        scan.setRecordFilter(new RecordTypeFilter(rt.getName()));
        scan.setReturnFields(new ReturnFields(ReturnFields.Type.ALL));
        Record record = repository.getScanner(scan).next();
        assertNotNull(record.getRecordTypeName());
        assertEquals(ns, record.getRecordTypeName().getNamespace());

        // Test NONE filter
        scan = new RecordScan();
        scan.setRecordFilter(new RecordTypeFilter(rt.getName()));
        scan.setReturnFields(new ReturnFields(ReturnFields.Type.NONE));
        record = repository.getScanner(scan).next();
        assertNotNull(record.getRecordTypeName());
        assertEquals(ns, record.getRecordTypeName().getNamespace());

        // Test ENUM filter
        scan = new RecordScan();
        scan.setRecordFilter(new RecordTypeFilter(rt.getName()));
        scan.setReturnFields(new ReturnFields(f1.getName(), f2.getName()));
        record = repository.getScanner(scan).next();
        assertNotNull(record.getRecordTypeName());
        assertEquals(ns, record.getRecordTypeName().getNamespace());
    }
View Full Code Here

        LTable table = repository.getTable(indexUpdateBuilder.getTable());
        final IdRecordScanner scanner = table.getScannerWithIds(scan);
        IdRecord next;
        while ((next = scanner.next()) != null) {
            try {
                final Record record = VersionTag.getIdRecord(next, indexUpdateBuilder.getVTag(), table, repository);
                result.add(record);
            } catch (RecordNotFoundException rnfe) {
                //ok
            } catch (VersionNotFoundException vnfe) {
                //ok
View Full Code Here

TOP

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

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.