Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.RecordId


    public void testVariantScansWithKeysUUID() throws Exception {
        doTestVariantScansWithKeys(idGenerator.newRecordId());
    }

    private void doTestVariantScansWithKeys(RecordId master) throws Exception {
        final RecordId variant = idGenerator.newRecordId(master, ImmutableMap.of("key1", "value1", "key2", "value2"));
        final RecordId variantWithOtherValues =
                idGenerator.newRecordId(master, ImmutableMap.of("key1", "other-value-1", "key2", "other-value-2"));
        final RecordId extendedVariant =
                idGenerator.newRecordId(master, ImmutableMap.of("key1", "value1", "key2", "value2", "key3", "value3"));

        repository.recordBuilder()
                .id(master)
                .recordType(recordType1.getName())
                .field(fieldType1.getName(), "foo")
                .create();

        repository.recordBuilder()
                .id(variant)
                .recordType(recordType1.getName())
                .field(fieldType1.getName(), "foo")
                .create();

        repository.recordBuilder()
                .id(extendedVariant)
                .recordType(recordType1.getName())
                .field(fieldType1.getName(), "foo")
                .create();

        repository.recordBuilder()
                .id(variantWithOtherValues)
                .recordType(recordType1.getName())
                .field(fieldType1.getName(), "foo")
                .create();

        {
            // master scan
            final RecordScan scan = new RecordScan();
            scan.setRecordFilter(new RecordVariantFilter(master, new HashMap<String, String>()));
            RecordScanner scanner = repository.getScanner(scan);
            assertEquals(master, scanner.next().getId());
            assertNull(scanner.next());
            scanner.close();
        }

        {
            // variant scan
            final HashMap<String, String> variantProperties = new HashMap<String, String>();
            variantProperties.put("foo", null);
            variantProperties.put("bar", null);

            final RecordScan scan = new RecordScan();
            scan.setRecordFilter(new RecordVariantFilter(variant.getMaster(), variantProperties));
            RecordScanner scanner = repository.getScanner(scan);
            assertNull(scanner.next()); // it doesn't match anything
            scanner.close();
        }

        {
            // variant scan for something completely different
            final HashMap<String, String> variantProperties = new HashMap<String, String>();
            variantProperties.put("key1", null);
            variantProperties.put("key2", null);

            final RecordScan scan = new RecordScan();
            scan.setRecordFilter(new RecordVariantFilter(variant.getMaster(), variantProperties));
            RecordScanner scanner = repository.getScanner(scan);
            assertEquals(variant, scanner.next().getId());
            assertEquals(variantWithOtherValues, scanner.next().getId());
            assertNull(scanner.next()); // it doesn't match the extendedVariant!
            scanner.close();
        }

        {
            // extended variant scan
            final HashMap<String, String> variantProperties = new HashMap<String, String>();
            variantProperties.put("key1", null);
            variantProperties.put("key2", null);
            variantProperties.put("key3", null);

            final RecordScan scan = new RecordScan();
            scan.setRecordFilter(
                    new RecordVariantFilter(extendedVariant.getMaster(), variantProperties));
            RecordScanner scanner = repository.getScanner(scan);
            assertEquals(extendedVariant, scanner.next().getId());
            assertNull(scanner.next());
            scanner.close();
        }
View Full Code Here


        }
    }

    @Test
    public void testVariantScansWithKeysAndValues() throws Exception {
        final RecordId master = idGenerator.newRecordId("VariantScanWithKeysAndValuesTest");
        final RecordId variant = idGenerator.newRecordId(master, ImmutableMap.of("key1", "value1", "key2", "value2"));
        final RecordId variantWithOtherValues =
                idGenerator.newRecordId(master, ImmutableMap.of("key1", "other-value-1", "key2", "value2"));
        final RecordId extendedVariant =
                idGenerator.newRecordId(master, ImmutableMap.of("key1", "value1", "key2", "value2", "key3", "value3"));

        repository.recordBuilder()
                .id(master)
                .recordType(recordType1.getName())
View Full Code Here

                .value("field2", "value2")
                .value("field3", "value3").build();

        record.setMetadata(fieldType1.getName(), metadata);
        record = repository.create(record);
        RecordId recordId = record.getId();

        // Now update metadata:
        //   - field1 is left unchanged and not specified
        //   - field2 is updated
        //   - field3 is deleted
View Full Code Here

        Record record = repository.newRecord();
        record.setRecordType(recordType1.getName());
        record.setField(fieldType2.getName(), new Integer(5));
        record.setMetadata(fieldType2.getName(), new MetadataBuilder().value("field1", "value1").build());
        record = repository.create(record);
        RecordId recordId = record.getId();

        // update only field value, metadata should not be lost be inherited from previous record state
        record = repository.newRecord();
        record.setId(recordId);
        record.setField(fieldType2.getName(), new Integer(7));
View Full Code Here

        record.setField(fieldType2.getName(), new Integer(5));
        record.setMetadata(fieldType2.getName(), new MetadataBuilder()
                .value("field1", "value1")
                .value("field2", "value2").build());
        record = repository.create(record);
        RecordId recordId = record.getId();

        // Update only metadata -- should create new version
        record = repository.newRecord();
        record.setId(recordId);
        record.setMetadata(fieldType2.getName(), new MetadataBuilder().value("field1", "value1a").build());
View Full Code Here

        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);
