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

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

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

Row.getToken介绍

[英]Returns the ith value of this row as a Token.

#getPartitionKeyToken() should generally be preferred to this method (unless the token column is aliased).
[中]返回此行的第i个值作为标记。
#getPartitionKeyToken()通常应优先于此方法(除非标记列有别名)。

代码示例

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
 * Ensures that an exception is raised when attempting to retrieve a token a non-token column.
 *
 * @test_category token
 * @expected_result an exception is raised.
 * @jira_ticket JAVA-312
 * @since 2.0.10, 2.1.5
 */
@Test(groups = "short", expectedExceptions = InvalidTypeException.class)
public void should_raise_exception_when_get_token_on_non_token() {
 Row row = session().execute("SELECT i FROM foo WHERE i = 1").one();
 row.getToken(0);
}

代码示例来源:origin: jsevellec/cassandra-unit

@Override
public Token getToken(String name)
{
  return row.getToken(name);
}

代码示例来源:origin: com.strapdata.cassandra/cassandra-all

@Override
public Token getToken(String name)
{
  return row.getToken(name);
}

代码示例来源:origin: jsevellec/cassandra-unit

@Override
public Token getToken(int i)
{
  return row.getToken(i);
}

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

@Override
public Token getToken(int i)
{
  return row.getToken(i);
}

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

@Override
public Token getToken(String name)
{
  return row.getToken(name);
}

代码示例来源:origin: bazaarvoice/emodb

@Override
public Token getToken(int i) {
  return _oldRow.getToken(i);
}

代码示例来源:origin: com.strapdata.cassandra/cassandra-all

@Override
public Token getToken(int i)
{
  return row.getToken(i);
}

代码示例来源:origin: com.bazaarvoice.emodb/emodb-sor

@Override
public Token getToken(int i) {
  return _oldRow.getToken(i);
}

代码示例来源:origin: bazaarvoice/emodb

@Override
public Token getToken(String name) {
  return _oldRow.getToken(name);
}

代码示例来源:origin: com.bazaarvoice.emodb/emodb-sor

