Discussion:
In drools what is the exact difference between Insert and Update ??
Bhushan Sonaje
2012-03-28 18:18:52 UTC
Permalink
what is the exact difference between Insert and Update ?? I am little
confused here when to used insert and when to use update ??
and is it possible to retrieved updated object from working memory without
using *UPDATE* keyword

--
View this message in context: http://drools.46999.n3.nabble.com/In-drools-what-is-the-exact-difference-between-Insert-and-Update-tp3865470p3865470.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
Bhushan Sonaje
2012-03-28 18:18:56 UTC
Permalink
what is the exact difference between Insert and Update ?? I am little
confused here when to used insert and when to use update ??
and is it possible to retrieved updated object from working memory without
using *UPDATE* keyword

--
View this message in context: http://drools.46999.n3.nabble.com/In-drools-what-is-the-exact-difference-between-Insert-and-Update-tp3865471p3865471.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
Vincent LEGENDRE
2012-03-28 19:06:05 UTC
Permalink
Quick summary of : http://docs.jboss.org/drools/release/5.4.0.Beta2/drools-expert-docs/html_single/index.html#d0e5989
insert = inserts a new object in the working memory
update = tells the engine that an existing object in the working memory has changed

Unexpected question from someone that "had written many rules in my previous project and also successfully applied it's (Drools) most of the features" (according to another post from you)...

These concepts are the very basic one of an expert-system (drools or others), and are described in details in the very first chapter of the drools-expert documentation (or in any description of how an inference engine works, like on wikipedia).
I think you should really start by reading the doc before asking such questions.
And I am still wondering how you can have used drools before without knowing that ...


----- Mail original -----
De: "Bhushan Sonaje" <***@gmail.com>
À: rules-***@lists.jboss.org
Envoyé: Mercredi 28 Mars 2012 20:18:56
Objet: [rules-users] In drools what is the exact difference between Insert and Update ??

what is the exact difference between Insert and Update ?? I am little
confused here when to used insert and when to use update ??
and is it possible to retrieved updated object from working memory without
using *UPDATE* keyword

--
View this message in context: http://drools.46999.n3.nabble.com/In-drools-what-is-the-exact-difference-between-Insert-and-Update-tp3865471p3865471.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
rules-***@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
Bhushan Sonaje
2012-03-28 20:45:01 UTC
Permalink
Hi Vincent Legendre Thanks for you valuable reply. We had implemented new
technologies in our legacy project one of them is drools(separated our
business logic).We had implemented many rules and also used UPDATE in that.
But from client (Architect) we got strict instruction that we should not
used *UPDATE* because it re executes the all relevant rules even though we
had used *no loop true* attribute to avoid re execution.Because of strict
requirement I am trying to find out some alternative for update but still
not got any success.Even if I want to use UPDATE I need some concrete
reason.

we are re Implementing our existing rules which we had written already using
below comments given by client architect.
1.remove all salience from rules and make the rules independent (don't
decide its execution flow)
2.we should not used function in drools try to avoid them write your most of
the logic in rules only (If you are using means there will be no difference
between java and drools)
3.Activation group we had used in project but they told us to remove it from
drool files
4.Don't use UPDATE and Global in drools .
5.you should not call any java function from drools Write all those logic in
drools.

According to client we should write the rules in such a manner so they can
handle Independently.If rules becomes Independent then rules engine will
decide which rules needs to be execute first.We should not put any
constraint on rule engine by using salience and Activation group.













--
View this message in context: http://drools.46999.n3.nabble.com/In-drools-what-is-the-exact-difference-between-Insert-and-Update-tp3865471p3865920.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
Davide Sottara
2012-03-28 21:54:13 UTC
Permalink
Dear Bhushan, the recommendations you got from your architect should be
intended as best practices, not as strict instructions. Indeed, it depends
on what kind of rules you are writing and their business logic.

I agree that functions and globals should not be abused, and that salience
and groups should be intended as execution constraints, not as fine-grained
flow control, but I would reason on a case-by-case basis.

