orientdb icon indicating copy to clipboard operation
orientdb copied to clipboard

in Hooks getOriginalValue for an embeddedlist returns null

Open SafwanHak opened this issue 9 years ago • 3 comments

OrientDB Version: 2.2.19

Java Version: 8

OS: CENTOS

Expected behavior

In Java hooks, getOriginalValue should return the embedded list before change.

Actual behavior

returns null

Steps to reproduce

getOriginalValue is returning null for embeddedList. we need to use getOriginalValue to see what was added to remove duplicates. We have records created as follows.

INSERT INTO V SET ID = 1; update #9:0 add blax = [13] select from #9:0

We used the sample hooks provided on the website and the code is as follows. Everytime we call add on an embedded list, the getOriginalValue returns null and the new value returns the entire list, not the just the new data.

` public RESULT onRecordBeforeUpdate(ODocument document) { System.out.println("Ran update hook"); for (String field : document.getDirtyFields()) { System.out.println("Field Modified:" + field); Object originalValue = document.getOriginalValue(field);

        if (originalValue == null)
        {
            System.out.print("original value is null");
        }

        System.out.println("original value:" + originalValue);
        System.out.println("new value:" + document.field(field));
    }

    return ORecordHook.RESULT.RECORD_NOT_CHANGED;
}`

SafwanHak avatar May 02 '17 15:05 SafwanHak

Hi @SafwanHak

Thank you very much, we'll check it asap and let you know

Thanks

Luigi

luigidellaquila avatar May 02 '17 15:05 luigidellaquila

hi @SafwanHak,

The original value is used only when the whole field is replaced in case of elements inside a collection the tracking is done using ODocument#getCollectionTimeLine that give a list of events of added an removed elements from the collection.

Hope this help.

Regards

tglman avatar May 03 '17 11:05 tglman

Thanks, that makes sense, I'll give it a try, do you have examples of how to use it? Should I send an email for documentation to add this in the example, or will you take care of that? It's not obvious of course.

On Wed, May 3, 2017 at 12:01 PM, tglman [email protected] wrote:

hi @SafwanHak https://github.com/SafwanHak,

The original value is used only when the whole field is replaced in case of elements inside a collection the tracking is done using ODocument# getCollectionTimeLine that give a list of events of added an removed elements from the collection.

Hope this help.

Regards

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/orientechnologies/orientdb/issues/7385#issuecomment-298880802, or mute the thread https://github.com/notifications/unsubscribe-auth/ABxEo3OcpPM_CAXVxwfk6gWK_fV_RDnfks5r2F5vgaJpZM4NORz- .

SafwanHak avatar May 03 '17 11:05 SafwanHak