Ticket #1 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Creating a record with no versions returns 1 on Record.getVersion()

Reported by: bruno Owned by: evert
Priority: major Milestone:
Component: Repository Version:
Keywords: Cc:

Description

Creating a record with no versions returns 1 on Record.getVersion().

I would rather expect it to return null (since it declares a Long object) or maybe 0. This allows to distinguish records with versions from records without versions.

Change History

comment:1 Changed 3 years ago by bruno

This is a (succeeding) testcase to illustrate some of the current behavior:

(this also relates to #2)

    @Test
    public void testVersionNumbers() throws Exception {
        // Create a record without versioned fields, the record will be without versions
        Record record = repository.newRecord();
        record.setRecordType(recordType1.getId(), recordType1.getVersion());
        record.setField(fieldType1.getName(), "hello");
        record = repository.create(record);

        // This is currently 1, but would rather expect 0 or null
        //assertEquals(null, record.getVersion());

        // This is to verify that the version number does not augment beyond 1
        // when we have no versions (should be: stays at 0/null)
        record.setField(fieldType1.getName(), "hello2");
        repository.update(record);
        record = repository.read(record.getId());
        assertEquals(new Long(1), record.getVersion());

        // add a versioned field to the record
        record.setField(fieldType2.getName(), new Integer(4));
        record = repository.update(record);

        // The below fails because actual value is 2
        //assertEquals(new Long(1), record.getVersion());

        // Verify the last version number after a fresh record read
        record = repository.read(record.getId());
        // The below fails because actual value is 2
        // assertEquals(new Long(1), record.getVersion());

        record = repository.read(record.getId(), 1L);
        assertEquals(new Long(1), record.getVersion());
        // Verify the version 1 is really an empty version
        assertFalse(record.hasField(fieldType2.getName()));
        assertEquals(1, record.getFields().size());

        record = repository.read(record.getId(), 2L);
        assertEquals(new Long(2), record.getVersion());

        try {
            repository.read(record.getId(), 3L);
            fail("Expected an exception.");
        } catch (RecordNotFoundException e) {}
    }

comment:2 Changed 3 years ago by bruno

  • Status changed from new to closed
  • Resolution set to fixed

(In [4074]) Fix #1: Creating a record with no versions returns 1 on Record.getVersion()
Fix #2: First version created in an existing record: version 2
In the records table, the current version column will be absent when there is no version.
Added test (from comment in #1), clarified Record.getVersion() javadoc, updated Indexer and its tests.

Note: See TracTickets for help on using tickets.