| ILOG JRules User Guide > Customizing JRules > Tasks > Customizing Rule Studio > Automating Queries with the Rule Studio API |
Automating Queries with the Rule Studio API |
PREVIOUS NEXT |
Services on top of the rule model API allow you to automate queries. You can automate queries by API with the entry point IlrQueryService.
You run a query in two or three steps, depending on whether you want to run the actions of the query or not:
Use the following to fetch the query service:
IlrQueryService queryService = (IlrQueryServiceImpl) IlrStudioQueryPlugin.getQueryService(ruleProject);
If you want to set a BOM parser other than the default, use:
queryService.setBom(IlrBOMGetter.getInstance().getBOM());
Depending on the elements you have, you can initialize the query service from:
IlrQuery project element
Find all business rules such that...)
Following is an example of how to initialize a query service with an IlrQuery element obtained from an IlrProject:
IlrQuery myQuery; queryService.initQuery(myQuery, null);
To pass your own IlrRuleQueryMatchCollector as second argument:
IlrQuery myQuery; IlrRuleQueryMatchCollector matchCollector; queryService.initQuery(myQuery, matchCollector);
Following is an example of how to initialize a query service with query text:
String myQuery = "Find all business rules such that the name of each business rule contains \"foobar\""; boolean useLocalScope = false; IProject currentProject; queryService.initQuery(myQuery, useLocalScope, currentProject, null);
The second Boolean parameter determines whether the query scope is restricted to the specified project, or if it includes project dependencies.
As with an IlrQuery, you can also pass an IlrRuleQueryMatchCollector as last parameter:
queryService.initQuery(myQuery, useLocalScope, currentProject, matchCollector);
To run a query, use:
List results = queryService.runQuery();
The contents of the list returned depends on the implementation of IlrRuleQueryMatchCollector. Using the default provided, a list of objects of one of the following type is returned:
If the query has actions (checked using IlrQueryService.queryHasActions()), you can run the actions with:
queryService.runQueryActions(results)
The results are those returned by runQuery(). If needed, you can change the list before passing it to runQueryActions().
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |