Package org.apache.commons.lang.text

Examples of org.apache.commons.lang.text.StrBuilder$StrBuilderReader


   * @param l The list of columns.
   *
   * @return A comma separated string of the query strings of the given columns.
   */
  /* package */ static String columnListToQueryString(List<AbstractColumn> l) {
    StrBuilder builder = new StrBuilder();
    List<String> stringList = Lists.newArrayList();
    for (AbstractColumn col : l) {
      stringList.add(col.toQueryString());
    }
    builder.appendWithSeparators(stringList, ", ");
    return builder.toString();
  }
View Full Code Here


   * @param whereClause A string builder representing the WHERE clause of the SQL query.
   * @param queryFilter The query filter.
   */
  private static void buildWhereCluaseForComparisonFilter(
      StrBuilder whereClause, QueryFilter queryFilter) {
    StrBuilder first = new StrBuilder();
    StrBuilder second = new StrBuilder();

    // Build the left part and the right part of the clause according to the filter's type.
    if (queryFilter instanceof ColumnColumnFilter) {
      ColumnColumnFilter filter = (ColumnColumnFilter) queryFilter;
      first.append(getColumnId(filter.getFirstColumn()));
      second.append(getColumnId(filter.getSecondColumn()));
    } else { // The filter is a ColumnValueFilter
      ColumnValueFilter filter = (ColumnValueFilter) queryFilter;
      first.append(getColumnId(filter.getColumn()));
      second.append(filter.getValue().toString());
      if ((filter.getValue().getType() == ValueType.TEXT)
          || (filter.getValue().getType() == ValueType.DATE)
          || (filter.getValue().getType() == ValueType.DATETIME)
          || (filter.getValue().getType() == ValueType.TIMEOFDAY)) {
        second.insert(0, "\"");
        second.insert(second.length(), "\"");
      }
    }
    whereClause.append(buildWhereClauseFromRightAndLeftParts(
        first, second, ((ComparisonFilter) queryFilter).getOperator()));
  }
View Full Code Here

      clauses.add("FORMAT " + userFormatOptions.toQueryString());
    }
    if (hasOptions()) {
      clauses.add("OPTIONS " + options.toQueryString());
    }
    StrBuilder result = new StrBuilder();
    result.appendWithSeparators(clauses, " ");
    return result.toString();
  }
View Full Code Here

   *
   * @return A string builder representing the where clause of the SQL query.
   */
  private static StrBuilder buildWhereClauseFromRightAndLeftParts(
      StrBuilder value1, StrBuilder value2, ComparisonFilter.Operator operator) {
    StrBuilder clause;
    switch (operator) {
      case EQ:
        clause = value1.append("=").append(value2);
        break;
      case NE:
        clause = value1.append("<>").append(value2);
        break;
      case LT:
        clause = value1.append("<").append(value2);
        break;
      case GT:
        clause = value1.append(">").append(value2);
        break;
      case LE:
        clause = value1.append("<=").append(value2);
        break;
      case GE:
        clause = value1.append(">=").append(value2);
        break;
      case CONTAINS:
        value2 = new StrBuilder(value2.toString().replace("\"", ""));
        clause = value1.append(" LIKE ").append("\"%").append(value2).append("%\"");
        break;
      case STARTS_WITH:
        value2 = new StrBuilder(value2.toString().replace("\"", ""));
        clause = value1.append(" LIKE ").append("\"").append(value2).append("%\"");
        break;
      case ENDS_WITH:
        value2 = new StrBuilder(value2.toString().replace("\"", ""));
        clause = value1.append(" LIKE ").append("\"%").append(value2).append("\"");
        break;
      case MATCHES:
        throw new RuntimeException("SQL does not support regular expression");
      case LIKE:
        value2 = new StrBuilder(value2.toString().replace("\"", ""));
        clause = value1.append(" LIKE ").append("\"").append(value2).append("\"");
        break;
      default:// Should never get here.
        throw new RuntimeException("Operator was not found: " + operator);
    }
    clause.insert(0, "(").append(")");
    return clause;
  }
