com.datastax.driver.core.Row.getString()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(121)

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

Row.getString介绍

[英]Returns the ith value of this row as a string.
[中]以字符串形式返回此行的第i个值。

代码示例

代码示例来源:origin: spring-projects/spring-data-examples

public CustomAddressbook convert(Row source) {
    CustomAddressbook result = new CustomAddressbook();
    result.setTheId(source.getString("id"));
    result.setMyDetailsAsJson(source.getString("me"));
    return result;
  }
}

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

private Iterator<Shard> getIteratorFromRows( List<Row> rows){
  List<Shard> shards = new ArrayList<>(rows.size());
  rows.forEach(row -> {
    final String queueName = row.getString( ShardSerializationImpl.COLUMN_QUEUE_NAME);
    final String region = row.getString( ShardSerializationImpl.COLUMN_REGION);
    final long shardId = row.getLong( ShardSerializationImpl.COLUMN_SHARD_ID);
    final UUID pointer = row.getUUID( ShardSerializationImpl.COLUMN_POINTER);
    shards.add(new Shard(queueName, region, shardType, shardId, pointer));
    nextStart = shardId;
  });
  return shards.iterator();
}

代码示例来源:origin: spring-projects/spring-data-examples

/**
   * Retrieve the Cassandra release version.
   *
   * @param session must not be {@literal null}.
   * @return the release {@link Version}.
   */
  public static Version getReleaseVersion(Session session) {

    Assert.notNull(session, "Session must not be null");

    ResultSet resultSet = session.execute("SELECT release_version FROM system.local;");
    Row row = resultSet.one();

    return Version.parse(row.getString(0));
  }
}

代码示例来源:origin: prestodb/presto

@Override
public VersionNumber getCassandraVersion()
{
  ResultSet result = executeWithSession(session -> session.execute("select release_version from system.local"));
  Row versionRow = result.one();
  if (versionRow == null) {
    throw new PrestoException(CASSANDRA_VERSION_ERROR, "The cluster version is not available. " +
        "Please make sure that the Cassandra cluster is up and running, " +
        "and that the contact points are specified correctly.");
  }
  return VersionNumber.parse(versionRow.getString("release_version"));
}

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

@Override
public List<String> getListOfQueues() {
  logger.trace( "getListOfQueues " );
  Statement select = QueryBuilder.select().all().from( TABLE_QUEUES );
  ResultSet rs = cassandraClient.getApplicationSession().execute( select );
  return rs.all().stream()
      .map( row -> row.getString( COLUMN_QUEUE_NAME ))
      .collect( Collectors.toList() );
}

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

private Iterator<DatabaseQueueMessage> getIteratorFromRows(List<Row> rows){
  List<DatabaseQueueMessage> messages = new ArrayList<>(rows.size());
  rows.forEach(row -> {
    final String queueName =    row.getString( COLUMN_QUEUE_NAME);
    final String region =       row.getString( COLUMN_REGION);
    final long shardId =        row.getLong(   COLUMN_SHARD_ID);
    final UUID queueMessageId = row.getUUID(   COLUMN_QUEUE_MESSAGE_ID);
    final UUID messageId =      row.getUUID(   COLUMN_MESSAGE_ID);
    final long queuedAt =       row.getLong(   COLUMN_QUEUED_AT);
    final long inflightAt =     row.getLong(   COLUMN_INFLIGHT_AT);
    messages.add(new DatabaseQueueMessage(
        messageId, messageType, queueName, region, shardId, queuedAt, inflightAt, queueMessageId));
    //queueMessageId is internal to the messages_available and messages_inflight tables
    nextStart = queueMessageId;
  });
  return messages.iterator();
}

代码示例来源:origin: prestodb/presto

private static void checkConnectivity(CassandraSession session)
{
  ResultSet result = session.execute("SELECT release_version FROM system.local");
  List<Row> rows = result.all();
  assertEquals(rows.size(), 1);
  String version = rows.get(0).getString(0);
  log.info("Cassandra version: %s", version);
}

代码示例来源:origin: prestodb/presto

