Automated query execution sample details
You use Rule Designer to run this sample.
Running this sample
To run the query execution:
- In Rule Designer, switch to the Rule perspective.
- Click .
- In the External Tools Configurations dialog, in the Configurations list,
click
Ant Build > queryexecution-application. - Click Run.
The console displays the results of the query execution. Three queries are run: one query that is contained in a compressed file, one that is accessed through the query path, and one with a query that is a string. For each query, the console displays a report that contains the text of each rule that matches the query criterion, and the number of rules.
How this sample works
The execution uses the class ilog.rules.studio.samples.queryexecution.Query to run the query. This class is defined in the Eclipse plug-in description file as an extension for org.eclipse.core.runtime.applications and implements org.eclipse.core.runtime.IPlatformRunnable. It is run from within the build.xml file as an Eclipse headless application by using:
ilog.rules.studio.samples.queryexecution.headless.application
Notice that the real query execution is delegated to the ilog.rules.studio.samples.queryexecution.helper.Model class.
You must supply the following mandatory parameters (see the supplied build.xml file for a full list of parameters):
-
Execution when the query is a
Queryobject:- targetproject = The name of the decision service (for example: Loan Validation Service).
query= "path:path/to/a/query/object/in/the/eclipse/workspace"scope=trueif the scope of the query is local to the project of the query project, orfalseif it encompasses the project dependencies.
-
Execution when the query is a simple text:
- targetproject = The name of the rule project. For example: loanvalidation-rules.
- query = a BQL query. For example:
“text:Find all business rules such that the documentation of each business rule is empty”. scope=trueif the scope of the query is local to the project of the query, orfalseif it encompasses the project dependencies.
-
Execution when the query is included in a compressed file:
- targetproject = The name of the rule project (for example:
loanvalidation-rules). query= "zip:path_to_the_zip_file/path_in_the_zip_file_to_the_query".scope=trueif the scope of the query is local to the project of the query, orfalseif it encompasses the project dependencies.
- targetproject = The name of the rule project (for example:
To define the application flow in Query.java:
- Check the input parameters.
- Check whether the decision service exists in the workspace, and then use it for the next steps.
- If the
path:mode is used, check whether the query exists in the workspace, and initialize a query service from it. - If the
text:orzip:mode is used, initialize a query service from the query string. - Run the query from the query service.
- Process the results that are returned by the query.
The command output is visible in the Console view of Rule Designer. For each query, console displays the text of the rule artifacts (rules and decision tables) that match the query conditions, the execution status, and the number of rule artifacts that match the conditions.
Source files
To display the source code of the queryexecution Eclipse plug-in, do the following steps:
- Click .
- In the Import wizard, select and click Next.
- In the Import As section, select the Projects with source folders option and click Next.
- In the Plug-ins and Fragments Found list, scroll down, select the ilog.rules.studio.samples.queryexecution plug-in, and then click Add.
- Click Finish.Rule Designer imports the plug-in source code and displays it in Rule Explorer.Note: You can ignore the warning that the build path specifies execution environment Java™SE-1.7. You can also remove it by either installing Java 7 on your Rule Designer instance, or setting the execution environment of the sample plug-in to 1.7.
- Switch to the Plug-in Development perspective.
Click . Select the Plug-in Development perspective and then click OK.
- In the Package Explorer, navigate to the Java source files
in the ilog.rules.studio.samples.queryexecution/queryexecutionsrc folder.
The following source file is of interest:
ilog.rules.studio.samples.queryexecution.helper.Model.java