Rule Builder > Business Query Language Reference > Customizing the Business Query Language

The BQL does not include a way to return all rules descending from a named package. For example, given the package structure below:

TopPackage

  • MidPackage
  • BottomPackage
  • Rule
  • it is not possible to return Rule in standard BQL when conducting a search on MidPackage.

    However, you can customize the BQL by extending it as shown in the following example:

    1. Write and compile a class with a function that tests if a rule has an ancestor with a particular name, for example:
    2. import ilog.rules.repository.model.IlrModelElement;
    3. public class MyQueryTools
    4. {
    5.   public static boolean hasAncestor(
    6.       IlrModelElement element, String ancestorName)
    7.   {
    8.     while(element != null) {
    9.       if(element.getName().equals(ancestorName)) {
    10.         return true;
    11.       }
    12.       element = (IlrModelElement) element.getContainer();
    13.     }
    14.     return false;
    15.   }
    16. }
    17. Start the Rule Builder and open your repository.
    18. Click Options on the File menu, click the Classpaths tab, and then add the class folder MyQueryTools to the User Java Classpath.
    19. Click Facility Explorer on the View menu and in the Facility toolbar verify that Query is selected (located to the right of the images/dt15sortascending_icon.png button.
    20. Click Query Library to expand it and then click Business Object Model.
    21. Go to the BOM Explorer and add a virtual function to the class ilog.rules.repository.brm.IlrBrmDefaultRule. In the Property Sheet of the virtual function, set alternate to it has {0} as ancestor, set returnType to boolean, and set translation to MyQueryTools.hasAncestor({this}, {0}). Add an argument of type String to the virtual function.
    22. Go back to the Facility Explorer, add a package, and then add a rule query to it. In the rule query, set <select a condition> to it has < String > as ancestor. Then set <String > to the name of the package in which you want to look for rules. In Code View, the when part of the query rule should contain the following lines:
    23. ilrBrmDefaultRule: IlrBrmDefaultRule(!isTemplate());
    24. evaluate((MyQueryTools.hasAncestor(ilrBrmDefaultRule, "{package-name}")));
    25. Execute the query to show all the rules descending from the named package in the Query Results panel.


    Customer Support | Copyright © 1987-2004 ILOG S.A. All rights reserved. Legal terms. PREVIOUS