這取決於你想要什麼樣的規則。數據庫支持的方法是有意義的,如果你有很多具有相同結構的規則,並且只根據某些「參數」而有所不同。在這種情況下,您可以編寫單個通用規則,並使用數據庫來存儲所有適用的組合。例如,假設您有一個規則來計算每個國家/地區的運費,例如訂單
rule "Shipping rates to France"
when
$order : Order(country == 'fr')
then
$order.setShippingRate(10.0);
update(order);
end
// Similar rules for other countries…
其中每個CountryShippingRate
指定一個國家的房價可能會取代從數據庫中這些規則的數據。然後,你插入所有CountryShippingRate
行作爲規則會話事實對象,單一規則,如:
rule "Shipping rates"
when
$order : Order($country : country)
CountryShippingRate($rate : rate, country == $country)
then
$order.setShippingRate($rate);
update(order);
end
在實踐中,事實證明,很多的決策表型規則可以寫成這樣。
我希望我可以upvote 10次:) – 2011-06-30 04:27:59
@Peter Hilton請看看這個問題。謝謝 http://stackoverflow.com/questions/26322576/stop-rules-on-update-facts-drools – Kumar 2014-10-12 07:35:03