Rulebase Service - Sample Code (DerbyRulebaseService)

The most common implementations of Rulebase Service plugins are for:

 

The Rulebase Service Plugin in this example:

Setup

The sample code that follows, needs the following to run:

About the Derby Rulebase Service plugin

 

To setup this scenario:

  1. Create the SQL Database; it doesn't have to be DERBY, but that is what the source code is set up for.
  2. Create the Rulebase in Oracle Policy Modeling, and run Build.
  3. Make sure that DERBY is running in network server mode.
  4. Upload the rulebase.zip from the rulebase output folder by using the java program ‘BlobInsert <rulebase output folder>’. You can upload other rulebases if you want by running the program several times.
  5. Copy the code for the DerbyRulebaseService plugin (you may need to modify the database connection details).
  6. Compile and JAR the DerbyRulebaseService (you may need class files for your specific database implementation).
  7. Install the JAR file in Web Determinations; for more information, refer to Create a Plugin.
  8. Copy the DERBY library files to Web Determination (for example, <webroot>\WEB-INF\lib).
  9. Run a Web Determinations Interview.

How the DerbyRulebaseService works

When Oracle Web Determinations runtime is started, it first loads the default RulebaseService. When Oracle Web Determinations runtime discovers a RulebaseService custom plugin (that is, DerbyRulebaseService) is available, it uses this to replace the default Rulebase Service.

When the user starts up Oracle Web Determinations, it usually presents the Rulebase Selection screen, which presents a list of rulebases. To load that screen, Oracle Web Determinations requests for a list of rulebases available via the Rulebase Service of the current Oracle Web Determinations runtime. In the database, each rulebase is stored as a row in a table. The DerbyRulebaseService plugin queries the table to retrieve a list of rulebase names, its identifier, and returns it as rulebase links to be displayed in the Rulebase Selection screen.

When the user selects a rulebase to load, Oracle Web Determinations uses the Rulebase Service of the current Oracle Web Determinations runtime to retrieve the selected rulebase. For DerbyRulebaseService to be able to retrieve the rulebase:

  1. It uses the rulebase identifier to retrieve the table row of the specific rulebase from the DERBY database
  2. The rulebase information in the table row is stored in XML format as a BLOB
  3. DerbyRulebaseService first retrieves the BLOB from the table row
  4. A BinaryStream object is attached to the BLOB, and used as the InputStream argument for the InterviewRulebase object to be returned
  5. Once the InterviewRulebase is instantiated, it is returned by the plugin

 

The getInstance method implementation tests that the database is available before returning an initialized instance of the plugin.

Source Code

Note that the following are just a guide for a possible implementation - the following two code samples are not intended to be used as-is. They are there merely as an example of how the rulebase service plugin could be implemented.

 

DerbyRulebaseService.java

 

BlobInsert.java