2011-04-28 35 views

回答

0

Drools是反動的工具。在插入對象時,drools創建一個rete樹以在觸發規則時觸發THEN條件。因此,你將不得不斷言工作記憶中的對象來觸發規則。

0

您需要從數據庫加載記錄並在運行規則之前將它們插入到知識庫中,或者您可以使用「from」關鍵字在規則執行期間獲取記錄。

下面是一個例子,你如何從「從」使用的數據庫得到記錄和Hibernate:

# Hibernate session is a global  
global org.hibernate.Session hibernateSession; 

rule "hibernate_from" 
    when 
     game:Game() from hibernateSession.createQuery("select games from Player p where p.age >= :age").setProperties({"age" : 18 }).list() 
    then 

     # This is the condition part of the rule, it contains MVEL or in this case Java code 
     System.out.println("The game "+game.getName() +"is owned by "+game.getPlayers()); 
end 

更新和插入記錄可以在Drools的規則的條件部分來完成。規則的這部分可以用與任何Java程序相同的方式編寫。

有關 「從」 查看詳細信息如下:

Drools documentation

Jaroslaw Kijanowski's blog

Drools & jBPM blog