Beispiel #1
0
  @SuppressWarnings("rawtypes")
  public static List<Object> performSearch(
      Condition where, OrderBy orderby, String cacheName, InfinispanConnection conn)
      throws TranslatorException {

    QueryBuilder qb = getQueryBuilder(cacheName, conn);

    if (orderby != null) {
      List<SortSpecification> sss = orderby.getSortSpecifications();
      for (SortSpecification spec : sss) {
        Expression exp = spec.getExpression();
        Column mdIDElement = ((ColumnReference) exp).getMetadataObject();
        SortOrder so = SortOrder.ASC;
        if (spec.getOrdering().name().equalsIgnoreCase(SortOrder.DESC.name())) {
          so = SortOrder.DESC;
        }
        qb = qb.orderBy(mdIDElement.getSourceName(), so);
      }
    }

    FilterConditionContext fcc = buildQueryFromWhereClause(where, qb, null);

    List<Object> results = null;

    Query query = null;
    if (fcc != null) {
      query = fcc.toBuilder().build();
      results = query.list();

      if (results == null) {
        return Collections.emptyList();
      }

    } else if (orderby != null) {
      query = qb.build();
      results = query.list();
      if (results == null) {
        return Collections.emptyList();
      }

    } else {
      results = new ArrayList<Object>();
      RemoteCache<?, Object> c = (RemoteCache<?, Object>) conn.getCache();
      for (Object id : c.keySet()) {
        results.add(c.get(id));
      }
    }

    return results;
  }
Beispiel #2
0
  private static FilterConditionContext buildQueryFromWhereClause(
      Condition criteria,
      @SuppressWarnings("rawtypes") QueryBuilder queryBuilder,
      FilterConditionBeginContext fcbc)
      throws TranslatorException {

    if (criteria == null) return null;
    FilterConditionContext fcc = null;

    if (criteria instanceof AndOr) {
      LogManager.logTrace(
          LogConstants.CTX_CONNECTOR, "Infinispan DSL Parsing compound criteria."); // $NON-NLS-1$
      AndOr crit = (AndOr) criteria;
      AndOr.Operator op = crit.getOperator();

      switch (op) {
        case AND:
          FilterConditionContext f_and =
              buildQueryFromWhereClause(crit.getLeftCondition(), queryBuilder, fcbc);
          FilterConditionBeginContext fcbca = null;
          if (f_and != null) {
            fcbca = f_and.and();
          }
          fcc = buildQueryFromWhereClause(crit.getRightCondition(), queryBuilder, fcbca);

          break;

        case OR:
          FilterConditionContext f_or =
              buildQueryFromWhereClause(crit.getLeftCondition(), queryBuilder, fcbc);
          FilterConditionBeginContext fcbcb = null;
          if (f_or != null) {
            fcbcb = f_or.or();
          }
          fcc = buildQueryFromWhereClause(crit.getRightCondition(), queryBuilder, fcbcb);

          break;

        default:
          throw new TranslatorException(
              InfinispanPlugin.Util.gs(
                  InfinispanPlugin.Event.TEIID25050, new Object[] {op, "And, Or"}));
      }

    } else if (criteria instanceof Comparison) {
      fcc = visit((Comparison) criteria, queryBuilder, fcbc);

    } else if (criteria instanceof Like) {
      fcc = visit((Like) criteria, queryBuilder, fcbc);

    } else if (criteria instanceof In) {
      fcc = visit((In) criteria, queryBuilder, fcbc);

    } else if (criteria instanceof IsNull) {
      fcc = visit((IsNull) criteria, queryBuilder, fcbc);
    } else if (criteria instanceof Not) {
      Condition c = ((Not) criteria).getCriteria();
      if (fcbc == null) {
        fcc = queryBuilder.not(buildQueryFromWhereClause(c, queryBuilder, fcbc));
      } else {
        fcc = fcbc.not(buildQueryFromWhereClause(c, queryBuilder, fcbc));
      }
    } else {
      throw new TranslatorException(
          InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25054, criteria.toString()));
    }
    return fcc;
  }