0
votes

I'm porting an application from drools 5.0.1 to drools 6.0.1. In 5.0.1 the following query code worked fine:

import org.drools.QueryResults;
import org.drools.QueryResult;  

QueryResults res = getSession().getQueryResults(
   "the_query_name" , new Object[]{intActId} );
for ( QueryResult row : res ) {
    ret = (RetrievedClass) row.get(0);
}

In 6.0.1 I'm supposed to use the kie API but I'm not sure how to retrieve the actual object. The class QueryResultsRow does not have get(int) method or any equivalent. It has get(string) but I've no idea what string to pass.

import org.kie.api.runtime.rule.QueryResults;
import org.kie.api.runtime.rule.QueryResultsRow;


QueryResults res =  getSession().getQueryResults(
    "the_query_name" , new Object[]{intActId} );
for ( QueryResultsRow row : results ) {
    ret = ????
}
1

1 Answers

0
votes

Since you didn't post the text of your query, consider this example from the Drools "Expert" manual:

query "people over the age of x"  (int x, String y)
    person : Person( age > x, location == y )
end

To retrieve something from a result row:

for ( QueryResultsRow row : results ) {
    Person person = ( Person ) row.get( "person" );
    System.out.println( person.getName() );
}

Also read the Javadoc for org.kie.api.runtime.rule.Row.get inherited by QueryResultRow:

get
Object get(String identifier)

Get the object that is bound to the given identifier
Parameters:
    identifier - The identifier of the bound object