readall

Retrieves all external rule object instances of a rule class (i.e. those which were created by client code). Internal rule object instances (i.e. those created from rules) are not retrieved.

See External and Internal Rule Objects for more details on the creation of rule objects.

Since Cúram V6, readall can be used to retrieve instances of a rule class from a different rule set, by setting the value of the optional ruleset XML attribute.

Since Cúram V6, the readall expression supports an optional match element which causes the readall expression to only retrieve rule objects whose value for a particular attribute matches that in the search criterion.

Important: Prior to Cúram V6, one way of retrieving rule objects that matched a criterion was to wrap a readall within a filter expression.

However, for CER Sessions that use a DatabaseDataStorage (see CER Sessions), in general it will be more performant to use the readall / match syntax introduced in Cúram V6. The new syntax will perform better:

  • when the attribute containing the readall expression is first calculated; and
  • when CER and the Dependency Manager identify that the attribute containing the readall expression is out-of-date and needs to be recalculated (see The Dependency Manager).

In situations where rule objects must be matched on more than one criteria, you should use the readall / match syntax to match on the most selective attribute, and then wrap the results in a filter to filter down to the other criteria.

Tip: If you only expect there to be a singleton instance of the rule class (perhaps after filtering or matching), consider wrapping the expression in a singleitem expression.
<?xml version="1.0" encoding="UTF-8"?>
<RuleSet name="Example_readall"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation=
"http://www.curamsoftware.com/CreoleRulesSchema.xsd">
  <Class name="Person">

    <Attribute name="socialSecurityNumber">
      <type>
        <javaclass name="String"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <!--
    Retrieve the one-and-only claim which will have been used to
    seed the session
    -->

    <Attribute name="claim">
      <type>
        <ruleclass name="Claim"/>
      </type>
      <derivation>
        <singleitem onEmpty="error" onMultiple="error">
          <readall ruleclass="Claim"/>
        </singleitem>
      </derivation>
    </Attribute>


    <!--
    Retrieve the benefit rule objects for this person (created from
    client code, probably by querying external storage).

    This implementation uses a <readall> with a nested <match> to
    retrieve only the matching rule objects, and (depending on data
    storage) will be more performant than the
    "benefitsFilterReadall" implementation below.
    -->

    <Attribute name="benefitsReadallMatch">
      <type>
        <javaclass name="List">
          <ruleclass name="Benefit"/>
        </javaclass>
      </type>
      <derivation>
        <readall ruleclass="Benefit">
          <match retrievedattribute="socialSecurityNumber">
            <reference attribute="socialSecurityNumber"/>
          </match>
        </readall>
      </derivation>
    </Attribute>


    <!--
    Retrieves the same rule objects as for "benefitsReadallMatch"
    above, but (depending on data storage) may not be as performant.
    -->
    <Attribute name="benefitsFilterReadall">
      <type>
        <javaclass name="List">
          <ruleclass name="Benefit"/>
        </javaclass>
      </type>
      <derivation>
        <filter>
          <list>
            <!-- retrieve all Benefit rule objects from external
                 storage -->
            <readall ruleclass="Benefit"/>
          </list>
          <listitemexpression>
            <equals>
              <!-- match up the social security numbers on
                the person rule object and the benefit
                rule object -->
              <reference attribute="socialSecurityNumber">
                <current/>
              </reference>
              <reference attribute="socialSecurityNumber"/>
            </equals>
          </listitemexpression>
        </filter>
      </derivation>
    </Attribute>

    <!--
    Retrieves the person's benefits of type "IncomeAssistance",
    using a <match> to retrieve all the person's benefits, and then
    a <filter> to extract only the "Income Assistance" benefits from
    the benefits for that person.

    This implementation may be suitable when the
    socialSecurityNumber is the most selective attribute for a
    Benefit in the data storage (i.e. there are many Benefit rule
    objects, but each socialSecurityNumber value is present on
    relatively few Benefit rule objects).
    -->
    <Attribute name="incomeAssistanceBenefitsMatchSSNFilterType">
      <type>
        <javaclass name="List">
          <ruleclass name="Benefit"/>
        </javaclass>
      </type>
      <derivation>
        <filter>
          <list>
            <!-- retrieve all Benefit rule objects for the Person
 -->
            <readall ruleclass="Benefit">
              <match retrievedattribute="socialSecurityNumber">
                <reference attribute="socialSecurityNumber"/>
              </match>
            </readall>
          </list>
          <listitemexpression>
            <equals>
              <!-- filter the Benefit rule objects for the Person
                   down to those of type "Income Assistance" only
                -->
              <reference attribute="type">
                <current/>
              </reference>
              <Code table="BenefitType">
                <!-- The value for Income Assistance -->
                <String value="BT1"/>
              </Code>
            </equals>
          </listitemexpression>
        </filter>
      </derivation>
    </Attribute>


    <!--
    Retrieves the person's benefits of type "IncomeAssistance",
    using a <match> to retrieve all the "Income Assistance"
    benefits, and then a <filter> to extract only the "Income
    Assistance" benefits for this Person.

    This implementation may be suitable when the type is the most
    selective attribute for a Benefit in the data storage (i.e.
    there are few Benefit rule objects of each type).
    -->
    <Attribute name="incomeAssistanceBenefitsMatchTypeFilterSSN">
      <type>
        <javaclass name="List">
          <ruleclass name="Benefit"/>
        </javaclass>
      </type>
      <derivation>
        <filter>
          <list>
            <!-- retrieve all Benefit rule objects of type "Income
                 Assistance" -->
            <readall ruleclass="Benefit">
              <match retrievedattribute="type">
                <Code table="BenefitType">
                  <!-- The value for Income Assistance -->
                  <String value="BT1"/>
                </Code>
              </match>
            </readall>
          </list>
          <listitemexpression>
            <equals>
              <!-- filter the Benefit rule objects of type "Income
                   Assistance"  down to those for this Person only
                -->
              <reference attribute="socialSecurityNumber">
                <current/>
              </reference>
              <reference attribute="socialSecurityNumber"/>
            </equals>
          </listitemexpression>
        </filter>
      </derivation>
    </Attribute>

    <!--
    Retrieves the rule objects for Benefits whose amount is greater
    than 100.

    Because "greater than" is not an exact match predicate, a
    <filter> must be used (<match> can only be used for an exact
    match criterion).
    -->
    <Attribute name="highPaymentBenefits">
      <type>
        <javaclass name="List">
          <ruleclass name="Benefit"/>
        </javaclass>
      </type>
      <derivation>
        <filter>
          <list>
            <!-- retrieve all Benefit rule objects for the Person
              -->
            <readall ruleclass="Benefit">
              <match retrievedattribute="socialSecurityNumber">
                <reference attribute="socialSecurityNumber"/>
              </match>
            </readall>
          </list>
          <listitemexpression>
            <!-- filter the Benefit rule objects for the Person down
                 to those of amount greater than 100 only -->
            <compare comparison=">">
              <reference attribute="amount">
                <current/>
              </reference>
              <Number value="100"/>
            </compare>
          </listitemexpression>
        </filter>
      </derivation>
    </Attribute>



  </Class>

  <Class name="Benefit">

    <Attribute name="socialSecurityNumber">
      <type>
        <javaclass name="String"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <Attribute name="type">
      <type>
        <codetableentry table="BenefitType"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <Attribute name="amount">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

  </Class>

  <!--
  This rule set expects that the code creating the session also
  creates a "bootstrap" single instance of this Claim rule
  class.
  -->
  <Class name="Claim">
    <Initialization>
      <Attribute name="claimIdentifier">
        <type>
          <javaclass name="String"/>
        </type>
      </Attribute>
      <Attribute name="claimDate">
        <type>
          <javaclass name="curam.util.type.Date"/>
        </type>
      </Attribute>
    </Initialization>
  </Class>

</RuleSet>