Multiple, combined OR conditions in ORMLite

前端 未结 2 1689
深忆病人
深忆病人 2020-12-17 18:42

I like to have a query like this:

select data from table
 where (x > 1 and x < 100)
    or (x > 250 and x < 300)

In ORMlite, th

2条回答
  •  囚心锁ツ
    2020-12-17 19:26

    Do you understand what the ... part of the declaration means? It means that you can pass in an array (and that the compiler will construct an array for you if you just specify values).

    So just create a list if you want, then convert it to an array (for all but the first condition) and then call the method. You may well want to make a static method to do the last part easily:

    public static  void or(Where target,
                                  List> conditions)
    {
        // TODO: Argument validation
        Where first = conditions.get(0);
        Where second = conditions.get(1);
        List> rest = conditions.subList(2, conditions.size());
        // You'll to suppress a warning here due to generics...
        Where[] restArray = rest.toArray(new Where[0]);
        target.where(first, second, restArray);
    }
    

提交回复
热议问题