Ejemplo n.º 1
0
  public static List<?> select(
      EntityManager em,
      FindQualifiers fq,
      Name name,
      List<?> keysIn,
      DynamicQuery.Parameter... restrictions) {
    // If keysIn is not null and empty, then search is over.
    if ((keysIn != null) && (keysIn.isEmpty())) return keysIn;

    if (name == null) return keysIn;

    DynamicQuery dynamicQry = new DynamicQuery(selectSQL);
    appendConditions(dynamicQry, fq, name);
    // Since this is a tModel, don't need to search the lazily deleted ones.
    dynamicQry
        .AND()
        .pad()
        .appendGroupedAnd(
            new DynamicQuery.Parameter(
                ENTITY_ALIAS + ".deleted", false, DynamicQuery.PREDICATE_EQUALS));
    if (restrictions != null && restrictions.length > 0)
      dynamicQry.AND().pad().appendGroupedAnd(restrictions);

    return getQueryResult(em, dynamicQry, keysIn, ENTITY_ALIAS + "." + KEY_NAME);
  }
Ejemplo n.º 2
0
  public static void appendConditions(DynamicQuery qry, FindQualifiers fq, Name name) {
    String namePredicate = DynamicQuery.PREDICATE_EQUALS;
    if (fq != null && fq.isApproximateMatch()) {
      namePredicate = DynamicQuery.PREDICATE_LIKE;
    }

    qry.WHERE().pad().openParen().pad();

    String nameTerm = ENTITY_ALIAS + ".name";
    String nameValue = name.getValue();
    if (fq != null && fq.isCaseInsensitiveMatch()) {
      nameTerm = "upper(" + ENTITY_ALIAS + ".name)";
      nameValue = name.getValue().toUpperCase();
    }
    // JUDDI-235: wildcards are provided by user (only commenting in case a new interpretation
    // arises)
    // if (fq.isApproximateMatch())
    //	nameValue = nameValue.endsWith(DynamicQuery.WILDCARD)?nameValue:nameValue +
    // DynamicQuery.WILDCARD;

    if (name.getLang() == null || name.getLang().length() == 0) {
      qry.appendGroupedAnd(new DynamicQuery.Parameter(nameTerm, nameValue, namePredicate));
    } else {
      String langValue =
          name.getLang().endsWith(DynamicQuery.WILDCARD)
              ? name.getLang().toUpperCase()
              : name.getLang().toUpperCase() + DynamicQuery.WILDCARD;
      qry.appendGroupedAnd(
          new DynamicQuery.Parameter(nameTerm, nameValue, namePredicate),
          new DynamicQuery.Parameter(
              "upper(" + ENTITY_ALIAS + ".langCode)", langValue, DynamicQuery.PREDICATE_LIKE));
    }

    qry.closeParen().pad();
    if (fq != null && fq.isSignaturePresent()) {
      qry.AND()
          .pad()
          .openParen()
          .pad()
          .append(TModelQuery.SIGNATURE_PRESENT)
          .pad()
          .closeParen()
          .pad();
    }
  }