ORecordHookAbstract is firing onRecordAfterRead twice.

14 views
Skip to first unread message

Antonio Dias

unread,
Feb 26, 2015, 11:44:43 AM2/26/15
to orient-...@googlegroups.com
Hello all,

We're using the hook functionality to implement encryption of some document fields "transparently" to the caller.
Basically the process is:

1 : when onRecordBeforeCreate or onRecordBeforeUpdate event fires we apply encryption to some data fields and change the document before is created or updated

byte[] data = doc.field("data");
byte[] encrypted = encrypt(data);
doc
.field("data", encrypted);


2 : when onRecordAfterRead fires we get the encrypted data from the document fields, decrypt them, and change the document fields again with the decrypted data.

byte[] encrypted = doc.field("data");
byte[] decrypted = decrypt(encrypted);
doc
.field("data", decrypted);


The problem is that the event onRecordAfterRead is firing twice and in the first time the data decrypts correctly (because is encrypted) but on the second time the decryption fails because we already had decrypted it, and so the document "load" fails.

Is there some "bug" with this, or some way to avoid the event firing twice?

Antonio Dias

unread,
Feb 26, 2015, 12:13:36 PM2/26/15
to orient-...@googlegroups.com
Ok, so i have new information about this problem:

It happens if the query that i execute to load the document uses some field of the document in the filter (where clause).
So for example,  the following query does not trigger the problem:

select count from Data;

but the following query triggers the problem:

select from Data where status ="processed";

This is because i don't have an index on the status field. If i add an index then it fires the event only once. So this is related with the use or not of the indexes.
Should the events be fired if OrientDB is "scanning" the documents when executing a query? Shouldn't it only fire when the matching documents are in fact loaded?
Reply all
Reply to author
Forward
0 new messages