[rules-users] Drools ruturn multiple results based on child objects data length

Vikrant Yagnick VikrantY at mastek.com
Mon Sep 8 09:00:06 EDT 2008


Hi Mohamed,

The logical 'OR' operator internally will create two different rules and both can fire, hence you are getting two different firings.
What you need to use is the following operator , '||'. This should treat it as one rule and fire if either of the two conditions are true.

Example:

rule "test"
when
order: Order

(

   exists ( condition-1 with child objects ||  condition-2 with child objects)
)

then

    SOP("order id "+order.getId());

result :


From: rules-users-bounces at lists.jboss.org [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of Mohamed Riyaz
Sent: Monday, September 08, 2008 6:12 PM
To: Rules Users List
Subject: Re: [rules-users] Drools ruturn multiple results based on child objects data length

Thanks Vikrant.

I have one more qurey on 'OR' logical operator for the following scenario:

I want the the boolen result from parent object which satisfies two different condition sets with child objects. I made the rule which is generated duplicated

results if both conditions are satisfied.

rule "test"
when
order: Order

(

   exists ( condition-1 with child objects)

   or

   exists (condition-2 with child objects)

)

then

    SOP("order id "+order.getId());

result :

     order id 1000

     order id 1000



return the results in twice if both the conditions (cond-1 & cond-2) are satisfied. It just combine
both results and behaves like 'union all' instead of 'union' function.

Can you help on this?


regards,riyaz

On 9/8/08, Vikrant Yagnick <VikrantY at mastek.com<mailto:VikrantY at mastek.com>> wrote:

My feeling after reading this post is that you need to execute a rule, if some child object exists.

I suggest using the Exists Feature in Drools for doing something like that.



It would be the same thing if you are writing SQL. If you join a Master Table with child tables you will get as many records as there are child records for each master record.



However, if you only want one master record if there are child record, you would need to use the exists statement.



Example:



rule "Multiple results set"
when

    order: Order
    exists ( Invoice from order.invoices)

  then

    System.out.println("Rule Example (Multiple results set)"+order.getId());
end;





Cheers,

Vikrant



From: rules-users-bounces at lists.jboss.org<mailto:rules-users-bounces at lists.jboss.org> [mailto:rules-users-bounces at lists.jboss.org<mailto:rules-users-bounces at lists.jboss.org>] On Behalf Of Mohamed Riyaz
Sent: Monday, September 08, 2008 12:05 PM
To: rules-users at lists.jboss.org<mailto:rules-users at lists.jboss.org>
Subject: [rules-users] Drools ruturn multiple results based on child objects data length





Hi,



In one-to-many relationship object type, Drools generate multiple results based on child objects data length. ie. No of child records
belongs to parent object. I wanted the RHS part should be executed only if conditions imposed
on child object satisfies.

I have two facts with 1-* relationship defined in object mapping.

class Invoice{}

class Order{

private Set<Invoice> invoices;

}

I wanted RHS should be executed with only one result  irrespective of child records length.

rule "Multiple results set"
when

    order: Order()
    invoice : Invoice() from order.invoices


  then

    System.out.println("Rule Example (Multiple results set)"+order.getId());
end;

Result:
 Rule Example (Multiple results set)1000
 Rule Example (Multiple results set)1000

Please help me in resolving this issue.

Regards,
Riyaz







MASTEK LTD.
Mastek in NASSCOM's 'India Top 20' Software Service Exporters List.
In the US, we're called MAJESCOMASTEK

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Opinions expressed in this e-mail are those of the individual and not that of Mastek Limited, unless specifically indicated to that effect. Mastek Limited does not accept any responsibility or liability for it. This e-mail and attachments (if any) transmitted with it are confidential and/or privileged and solely for the use of the intended person or entity to which it is addressed. Any review, re-transmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. This e-mail and its attachments have been scanned for the presence of computer viruses. It is the responsibility of the recipient to run the virus check on e-mails and attachments before opening them. If you have received this e-mail in error, kindly delete this e-mail from desktop and server.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


_______________________________________________
rules-users mailing list
rules-users at lists.jboss.org<mailto:rules-users at lists.jboss.org>
https://lists.jboss.org/mailman/listinfo/rules-users




MASTEK LTD.
Mastek in NASSCOM's 'India Top 20' Software Service Exporters List.
In the US, we're called MAJESCOMASTEK

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Opinions expressed in this e-mail are those of the individual and not that of Mastek Limited, unless specifically indicated to that effect. Mastek Limited does not accept any responsibility or liability for it. This e-mail and attachments (if any) transmitted with it are confidential and/or privileged and solely for the use of the intended person or entity to which it is addressed. Any review, re-transmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. This e-mail and its attachments have been scanned for the presence of computer viruses. It is the responsibility of the recipient to run the virus check on e-mails and attachments before opening them. If you have received this e-mail in error, kindly delete this e-mail from desktop and server.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20080908/42a7c865/attachment.html 


More information about the rules-users mailing list