Ejemplo n.º 1
0
 Comparable<?> getOperatorPredicateValue(
     OperatorPredicate predicate, Map<String, Comparable<?>> parameterMap) {
   Comparable<?> value = predicate.getValue();
   if (value instanceof String) {
     String stringValue = (String) value;
     if ((stringValue.charAt(0) == '?') && (stringValue.charAt(stringValue.length() - 1) == '?')) {
       String parameterName = stringValue.substring(1, stringValue.length() - 1);
       value = parameterMap.get(parameterName);
     }
   }
   return value;
 }
Ejemplo n.º 2
0
  NoSqlPredicate convertPredicate(
      IPredicate predicate, String tableName, Map<String, Comparable<?>> parameterMap) {
    if (predicate == null) return null;
    NoSqlPredicate convertedPredicate = null;
    if (predicate instanceof CompoundPredicate) {
      CompoundPredicate compoundPredicate = (CompoundPredicate) predicate;
      ArrayList<NoSqlPredicate> noSqlPredicateList = new ArrayList<NoSqlPredicate>();
      for (IPredicate childPredicate : compoundPredicate.getPredicateList()) {
        boolean incorporated = false;
        if (childPredicate instanceof OperatorPredicate) {
          OperatorPredicate childOperatorPredicate = (OperatorPredicate) childPredicate;
          for (NoSqlPredicate childNoSqlPredicate : noSqlPredicateList) {
            incorporated =
                childNoSqlPredicate.incorporateComparison(
                    childOperatorPredicate.getColumnName(),
                    childOperatorPredicate.getOperator(),
                    getOperatorPredicateValue(childOperatorPredicate, parameterMap),
                    compoundPredicate.getOperator());
            if (incorporated) break;
          }
        }
        if (!incorporated) {
          NoSqlPredicate noSqlPredicate = convertPredicate(childPredicate, tableName, parameterMap);
          noSqlPredicateList.add(noSqlPredicate);
        }
      }
      convertedPredicate =
          new NoSqlCompoundPredicate(
              this,
              tableName,
              compoundPredicate.getOperator(),
              compoundPredicate.isNegated(),
              noSqlPredicateList);
    } else if (predicate instanceof OperatorPredicate) {
      OperatorPredicate operatorPredicate = (OperatorPredicate) predicate;
      Comparable<?> value = getOperatorPredicateValue(operatorPredicate, parameterMap);
      switch (operatorPredicate.getOperator()) {
        case EQ:
          convertedPredicate =
              new NoSqlRangePredicate(
                  this, tableName, operatorPredicate.getColumnName(), value, true, value, true);
          break;
        case LT:
          convertedPredicate =
              new NoSqlRangePredicate(
                  this, tableName, operatorPredicate.getColumnName(), null, false, value, false);
          break;
        case LTE:
          convertedPredicate =
              new NoSqlRangePredicate(
                  this, tableName, operatorPredicate.getColumnName(), null, false, value, true);
          break;
        case GT:
          convertedPredicate =
              new NoSqlRangePredicate(
                  this, tableName, operatorPredicate.getColumnName(), value, false, null, false);
          break;
        case GTE:
          convertedPredicate =
              new NoSqlRangePredicate(
                  this, tableName, operatorPredicate.getColumnName(), value, true, null, false);
          break;
        default:
          convertedPredicate =
              new NoSqlOperatorPredicate(
                  this, operatorPredicate.getColumnName(), operatorPredicate.getOperator(), value);
      }
    } else {
      throw new StorageException("Unknown predicate type");
    }

    return convertedPredicate;
  }