Ejemplo n.º 1
0
  @SuppressWarnings("rawtypes")
  private static QueryBuilder getQueryBuilder(String cacheName, InfinispanConnection conn)
      throws TranslatorException {

    Class<?> type = conn.getCacheClassType();

    QueryFactory qf = conn.getQueryFactory();

    QueryBuilder qb = qf.from(type);

    return qb;
  }
Ejemplo n.º 2
0
  public static Object performKeySearch(
      String cacheName, String columnNameInSource, Object value, InfinispanConnection conn)
      throws TranslatorException {

    RemoteCache<?, Object> c = (RemoteCache<?, Object>) conn.getCache();
    Object v = c.get(value);
    return v;
  }
Ejemplo n.º 3
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;
  }