@Override
public Token getToken(String name) {
  return _oldRow.getToken(name);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_create_token_from_partition_key() {
 Metadata metadata = cluster().getMetadata();
 Row row = session().execute("SELECT token(i) FROM foo WHERE i = 1").one();
 Token expected = row.getToken(0);
 ProtocolVersion protocolVersion =
   cluster().getConfiguration().getProtocolOptions().getProtocolVersion();
 assertThat(metadata.newToken(TypeCodec.cint().serialize(1, protocolVersion)))
   .isEqualTo(expected);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

/**
 * Validates that a {@link Token} can be retrieved and parsed by using bind variables and
 * aliasing.
 *
 * <p>
 *
 * <p>This test does the following:
 *
 * <p>
 *
 * <ol>
 *   <li>Retrieve the token by alias for the key '1', and ensure it matches the token by index.
 *   <li>Select data by token using setToken by name.
 * </ol>
 */
@Test(groups = "short")
@CassandraVersion("2.0")
public void should_get_token_from_row_and_set_token_in_query_with_binding_and_aliasing() {
 Row row = session().execute("SELECT token(i) AS t FROM foo WHERE i = 1").one();
 Token token = row.getToken("t");
 assertThat(token.getType()).isEqualTo(expectedTokenType);
 PreparedStatement pst = session().prepare("SELECT * FROM foo WHERE token(i) = :myToken");
 row = session().execute(pst.bind().setToken("myToken", token)).one();
 assertThat(row.getInt(0)).isEqualTo(1);
 row = session().execute("SELECT * FROM foo WHERE token(i) = ?", token).one();
 assertThat(row.getInt(0)).isEqualTo(1);
}

代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core

Token token = row.getToken(0);
assertThat(token.getType()).isEqualTo(expectedTokenType);

代码示例来源:origin: com.teradata.tempto/tempto-core

public QueryResult executeQuery(String sql)
    throws QueryExecutionException
{
  ensureConnected();
  ResultSet rs = session.execute(sql);
  List<ColumnDefinitions.Definition> definitions = rs.getColumnDefinitions().asList();
  List<JDBCType> types = definitions.stream()
      .map(definition -> getJDBCType(definition.getType()))
      .collect(toList());
  List<String> columnNames = definitions.stream()
      .map(ColumnDefinitions.Definition::getName)
      .collect(toList());
  QueryResult.QueryResultBuilder resultBuilder = new QueryResult.QueryResultBuilder(types, columnNames);
  for (Row row : rs) {
    List<Object> builderRow = newArrayList();
    for (int i = 0; i < types.size(); ++i) {
      builderRow.add(row.getToken(i).getValue());
    }
    resultBuilder.addRow(builderRow);
  }
  return resultBuilder.build();
}

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

public QueryResult executeQuery(String sql)
    throws QueryExecutionException
{
  ensureConnected();
  ResultSet rs = session.execute(sql);
  List<ColumnDefinitions.Definition> definitions = rs.getColumnDefinitions().asList();
  List<JDBCType> types = definitions.stream()
      .map(definition -> getJDBCType(definition.getType()))
      .collect(toList());
  List<String> columnNames = definitions.stream()
      .map(ColumnDefinitions.Definition::getName)
      .collect(toList());
  QueryResult.QueryResultBuilder resultBuilder = new QueryResult.QueryResultBuilder(types, columnNames);
  for (Row row : rs) {
    List<Object> builderRow = newArrayList();
    for (int i = 0; i < types.size(); ++i) {
      builderRow.add(row.getToken(i).getValue());
    }
    resultBuilder.addRow(builderRow);
  }
  return resultBuilder.build();
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

/**
 * Ensures that an exception is raised when attempting to retrieve a token a non-token column.
 *
 * @test_category token
 * @expected_result an exception is raised.
 * @jira_ticket JAVA-312
 * @since 2.0.10, 2.1.5
 */
@Test(groups = "short", expectedExceptions = InvalidTypeException.class)
public void should_raise_exception_when_get_token_on_non_token() {
 Row row = session().execute("SELECT i FROM foo WHERE i = 1").one();
 row.getToken(0);
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

@Test(groups = "short")
public void should_create_token_from_partition_key() {
 Metadata metadata = cluster().getMetadata();
 Row row = session().execute("SELECT token(i) FROM foo WHERE i = 1").one();
 Token expected = row.getToken(0);
 ProtocolVersion protocolVersion =
   cluster().getConfiguration().getProtocolOptions().getProtocolVersion();
 assertThat(metadata.newToken(TypeCodec.cint().serialize(1, protocolVersion)))
   .isEqualTo(expected);
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

/**
 * Validates that a {@link Token} can be retrieved and parsed by using bind variables and
 * aliasing.
 *
 * <p>
 *
 * <p>This test does the following:
 *
 * <p>
 *
 * <ol>
 *   <li>Retrieve the token by alias for the key '1', and ensure it matches the token by index.
 *   <li>Select data by token using setToken by name.
 * </ol>
 */
@Test(groups = "short")
@CassandraVersion("2.0")
public void should_get_token_from_row_and_set_token_in_query_with_binding_and_aliasing() {
 Row row = session().execute("SELECT token(i) AS t FROM foo WHERE i = 1").one();
 Token token = row.getToken("t");
 assertThat(token.getType()).isEqualTo(expectedTokenType);
 PreparedStatement pst = session().prepare("SELECT * FROM foo WHERE token(i) = :myToken");
 row = session().execute(pst.bind().setToken("myToken", token)).one();
 assertThat(row.getInt(0)).isEqualTo(1);
 row = session().execute("SELECT * FROM foo WHERE token(i) = ?", token).one();
 assertThat(row.getInt(0)).isEqualTo(1);
}

代码示例来源:origin: com.datastax.dse/dse-java-driver-core

Token token = row.getToken(0);
assertThat(token.getType()).isEqualTo(expectedTokenType);

相关文章