use of com.orientechnologies.orient.core.hook.ORecordHook in project orientdb by orientechnologies.
the class ODatabaseDocumentTx method resetInitialization.
@Override
public void resetInitialization() {
for (ORecordHook h : hooks.keySet()) h.onUnregister();
hooks.clear();
compileHooks();
close();
initialized = false;
}
use of com.orientechnologies.orient.core.hook.ORecordHook in project orientdb by orientechnologies.
the class CRUDObjectInheritanceTestSchemaFull method beforeClass.
@BeforeClass
public void beforeClass() throws Exception {
super.beforeClass();
database.close();
database = new OObjectDatabaseTx(url + "_objectschema");
ODatabaseHelper.dropDatabase(database, getStorageType());
ODatabaseHelper.createDatabase(database, url + "_objectschema", getStorageType());
try {
ODatabaseDocumentTx exportDatabase = new ODatabaseDocumentTx(url);
exportDatabase.open("admin", "admin");
OCommandOutputListener listener = new OCommandOutputListener() {
@Override
public void onMessage(String iText) {
}
};
ODatabaseExport export = new ODatabaseExport(exportDatabase, EXPORT_DIR, listener);
export.exportDatabase();
export.close();
exportDatabase.close();
ODatabaseDocumentTx importDatabase = new ODatabaseDocumentTx(url + "_objectschema");
if (url.startsWith("remote")) {
importDatabase.open("root", ODatabaseHelper.getServerRootPassword());
} else {
importDatabase.open("admin", "admin");
}
ODatabaseImport impor = new ODatabaseImport(importDatabase, EXPORT_DIR, listener);
// UNREGISTER ALL THE HOOKS
for (ORecordHook hook : new ArrayList<ORecordHook>(importDatabase.getHooks().keySet())) {
importDatabase.unregisterHook(hook);
}
impor.setDeleteRIDMapping(true);
impor.importDatabase();
impor.close();
importDatabase.close();
final File importDir = new File(EXPORT_DIR);
importDir.delete();
} catch (IOException e) {
Assert.fail("Export import didn't go as expected", e);
}
database.open("admin", "admin");
if (database.getMetadata().getSchema().existsClass("Company"))
database.command(new OCommandSQL("delete from Company")).execute();
if (database.getMetadata().getSchema().existsClass("Account"))
database.command(new OCommandSQL("delete from Account")).execute();
if (database.getMetadata().getSchema().existsClass("JavaComplexTestClass"))
database.command(new OCommandSQL("delete from JavaComplexTestClass")).execute();
if (database.getMetadata().getSchema().existsClass("Profile"))
database.command(new OCommandSQL("delete from Profile")).execute();
if (database.getMetadata().getSchema().existsClass("IdentityChild"))
database.command(new OCommandSQL("delete from IdentityChild")).execute();
database.close();
}
use of com.orientechnologies.orient.core.hook.ORecordHook in project wicket-orientdb by OrienteerBAP.
the class TestInAppOrientDBCompatibility method testDocumentTrackingSimple.
@Test
public void testDocumentTrackingSimple() {
final String className = "TestDocumentTrackingSimple";
ODatabaseDocument db = wicket.getTester().getDatabase();
OSchema schema = db.getMetadata().getSchema();
final OClass classA = schema.createClass(className);
classA.createProperty("a", OType.STRING);
db.registerHook(new ORecordHook() {
@Override
public void onUnregister() {
// NOP
}
@Override
public RESULT onTrigger(TYPE iType, ORecord iRecord) {
if (iRecord instanceof ODocument) {
ODocument doc = (ODocument) iRecord;
if (classA.isSuperClassOf(doc.getSchemaClass())) {
// System.out.println("During "+iType+" document should track changes: "+doc.isTrackingChanges());
assertTrue("During " + iType + " document should track changes", doc.isTrackingChanges());
}
}
return RESULT.RECORD_NOT_CHANGED;
}
@Override
public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE;
}
});
db.commit();
ODocument doc = new ODocument(classA);
doc.field("a", "test");
doc.save();
doc.reload();
doc.field("a", "test2");
doc.save();
doc.reload();
doc.delete();
}
use of com.orientechnologies.orient.core.hook.ORecordHook in project orientdb by orientechnologies.
the class HookRegisterRemoveTest method addAndRemoveHookTest.
@Test
public void addAndRemoveHookTest() {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:" + HookRegisterRemoveTest.class.getSimpleName());
db.create();
final AtomicInteger integer = new AtomicInteger(0);
ORecordHook iHookImpl = new ORecordHook() {
@Override
public void onUnregister() {
}
@Override
public RESULT onTrigger(TYPE iType, ORecord iRecord) {
integer.incrementAndGet();
return null;
}
@Override
public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
return null;
}
};
db.registerHook(iHookImpl);
db.save(new ODocument().field("test", "test"));
assertEquals(3, integer.get());
db.unregisterHook(iHookImpl);
db.save(new ODocument());
assertEquals(3, integer.get());
db.drop();
}
use of com.orientechnologies.orient.core.hook.ORecordHook in project orientdb by orientechnologies.
the class OConfigurableHooksManager method onOpen.
public void onOpen(ODatabaseInternal iDatabase) {
if (!iDatabase.getStorage().isRemote()) {
final ODatabase<?> db = (ODatabase<?>) iDatabase;
for (OServerHookConfiguration hook : configuredHooks) {
try {
final ORecordHook.HOOK_POSITION pos = ORecordHook.HOOK_POSITION.valueOf(hook.position);
final ORecordHook h = (ORecordHook) Class.forName(hook.clazz).newInstance();
if (hook.parameters != null && hook.parameters.length > 0)
try {
final Method m = h.getClass().getDeclaredMethod("config", new Class[] { OServerParameterConfiguration[].class });
m.invoke(h, new Object[] { hook.parameters });
} catch (Exception e) {
OLogManager.instance().warn(this, "[configure] Failed to configure hook '%s'. Parameters specified but hook don support parameters. Should have a method config with parameters OServerParameterConfiguration[] ", hook.clazz);
}
db.registerHook(h, pos);
} catch (Exception e) {
OLogManager.instance().error(this, "[configure] Failed to configure hook '%s' due to the an error : ", e, hook.clazz, e.getMessage());
}
}
}
}
Aggregations