View Full Code Here

            throws AvroRepositoryException, AvroInterruptedException {
        try {
            AuthorizationContextHolder.setCurrentContext(converter.convert(authzContext));
            LRepository repository = repositoryManager.getRepository(repositoryName);
            LTable table = repository.getTable(tableName);
            RecordId decodedRecordId = converter.convertAvroRecordId(recordId, repository);
            Record record = null;
            if (attributes == null) {
                record = table.delete(decodedRecordId, converter.convertFromAvro(conditions, repository));
            } else if (conditions == null) {
                Record toDelete = table.newRecord(decodedRecordId);
View Full Code Here

        DataInput[] splitted = id.factory.splitInMasterAndVariant(dataInput);
        DataInput masterIdInput = splitted[0];
        DataInput variantParamsInput = splitted[1];

        RecordId masterRecordId = id.factory.fromBytes(masterIdInput, this);

        if (variantParamsInput != null) {
            return new VariantRecordId(masterRecordId, variantParamsInput, this);
        } else {
            return masterRecordId;
View Full Code Here

            throw new IllegalArgumentException("Invalid record id: unknown type '" + type + "' in record id '" +
                    recordIdString + "'.");
        }

        checkEscapedReservedCharacters(id);
        RecordId masterRecordId = factory.fromString(StringEscapeUtils.unescapeJava(id), this);

        if (variantString == null) {
            return masterRecordId;
        }
View Full Code Here

        idGenerator = new IdGeneratorImpl();
    }

    @Test
    public void testPlainRecordId() {
        RecordId recordId = idGenerator.newRecordId("123");

        Link link = Link.newBuilder().recordId(recordId).create();
        assertTrue(link.copyAll());
        assertEquals(recordId, link.getMasterRecordId());

        assertEquals("USER.123", link.toString());
        assertEquals(link, Link.fromString(link.toString(), idGenerator));
        DataOutput dataOutput = new DataOutputImpl();
        link.write(dataOutput);
        assertEquals(link, Link.read(new DataInputImpl(dataOutput.toByteArray()), idGenerator));

        RecordId ctx = idGenerator.newRecordId("0");
        RecordId resolved = link.resolve(ctx, idGenerator);
        assertEquals(recordId, resolved);

        // test the copy all
        Map<String, String> varProps = new HashMap<String, String>();
        varProps.put("a", "1");
        varProps.put("b", "2");

        ctx = idGenerator.newRecordId(ctx, varProps);
        resolved = link.resolve(ctx, idGenerator);
        assertEquals(recordId, resolved.getMaster());
        assertEquals(2, resolved.getVariantProperties().size());
    }
View Full Code Here

TOP

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

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.