orientechnologies / orientechnologies/orientdb

Different behavior of reload() in and out a transaction

Open
#3,555 6 comments 0 reactions 1 assignee View on GitHub

@tglman is already working on this.

Since Feb 18, 2017.

Dominant language
Java
Stars
5k
Forks
868
Avg merge
15h 6m
Merged PRs (30d)
18

Description

Guys,

I consider following as a bug (OrientDB 2.0.1):

    @Test
    public void testUpdatesInHooks()
    {
        final String className = "TestUpdatesInHook";
        ODatabaseDocument db = wicket.getTester().getDatabase();
        db.registerHook(new ODocumentHookAbstract() {

            {
                setIncludeClasses(className);
            }

            @Override
            public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
                return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE;
            }

            @Override
            public RESULT onRecordBeforeCreate(ODocument iDocument) {
                return onRecordBeforeUpdate(iDocument);
            }

            @Override
            public RESULT onRecordBeforeUpdate(ODocument iDocument) {
                iDocument.undo("b");
                return RESULT.RECORD_CHANGED;
            }

            @Override
            public void onRecordAfterRead(ODocument iDocument) {
                if(!iDocument.containsField("b"))
                    iDocument.field("b", iDocument.field("a"));
            }


        });
        OSchema schema = db.getMetadata().getSchema();
        OClass classA = schema.createClass(className);
        classA.createProperty("a", OType.STRING);
        classA.createProperty("b", OType.STRING);
        db.commit();
        ODocument doc = new ODocument(classA);
        doc.field("a", "test1");
        doc.save();
        doc.reload();
        assertEquals(doc.field("a"), doc.field("b"));
        doc.field("a", "test2");
        doc.save();
        doc.reload();
        assertEquals(doc.field("a"), doc.field("b"));
        db.begin();
        doc.field("a", "test3");
        doc.save();
        doc.reload();
        assertEquals(doc.field("a"), doc.field("b"));
        doc.field("a", "test4");
        doc.save();
        doc.reload();
        assertEquals(doc.field("a"), doc.field("b"));
        db.commit();
    }

Can you guess which particular assert is failing?

The third one.

It seams that reload() in transaction doesn fire onRecordAfterRead().

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.