a global hibernate session, that can be used for DB interactions in the rules. ksession.execute( collection ); // this will now execute and will be able to resolve the "hbnSession" identifier.
The third way is execution scopped globals using the CommandExecutor and SetGlobal Commands:
List cmds = new ArrayList(); cmds.add( CommandFactory.newSetGlobal( "list1", new ArrayList() ) ); cmds.add( CommandFactory.newInsert( new Person( "jon", 102 ) ) ); ksession.execute( CommandFactory.newBatchExecution( cmds ) );
The CommandExecutor interface also supports the ability to export data via "out" parameters. Inserted facts, globals and query results can all be returned.
List cmds = new ArrayList(); cmds.add( CommandFactory.newSetGlobal( "list1", new ArrayList(), true ) ); cmds.add( CommandFactory.newInsert( new Person( "jon", 102 ), "person" ) ); cmds.add( CommandFactory.newQuery( "Get People" "getPeople" ); ExecutionResults results = ksession.execute( CommandFactory.newBatchExecution( cmds ) ); results.getValue( "list1" ); // returns the ArrayList results.getValue( "person" ); // returns the inserted fact Person results.getValue( "Get People" );// returns the query as a QueryResults instance.
@see org.drools.runtime.CommandExecutor
@see org.drools.runtime.command.CommandFactory
@see org.drools.runtime.command.BatchExecution
@see org.drools.runtime.ExecutionResults.BatchExecutionResults
@see org.drools.runtime.help.BatchExecutionHelp
@see org.drools.runtime.pipeline.PipelineFactory
@see org.drools.runtime.Globals