Now, as far as "update" is concerned... update is NEEDED to let the engine
know that some fact has changed. The only way not to use update is NOT TO
LET FACTS CHANGE. This is hardly possible in dynamic systems.
In that case, the only alternative is to replicate and insert the facts with
different state identifiers (e.g. timestamps): Person( name=david, age=25 ),
Person( name=david, age=26 ), Person( name=david, age=27 ).....
This is indeed a purely declarative approach, which you pay with additional
logic - to select only the "current" facts - and additional memory
consumption.
If the reason for not using update is that rules fire when they shouldn't,
then I agree that no-loop is not the best choice. It works only for the same
rule where you do the update, so it's hardly a safe way to proceed.
I would suggest, instead, to add constraints preventing the modified version
of the fact to trigger rules which have already fired. If you could provide
an example with one of your use cases, it would be easier to discuss the
pros and cons
Best
Davide

--
View this message in context: http://drools.46999.n3.nabble.com/In-drools-what-is-the-exact-difference-between-Insert-and-Update-tp3865471p3866107.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
Wolfgang Laun
2012-03-29 07:03:20 UTC
Permalink
Hi Bhushan,

some amendments to Davide's comments.

Salience: You might argue for one (1) rule (per class) with low
salience to detect a fact (of that class) that failed to be processed
(similar to the "default" in a switch).

Globals: In LHS *only* for introducing *constant* data, to compare to
fact data. In RHS code where the global is an object providing a
service, e.g., to send a matched fact to some external processor,
store it in a DB or whatever.

RHS all in Drools: Using Java static methods for certain tasks has the
benefit that they are easier to unit test.

UPDATE: You must use update (or, preferably, modify) if, and only if,
you have to change your facts AND changed facts must be processed by
other rules. - There is a scenario where you might invoke setters on a
fact object but you do not intend that the modified field is ever
processed by a rule: then do not call update/modify.

However, you might also design your system in a way where you do not
update/modify primary facts. Instead, to keep track of truths
discovered by
your rules, you insert new (secondary) facts of types according to
your design, linking them to your primary fact.

rule discover
when
$p: Primary( color == Color.GREEN, shape == Shape.ROUND )
then
insert( new RoundAndGreen( $p ) )
end

rule process
when
$p: Primary()
$rag: RoundAndGreen( primary == $p )
then
process(...)...
retract(...),...
end

HTH
-W
Post by Davide Sottara
Dear Bhushan, the recommendations you got from your architect should be
intended as best practices, not as strict instructions. Indeed, it depends
on what kind of rules you are writing and their business logic.
I agree that functions and globals should not be abused, and that salience
and groups should be intended as execution constraints, not as fine-grained
flow control, but I would reason on a case-by-case basis.
Now, as far as "update" is concerned... update is NEEDED to let the engine
know that some fact has changed. The only way not to use update is NOT TO
LET FACTS CHANGE. This is hardly possible in dynamic systems.
In that case, the only alternative is to replicate and insert the facts with
different state identifiers (e.g. timestamps): Person( name=david, age=25 ),
Person( name=david, age=26 ), Person( name=david, age=27 ).....
This is indeed a purely declarative approach, which you pay with additional
logic - to select only the "current" facts - and additional memory
consumption.
If the reason for not using update is that rules fire when they shouldn't,
then I agree that no-loop is not the best choice. It works only for the same
rule where you do the update, so it's hardly a safe way to proceed.
I would suggest, instead, to add constraints preventing the modified version
of the fact to trigger rules which have already fired. If you could provide
an example with one of your use cases, it would be easier to discuss the
pros and cons
Best
Davide
--
http://drools.46999.n3.nabble.com/In-drools-what-is-the-exact-difference-between-Insert-and-Update-tp3865471p3866107.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
Davide Sottara
2012-03-29 09:25:03 UTC
Permalink
Thanks @Wolfgang for the more detailed explanation.

@Bhushan: you might also want to take a look at one of the newest features,
"property specific".
When enabled, it allows to filter the re-evaluations on a field by field
basis. E.g. if you have a bean
"Person" with fields "name" and "age", and configure a pattern to be
property-specific on "age", any
modifies on "name" will not cause that pattern to propagate again (of course
the initial insertion will
still work).


