Is it possible to import a database table to Drools Guvnor as a decision table?

3.3k Views Asked by At

We will be having data fed in this database table regularly, and I was wondering if it was possible to import this data on a timely basis into Drools Guvnor?

1

There are 1 best solutions below

4
On

If you want to maintain rules in a database table, then you should be looking at rule templates:

http://docs.jboss.org/drools/release/6.0.1.Final/drools-docs/html_single/index.html#d0e4969

Rule templates provide a relatively simple mechanism for merging DRL with data.

FWIW - The documentation for this in the manual is poor, so here is a hint on the kind of thing you need to do:

To generate rules from a combination of database data and a template, you will need to import org.drools.template.jdbc.ResultSetGenerator. This class can be used to generate DRL code from a database query result set and a template.

// Get results from your DB query...
resultSet = preparedStmt.executeQuery();
// Generate the DRL...
resultSetGenerator = new ResultSetGenerator();
String drl = resultSetGenerator.compile(resultSet, 
         new FileInputStream("path/to/template.drt"));

Then you create a package through the API and add that generated DRL to it.