2015-04-23 85 views
3

我只是嘗試了所有東方掛鉤,但我不知道如何在我的圖上註冊ORecordHooks。OrientDB寄存器掛鉤

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"); 
    } 
} 

創建和刪除一堆頂點和邊只有鉤1,13和12個火,所以這將是getPriority(),onCreateClass(後)和onClose()。爲什麼我的任何一個ORecordHooks沒有啓動?

+0

由於鉤10和11沒有開槍,我猜你的鉤子未註冊。是嗎? – vitorenesduarte

+0

這很可能是這種情況,但我如何在圖表上註冊它們? – Blue

+0

你試過'graph.getRawGraph()。registerHook(hook);'? – vitorenesduarte

回答

3

要在OrientGraph比如,你可以做以下的註冊掛鉤

graph.getRawGraph().registerHook(hook);