cppcoder
cppcoder

Reputation: 23095

How do I retrieve a fact from drools session?

Assume that I have a class as follows:

public class A {
    private int id1;  
    private int id2;  
    HashMap<String, String> attrMap;  
}  


StatefulKnowledgeSession session = knowledgeBase.newStatefulKnowledgeSession(); 
session.insert(a1);
session.insert(a2);
session.insert(a3);
session.insert(a4);  

Now how do I retrieve the fact from the session who has id1 = 2.
I know that I can retrieve the facts using getFactHandle(Object), but here I want to retrieve fact using one member value.

How can I achieve this?

Upvotes: 0

Views: 5080

Answers (1)

Esteban Aliverti
Esteban Aliverti

Reputation: 6322

If you want to get those facts out of your ksession, then you may want to use a query. For more information, please take a look at my answer here: Retrieving facts of a specific type from working memory

Even if my answer in the other post is about extracting facts for certain class, it can be easily modified to do what you are looking for.

Upvotes: 1

Related Questions