--
View this message in context: http://drools.46999.n3.nabble.com/In-drools-what-is-the-exact-difference-between-Insert-and-Update-tp3865471p3867184.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
Bhushan
2012-04-02 20:37:41 UTC
Permalink
Hey Luane Thanks a lot man... I wlll keep all these points as a Best
Practices in my notes.Do u have any material Which talks about best
practices and it's example in drools.If yes could you please share with me
on my mail id @***@gmail.com.Actually We don't have any drool
expert in our project who know's all these things.

*Luane* Ones again Thanks
Post by Wolfgang Laun
Hi Bhushan,
some amendments to Davide's comments.
Salience: You might argue for one (1) rule (per class) with low
salience to detect a fact (of that class) that failed to be processed
(similar to the "default" in a switch).
Globals: In LHS *only* for introducing *constant* data, to compare to
fact data. In RHS code where the global is an object providing a
service, e.g., to send a matched fact to some external processor,
store it in a DB or whatever.
RHS all in Drools: Using Java static methods for certain tasks has the
benefit that they are easier to unit test.
UPDATE: You must use update (or, preferably, modify) if, and only if,
you have to change your facts AND changed facts must be processed by
other rules. - There is a scenario where you might invoke setters on a
fact object but you do not intend that the modified field is ever
processed by a rule: then do not call update/modify.
However, you might also design your system in a way where you do not
update/modify primary facts. Instead, to keep track of truths
discovered by
your rules, you insert new (secondary) facts of types according to
your design, linking them to your primary fact.
rule discover
when
$p: Primary( color == Color.GREEN, shape == Shape.ROUND )
then
insert( new RoundAndGreen( $p ) )
end
rule process
when
$p: Primary()
$rag: RoundAndGreen( primary == $p )
then
process(...)...
retract(...),...
end
HTH
-W
Post by Davide Sottara
Dear Bhushan, the recommendations you got from your architect should be
intended as best practices, not as strict instructions. Indeed, it depends
on what kind of rules you are writing and their business logic.
I agree that functions and globals should not be abused, and that salience
and groups should be intended as execution constraints, not as fine-grained
flow control, but I would reason on a case-by-case basis.
Now, as far as "update" is concerned... update is NEEDED to let the engine
know that some fact has changed. The only way not to use update is NOT TO
LET FACTS CHANGE. This is hardly possible in dynamic systems.
In that case, the only alternative is to replicate and insert the facts with
different state identifiers (e.g. timestamps): Person( name=david, age=25 ),
Person( name=david, age=26 ), Person( name=david, age=27 ).....
This is indeed a purely declarative approach, which you pay with additional
logic - to select only the "current" facts - and additional memory
consumption.
If the reason for not using update is that rules fire when they shouldn't,
then I agree that no-loop is not the best choice. It works only for the same
rule where you do the update, so it's hardly a safe way to proceed.
I would suggest, instead, to add constraints preventing the modified version
of the fact to trigger rules which have already fired. If you could provide
an example with one of your use cases, it would be easier to discuss the
pros and cons
Best
Davide
--
http://drools.46999.n3.nabble.com/In-drools-what-is-the-exact-difference-between-Insert-and-Update-tp3865471p3866107.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
--
View this message in context: http://drools.46999.n3.nabble.com/In-drools-what-is-the-exact-difference-between-Insert-and-Update-tp3865471p3878956.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
Vincent LEGENDRE
2012-03-29 12:21:05 UTC
Permalink
Far much valuable reply than mine :)
A great summary of common concerns that must be evaluated before starting coding a rule system.

Also consider :
- using rule flow (if you are allowed to)
- use sequential mode and pipe your data 'in the next rule box' programmatically (using rules?)
- ask your architect ? He is true for no-loop, but for others, re-writing existing DRL code that used all that stuff, and throw all at once is farly more dangerous ...
"remove all salience from rules and make the rules independent (don't decide its execution flow)"
This is all the question.
It mainly depends of the usage, as Davide said.
It also depends of who is authoring/specifying rules : if the guy supposes some flow, he is not writing independant rules ...

these other rules depend of the first :
2.no drools functions
3.Activation group / ruleflow / salience ...
5.don't call any java function (thus no functions at all, no predicates/utils methods, only DSL? only POJO?).

