Annotation Type Query


  • @Documented
    @Inherited
    @Retention(RUNTIME)
    public @interface Query
    The query element declares a static query. It contains an optional description, optional query options, zero or more query parameters, and a query search term defined inside an Expression.

    A simple query represented in xml such as this:

     <query name="simple">
        <query-parameter name="simpleParam1" type="java.lang.String"/>
        <compare attribute-name="countryCode" op="equals" parameter="simpleParam1"/>
     </query>
     

    can be created by constructing a query structure such as:

    @Query(name="simple",
           queryParameters = ,
           expression = @Expression(
               term = @Term(compare = @Compare(attributeName = "countryCode", op="equals", parameter="simpleParam1"))
           )
    )
     

    Complex queries that use conditional operators need to be constructed using a ConditionalExpression. A ConditionalExpression allows the operator (AND,OR,NOT) to be used with a number of Term's. To construct the more complex example below that contains nested conditions:

     <query name="AConditionalQuery">
        <and>
            <has-prefix attribute-name="anAttr" value="val1"/>
            <or>
                <has-prefix attribute-name="anotherAttr" value="val2"/>
                <compare attribute-name="yetAnotherAttr" op="equals" value="val3"/>
            </or>
        </and>
     </query>
     

    A structure such as the one described below would be used. Care should be taken to ensure that the conditional alias's are used correctly.

     @Query(name = "AConditionalQuery",
            expression = @Expression(
                             term = @Term(conditionalExpressionAlias = "conditionalAND"),
                             conditionalExpressions = {
                                 @ConditionalExpression(
                                         alias="conditionalAND",
                                         condition = Condition.and,
                                         terms = {
                                            @Term(hasPrefix = @HasPrefix(attributeName = "anAttr", value="val1")),
                                            @Term(conditionalExpressionAlias = "conditionalOR")
                                         }
                                 ),
                                 @ConditionalExpression(
                                          alias="conditionalOR",
                                          condition = Condition.or,
                                          terms = {
                                              @Term(hasPrefix = @HasPrefix(attributeName = "anotherAttr", value="val2")),
                                              @Term(compare = @Compare(attributeName = "yetAnotherAttr", op="equals", value="val3"))
                                          }
                                 )
                 }
    )
     
    • Element Detail

      • name

        String name
        Default:
        ""
      • description

        String description
        Default:
        ""
      • queryOptions

        QueryOptions queryOptions
        Default:
        @javax.slee.annotation.QueryOptions
      • expression

        Expression expression
        Default:
        @javax.slee.annotation.Expression