Package org.lilyproject.repository.api

Examples of org.lilyproject.repository.api.Record


    @Test
    public void testIndexer_AddAndUpdate_DisabledIndexing() throws Exception {
        changeIndexUpdater("indexerconf1.xml");

        // Create a record that should be indexed
        Record recordToIndex = defaultTable.newRecord();
        recordToIndex.setRecordType(nvRecordType1.getName());
        recordToIndex.setField(nvfield1.getName(), "mango");
        recordToIndex.setField(nvTag.getName(), 0L);
        recordToIndex = defaultTable.create(recordToIndex);


        // Create a record that shouldn't be indexed (due to the "lily.mq" attribute
        Record recordToNotIndex = defaultTable.newRecord();
        recordToNotIndex.setRecordType(nvRecordType1.getName());
        recordToNotIndex.setField(nvfield1.getName(), "mango");
        recordToNotIndex.setField(nvTag.getName(), 0L);

        // Mark this record to not be indexed
        recordToNotIndex.getAttributes().put("lily.mq", "false");
        recordToNotIndex = defaultTable.create(recordToNotIndex);

        commitIndex();
        verifyResultCount("lily.id:" + recordToIndex.getId().toString(), 1);
        verifyResultCount("lily.id:" + recordToNotIndex.getId().toString(), 0);
        verifyResultCount("nv_field1:mango", 1);

        // Now we'll update the recordToIndex, first without indexing, and then with it

        recordToIndex.setField(nvfield1.getName(), "orange");
View Full Code Here


    @Test
    public void testIndexer_Delete_DisabledIndexing() throws Exception {
        changeIndexUpdater("indexerconf1.xml");

        // Create a record that should be indexed
        Record recordToIndex = defaultTable.newRecord();
        recordToIndex.setRecordType(nvRecordType1.getName());
        recordToIndex.setField(nvfield1.getName(), "papaya");
        recordToIndex.setField(nvTag.getName(), 0L);
        recordToIndex = defaultTable.create(recordToIndex);


        // Create a record that shouldn't be indexed (due to the "lily.mq" attribute
        Record recordToNotIndex = defaultTable.newRecord();
        recordToNotIndex.setRecordType(nvRecordType1.getName());
        recordToNotIndex.setField(nvfield1.getName(), "papaya");
        recordToNotIndex.setField(nvTag.getName(), 0L);
        recordToNotIndex = defaultTable.create(recordToNotIndex);

        commitIndex();

        // Sanity check
        verifyResultCount("lily.id:" + recordToIndex.getId().toString(), 1);
        verifyResultCount("lily.id:" + recordToNotIndex.getId().toString(), 1);
        verifyResultCount("nv_field1:papaya", 2);


        // Now delete both records, but disable indexing on one of them
        recordToNotIndex.getAttributes().put("lily.mq", "false");

        defaultTable.delete(recordToIndex);
        defaultTable.delete(recordToNotIndex);
        commitIndex();

        // And check that the index has only been updated for the record that should be indexed
        verifyResultCount("lily.id:" + recordToIndex.getId().toString(), 0);
        verifyResultCount("lily.id:" + recordToNotIndex.getId().toString(), 1);
        verifyResultCount("nv_field1:papaya", 1);
    }
View Full Code Here

        changeIndexUpdater("indexerconf1.xml");

        messageVerifier.init();

        log.debug("Begin test deref single table");
        Record record1 = defaultTable.newRecord();
        record1.setRecordType(nvRecordType1.getName());
        record1.setField(nvfield1.getName(), "derefsinglepear");
        record1.setField(nvTag.getName(), 0L);
        expectEvent(CREATE, Table.RECORD.name, record1.getId(), nvfield1.getId(), nvTag.getId());
        record1 = defaultTable.create(record1);

        Record record2 = defaultTable.newRecord();
        record2.setRecordType(nvRecordType1.getName());
        record2.setField(nvLinkField1.getName(), new Link(record1.getId()));
        record2.setField(nvTag.getName(), 0L);
        expectEvent(CREATE, Table.RECORD.name, record2.getId(), nvLinkField1.getId(), nvTag.getId());
        record2 = defaultTable.create(record2);

        commitIndex();
        verifyResultCount("nv_deref1:derefsinglepear", 1);
View Full Code Here

        changeIndexUpdater("indexerconf1.xml", Table.RECORD.name, false);

        messageVerifier.init();

        log.debug("Begin test disabled deref");
        Record record1 = defaultTable.newRecord();
        record1.setRecordType(nvRecordType1.getName());
        record1.setField(nvfield1.getName(), "noderefSnickers");
        record1.setField(nvTag.getName(), 0L);
        expectEvent(CREATE, Table.RECORD.name, record1.getId(), nvfield1.getId(), nvTag.getId());
        record1 = defaultTable.create(record1);

        Record record2 = defaultTable.newRecord();
        record2.setRecordType(nvRecordType1.getName());
        record2.setField(nvLinkField1.getName(), new Link(record1.getId()));
        record2.setField(nvTag.getName(), 0L);
        expectEvent(CREATE, Table.RECORD.name, record2.getId(), nvLinkField1.getId(), nvTag.getId());
        record2 = defaultTable.create(record2);

        commitIndex();
        verifyResultCount("nv_deref1:noderefSnickers", 1);
View Full Code Here

        changeIndexUpdater("indexerconf1.xml", alternateTable.getTableName());

        messageVerifier.init();

        log.debug("Begin test deref single non-standard table");
        Record record1 = alternateTable.newRecord();
        record1.setRecordType(nvRecordType1.getName());
        record1.setField(nvfield1.getName(), "derefsinglenonstandardpear");
        record1.setField(nvTag.getName(), 0L);
        expectEvent(CREATE, ALTERNATE_TABLE, record1.getId(), nvfield1.getId(), nvTag.getId());
        record1 = alternateTable.create(record1);

        Record record2 = alternateTable.newRecord();
        record2.setRecordType(nvRecordType1.getName());
        record2.setField(nvLinkField1.getName(), new Link(ALTERNATE_TABLE, record1.getId()));
        record2.setField(nvTag.getName(), 0L);
        expectEvent(CREATE, ALTERNATE_TABLE, record2.getId(), nvLinkField1.getId(), nvTag.getId());
        record2 = alternateTable.create(record2);

        commitIndex();
        verifyResultCount("nv_deref1:derefsinglenonstandardpear", 1);
View Full Code Here

        changeIndexUpdater("indexerconf1.xml", ALTERNATE_TABLE);

        messageVerifier.init();

        log.debug("Begin test deref single non-standard table");
        Record record1 = alternateTable.newRecord();
        record1.setRecordType(nvRecordType1.getName());
        record1.setField(nvfield1.getName(), "derefsinglenonstandardnolinkpear");
        record1.setField(nvTag.getName(), 0L);
        expectEvent(CREATE, ALTERNATE_TABLE, record1.getId(), nvfield1.getId(), nvTag.getId());
        record1 = alternateTable.create(record1);

        Record record2 = alternateTable.newRecord();
        record2.setRecordType(nvRecordType1.getName());
        record2.setField(nvLinkField1.getName(), new Link(record1.getId()));
        record2.setField(nvTag.getName(), 0L);
        expectEvent(CREATE, ALTERNATE_TABLE, record2.getId(), nvLinkField1.getId(), nvTag.getId());
        record2 = alternateTable.create(record2);

        commitIndex();
        verifyResultCount("nv_deref1:derefsinglenonstandardnolinkpear", 1);
View Full Code Here

        }
    }

    private ActionResult createRecord(TestRecordType recordTypeToCreate) {
        double duration = 0;
        Record record;
        if (testActionContext.roundRobinPrefixGenerator == null) {
            record = testActionContext.repository.getRecordFactory().newRecord();
        } else {
            record = testActionContext.repository.getRecordFactory().newRecord(createPrefixedRecordId());
        }

        // Prepare record by generating values for the fields
        record.setRecordType(recordTypeToCreate.getRecordType().getName());
        List<TestFieldType> fieldTypesToCreate = recordTypeToCreate.getFieldTypes();
        for (TestFieldType testFieldType : fieldTypesToCreate) {
            QName fieldQName = testFieldType.getFieldType().getName();
            ActionResult result = testFieldType.generateValue(this);
            duration += result.duration;
            if (!result.success) {
                return new ActionResult(false, null, duration);
            }
            record.setField(fieldQName, result.object);
        }

        // Perform the actual creation of the record on the repository
        boolean success;
        long before = System.nanoTime();
View Full Code Here

        changeIndexUpdater("indexerconf1.xml", "(record|alternate)");

        messageVerifier.init();

        log.debug("Begin test deref multiple tables");
        Record record1 = defaultTable.newRecord();
        record1.setRecordType(nvRecordType1.getName());
        record1.setField(nvfield1.getName(), "derefmultipear");
        record1.setField(nvTag.getName(), 0L);
        expectEvent(CREATE, ALTERNATE_TABLE, record1.getId(), nvfield1.getId(), nvTag.getId());
        record1 = alternateTable.create(record1);

        Record record2 = defaultTable.newRecord();
        record2.setRecordType(nvRecordType1.getName());
        record2.setField(nvLinkField1.getName(), new Link(ALTERNATE_TABLE, record1.getId()));
        record2.setField(nvTag.getName(), 0L);
        expectEvent(CREATE, Table.RECORD.name, record2.getId(), nvLinkField1.getId(), nvTag.getId());
        record2 = defaultTable.create(record2);

        commitIndex();
        verifyResultCount("nv_deref1:derefmultipear", 1);
View Full Code Here

        assertEquals(rtName, record.getRecordTypeName());
    }

    @Test
    public void testUpdateMutableField() throws Exception {
        Record record = repository.newRecord();
        record.setRecordType(recordType2.getName(), recordType2.getVersion());
        record.setField(fieldType4.getName(), 123);
        record.setField(fieldType5.getName(), true);
        record.setField(fieldType6.getName(), "value1");
        record = repository.create(record);

        Record updateRecord = record.cloneRecord();
        updateRecord.setField(fieldType4.getName(), 456);
        updateRecord.setField(fieldType5.getName(), false);
        updateRecord.setField(fieldType6.getName(), "value2");
        repository.update(updateRecord);

        // Read version 1
        Record readRecord = repository.read(record.getId(), Long.valueOf(1));
        assertEquals(456, readRecord.getField(fieldType4.getName()));
        assertEquals(true, readRecord.getField(fieldType5.getName()));
        assertEquals("value1", readRecord.getField(fieldType6.getName()));

        // Update mutable version 1
        Record mutableRecord = repository.newRecord(record.getId());
        mutableRecord.setRecordType(recordType2.getName(), recordType2.getVersion());
        mutableRecord.setField(fieldType6.getName(), "value3");
        mutableRecord.setVersion(1L);
        mutableRecord = repository.update(mutableRecord, true, false);

        // Read version 1 again
        readRecord = repository.read(record.getId(), 1L);
        assertEquals(456, readRecord.getField(fieldType4.getName()));
        assertEquals(true, readRecord.getField(fieldType5.getName()));
        assertEquals("value3", readRecord.getField(fieldType6.getName()));

        // Update mutable version 2
        mutableRecord.setVersion(2L);
        mutableRecord.setField(fieldType6.getName(), "value4");
        mutableRecord = repository.update(mutableRecord, true, false);

        // Read version 2
        readRecord = repository.read(record.getId(), 2L);
        assertEquals(456, readRecord.getField(fieldType4.getName()));
View Full Code Here

    }

    @Test
    public void testUpdateMutableFieldWithNewRecordType() throws Exception {
        // Create default record
        Record record = createDefaultRecord();

        // Update the record, creates a second version
        Record updateRecord = record.cloneRecord();
        updateRecord.setField(fieldType1.getName(), "value2");
        updateRecord.setField(fieldType2.getName(), 789);
        updateRecord.setField(fieldType3.getName(), false);
        repository.update(updateRecord, false, false);

        // Read the first version of the record
        Record readRecord = repository.read(record.getId(), Long.valueOf(1));
        assertEquals(recordType1.getName(), readRecord.getRecordTypeName());
        assertEquals(recordType1.getVersion(), readRecord.getRecordTypeVersion());
        assertEquals(recordType1.getName(), readRecord.getRecordTypeName(Scope.NON_VERSIONED));
        assertEquals(recordType1.getVersion(), readRecord.getRecordTypeVersion(Scope.NON_VERSIONED));
        assertEquals(recordType1.getName(), readRecord.getRecordTypeName(Scope.VERSIONED));
        assertEquals(recordType1.getVersion(), readRecord.getRecordTypeVersion(Scope.VERSIONED));
        assertEquals(recordType1.getName(), readRecord.getRecordTypeName(Scope.VERSIONED_MUTABLE));
        assertEquals(recordType1.getVersion(), readRecord.getRecordTypeVersion(Scope.VERSIONED_MUTABLE));

        // Do a mutable update of the first version of the record, change the record type
        Record updateMutableRecord = repository.newRecord(record.getId());
        updateMutableRecord.setVersion(Long.valueOf(1));
        updateMutableRecord.setRecordType(recordType2.getName(), recordType2.getVersion());
        updateMutableRecord.setField(fieldType4.getName(), 888);
        updateMutableRecord.setField(fieldType5.getName(), false);
        updateMutableRecord.setField(fieldType6.getName(), "value3");

        Record updatedMutableRecord = repository.update(updateMutableRecord, true, false);
        assertEquals(Long.valueOf(1), updatedMutableRecord.getVersion());

        // Read the first version of the record again
        readRecord = repository.read(record.getId(), Long.valueOf(1));
        assertEquals(Long.valueOf(1), readRecord.getVersion());
        assertEquals("value2", readRecord.getField(fieldType1.getName()));
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.