this one is suspect ...
4.Don't use UPDATE and Global in drools .
Patrik Dufresne
2012-03-29 13:20:21 UTC
Permalink
Sorry to disrupt your discussion,

I've start using Drools a while ago and I find your discussion very
interesting about how to use what feature when and why. The current Drools
Expert user guide is very nice, but it miss this crucial information. May I
suggest to create a 'Best Practice' chapter with the recommendation you
made.

Patrik Dufresne


On Thu, Mar 29, 2012 at 8:21 AM, Vincent LEGENDRE <
Post by Vincent LEGENDRE
Far much valuable reply than mine :)
A great summary of common concerns that must be evaluated before starting
coding a rule system.
- using rule flow (if you are allowed to)
- use sequential mode and pipe your data 'in the next rule box'
programmatically (using rules?)
- ask your architect ? He is true for no-loop, but for others,
re-writing existing DRL code that used all that stuff, and throw all at
once is farly more dangerous ...
"remove all salience from rules and make the rules independent (don't
decide its execution flow)"
This is all the question.
It mainly depends of the usage, as Davide said.
It also depends of who is authoring/specifying rules : if the guy supposes
some flow, he is not writing independant rules ...
2.no drools functions
3.Activation group / ruleflow / salience ...
5.don't call any java function (thus no functions at all, no
predicates/utils methods, only DSL? only POJO?).
this one is suspect ...
4.Don't use UPDATE and Global in drools .
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
Vincent LEGENDRE
2012-03-29 15:40:18 UTC
Permalink
Drools expert doc has a first chapter that adresses these questions (section 1.2) , or at least the questions that must be asked at start of a project.
It covers in details the main key question : rules or not ? Using rules implies more constraints on IT because you allow more freedom in business logic part, so you need a more robust IT code .

Best pratices are then edicted by the architect, this last one having in mind the requirements of :
- business users (most important as they specify rules, at least some representatives samples),
- the people who will write the rules (very very important if they are the business users, who are not IT guys, which to me forbid the usage of salience or groups or functions ...)
- the other IT guys that will provide data streams to your new application, or who will call your app (it can bring constraints because of data volumetry by instance)

In fact, you can't start a real rule project without having enough material in specifications, but this is also true for any project.
So there is no (in my opinion) "global best pratices" (as there is no global best pratices for a random IT project...), with eventually an exception for no-loop (its usage generally shows a lack of design, again, it is my opinion, and I already used them anyway...).
Once again, as Davide said, it depends of the usage. So it seems barely impossible to edit (and keep up to date) such a section with all potential use-cases ...

May be create a rule application that deduce best pratices ;) ?

----- Mail original -----

De: "Patrik Dufresne" <***@gmail.com>
À: "Rules Users List" <rules-***@lists.jboss.org>
Envoyé: Jeudi 29 Mars 2012 15:20:21
Objet: Re: [rules-users] In drools what is the exact difference between Insert and Update ??


Sorry to disrupt your discussion,


I've start using Drools a while ago and I find your discussion very interesting about how to use what feature when and why. The current Drools Expert user guide is very nice, but it miss this crucial information. May I suggest to create a 'Best Practice' chapter with the recommendation you made.
Patrik Dufresne



On Thu, Mar 29, 2012 at 8:21 AM, Vincent LEGENDRE < ***@eurodecision.com > wrote:


Far much valuable reply than mine :)
A great summary of common concerns that must be evaluated before starting coding a rule system.

Also consider :
- using rule flow (if you are allowed to)
- use sequential mode and pipe your data 'in the next rule box' programmatically (using rules?)
- ask your architect ? He is true for no-loop, but for others, re-writing existing DRL code that used all that stuff, and throw all at once is farly more dangerous ...
"remove all salience from rules and make the rules independent (don't decide its execution flow)"
This is all the question.
It mainly depends of the usage, as Davide said.
It also depends of who is authoring/specifying rules : if the guy supposes some flow, he is not writing independant rules ...

these other rules depend of the first :
2.no drools functions
3.Activation group / ruleflow / salience ...
5.don't call any java function (thus no functions at all, no predicates/utils methods, only DSL? only POJO?).

