com.datastax.driver.core.querybuilder.Insert.getQueryString()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.5k)|赞(0)|评价(0)|浏览(88)

本文整理了Java中com.datastax.driver.core.querybuilder.Insert.getQueryString()方法的一些代码示例,展示了Insert.getQueryString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Insert.getQueryString()方法的具体详情如下:
包路径:com.datastax.driver.core.querybuilder.Insert
类名称:Insert
方法名:getQueryString

Insert.getQueryString介绍

暂无

代码示例

代码示例来源:origin: Netflix/conductor

/**
 * @return cql query statement to insert a new task into the "workflows" table
 */
public String getInsertTaskStatement() {
  return QueryBuilder.insertInto(keyspace, TABLE_WORKFLOWS)
      .value(WORKFLOW_ID_KEY, bindMarker())
      .value(SHARD_ID_KEY, bindMarker())
      .value(TASK_ID_KEY, bindMarker())
      .value(ENTITY_KEY, ENTITY_TYPE_TASK)
      .value(PAYLOAD_KEY, bindMarker())
      .getQueryString();
}

代码示例来源:origin: jooby-project/jooby

private static String insertSQL(final String table, final int timeout) {
 Insert insertInto = insertInto(table)
   .value(ID, raw("?"))
   .value(CREATED_AT, raw("?"))
   .value(ACCESSED_AT, raw("?"))
   .value(SAVED_AT, raw("?"))
   .value(ATTRIBUTES, raw("?"));
 if (timeout > 0) {
  insertInto.using(ttl(timeout));
 }
 return insertInto.getQueryString();
}

代码示例来源:origin: Netflix/conductor

/**
 * @return cql query statement to insert a new workflow into the "workflows" table
 */
public String getInsertWorkflowStatement() {
  return QueryBuilder.insertInto(keyspace, TABLE_WORKFLOWS)
      .value(WORKFLOW_ID_KEY, bindMarker())
      .value(SHARD_ID_KEY, bindMarker())
      .value(TASK_ID_KEY, bindMarker())
      .value(ENTITY_KEY, ENTITY_TYPE_WORKFLOW)
      .value(PAYLOAD_KEY, bindMarker())
      .value(TOTAL_TASKS_KEY, bindMarker())
      .value(TOTAL_PARTITIONS_KEY, bindMarker())
      .getQueryString();
}

代码示例来源:origin: scalar-labs/scalardb

@Override
@Nonnull
protected PreparedStatement prepare(Operation operation) {
 checkArgument(operation, Put.class);
 Put put = (Put) operation;
 Insert insert = prepare(put);
 String query = insert.getQueryString();
 return prepare(query);
}

代码示例来源:origin: org.apache.gora/gora-cassandra

/**
 * This method return the CQL query to insert data in to the table.
 * refer : http://docs.datastax.com/en/cql/3.1/cql/cql_reference/insert_r.html
 *
 * @param mapping Cassandra Mapping {@link CassandraMapping}
 * @param fields  available fields
 * @return CQL Query
 */
static String getInsertDataQuery(CassandraMapping mapping, List<String> fields) {
 String[] columnNames = getColumnNames(mapping, fields);
 String[] objects = new String[fields.size()];
 Arrays.fill(objects, "?");
 return QueryBuilder.insertInto(mapping.getKeySpace().getName(), mapping.getCoreName()).values(columnNames, objects).getQueryString();
}

代码示例来源:origin: Stratio/ingestion

public void save(final List<Event> events) {
 final BatchStatement batch = new BatchStatement();
 for (final Event event : events) {
  final Map<String, Object> parsedEvent = parse(event);
  if (parsedEvent.isEmpty()) {
   log.warn("Event {} could not be mapped. Suggestion: Cassandra is case sensitive, so maybe you can check field names.", event);
   continue;
  }
  if (!hasPrimaryKey(parsedEvent)) {
   break;
  }
  final Insert insert = QueryBuilder.insertInto(table);
  for (final Map.Entry<String, Object> entry : parsedEvent.entrySet()) {
   insert.value(entry.getKey(), entry.getValue());
  }
  if (log.isTraceEnabled()) {
   log.trace("Preparing insert for table {}: {}", table.getName(), insert.getQueryString());
  }
  batch.add(insert);
 }
 if (batch.getStatements().isEmpty()) {
  log.warn("No event produced insert query for table {}", table.getName());
  return;
 }
 batch.setConsistencyLevel(consistencyLevel);
 session.execute(batch);
}

代码示例来源:origin: apache/gora

/**
 * This method return the CQL query to insert data in to the table.
 * refer : http://docs.datastax.com/en/cql/3.1/cql/cql_reference/insert_r.html
 *
 * @param mapping Cassandra Mapping {@link CassandraMapping}
 * @param fields  available fields
 * @return CQL Query
 */
static String getInsertDataQuery(CassandraMapping mapping, List<String> fields) {
 String[] columnNames = getColumnNames(mapping, fields);
 String[] objects = new String[fields.size()];
 Arrays.fill(objects, "?");
 return QueryBuilder.insertInto(mapping.getKeySpace().getName(), mapping.getCoreName()).values(columnNames, objects).getQueryString();
}

代码示例来源:origin: apache/streams

private void createInsertStatement() {
  Insert insertBuilder = QueryBuilder.insertInto(config.getTable());
  insertBuilder.value(config.getPartitionKeyColumn(), new Object());
  insertBuilder.value(config.getColumn(), new Object());
  insertStatement = session.prepare(insertBuilder.getQueryString());
 }
}

代码示例来源:origin: apifest/apifest-oauth20

@Override
public boolean storeScope(Scope scope) {
  Insert stmt = QueryBuilder.insertInto(KEYSPACE_NAME, SCOPE_TABLE_NAME)
      .value("scope", scope.getScope())
      .value("description", scope.getDescription())
      .value("cc_expires_in", scope.getCcExpiresIn())
      .value("pass_expires_in", scope.getPassExpiresIn())
      .value("refresh_expires_in", scope.getRefreshExpiresIn())
      ;
  try {
    session.execute(stmt);
  } catch (NoHostAvailableException e) {
    log.error("No host in the %s cluster can be contacted to execute the query.\n",
        session.getCluster());
  } catch (QueryExecutionException e) {
    log.error("An exception was thrown by Cassandra because it cannot " +
        "successfully execute the query with the specified consistency level.");
  } catch (QueryValidationException e) {
    log.error(String.format("The query %s \nis not valid, for example, incorrect syntax.\n",
        stmt.getQueryString()));
  } catch (IllegalStateException e) {
    log.error("The BoundStatement is not ready.");
  }
  return true;
}

代码示例来源:origin: apifest/apifest-oauth20

@Override
public void storeAuthCode(AuthCode authCode) {
  Insert stmt = QueryBuilder.insertInto(KEYSPACE_NAME, AUTH_CODE_TABLE_NAME)
    .value("code", authCode.getCode())
    .value("client_id", authCode.getClientId())
    .value("redirect_uri", authCode.getRedirectUri())
    .value("state", authCode.getState())
    .value("scope", authCode.getScope())
    .value("type", authCode.getType())
    .value("valid", authCode.isValid())
    .value("user_id", authCode.getUserId())
    .value("created", authCode.getCreated())
  ;
  try {
    session.execute(stmt);
  } catch (NoHostAvailableException e) {
    log.error("No host in the %s cluster can be contacted to execute the query.\n",
        session.getCluster());
  } catch (QueryExecutionException e) {
    log.error("An exception was thrown by Cassandra because it cannot " +
        "successfully execute the query with the specified consistency level.");
  } catch (QueryValidationException e) {
    log.error(String.format("The query %s \nis not valid, for example, incorrect syntax.\n",
        stmt.getQueryString()));
  } catch (IllegalStateException e) {
    log.error("The BoundStatement is not ready.");
  }
}

