Пример #1
0
 /**
  * The token of column names.
  *
  * <p>This variant is most useful when the partition key is composite.
  *
  * @param columnNames the column names to take the token of.
  * @return a string reprensenting the token of the provided column names.
  */
 public static String token(String... columnNames) {
   StringBuilder sb = new StringBuilder();
   sb.append("token(");
   Utils.joinAndAppendNames(sb, ",", Arrays.asList(columnNames));
   sb.append(")");
   return sb.toString();
 }
Пример #2
0
 /**
  * The token of a column name.
  *
  * @param columnName the column name to take the token of.
  * @return {@code "token(" + columnName + ")"}.
  */
 public static String token(String columnName) {
   StringBuilder sb = new StringBuilder();
   sb.append("token(");
   Utils.appendName(columnName, sb);
   sb.append(")");
   return sb.toString();
 }
Пример #3
0
 /**
  * Quotes a columnName to make it case sensitive.
  *
  * @param columnName the column name to quote.
  * @return the quoted column name.
  */
 public static String quote(String columnName) {
   StringBuilder sb = new StringBuilder();
   sb.append("\"");
   Utils.appendName(columnName, sb);
   sb.append("\"");
   return sb.toString();
 }
Пример #4
0
  @Override
  protected String buildQueryString() {
    StringBuilder builder = new StringBuilder();

    builder.append("INSERT INTO ");
    if (keyspace != null) Utils.appendName(keyspace, builder).append(".");
    Utils.appendName(table, builder);
    builder.append("(");
    Utils.joinAndAppendNames(builder, ",", names);
    builder.append(") VALUES (");
    Utils.joinAndAppendValues(builder, ",", values);
    builder.append(")");

    if (!usings.usings.isEmpty()) {
      builder.append(" USING ");
      Utils.joinAndAppend(builder, " AND ", usings.usings);
    }

    return builder.toString();
  }
Пример #5
0
  protected String buildQueryString() {
    StringBuilder builder = new StringBuilder();

    builder.append("UPDATE ");
    if (keyspace != null) Utils.appendName(keyspace, builder).append(".");
    Utils.appendName(table, builder);

    if (!usings.usings.isEmpty()) {
      builder.append(" USING ");
      Utils.joinAndAppend(builder, " AND ", usings.usings);
    }

    if (!assignments.assignments.isEmpty()) {
      builder.append(" SET ");
      Utils.joinAndAppend(builder, ",", assignments.assignments);
    }

    if (!where.clauses.isEmpty()) {
      builder.append(" WHERE ");
      Utils.joinAndAppend(builder, ",", where.clauses);
    }

    return builder.toString();
  }
Пример #6
0
  protected String buildQueryString() {
    StringBuilder builder = new StringBuilder();
    builder.append(isCounterOp() ? "BEGIN COUNTER BATCH" : "BEGIN BATCH");

    if (!usings.usings.isEmpty()) {
      builder.append(" USING ");
      Utils.joinAndAppend(builder, " AND ", usings.usings);
    }
    builder.append(" ");

    for (int i = 0; i < statements.size(); i++) {
      String str = statements.get(i).getQueryString();
      builder.append(str);
      if (!str.trim().endsWith(";")) builder.append(";");
    }
    builder.append("APPLY BATCH;");
    return builder.toString();
  }