/** * 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); }
@Override public Token getToken(String name) { return row.getToken(name); }
@Override public Token getToken(String name) { return row.getToken(name); }
@Override public Token getToken(int i) { return row.getToken(i); }
@Override public Token getToken(int i) { return row.getToken(i); }
@Override public Token getToken(String name) { return row.getToken(name); }
@Override public Token getToken(int i) { return _oldRow.getToken(i); }
@Override public Token getToken(int i) { return row.getToken(i); }
@Override public Token getToken(int i) { return _oldRow.getToken(i); }
@Override public Token getToken(String name) { return _oldRow.getToken(name); }
@Override public Token getToken(String name) { return _oldRow.getToken(name); }
@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); }
/** * 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); }
Token token = row.getToken(0); assertThat(token.getType()).isEqualTo(expectedTokenType);
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(); }
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(); }
/** * 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); }
@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); }
/** * 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); }
Token token = row.getToken(0); assertThat(token.getType()).isEqualTo(expectedTokenType);