this one is suspect ...

4.Don't use UPDATE and Global in drools .


_______________________________________________
rules-users mailing list
rules-***@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users




_______________________________________________
rules-users mailing list
rules-***@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
Wolfgang Laun
2012-03-29 17:38:24 UTC
Permalink
Even attentive followers of this list may not be aware of my boot camp
"Rule-Based Programming Design Patterns" I was delivering to a select few
last October at Rules Fest 2011 <http://intellifest.org/html/agenda.html>.
I'm convinced that programming with rules follows the same universal
principles we all have learned about programming since the 1950ies or have
been taught in the ensuing decades - most notably, design patterns that can
be applied as the situation demands. It may be a different grass, but it's
still the grass roots you've got to make your own.

-W
Post by Vincent LEGENDRE
Drools expert doc has a first chapter that adresses these questions
(section 1.2), or at least the questions that must be asked at start of a
project.
It covers in details the main key question : rules or not ? Using rules
implies more constraints on IT because you allow more freedom in business
logic part, so you need a more robust IT code.
Best pratices are then edicted by the architect, this last one having in
- business users (most important as they specify rules, at least some
representatives samples),
- the people who will write the rules (very very important if they are
the business users, who are not IT guys, which to me forbid the usage of
salience or groups or functions ...)
- the other IT guys that will provide data streams to your new
application, or who will call your app (it can bring constraints because of
data volumetry by instance)
In fact, you can't start a real rule project without having enough
material in specifications, but this is also true for any project.
So there is no (in my opinion) "global best pratices" (as there is no
global best pratices for a random IT project...), with eventually an
exception for no-loop (its usage generally shows a lack of design, again,
it is my opinion, and I already used them anyway...).
Once again, as Davide said, it depends of the usage. So it seems barely
impossible to edit (and keep up to date) such a section with all potential
use-cases ...
May be create a rule application that deduce best pratices ;) ?
------------------------------
*Envoyé: *Jeudi 29 Mars 2012 15:20:21
*Objet: *Re: [rules-users] In drools what is the exact difference between
Insert and Update ??
Sorry to disrupt your discussion,
I've start using Drools a while ago and I find your discussion very
interesting about how to use what feature when and why. The current Drools
Expert user guide is very nice, but it miss this crucial information. May I
suggest to create a 'Best Practice' chapter with the recommendation you
made.
Patrik Dufresne
On Thu, Mar 29, 2012 at 8:21 AM, Vincent LEGENDRE <
Post by Vincent LEGENDRE
Far much valuable reply than mine :)
A great summary of common concerns that must be evaluated before starting
coding a rule system.
- using rule flow (if you are allowed to)
- use sequential mode and pipe your data 'in the next rule box'
programmatically (using rules?)
- ask your architect ? He is true for no-loop, but for others,
re-writing existing DRL code that used all that stuff, and throw all at
once is farly more dangerous ...
"remove all salience from rules and make the rules independent (don't
decide its execution flow)"
This is all the question.
It mainly depends of the usage, as Davide said.
It also depends of who is authoring/specifying rules : if the guy
supposes some flow, he is not writing independant rules ...
2.no drools functions
3.Activation group / ruleflow / salience ...
5.don't call any java function (thus no functions at all, no
predicates/utils methods, only DSL? only POJO?).
this one is suspect ...
4.Don't use UPDATE and Global in drools .
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
Richard Calmbach
2012-03-30 18:50:10 UTC
Permalink
Wolfgang: Are the slides for your presentation online? This would be very
helpful. I have searched repeatedly for a rule design best practices
document and have only found conference agenda items on the topic but no
actual document. After more than a year of working with Drools, I have
figured out key best practices (in particular, secondary facts) myself, but
it sure would have helped to have this information upfront (and, yes, I
have read the manual - the information I'm talking about is not in there).
Post by Wolfgang Laun
Even attentive followers of this list may not be aware of my boot camp
"Rule-Based Programming Design Patterns" I was delivering to a select few
last October at Rules Fest 2011 <http://intellifest.org/html/agenda.html>.
I'm convinced that programming with rules follows the same universal
principles we all have learned about programming since the 1950ies or have
been taught in the ensuing decades - most notably, design patterns that can
be applied as the situation demands. It may be a different grass, but it's
still the grass roots you've got to make your own.
-W
Post by Vincent LEGENDRE
Drools expert doc has a first chapter that adresses these questions
(section 1.2), or at least the questions that must be asked at start of a
project.
It covers in details the main key question : rules or not ? Using rules
implies more constraints on IT because you allow more freedom in business
logic part, so you need a more robust IT code.
Best pratices are then edicted by the architect, this last one having in
- business users (most important as they specify rules, at least some
representatives samples),
- the people who will write the rules (very very important if they
are the business users, who are not IT guys, which to me forbid the usage
of salience or groups or functions ...)
- the other IT guys that will provide data streams to your new
application, or who will call your app (it can bring constraints because of
data volumetry by instance)
In fact, you can't start a real rule project without having enough
material in specifications, but this is also true for any project.
So there is no (in my opinion) "global best pratices" (as there is no
global best pratices for a random IT project...), with eventually an
exception for no-loop (its usage generally shows a lack of design, again,
it is my opinion, and I already used them anyway...).
Once again, as Davide said, it depends of the usage. So it seems barely
impossible to edit (and keep up to date) such a section with all potential
use-cases ...
May be create a rule application that deduce best pratices ;) ?
------------------------------
*Envoyé: *Jeudi 29 Mars 2012 15:20:21
*Objet: *Re: [rules-users] In drools what is the exact difference
between Insert and Update ??
Sorry to disrupt your discussion,
I've start using Drools a while ago and I find your discussion very
interesting about how to use what feature when and why. The current Drools
Expert user guide is very nice, but it miss this crucial information. May I
suggest to create a 'Best Practice' chapter with the recommendation you
made.
Patrik Dufresne
On Thu, Mar 29, 2012 at 8:21 AM, Vincent LEGENDRE <
Post by Vincent LEGENDRE
Far much valuable reply than mine :)
A great summary of common concerns that must be evaluated before
starting coding a rule system.
- using rule flow (if you are allowed to)
- use sequential mode and pipe your data 'in the next rule box'
programmatically (using rules?)
- ask your architect ? He is true for no-loop, but for others,
re-writing existing DRL code that used all that stuff, and throw all at
once is farly more dangerous ...
"remove all salience from rules and make the rules independent
(don't decide its execution flow)"
This is all the question.
It mainly depends of the usage, as Davide said.
It also depends of who is authoring/specifying rules : if the guy
supposes some flow, he is not writing independant rules ...
2.no drools functions
3.Activation group / ruleflow / salience ...
5.don't call any java function (thus no functions at all, no
predicates/utils methods, only DSL? only POJO?).
this one is suspect ...
4.Don't use UPDATE and Global in drools .
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
Wolfgang Laun
2012-04-03 06:50:45 UTC
Permalink
@Richard and all others inquiring for my design patterns/best practices

