コード例 #1
0
  /////////////////////////////////////////////////////////////////////////////////////////
  //  QUERY
  /////////////////////////////////////////////////////////////////////////////////////////
  protected void _setJPAQueryParams(final Query qry, final BooleanQueryClause qryClause) {
    Set<QualifiedQueryClause<? extends QueryClause>> clauses = qryClause.getClauses();
    for (Iterator<QualifiedQueryClause<? extends QueryClause>> clauseIt = clauses.iterator();
        clauseIt.hasNext(); ) {
      QueryClause clause = clauseIt.next().getClause();

      String dbFieldId = clause.getFieldId().asString();

      if (clause instanceof BooleanQueryClause) {
        BooleanQueryClause boolQry = (BooleanQueryClause) clause;
        _setJPAQueryParams(qry, boolQry); // recurse!
      } else if (clause instanceof EqualsQueryClause<?>) {
        EqualsQueryClause<?> eqQry = (EqualsQueryClause<?>) clause;
        qry.setParameter(dbFieldId, eqQry.getValue().toString());
      } else if (clause instanceof ContainsTextQueryClause) {
        ContainsTextQueryClause containsTxtClause = (ContainsTextQueryClause) clause;
        qry.setParameter(dbFieldId, containsTxtClause.getText());
      } else if (clause instanceof RangeQueryClause<?>) {
        RangeQueryClause<?> rangeQry = (RangeQueryClause<?>) clause;
        if (rangeQry.getRange().hasLowerBound() && rangeQry.getRange().hasUpperBound()) {
          qry.setParameter(dbFieldId + "Start", rangeQry.getRange().lowerEndpoint());
          qry.setParameter(dbFieldId + "End", rangeQry.getRange().lowerEndpoint());
        } else if (rangeQry.getRange().hasLowerBound()) {
          qry.setParameter(dbFieldId, rangeQry.getRange().lowerEndpoint());
        } else if (rangeQry.getRange().hasUpperBound()) {
          qry.setParameter(dbFieldId, rangeQry.getRange().upperEndpoint());
        }
      } else if (clause instanceof ContainedInQueryClause<?>) {
        ContainedInQueryClause<?> containedInQry = (ContainedInQueryClause<?>) clause;
        Collection<?> spectrum = Lists.newArrayList(containedInQry.getSpectrum());
        qry.setParameter(dbFieldId, spectrum);
      }
    }
  }
コード例 #2
0
 private static String _jpqlQueryFrom(final ContainedInQueryClause<?> containedInQry) {
   String dbFieldId = containedInQry.getFieldId().asString();
   String outJPQL = Strings.of("e._{} IN :{}").customizeWith(dbFieldId, dbFieldId).asString();
   return outJPQL;
 }