View Full Code Here

   * @param abstractColumn The column.
   *
   * @return The column id for the data table.
   */
  private static StrBuilder getColumnId(AbstractColumn abstractColumn) {
    StrBuilder columnId = new StrBuilder();

    // For simple column the id is simply the column id.
    if (abstractColumn instanceof SimpleColumn) {
      columnId.append("`").append(abstractColumn.getId()).append("`");
    } else {
      // For aggregation column build the id from the aggregation type and the
      // column id (e.g. for aggregation type 'min' and column id 'salary', the
      // sql column id will be: min(`salary`);
      AggregationColumn aggregationColumn = (AggregationColumn) abstractColumn;
      columnId.append(getAggregationFunction(
          aggregationColumn.getAggregationType())).append("(`").
          append(aggregationColumn.getAggregatedColumn()).append("`)");
    }
    return columnId;
  }
View Full Code Here

            if (args == 0)
            {
                return method.getName();
            }

            StrBuilder methodKey = new StrBuilder((args+1)*16).append(method.getName());

            for (int j = 0; j < args; j++)
            {
                /*
                 * If the argument type is primitive then we want
                 * to convert our primitive type signature to the
                 * corresponding Object type so introspection for
                 * methods with primitive types will work correctly.
                 *
                 * The lookup map (convertPrimitives) contains all eight
                 * primitives (boolean, byte, char, double, float, int, long, short)
                 * known to Java. So it should never return null for the key passed in.
                 */
                if (parameterTypes[j].isPrimitive())
                {
                    methodKey.append((String) convertPrimitives.get(parameterTypes[j]));
                }
                else
                {
                    methodKey.append(parameterTypes[j].getName());
                }
            }

            return methodKey.toString();
        }
View Full Code Here

            if (args == 0)
            {
                return method;
            }

            StrBuilder methodKey = new StrBuilder((args+1)*16).append(method);

            for (int j = 0; j < args; j++)
            {
                Object arg = params[j];
                if (arg == null)
                {
                    methodKey.append(NULL_ARG);
                }
                else
                {
                    methodKey.append(arg.getClass().getName());
                }
            }

            return methodKey.toString();
        }
View Full Code Here

            getLog().error(msg);
            throw new VelocityException(msg);
        }

        /* now just create the VM call, and use evaluate */
        StrBuilder template = new StrBuilder("#");
        template.append(vmName);
        template.append("(");
        for( int i = 0; i < params.length; i++)
        {
            template.append(" $");
            template.append(params[i]);
        }
        template.append(" )");

        return evaluate(context, writer, logTag, template.toString());
    }
View Full Code Here

     *
     * @param ba input binary byte array
     * @return hex representation of binary input
     */
    public static String baToHexString(byte ba[]) {
        StrBuilder sb = new StrBuilder(ba.length*2);
        for (int i = 0; i < ba.length; i++) {
            int j = ba[i] & 0xff;
            if (j < 16) {
                sb.append("0"); // $NON-NLS-1$ add zero padding
            }
            sb.append(Integer.toHexString(j));
        }
        return sb.toString();
    }
View Full Code Here

     * ftp://ftp.nowhere.com/pub/README.txt
     *
     * @return a formatted string label describing this sampler
     */
    public String getLabel() {
        StrBuilder sb = new StrBuilder();
        sb.setNullText("null");// $NON-NLS-1$
        sb.append("ftp://");// $NON-NLS-1$
        sb.append(getServer());
        String port = getPort();
        if (port.length() > 0){
            sb.append(':');
            sb.append(port);
        }
        sb.append("/");// $NON-NLS-1$
        sb.append(getRemoteFilename());
        sb.append(isBinaryMode() ? " (Binary) " : " (Ascii) ");// $NON-NLS-1$ $NON-NLS-2$
        sb.append(isUpload() ? " <- " : " -> "); // $NON-NLS-1$ $NON-NLS-2$
        sb.append(getLocalFilename());
        return sb.toString();
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.lang.text.StrBuilder$StrBuilderReader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.