Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    fetching a DataSource with 2 Criteria "OR"-combined

    Hi,

    i am using a DMI class to get the data from the DB. I want to use a DSRequest with two Criteria that are combined by an "OR". How do i do that? I introduced 2 Criteria via dsRequest.getCriteria().put("field", "value");. This already works but with an "AND" operator between the two Criterias. Any idea how to change it to "OR".

    thanks
    kissev

    #2
    Take a look at the docs for AdvancedCriteria - it explains the AdvancedCriteria and how it is translated to Java when one is created on the client-side. You want to form the same Java structure.

    In outline, a Map containing a key "operator" set to "or", containing a second key "criteria" which has a List of two additional Maps, each of the Maps being one of the criteria being OR'd.

    Comment


      #3
      This code snippet shows a simple "OR" criteria.

      Code:
      		AdvancedCriteria dateCriteria[] = new AdvancedCriteria[2];
      		
      		dateCriteria[ 0 ] = new AdvancedCriteria( "CANCELLED_DATE", OperatorId.GREATER_OR_EQUAL, new Date(0) );
      		dateCriteria[ 1 ] = new AdvancedCriteria( "EFFECTIVE_DATE", OperatorId.GREATER_OR_EQUAL, new Date(0) );
      		
      		AdvancedCriteria orCriteria = new AdvancedCriteria( OperatorId.OR, dateCriteria );

      Comment


        #4
        Is there a utility method in the server-side Isomorphic toolbox somewhere that will create an AdvancedCriteria object from a String that contains the properly formatted JSON. In other words, is there an easy method for translating something like this into an Object that will work as AdvancedCrtieria?
        Code:
        {operator:"or", criteria:{{fieldName:"aField", operator:"lessThan", value:"10"},{fieldName:"aField", operator:"greaterThan", value:"50"}}}

        Comment


          #5
          Not really, but if you're just trying for similar compactness, try using Java's anonymous class and anonymous constructor blocks like so:

          Code:
          new HashMap () {{
              put("operator", "or");
              put("criteria", new ArrayList () {{
                  add(new HashMap({{
                       put("fieldName", [i]fieldName[/i]);
                       put("operator", [i]operator[/i]);
                       put("value", [i]value[/i]);
                  }});
                  add(new HashMap({{
                       put("fieldName", [i]fieldName[/i]);
                       put("operator", [i]operator[/i]);
                       put("value", [i]value[/i]);
                  }});
              }});
          }};

          Comment


            #6
            Thanks for the help - it works now

            Comment

            Working...
            X