示例#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 ContainsTextQueryClause containsTextQry) {
    String dbFieldId = containsTextQry.getFieldId().asString();

    String template = null;
    if (containsTextQry.isBegining()) {
      template = "e._{} LIKE '%:{}'";
    } else if (containsTextQry.isEnding()) {
      template = "e._{} LIKE ':{}%'";
    } else if (containsTextQry.isContaining()) {
      template = "e._{} LIKE '%:{}%'";
    } else if (containsTextQry.isFullText()) {
      template = "SQL(  'MATCH({}) " + "AGAINST(? IN BOOLEAN MODE)',':{}')";
    }
    return Strings.of(template).customizeWith(dbFieldId, dbFieldId).asString();
  }