Query in stateless knowledge session returns no results
by Heijink, Hank
Hi all,
I'm new to Drools, so please excuse me if I'm asking about the obvious--it's certainly not obvious to me. The problem is this: I use a stateless knowledge session where a list of facts is inserted. The rules that fire create new facts, and after all the rules have fired, I'd like to obtain a list of all the facts (the old and the new). The best way seemed to use a query. I'm using Drools 5.1 on Linux.
This is part of my .drl file (without the imports):
rule "create badge"
when
Event ( eventType == EventType.SOME_EVENT_TYPE )
not BadgeState ( identifier == "badge" )
then
insert( new BadgeState("badge") );
end
query "all badges"
aBadge : BadgeState()
end
This is the Java code:
StatelessKnowledgeSession ksession = StatsKnowledgeBase.getKnowledgeBase().newStatelessKnowledgeSession();
// Create a list of share events
ArrayList<Event> events = new ArrayList<Event>();
Date now = new Date();
MobileDevice aDevice = new MobileDevice("uniqueId", "deviceType");
for (int i = 0; i < 5; i++) {
Event anEvent = new Event.Builder(now, aDevice, "aCustomer", EventType.SOME_EVENT_TYPE).build();
events.add(anEvent);
}
// Create the query for the badges
List<Command> commands = new ArrayList<Command>();
commands.add(CommandFactory.newInsertElements(events));
commands.add(CommandFactory.newQuery("all badges", "all badges"));
// Feed the events into Drools
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession);
ExecutionResults results = ksession.execute( CommandFactory.newBatchExecution(commands) );
NativeQueryResults queryResults = (NativeQueryResults)results.getValue("all badges");
// At this point, queryResults is empty.
logger.close();
// Get a list of badges
List<BadgeState> badges = new ArrayList<BadgeState>();
for (Iterator<QueryResultsRow> i = queryResults.iterator(); i.hasNext(); ) {
QueryResultsRow result = i.next();
BadgeState obj = (BadgeState)result.get("aBadge");
badges.add(obj);
}
The logger shows me that the BadgeState object is created, but the query returns an empty list. I've searched the documentation, which suggests that I'm doing it right (http://drools.herod.net/drools-expert/html/ch03.html#d0e1956, example 3.37), the archives of this mailinglist, and the web, so far without success.
Clearly, I'm missing something, and I have the nagging feeling that it's something simple...
Any help is much appreciated!
Best,
Hank
14 years, 5 months
Rule Task
by S.M.H.Jamali
Thank You Mr.Surdilovic
I clone from master and execute "mvn clean install -DskipTests -Dfull" successfully but at runtime When i run gwt-console and refresh process list i get an exception. I attache its logs.
Is there any solution to solve this problem ?
Thanks
S.M.H.Jamali
________________________________
From: Tihomir Surdilovic <tsurdilo(a)redhat.com>
To: rules-users(a)lists.jboss.org
Sent: Monday, August 1, 2011 6:15 AM
Subject: Re: [rules-users] Rule Task
On 7/31/11 11:30 AM, S.M.H.Jamali wrote:
Thanks ,
>
>I add this
>
>jbpm-gwt/jbpm-gwt-core/src/main/java/org/jbpm/integration/console/CommandDelegate.java
>to gwt-console in its location but i can not build jbpm from source ! it seems it has very bugs !
>
clone from master https://github.com/droolsjbpm/jbpm and just
mvn clean install -DskipTests -Dfull
show the bugs or they do not exists :)
>
>Is there any stable version of Jbpm with its bug fixes ?
>
>S.M.H.Jamali
>
>
>________________________________
>From: Tihomir Surdilovic <tsurdilo(a)redhat.com>
>To: rules-users(a)lists.jboss.org
>Sent: Wednesday, July 27, 2011 9:49 PM
>Subject: Re: [rules-users] Rule Task
>
>On 7/27/11 7:18 AM, S.M.H.Jamali wrote:
>> My problem is : when i create a new instance of my
process (in jbpm
>> console) , first Script Task run fine , but execution
of the process
>> stops at Rule Task and no rule fired ! Am i missing
something ?
>This is a known issue in jbpm-console which just got fixed:
>https://issues.jboss.org/browse/JBPM-3301.
>
>Thanks.
>_______________________________________________
>rules-users mailing list
>rules-users(a)lists.jboss.org
>https://lists.jboss.org/mailman/listinfo/rules-users
>
>
>
>
>
>_______________________________________________
rules-users mailing list rules-users(a)lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
14 years, 5 months
java int problem
by gbelin
I have a problem with int data in drools.
I have created a test class for persons with it setters and getters:
/public class A {
private int age;
private String sex;
private String name;
public A () {
System.out.println ("creating A.");
}/
I have a rule that gets the person with de min age
/rule "min age"
ruleflow-group 'group1'
salience 10
when
$a : A ()
not A (age<$a.age)
then
System.out.println (" *** the min age "+$a.getAge()+" corresponds to " +
$a.getName());
end
/
I insert 4 persons in the knowledge base with different ages, then, when I
run the rule, it returns all the 4 persons.
If I set another rule with more priority that sets the ages of all persons,
then the "min age" rule works propertly and write the message for the person
with de minimun age.
/rule "set age"
ruleflow-group 'group1'
salience 11
no-loop
when
$a : A ()
then
$a.setAge($a.getAge());
update($a);
System.out.println( "Person " + $a.getName() + " has an age of " +
$a.getAge() + " years" );
end
/
Is there any problem with drools and ints?
Thanks in advance.
--
View this message in context: http://drools.46999.n3.nabble.com/java-int-problem-tp3215383p3215383.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
14 years, 5 months