droolsdrools-guvnordrools-planner

Drools rule to replace a database accessing method?


My requirement: I have a method which goes to db and gets info from a table. And using this table info I validate the user input coming to my app. Now I want to REPLACE this method and achieve same functionality (going to DB to fetch some data and using that data validate the user input) to a rule in drools. How do I do it? How the facts (here in my case the data in database) should be inserted into drools knowledge session ?? Do I have to get the facts in POJO first and then insert the same POJO in knowledge session (I'm less interested in this approach if its possible at all)? Is there any way to represent the facts itself in a .drl or any other external source(other than database) and then load those facts in POJO and insert pojo in knowledge session?

response is highly appreciated!! Thank you


Solution

  • Data can be made available via POJOs inserted as facts or stored as globals. How the data is taken from an "external source" and inserted or stored is completely arbitrary, and you can use whatever fits your use case best (XML, JSON, Java serialization,...). Also, expanding DB data into LHS rule code has been tried, but this may not be efficient enough.