Getting facts of a certain type from working memory

Instead of extracting all the facts, I need to get certain types of facts from working memory.

I found out that I can extract all the facts from working memory, as shown below.

drools.getWorkingMemory().getWorkingMemoryEntryPoint("Stream").getObjects();

Please indicate some pointers to getting a certain type of object from working memory.

+5
source share
2 answers

You can use ObjectFilter

Collection<Object> myfacts = session.getObjects( new ClassObjectFilter(MyFact.class) );

Unfortunately, in Drools 5.5.0 Final, the resulting collection contains a method that does not work properly. Typically, the contains method returns true if the searched object is equal to something in the collection, but the Drool collection finds only objects that have the same link (== is used to compare objects).

+5
source

getObjects() . RHS:

query "getObjectsOfClassA"
    $result: ClassA()
end

DRL . : http://docs.jboss.org/drools/release/5.5.0.Final/drools-expert-docs/html_single/#d0e7632

Java- , :

QueryResults results = ksession.getQueryResults( "getObjectsOfClassA" ); 
for ( QueryResultsRow row : results ) {
    ClassA classA = ( ClassA ) row.get( "$result" ); //you can retrieve all the bounded variables here
    //do whatever you want with classA
}

ClassA, .

, ,

+4

All Articles