代码示例来源:origin: apifest/apifest-oauth20

@Override
public void storeClientCredentials(ClientCredentials clientCreds) {
  Insert stmt = QueryBuilder.insertInto(KEYSPACE_NAME, CLIENTS_TABLE_NAME)
    .value("client_id", clientCreds.getId())
      .value("client_secret", clientCreds.getSecret())
      .value("scope", clientCreds.getScope())
      .value("name", clientCreds.getName())
      .value("created", clientCreds.getCreated())
      .value("uri", clientCreds.getUri())
      .value("descr", clientCreds.getDescr())
      .value("type", clientCreds.getType())
      .value("status", clientCreds.getStatus())
      .value("details", clientCreds.getApplicationDetails());
  try {
    session.execute(stmt);
  } catch (NoHostAvailableException e) {
    log.error("No host in the %s cluster can be contacted to execute the query.\n",
        session.getCluster());
  } catch (QueryExecutionException e) {
    log.error("An exception was thrown by Cassandra because it cannot " +
        "successfully execute the query with the specified consistency level.");
  } catch (QueryValidationException e) {
    log.error(String.format("The query %s \nis not valid, for example, incorrect syntax.\n",
        stmt.getQueryString()));
  } catch (IllegalStateException e) {
    log.error("The BoundStatement is not ready.");
  }
}

代码示例来源:origin: apifest/apifest-oauth20

} catch (QueryValidationException e) {
  log.error(String.format("The query %s \nis not valid, for example, incorrect syntax.\n",
      stmt.getQueryString()));
} catch (IllegalStateException e) {
  log.error("The BoundStatement is not ready.");

代码示例来源:origin: com.moz.fiji.schema/fiji-schema-cassandra

/**
 * Prepare the statement for writing to the hash table.
 *
 * @param admin The Cassandra cluster connection.
 * @param schemaHashTable The table name.
 * @return A write statement for the hash table.
 */
private static PreparedStatement prepareQueryWriteHashTable(
  final CassandraAdmin admin,
  final CassandraTableName schemaHashTable
) {
 final Insert insert =
   QueryBuilder.insertInto(schemaHashTable.getKeyspace(), schemaHashTable.getTable())
     .value(SCHEMA_COLUMN_HASH_KEY, bindMarker())
     .value(SCHEMA_COLUMN_TIME, bindMarker())
     .value(SCHEMA_COLUMN_VALUE, bindMarker());
 return admin.getPreparedStatement(insert.getQueryString());
}

代码示例来源:origin: com.moz.fiji.schema/fiji-schema-cassandra

/**
 * Prepare the statement for writing to the ID table.
 *
 * @param admin The Cassandra cluster connection.
 * @param schemaIdTable The table name.
 * @return A write statement for the id table.
 */
private PreparedStatement prepareQueryWriteIdTable(
  final CassandraAdmin admin,
  final CassandraTableName schemaIdTable
) {
 final Insert insert =
   QueryBuilder.insertInto(schemaIdTable.getKeyspace(), schemaIdTable.getTable())
     .value(SCHEMA_COLUMN_ID_KEY, bindMarker())
     .value(SCHEMA_COLUMN_TIME, bindMarker())
     .value(SCHEMA_COLUMN_VALUE, bindMarker());
 return admin.getPreparedStatement(insert.getQueryString());
}

代码示例来源:origin: org.jooby/jooby-cassandra

private static String insertSQL(final String table, final int timeout) {
 Insert insertInto = insertInto(table)
   .value(ID, raw("?"))
   .value(CREATED_AT, raw("?"))
   .value(ACCESSED_AT, raw("?"))
   .value(SAVED_AT, raw("?"))
   .value(ATTRIBUTES, raw("?"));
 if (timeout > 0) {
  insertInto.using(ttl(timeout));
 }
 return insertInto.getQueryString();
}

相关文章