I have been able to create a java hook exactly with the method specified here: https://orientdb.com/docs/2.2.x/Tutorial-Java-Hooks.html
But I don't want my hook to run for every database present on the server. I want to enable it only for one specific database.
Is it possible to do that simply by specifying it declaratively on the orientdb-server-config.xml ? or By configuring the hook in my Java class extending ODocumentHookAbstract
? Otherwise any idea how to do it programmatically ?
You can do this programatically by conditionally registering your hook based on the database name and implementing the database life cycle listener ODatabaseLifecycleListener
. From the docs on hook self registration, you can do this in the overridden onOpen()
method with something like:
public class MyHook extends ODocumentHookAbstract implements ODatabaseLifecycleListener {
...
@Override
public void onOpen(final ODatabase iDatabase) {
if("someSpecificDatabaseName".equals(iDatabase.getName()) {
// REGISTER THE HOOK
((ODatabaseComplex<?>)iDatabase).registerHook(this);
}
}
}