Currently, the copyright to this material is being held by my employer.
This does not mean that a publication of all or some of that material is
out of the question, but it's not as simple as uploading it to my private
home page...

Thank you for your interest. Any news will be posted on this list.
Wolfgang Laun
Post by Richard Calmbach
Wolfgang: Are the slides for your presentation online? This would be very
helpful. I have searched repeatedly for a rule design best practices
document and have only found conference agenda items on the topic but no
actual document. After more than a year of working with Drools, I have
figured out key best practices (in particular, secondary facts) myself, but
it sure would have helped to have this information upfront (and, yes, I
have read the manual - the information I'm talking about is not in there).
On Thu, Mar 29, 2012 at 10:38 AM, Wolfgang Laun
Post by Wolfgang Laun
Even attentive followers of this list may not be aware of my boot camp
"Rule-Based Programming Design Patterns" I was delivering to a select few
last October at Rules Fest 2011 <http://intellifest.org/html/agenda.html>.
I'm convinced that programming with rules follows the same universal
principles we all have learned about programming since the 1950ies or have
been taught in the ensuing decades - most notably, design patterns that can
be applied as the situation demands. It may be a different grass, but it's
still the grass roots you've got to make your own.
-W
Post by Vincent LEGENDRE
Drools expert doc has a first chapter that adresses these questions
(section 1.2), or at least the questions that must be asked at start of a
project.
It covers in details the main key question : rules or not ? Using rules
implies more constraints on IT because you allow more freedom in business
logic part, so you need a more robust IT code.
Best pratices are then edicted by the architect, this last one having in
- business users (most important as they specify rules, at least some
representatives samples),
- the people who will write the rules (very very important if they
are the business users, who are not IT guys, which to me forbid the usage
of salience or groups or functions ...)
- the other IT guys that will provide data streams to your new
application, or who will call your app (it can bring constraints because of
data volumetry by instance)
In fact, you can't start a real rule project without having enough
material in specifications, but this is also true for any project.
So there is no (in my opinion) "global best pratices" (as there is no
global best pratices for a random IT project...), with eventually an
exception for no-loop (its usage generally shows a lack of design, again,
it is my opinion, and I already used them anyway...).
Once again, as Davide said, it depends of the usage. So it seems barely
impossible to edit (and keep up to date) such a section with all potential
use-cases ...
May be create a rule application that deduce best pratices ;) ?
------------------------------
*Envoyé: *Jeudi 29 Mars 2012 15:20:21
*Objet: *Re: [rules-users] In drools what is the exact difference
between Insert and Update ??
Sorry to disrupt your discussion,
I've start using Drools a while ago and I find your discussion very
interesting about how to use what feature when and why. The current Drools
Expert user guide is very nice, but it miss this crucial information. May I
suggest to create a 'Best Practice' chapter with the recommendation you
made.
Patrik Dufresne
On Thu, Mar 29, 2012 at 8:21 AM, Vincent LEGENDRE <
Post by Vincent LEGENDRE
Far much valuable reply than mine :)
A great summary of common concerns that must be evaluated before
starting coding a rule system.
- using rule flow (if you are allowed to)
- use sequential mode and pipe your data 'in the next rule box'
programmatically (using rules?)
- ask your architect ? He is true for no-loop, but for others,
re-writing existing DRL code that used all that stuff, and throw all at
once is farly more dangerous ...
"remove all salience from rules and make the rules independent
(don't decide its execution flow)"
This is all the question.
It mainly depends of the usage, as Davide said.
It also depends of who is authoring/specifying rules : if the guy
supposes some flow, he is not writing independant rules ...
2.no drools functions
3.Activation group / ruleflow / salience ...
5.don't call any java function (thus no functions at all, no
predicates/utils methods, only DSL? only POJO?).
this one is suspect ...
4.Don't use UPDATE and Global in drools .
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
Bhushan
2012-04-02 20:25:38 UTC
Permalink
Thanks *Davide and laune* for your all suggestions.Davide u r right all
those are best practices suggested by client :) .Davide can we discuss
below example .how to rewrite this example using best practices (which is
mention by u and laune in your earlier posts)


