The package "com.openrules.datasource.db" supports a very simple datasource protocol that allows OpenRules to access xls-files saved in a database without necessity to download them in a file system. You may use ant relational database and save your Excel files with OpenRules tables inside one database table as blob objects. You may give each file (blob-object) an unique name that usually corresponds to the relative path of this file.
Example
Let's assume that your OpenRules repository was organized in your file system starting from the directory "examples/RulesRepositoryDB/rules/". Here is a description of the existing repository using the Environment table located in the file Main.xls:
Environment | |
import.java | myjava.package1.* |
import.static | com.openrules.tools.Methods |
include.path | ../ |
include | <CategoryA/RulesA1.xls> |
<CategoryA/RulesA2.xls> | |
<CategoryB/RulesB1.xls> | |
<CategoryB/RulesB2.xls> | |
<Common/libA/libRulesX.xls> | |
<Common/libA/libRulesY.xls> |
Now, you decided to move this repository to a database. All xls-files (accept the Main.xls) will be saved in one database table using BLOB objects with unique keys that corresponds to complete file names. After moving all your included files into a database, your Environment table will look like:
Environment | |
datasource | classpath:/db.properties |
import.java | myjava.package1.* |
import.static | com.openrules.tools.Methods |
include.path | db:/examples/RulesRepositoryDB/rules/ |
include | <CategoryA/RulesA1.xls> |
<CategoryA/RulesA2.xls> | |
<CategoryB/RulesB1.xls> | |
<CategoryB/RulesB2.xls> | |
<Common/libA/libRulesX.xls> | |
<Common/libA/libRulesY.xls> |
Please, note that you still need your Main.xls file with this Environment table to let OpenRules know where a new rules repository is located. The new Environment table has a new attribute "datasource" that uses the standard OpenRules convention to specify a file "db.properties" with different database properties. The only other change is the modified "include.path" that now looks like this:
db:/examples/RulesRepositoryDB/rules/
Here the word "db:' specifies a new protocol similar to traditional "file:"
protocol. This protocol is defined in the file "db.properties". The name "/examples/RulesRepositoryDB/rules/"
is a common entry point for DB identifiers (keys) of all other xls-files
(blobs). For example, it assumes that the included file <CategoryA/RulesA1.xls>
was saved in the database with the key "/examples/RulesRepositoryDB/rules/CategoryA/RulesA1.xls".
Database Configuration
The database is configured using a property file such "db.properties" that in
this case should be located in the project classpath. Here is an example of the
db.properties file:
protocol=db #protocol implementation class class=com.openrules.datasource.db.DbDataSourceHandler #options db.user=embedded db.password=none db.url=jdbc:derby:rulesDB;create=false db.driver=org.apache.derby.jdbc.EmbeddedDriver db.selectSql=select content from dbstorage where name = ?The property "protocol" defines a new protocol "db:" that is similar to traditional "file:", "http:", and other OpenRules data source protocols. It would be used to access rules saved in this particular database.
The property "class" defines an implementation class for this protocol. This class is available via the standard openrules.all.jar.
Properties "db.user" and "db.password" identify user's credentials in the
selected database.
The property "db.url" identifies a URL to a physical database. For example,
the string "jdbc:derby:dist/dbstorage;create=false" identifies a standard
Apache Derby database, that is an open source relational database implemented
entirely in Java - see http://db.apache.org/derby/. The string such as "rulesDB"
defines a name of the database instance. You may use a name (like "rulesDB" that is
is relative to the current directory. You also may specify an absolute path by
starting the db name from the characher "/" (e.g. "/repository/rulesDB") or with
a drive name (e.g. "C:/repository/rulesDB").
The property "db.driver" identifies a database driver. For example, the string
"org.apache.derby.jdbc.EmbeddedDriver" identifies a standard
Apache Derby driver that usually requires only one reference to the derby.jar.
It is assumed that the database includes a table (e.g. with the name "dbstorage")
that contains different BLOB objects (placeholders for xls-files) with unique names.
This table consists of two attributes:
"select content from dbstorage where name = ?"
OpenRules includes a sample project RulesRepositoryDB that demonstrates how to organize and execute rules defined inside Apache Derby database.