org.hdpagination.dataaccess.support
Class NamedParamRestrictions

java.lang.Object
  extended by org.hdpagination.dataaccess.support.NamedParamRestrictions

public final class NamedParamRestrictions
extends java.lang.Object

This class provides static factory methods to produce an object of NamedParamRestriction. Typically, these factory methods are called when calling HBN3QueryCallbackNamedParamWrapper.addRestriction(NamedParamRestriction) or JPAQueryCallbackNamedParamWrapper.addRestriction(NamedParamRestriction).

A sample code is as follows:

   HBN3QueryCallbackNamedParamWrapper callback = HBN3QueryCallbackNamedParamWrapper.newInstance("from ProductVO p")
       .addRestriction( NamedParamRestrictions.eq("prodNo", "prodNo", crit.getProdNo()) )
       .addRestriction( NamedParamRestrictions.contains("madeIn", "madeIn", crit.getMadeIn()) );

One generic rule applied to all the static factory methods is:

  • If the type of argument paramValue is java.lang.String, it returns null when the paramValue is null or blank.
  • If the argument paramValue is of other types, it returns null when the paramValue is null.
  • If the Restriction object passed to the method HBN3QueryCallbackNamedParamWrapper.addRestriction(NamedParamRestriction) or JPAQueryCallbackNamedParamWrapper.addRestriction(NamedParamRestriction) is null, the restriction will not be added.

    The benefit of doing this way is you can avoid IF ELSE check in your code. Consequently, the code is much neater.

    Since:
    1.3.1
    Author:
    Liangfeng Ren

    Method Summary
    static NamedParamRestriction contains(java.lang.String column, java.lang.String paramName, java.lang.String paramValue)
              Apply "LIKE" constraint ([column] like :[paramName]).
    static NamedParamRestriction endsWith(java.lang.String column, java.lang.String paramName, java.lang.String paramValue)
              Apply "LIKE" constraint ([column] like :[paramName]).
    static NamedParamRestriction eq(java.lang.String column, java.lang.String paramName, java.lang.Object paramValue)
              Apply "equal" constraint ([column] = :[paramName]).
    static NamedParamRestriction ge(java.lang.String column, java.lang.String paramName, java.lang.Object paramValue)
              Apply "greater than or equal" constraint ([column] >= :[paramName]).
    static NamedParamRestriction gt(java.lang.String column, java.lang.String paramName, java.lang.Object paramValue)
              Apply "great than" constraint ([column] > :[paramName]).
    static NamedParamRestriction le(java.lang.String column, java.lang.String paramName, java.lang.Object paramValue)
              Apply "less than or equal" constraint ([column] <= :[paramName]).
    static NamedParamRestriction lt(java.lang.String column, java.lang.String paramName, java.lang.Object paramValue)
              Apply "less than" constraint ([column] < :[paramName]).
    static NamedParamRestriction startsWith(java.lang.String column, java.lang.String paramName, java.lang.String paramValue)
              Apply "LIKE" constraint ([column] like :[paramName]).
     
    Methods inherited from class java.lang.Object
    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
     

    Method Detail

    eq

    public static NamedParamRestriction eq(java.lang.String column,
                                           java.lang.String paramName,
                                           java.lang.Object paramValue)
    Apply "equal" constraint ([column] = :[paramName]). If the value of parameter (argument paramValue) is null, then return null. It also returns null if the value of parameter (with the type of java.lang.String) is blank.

    Parameters:
    column - The column (before =) in the clause fragment. It can not be null or empty.
    paramName - In Hibernate or JPA query, mamed query parameters are tokens of the form :name in the query string. Here, name (":" excluded) will be replaced by the value of this argument. For example, if the argument column is "madeIn" and the argument paramName is "country", then the generated WHERE clause fragment will be "madeIn = :country". This argument can not be null or empty.
    paramValue - actual value of the parameter.
    Returns:

    gt

    public static NamedParamRestriction gt(java.lang.String column,
                                           java.lang.String paramName,
                                           java.lang.Object paramValue)
    Apply "great than" constraint ([column] > :[paramName]). If the value of parameter (argument paramValue) is null, then return null. It also returns null if the value of parameter (with the type of java.lang.String) is blank.

    Parameters:
    column - The column (before >) in the clause fragment. It can not be null or empty.
    paramName - In Hibernate or JPA query, mamed query parameters are tokens of the form :name in the query string. Here, name (":" excluded) will be replaced by the value of this argument. For example, if the argument column is "price" and the argument paramName is "priceFrom", then the generated WHERE clause fragment will be "price > :priceFrom". This argument can not be null or empty.
    paramValue - actual value of the parameter.
    Returns:

    ge

    public static NamedParamRestriction ge(java.lang.String column,
                                           java.lang.String paramName,
                                           java.lang.Object paramValue)
    Apply "greater than or equal" constraint ([column] >= :[paramName]). If the value of parameter (argument paramValue) is null, then return null. It also returns null if the value of parameter (with the type of java.lang.String) is blank.

    Parameters:
    column - The column (before >=) in the clause fragment. It can not be null or empty.
    paramName - In Hibernate or JPA query, mamed query parameters are tokens of the form :name in the query string. Here, name (":" excluded) will be replaced by the value of this argument. For example, if the argument column is "price" and the argument paramName is "priceFrom", then the generated WHERE clause fragment will be "price >= :priceFrom". This argument can not be null or empty.
    paramValue - actual value of the parameter.
    Returns:

    lt

    public static NamedParamRestriction lt(java.lang.String column,
                                           java.lang.String paramName,
                                           java.lang.Object paramValue)
    Apply "less than" constraint ([column] < :[paramName]). If the value of parameter (argument paramValue) is null, then return null. It also returns null if the value of parameter (with the type of java.lang.String) is blank.

    Parameters:
    column - The column (before <) in the clause fragment. It can not be null or empty.
    paramName - In Hibernate or JPA query, mamed query parameters are tokens of the form :name in the query string. Here, name (":" excluded) will be replaced by the value of this argument. For example, if the argument column is "price" and the argument paramName is "priceTo", then the generated WHERE clause fragment will be "price < :priceTo". This argument can not be null or empty.
    paramValue - actual value of the parameter.
    Returns:

    le

    public static NamedParamRestriction le(java.lang.String column,
                                           java.lang.String paramName,
                                           java.lang.Object paramValue)
    Apply "less than or equal" constraint ([column] <= :[paramName]). If the value of parameter (argument paramValue) is null, then return null. It also returns null if the value of parameter (with the type of java.lang.String) is blank.

    Parameters:
    column - The column (before <=) in the clause fragment. It can not be null or empty.
    paramName - In Hibernate or JPA query, mamed query parameters are tokens of the form :name in the query string. Here, name (":" excluded) will be replaced by the value of this argument. For example, if the argument column is "price" and the argument paramName is "priceTo", then the generated WHERE clause fragment will be "price <= :priceTo". This argument can not be null or empty.
    paramValue - actual value of the parameter.
    Returns:

    contains

    public static NamedParamRestriction contains(java.lang.String column,
                                                 java.lang.String paramName,
                                                 java.lang.String paramValue)
    Apply "LIKE" constraint ([column] like :[paramName]). The actual binding parameter value is %paramValue%. If the value of parameter (argument paramValue) is null, then return null. It also returns null if the value of parameter (with the type of java.lang.String) is blank.

    Parameters:
    column - The column (before like) in the clause fragment
    paramName - In Hibernate or JPA query, mamed query parameters are tokens of the form :name in the query string. Here, name (":" excluded) will be replaced by the value of this argument. For example, if the argument column is "description" and the argument paramName is "desc", then the generated WHERE clause fragment will be "description LIKE :desc". This argument can not be null or empty.
    paramValue - The actual binding parameter value will be %paramValue%.
    Returns:

    startsWith

    public static NamedParamRestriction startsWith(java.lang.String column,
                                                   java.lang.String paramName,
                                                   java.lang.String paramValue)
    Apply "LIKE" constraint ([column] like :[paramName]). The actual binding parameter value is paramValue%. If the value of parameter (argument paramValue) is null, then return null. It also returns null if the value of parameter (with the type of java.lang.String) is blank.

    Parameters:
    column - The column (before like) in the clause fragment
    paramName - In Hibernate or JPA query, mamed query parameters are tokens of the form :name in the query string. Here, name (":" excluded) will be replaced by the value of this argument. For example, if the argument column is "description" and the argument paramName is "desc", then the generated WHERE clause fragment will be "description LIKE :desc". This argument can not be null or empty.
    paramValue - The actual binding parameter value will be paramValue%.
    Returns:

    endsWith

    public static NamedParamRestriction endsWith(java.lang.String column,
                                                 java.lang.String paramName,
                                                 java.lang.String paramValue)
    Apply "LIKE" constraint ([column] like :[paramName]). The actual binding parameter value is %paramValue. If the value of parameter (argument paramValue) is null, then return null. It also returns null if the value of parameter (with the type of java.lang.String) is blank.

    Parameters:
    column - The column (before like) in the clause fragment
    paramName - In Hibernate or JPA query, mamed query parameters are tokens of the form :name in the query string. Here, name (":" excluded) will be replaced by the value of this argument. For example, if the argument column is "description" and the argument paramName is "desc", then the generated WHERE clause fragment will be "description LIKE :desc". This argument can not be null or empty.
    paramValue - The actual binding parameter value will be %paramValue.
    Returns:


    Copyright © 2008 HDPagination All Rights Reserved.