Search in sources :

Example 1 with ORecordHookAbstract

use of com.orientechnologies.orient.core.hook.ORecordHookAbstract in project orientdb by orientechnologies.

the class HookTxTest method testHookCannotBeginTx.

@Test(dependsOnMethods = "testHookCallsDelete")
public void testHookCannotBeginTx() throws IOException {
    final AtomicBoolean exc = new AtomicBoolean(false);
    database.activateOnCurrentThread();
    database.registerHook(new ORecordHookAbstract() {

        @Override
        public RESULT onRecordBeforeCreate(ORecord iRecord) {
            try {
                database.activateOnCurrentThread();
                database.begin();
            } catch (IllegalStateException e) {
                exc.set(true);
            }
            return null;
        }

        @Override
        public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
            return DISTRIBUTED_EXECUTION_MODE.BOTH;
        }
    });
    Assert.assertFalse(exc.get());
    new ODocument().field("test-hook", true).save();
    Assert.assertTrue(exc.get());
    database.activateOnCurrentThread();
    database.close();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ORecord(com.orientechnologies.orient.core.record.ORecord) ORecordHookAbstract(com.orientechnologies.orient.core.hook.ORecordHookAbstract) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Aggregations

ORecordHookAbstract (com.orientechnologies.orient.core.hook.ORecordHookAbstract)1 ORecord (com.orientechnologies.orient.core.record.ORecord)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.testng.annotations.Test)1