@Override
public List<SizeEstimate> getSizeEstimates(String keyspaceName, String tableName)
{
  checkSizeEstimatesTableExist();
  Statement statement = select("range_start", "range_end", "mean_partition_size", "partitions_count")
      .from(SYSTEM, SIZE_ESTIMATES)
      .where(eq("keyspace_name", keyspaceName))
      .and(eq("table_name", tableName));
  ResultSet result = executeWithSession(session -> session.execute(statement));
  ImmutableList.Builder<SizeEstimate> estimates = ImmutableList.builder();
  for (Row row : result.all()) {
    SizeEstimate estimate = new SizeEstimate(
        row.getString("range_start"),
        row.getString("range_end"),
        row.getLong("mean_partition_size"),
        row.getLong("partitions_count"));
    estimates.add(estimate);
  }
  return estimates.build();
}

代码示例来源:origin: prestodb/presto

case TEXT:
case VARCHAR:
  return CassandraCqlUtils.quoteStringLiteral(row.getString(i));
case INT:
  return Integer.toString(row.getInt(i));

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

@Override
public DatabaseQueueMessageBody loadMessageData(final UUID messageId ){
  logger.trace("loadMessageData {}", messageId);
  Clause messageIdClause = QueryBuilder.eq( COLUMN_MESSAGE_ID, messageId );
  Statement select = QueryBuilder.select().from( TABLE_MESSAGE_DATA).where(messageIdClause);
  Row row = cassandraClient.getApplicationSession().execute(select).one();
  if ( row == null ) {
    return null;
  }
  return new DatabaseQueueMessageBody(
      row.getBytes( COLUMN_MESSAGE_DATA),
      row.getString( COLUMN_CONTENT_TYPE));
}

代码示例来源:origin: prestodb/presto

public static NullableValue getColumnValueForPartitionKey(Row row, int i, CassandraType cassandraType, List<CassandraType> typeArguments)
{
  Type nativeType = cassandraType.getNativeType();
  if (row.isNull(i)) {
    return NullableValue.asNull(nativeType);
  }
  switch (cassandraType) {
    case ASCII:
    case TEXT:
    case VARCHAR:
      return NullableValue.of(nativeType, utf8Slice(row.getString(i)));
    case UUID:
    case TIMEUUID:
      return NullableValue.of(nativeType, utf8Slice(row.getUUID(i).toString()));
    default:
      return getColumnValue(row, i, cassandraType, typeArguments);
  }
}

代码示例来源:origin: kairosdb/kairosdb

@Override
public Iterable<String> listServiceKeys(String service)
    throws DatastoreException
{
  List<String> ret = new ArrayList<>();
  if (m_metaCluster.psServiceIndexListServiceKeys == null)
  {
    throw new DatastoreException("List Service Keys is not available on this version of Cassandra.");
  }
  BoundStatement statement = new BoundStatement(m_metaCluster.psServiceIndexListServiceKeys);
  statement.setString(0, service);
  statement.setConsistencyLevel(m_metaCluster.getReadConsistencyLevel());
  ResultSet resultSet = m_metaCluster.execute(statement);
  while (!resultSet.isExhausted())
  {
    ret.add(resultSet.one().getString(0));
  }
  return ret;
}

代码示例来源:origin: kairosdb/kairosdb

@Override
public Iterable<String> listKeys(String service, String serviceKey) throws DatastoreException
{
  List<String> ret = new ArrayList<>();
  BoundStatement statement = new BoundStatement(m_metaCluster.psServiceIndexListKeys);
  statement.setString(0, service);
  statement.setString(1, serviceKey);
  statement.setConsistencyLevel(m_metaCluster.getReadConsistencyLevel());
  ResultSet resultSet = m_metaCluster.execute(statement);
  while (!resultSet.isExhausted())
  {
    String key = resultSet.one().getString(0);
    if (key != null) {  // The last row for the primary key doesn't get deleted and has a null key and isExhausted still return false. So check for null
      ret.add(key);
    }
  }
  return ret;
}

代码示例来源:origin: kairosdb/kairosdb

