Search in sources :

Example 6 with DISTRIBUTED_EXECUTION_MODE

use of com.orientechnologies.orient.core.hook.ORecordHook.DISTRIBUTED_EXECUTION_MODE in project wicket-orientdb by OrienteerBAP.

the class TestInAppOrientDBCompatibility method testDocumentTrackingComplex.

@Test
@Ignore
public void testDocumentTrackingComplex() {
    final String className = "TestDocumentTrackingComplex";
    ODatabaseDocument db = wicket.getTester().getDatabase();
    OSchema schema = db.getMetadata().getSchema();
    final OClass classA = schema.createClass(className);
    classA.createProperty("a", OType.STRING);
    classA.createProperty("b", OType.STRING);
    db.registerHook(new ODocumentHookAbstract(db) {

        {
            setIncludeClasses(className);
        }

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

        @Override
        public void onRecordAfterCreate(ODocument iDocument) {
            System.out.println("onRecordAfterCreate");
            iDocument.field("a", "onRecordAfterCreate");
        }

        @Override
        public void onRecordAfterUpdate(ODocument iDocument) {
            System.out.println("onRecordAfterUpdate");
            iDocument.field("a", "onRecordAfterUpdate");
        }

        @Override
        public RESULT onRecordBeforeUpdate(ODocument iDocument) {
            System.out.println("onRecordAfterUpdate before undo: " + iDocument.field("a"));
            iDocument.undo("a");
            System.out.println("onRecordAfterUpdate after  undo: " + iDocument.field("a"));
            return RESULT.RECORD_CHANGED;
        }

        @Override
        public void onRecordAfterRead(ODocument iDocument) {
            assertEquals("original", iDocument.field("a"));
        }
    });
    db.commit();
    ODocument doc = new ODocument(classA);
    doc.field("a", "original");
    doc.save();
    doc.field("b", "other change");
    doc.save();
    doc.reload();
    doc.field("a", "updated");
    doc.save();
    doc.field("b", "other change");
    doc.save();
    doc.reload();
    doc.delete();
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) ODocumentHookAbstract(com.orientechnologies.orient.core.hook.ODocumentHookAbstract) ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) RESULT(com.orientechnologies.orient.core.hook.ORecordHook.RESULT) DISTRIBUTED_EXECUTION_MODE(com.orientechnologies.orient.core.hook.ORecordHook.DISTRIBUTED_EXECUTION_MODE) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)6 DISTRIBUTED_EXECUTION_MODE (com.orientechnologies.orient.core.hook.ORecordHook.DISTRIBUTED_EXECUTION_MODE)6 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)6 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)6 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)6 Test (org.junit.Test)6 ODocumentHookAbstract (com.orientechnologies.orient.core.hook.ODocumentHookAbstract)5 RESULT (com.orientechnologies.orient.core.hook.ORecordHook.RESULT)5 Ignore (org.junit.Ignore)3 ORecordHook (com.orientechnologies.orient.core.hook.ORecordHook)1 ORecord (com.orientechnologies.orient.core.record.ORecord)1 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)1 List (java.util.List)1