[rules-users] Drools get value from stateful session

Stephen Masters stephen.masters at me.com
Sun Nov 10 04:23:35 EST 2013


Good point Wolfgang … it’s a bit of my code that I provided. I tend to use SimpleName to make it easy to find declared types as well as Java classes. But if a Java fact is being used, then getClass() is a much better idea.


On 10 Nov 2013, at 07:27, Wolfgang Laun <wolfgang.laun at gmail.com> wrote:

> Digging a bit into Java's API always helps ;-) Note that
> Class.getSimpleName() really does what it says, as opposed to
> Class.getName().
> 
> It would be best to avoid the String representation:
> 
> Collection findFacts( StatefulKnowledgeSession session, Class factClass ){...
> public boolean accept( Object object ){
>   return object.getClass().( factClass );
> }...}
> 
> -W
> 
> On 10/11/2013, forsakendoll <forsakendoll at hotmail.com> wrote:
>> How can I get the value from a stateful session. As they say I can use
>> this:
>> 
>> protected Collection findFacts( final StatefulKnowledgeSession session,
>> final String factClass )
>> {
>>        ObjectFilter filter = new ObjectFilter()
>>        {
>>            @Override
>>            public boolean accept( Object object )
>>            {
>>                return object.getClass().getSimpleName().equals( factClass
>> );
>>            }
>>        };
>> 
>>        Collection results = session.getObjects( filter );
>> 
>>        return results;
>> }
>> 
>> to get the value from the rules. Given the fact the code already red the
>> rules when I  tried this:
>> 
>> StatefulKnowledgeSession ksession =
>> aKnowledgeBase.newStatefulKnowledgeSession();
>> 
>> ksession.insert( aBean );
>> ksession.fireAllRules();
>> 
>> Collection result = findFacts( ksession,
>> "com.neu.als.thesis.db.beans.StudentBean" );
>> 
>> ksession.dispose();
>> for( Object test : result )
>> {
>>      System.out.println( test == null );
>>      System.out.println( test );
>> }
>> 
>> Nothing is printed. What is the proper way to get bean that I inserted in
>> the rules?
>> 
>> 
>> 
>> 
>> --
>> View this message in context:
>> http://drools.46999.n3.nabble.com/Drools-get-value-from-stateful-session-tp4026712.html
>> Sent from the Drools: User forum mailing list archive at Nabble.com.
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>> 
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users




More information about the rules-users mailing list