Consider Bank Class which contains Account details

Acnt_holder_name
account_no
branch_name


we have some PreDefined exceptions in DB with error code

101-"account holder name can not be blank"
102-"account_no can not be null"
103-"account_no can not be blank"
104-"Wrong branch"



Rule "Base-Rule"
Salience 200
lock-on-active true
when
$Customer : Bank($account:account)
then
//Do nothing this is base rule for defining customer
end


rule "madatory-rule-1" extends "Base-Rule"
Salience 190
lock-on-active true
when
Account(Acnt_holder_name.trim =="") from $Customer
then
$Customer.AddNewException(101)
update($Customer);
end


rule "madatory-rule-2" extends "Base-Rule"
Salience 180
lock-on-active true
when
Account(account_no ==null) from $Customer
then
$Customer.AddNewException(102)
update($Customer);
end


rule "madatory-rule-3" extends "Base-Rule"
Salience 170
lock-on-active true
when
Account(account_no.trim=="") from $Customer
then
$Customer.AddNewException(103)
update($Customer);

end

rule "madatory-rule-4" extends "Base-Rule"
Salience 160
lock-on-active true
when
Account(branch_name=="mumbai") from $Customer
then
$Customer.AddNewException(103)
update($Customer);

end


rule "madatory-rule-5"
Salience 150
lock-on-active true
when
$Customer : Bank(exceptionList.size>0)
then
$Customer.setCustomerValidationSuccess(false)
drools.halt();

