Orientdb: Automatic update of timestamp field on every change of data.

Created on 11 Oct 2018  Â·  6Comments  Â·  Source: orientechnologies/orientdb

OrientDB Version: OrientDB Server v3.0.8

Java Version: 1.8.0_181

OS: MacOS 10.14

I have VERTEX class and I would like to automatically update field with timestamp (DATETIME) on every that record data change.

Thank you guys.

question

Most helpful comment

@luigidellaquila , I really appreciate your help and patience.
Thanks to your help, I was able to come up with solution, so here it is :

CREATE FUNCTION updateDT "doc.field('fieldNameDT', new Date().getTime());" LANGUAGE Javascript

CREATE CLASS MyClass IF NOT EXISTS EXTENDS OTriggered;
ALTER CLASS MyClass CUSTOM onAfterUpdate='updateDT';

But in my case I had to extend EDGE class so instead CREATE CLASS MyClass IF NOT EXISTS EXTENDS OTriggered; use :

CREATE CLASS MyClass IF NOT EXISTS EXTENDS E;
ALTER CLASS MyClass SUPERCLASS +OTriggered;

Thanks

All 6 comments

Thank you,.. But can I use Dynamic Hooks in Vertex class ?

Sure, there is no limitation in terms of document types

But in my case, I am already extending the vertex class :
e.g. : CREATE CLASS MyVertexClass EXTENDS V

So, if I understand right to be able to use Dynamic Hooks I need to extend the class following way : CREATE CLASS MyVertexClass EXTENDS OTriggered

And that is changing the type of class to "Generic Class" and it is not Vertex anymore right ? Is this proper ? Or how to do this please ?

Thank you

Hi @petervavro

OrientDB supports multiple inheritance since v 2.1, see https://orientdb.com/docs/2.2.x/SQL-Alter-Class.html

Thanks

Luigi

@luigidellaquila , I really appreciate your help and patience.
Thanks to your help, I was able to come up with solution, so here it is :

CREATE FUNCTION updateDT "doc.field('fieldNameDT', new Date().getTime());" LANGUAGE Javascript

CREATE CLASS MyClass IF NOT EXISTS EXTENDS OTriggered;
ALTER CLASS MyClass CUSTOM onAfterUpdate='updateDT';

But in my case I had to extend EDGE class so instead CREATE CLASS MyClass IF NOT EXISTS EXTENDS OTriggered; use :

CREATE CLASS MyClass IF NOT EXISTS EXTENDS E;
ALTER CLASS MyClass SUPERCLASS +OTriggered;

Thanks

Was this page helpful?
0 / 5 - 0 ratings