Thomas
2012-07-11 10:16:11 UTC
Hi,
Using orientdb-graphed-1.0.1-SNAPSHOT I'm trying to create a history
solution using Hooks.
following which work except for the final save operation :-(
1. Copy a document that is about to be saved or deleted. The copy will be
used to create a history document.
2. Get all dirty fields from the document that is about to be updated and
then
3. Copy the original values from the ODocument (if any exist) and finally
4. save the document to a History cluster.
@Override
public boolean onRecordBeforeUpdate(ORecord<?> iRecord) {
if( iRecord instanceof ODocument ){
ODocument doc = (ODocument) iRecord;
if(validateClusterId(doc)) {
ODocument copy = doc.copy(); // Contains dirty fields that
we need to update with the old values before we can save the document to
History.
String[] dirtyFields = doc.getDirtyFields();
for(int i=0;i<dirtyFields.length;i++){
if(doc.getOriginalValue(dirtyFields[i]) == null)
System.out.println("Field [ " + dirtyFields[i] + " ] did not exist in
previous version");
else {
System.out.println("Original Value of dirty field [
" + dirtyFields[i] +
" ] will be copied to History version.
Original value to be copied to the History version is [ " +
doc.getOriginalValue(dirtyFields[i]) + " ]
New value is [ " + doc.field(dirtyFields[i]) + " ]");
copy.field(dirtyFields[i],
doc.getOriginalValue(dirtyFields[i]));
}
}
copy.save("History");
}
}
return true;
}
The problem is the final save operation which give the following exception:
com.orientechnologies.orient.core.exception.OConcurrentModificationException:
Cannot update record #8:0 in storage 'orientdb' because the version is not
the latest.
Probably you are updating an old record or it has been modified by another
user (db=v1 your=v0)
I have also tried to use doc.getDatabase() and then create a new Vertex or
Edge, but this is not possible.
Any suggestions on how to save from inside the Hook?
Thanks
Using orientdb-graphed-1.0.1-SNAPSHOT I'm trying to create a history
solution using Hooks.
From inside the hooks (ONLY onRecordBeforeUpdate and onRecordBeforeDelete)
I want to do thefollowing which work except for the final save operation :-(
1. Copy a document that is about to be saved or deleted. The copy will be
used to create a history document.
2. Get all dirty fields from the document that is about to be updated and
then
3. Copy the original values from the ODocument (if any exist) and finally
4. save the document to a History cluster.
@Override
public boolean onRecordBeforeUpdate(ORecord<?> iRecord) {
if( iRecord instanceof ODocument ){
ODocument doc = (ODocument) iRecord;
if(validateClusterId(doc)) {
ODocument copy = doc.copy(); // Contains dirty fields that
we need to update with the old values before we can save the document to
History.
String[] dirtyFields = doc.getDirtyFields();
for(int i=0;i<dirtyFields.length;i++){
if(doc.getOriginalValue(dirtyFields[i]) == null)
System.out.println("Field [ " + dirtyFields[i] + " ] did not exist in
previous version");
else {
System.out.println("Original Value of dirty field [
" + dirtyFields[i] +
" ] will be copied to History version.
Original value to be copied to the History version is [ " +
doc.getOriginalValue(dirtyFields[i]) + " ]
New value is [ " + doc.field(dirtyFields[i]) + " ]");
copy.field(dirtyFields[i],
doc.getOriginalValue(dirtyFields[i]));
}
}
copy.save("History");
}
}
return true;
}
The problem is the final save operation which give the following exception:
com.orientechnologies.orient.core.exception.OConcurrentModificationException:
Cannot update record #8:0 in storage 'orientdb' because the version is not
the latest.
Probably you are updating an old record or it has been modified by another
user (db=v1 your=v0)
I have also tried to use doc.getDatabase() and then create a new Vertex or
Edge, but this is not possible.
Any suggestions on how to save from inside the Hook?
Thanks