S2JDBCのWhere条件で「OR」を使う

S2JDBCの条件にてORを使いたい場合はComplexWhereを使うとのこと。

SimpleWhereとCOmplexWhereを絡めたパターン

たとえば顧客情報テーブルというのがあって以下のような項目がある
・名前
・名前(カナ)
・住所
・備考
・削除フラグ

んで、とりあえずキーワードで名前〜備考あたりをひっかけて、かつ削除フラグが立ってないデータを抽出したい場合はこんな感じ。

select()
.where(
    new ComplexWhere()
      .like("customer.name", condition.getKeyword())
      .or().like("customer.nameKana", condition.getKeyword())
      .or().like("customer.address", condition.getKeyword())
      .or().like("customer.remarks", condition.getKeyword())
    , new SimpleWhere()
      .eq("deleteFlag", false));

Whereに直接条件を記入した場合

select()
.where("(COALESCE(customerCharge.name, '') " +
    "|| COALESCE(customerCharge.nameKana, '') " +
    "|| COALESCE(customerCharge.customer.name, '') " +
    "|| COALESCE(customerCharge.customer.nameKana, '')) like ? "
    + " and delete_flag = ? "
    ,condition.getKeyword(), false);