title: Java Database Driven Business Rules - Design Thoughts?
body: <p>My enterprise application is currently Running on Weblogic 10.3.4, Java 1.6 and Spring 2.0.8. It's a recent upgrade hence Spring is yet to be updated and some of the java code base is still in old 1.4 style.</p>
  
  <p>At the moment we use a propriatory rules engine to run our business rules. However, this is overkill as we use none of the inference engine functionality and we can no longer justify the license costs. The plan is to write a database driven rules engine.</p>
  
  <p>Each form request will have any number of rules associated with it, which wiull be configured using a few basic database tables.</p>
  
  <p>My design so far is that each rule defined in the database will map via Spring to a Singleton Stateless Spring bean. Given a form state each rule will return a Result respose object. See code snippet below:</p>
  
  <pre><code> //get List of rules for form from database
   List&lt;RuleConfiguration&gt;  rules = RulesService.getRulesForFormRuleset(formType, filingMethod, rsName, document);
  
      IssueDocument issues = new IssueDocumentImpl();
  
       for (RuleConfiguration ruleConfig : rules) {
  
  
           //create a rule instance from the Spring Bean Factory
           Rule rule = (Rule) beanFactory.getBean(ruleConfig.getRule().getRuleBeanName());
           RulesIssue issue = rule.runRule(document, ruleConfig);
  
              if (issue != null)  {  //Issue has been populated rule must have fired
                  issues.addNewIssue(issue);
              }
       }
  
      return issues;
  </code></pre>
  
  <p>Does this sound like a sensible solution? I was keen to implement a "light-touch" solution so steered clear of EJB as there are over 500 rules that will eventually have to be written. My main concern is that as these are all singletons and there will be a heavy demand on my "rules engine" do I need to consider some sort of bean pooling? Any other feedback would be most welcome. Rip me to shreds if you like - I can take it!</p>
  
  <p>Many Thanks</p>