end


Here I want to avoid salience and update (Like this I am also using lots of
setter methods in my drools project.Now I am trying to use all these setter
methods without using UPDDATE.But in some cases rules are dependent on other
rules so I dnt have any other choice left .In such cases I am using *update*
keyword so other rules can use updated object fom working memory).



--
View this message in context: http://drools.46999.n3.nabble.com/In-drools-what-is-the-exact-difference-between-Insert-and-Update-tp3865471p3878911.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
Wolfgang Laun
2012-04-03 06:27:34 UTC
Permalink
Here's how I'd do it. Note:
* Don't look at the Customer until you really need to.
* One salience level for the additional "background" rule.
* Don't use halt() - fireAllRules() should do the trick.
* Don't modify Account facts all over the place - this avoids loops
and, therefore, salience or lock-on-active.
* Use auxiliary facts to avoid updates of primary facts.
* Always add a test != null when checking a field that might be null.

class AccountException {
Account account;
int code;
}

rule "madatory-rule-2"
when
$account: Account( account_no == null )
then
insert( new AccountException( $account, 102 ) );
end

rule "madatory-rule-3"
when
$account: Account( account_no != null && account_no.trim == "" )
then
insert( new AccountException( $account, 103 ) );
end

And then there is:

rule "collect-account-exceptions"
salience -1000
when
AccountException( $account: account )
$elist: List() from collect( AccountException( account == $account ) )
$customer: Customer( account == $account )
then
modify( $customer ){
setExceptions( $elist ),
setCustomerValidationSuccess( false )
}
for( Object objec: $elist ) retract( $object );
end

-W
Post by Bhushan
Thanks *Davide and laune* for your all suggestions.Davide u r right all
those are best practices suggested by client :) .Davide can we discuss
below example .how to rewrite this example using best practices (which is
mention by u and laune in your earlier posts)
Consider Bank Class which contains Account details
Acnt_holder_name
account_no
branch_name
we have some PreDefined exceptions in DB with error code
101-"account holder name can not be blank"
102-"account_no can not be null"
103-"account_no can not be blank"
104-"Wrong branch"
Rule "Base-Rule"
Salience 200
lock-on-active true
when
$Customer : Bank($account:account)
then
//Do nothing this is base rule for defining customer
end
rule "madatory-rule-1" extends "Base-Rule"
Salience 190
lock-on-active true
when
Account(Acnt_holder_name.trim =="") from $Customer
then
$Customer.AddNewException(101)
update($Customer);
end
rule "madatory-rule-2" extends "Base-Rule"
Salience 180
lock-on-active true
when
Account(account_no ==null) from $Customer
then
$Customer.AddNewException(102)
update($Customer);
end
rule "madatory-rule-3" extends "Base-Rule"
Salience 170
lock-on-active true
when
Account(account_no.trim=="") from $Customer
then
$Customer.AddNewException(103)
update($Customer);
end
rule "madatory-rule-4" extends "Base-Rule"
Salience 160
lock-on-active true
when
Account(branch_name=="mumbai") from $Customer
then
$Customer.AddNewException(103)
update($Customer);
end
rule "madatory-rule-5"
Salience 150
lock-on-active true
when
$Customer : Bank(exceptionList.size>0)
then
$Customer.setCustomerValidationSuccess(false)
drools.halt();
end
Here I want to avoid salience and update (Like this I am also using lots of
setter methods in my drools project.Now I am trying to use all these setter
methods without using UPDDATE.But in some cases rules are dependent on other
rules so I dnt have any other choice left .In such cases I am using *update*
keyword so other rules can use updated object fom working memory).
--
http://drools.46999.n3.nabble.com/In-drools-what-is-the-exact-difference-between-Insert-and-Update-tp3865471p3878911.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
_______________________________________________
rules-users mailing list
https://lists.jboss.org/mailman/listinfo/rules-users
Loading...