@Override
public ServiceKeyValue getValue(String service, String serviceKey, String key) throws DatastoreException
{
  BoundStatement statement = new BoundStatement(m_metaCluster.psServiceIndexGet);
  statement.setString(0, service);
  statement.setString(1, serviceKey);
  statement.setString(2, key);
  statement.setConsistencyLevel(m_metaCluster.getReadConsistencyLevel());
  ResultSet resultSet = m_metaCluster.execute(statement);
  Row row = resultSet.one();
  if (row != null)
    return new ServiceKeyValue(row.getString(0), new Date(row.getTime(1)));
  return null;
}

代码示例来源:origin: kaaproject/kaa

@Override
public CassandraEndpointProfile findEndpointIdByKeyHash(byte[] endpointKeyHash) {
 LOG.debug("Try to check if endpoint profile exists with key hash [{}]", Utils.encodeHexString(endpointKeyHash));
 CassandraEndpointProfile profile = null;
 ResultSet resultSet = execute(select(EP_ENDPOINT_ID_PROPERTY).from(getColumnFamilyName())
   .where(eq(EP_EP_KEY_HASH_PROPERTY, getByteBuffer(endpointKeyHash))));
 Row row = resultSet.one();
 if (row != null) {
  profile = new CassandraEndpointProfile();
  profile.setId(row.getString(EP_ENDPOINT_ID_PROPERTY));
 }
 LOG.debug("{} endpoint profile exists with key hash [{}]", Utils.encodeHexString(endpointKeyHash), profile);
 return profile;
}

代码示例来源:origin: testcontainers/testcontainers-java

private void testInitScript(CassandraContainer cassandraContainer) {
  ResultSet resultSet = performQuery(cassandraContainer, "SELECT * FROM keySpaceTest.catalog_category");
  assertTrue("Query was not applied", resultSet.wasApplied());
  Row row = resultSet.one();
  assertEquals("Inserted row is not in expected state", 1, row.getLong(0));
  assertEquals("Inserted row is not in expected state", "test_category", row.getString(1));
}

代码示例来源:origin: testcontainers/testcontainers-java

@Test
public void testSimple() {
  try (CassandraContainer cassandraContainer = new CassandraContainer<>()) {
    cassandraContainer.start();
    ResultSet resultSet = performQuery(cassandraContainer, "SELECT release_version FROM system.local");
    assertTrue("Query was not applied", resultSet.wasApplied());
    assertNotNull("Result set has no release_version", resultSet.one().getString(0));
  }
}

代码示例来源:origin: testcontainers/testcontainers-java

@Test
public void testSpecificVersion() {
  String cassandraVersion = "3.0.15";
  try (CassandraContainer cassandraContainer = new CassandraContainer<>("cassandra:" + cassandraVersion)) {
    cassandraContainer.start();
    ResultSet resultSet = performQuery(cassandraContainer, "SELECT release_version FROM system.local");
    assertTrue("Query was not applied", resultSet.wasApplied());
    assertEquals("Cassandra has wrong version", cassandraVersion, resultSet.one().getString(0));
  }
}

代码示例来源:origin: testcontainers/testcontainers-java

@Test
public void testConfigurationOverride() {
  try (
    CassandraContainer cassandraContainer = new CassandraContainer<>()
      .withConfigurationOverride("cassandra-test-configuration-example")
  ) {
    cassandraContainer.start();
    ResultSet resultSet = performQuery(cassandraContainer, "SELECT cluster_name FROM system.local");
    assertTrue("Query was not applied", resultSet.wasApplied());
    assertEquals("Cassandra configuration is not overridden", TEST_CLUSTER_NAME_IN_CONF, resultSet.one().getString(0));
  }
}

代码示例来源:origin: testcontainers/testcontainers-java

@Test
public void testCassandraGetCluster() {
  try (CassandraContainer cassandraContainer = new CassandraContainer<>()) {
    cassandraContainer.start();
    ResultSet resultSet = performQuery(cassandraContainer.getCluster(), "SELECT release_version FROM system.local");
    assertTrue("Query was not applied", resultSet.wasApplied());
    assertNotNull("Result set has no release_version", resultSet.one().getString(0));
  }
}

相关文章