gpt4 book ai didi

java - OrientDB 注册 Hooks

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:44:01 25 4
gpt4 key购买 nike

我只是尝试了 orientdb 上的所有 Hook ,但我不确定如何在我的图表上注册 ORecordHooks。

OrientGraph graph = new OrientGraph("remote:localhost/test");
MyHook hook = new MyHook();

MyHook 类如下所示:

public class MyHook extends ORecordHookAbstract implements
ODatabaseLifecycleListener {

public MyHook() {
Orient.instance().addDbLifecycleListener(this);
}
@Override
public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
System.out.println("0");
return null;
}
@Override
public PRIORITY getPriority() {
System.out.println("1");
return PRIORITY.FIRST;
}
@Override
public void onRecordAfterCreate(ORecord iRecord) {
System.out.println("2");
}
@Override
public RESULT onRecordBeforeCreate(ORecord iRecord) {
System.out.println("3");
return ORecordHook.RESULT.RECORD_CHANGED;
}
@Override
public RESULT onRecordBeforeRead(ORecord iRecord) {
System.out.println("4");
return ORecordHook.RESULT.RECORD_CHANGED;
}
@Override
public void onRecordAfterRead(ORecord iRecord) {
System.out.println("5");
}
@Override
public RESULT onRecordBeforeUpdate(ORecord iRecord) {
System.out.println("6");
return ORecordHook.RESULT.RECORD_CHANGED;
}
@Override
public void onRecordAfterUpdate(ORecord iRecord) {
System.out.println("7");
}
@Override
public RESULT onRecordBeforeDelete(ORecord iRecord) {
System.out.println("8");
return ORecordHook.RESULT.RECORD_CHANGED;
}
@Override
public void onRecordAfterDelete(ORecord iRecord) {
System.out.println("9");
}
@Override
public void onCreate(ODatabaseInternal iDatabase) {e
System.out.println("10");
iDatabase.registerHook(this);
}
@Override
public void onOpen(ODatabaseInternal iDatabase) {
System.out.println("11");
iDatabase.registerHook(this);
}
@Override
public void onClose(ODatabaseInternal iDatabase) {
System.out.println("12");
iDatabase.unregisterHook(this);
}
@Override
public void onCreateClass(ODatabaseInternal iDatabase, OClass iClass) {
System.out.println("13");
}
@Override
public void onDropClass(ODatabaseInternal iDatabase, OClass iClass) {
System.out.println("14");
}
}

在创建和删除一堆顶点和边之后,只有 Hooks 1、13 和 12 触发,所以它们是 getPriority()、onCreateClass() 和 onClose()。为什么我的 ORecordHooks 没有触发?

最佳答案

要在 OrientGraph 实例上注册一个 Hook,您可以执行以下操作:

 graph.getRawGraph().registerHook(hook);

关于java - OrientDB 注册 Hooks,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29818813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com