/** * {@inheritDoc} */ @Override public BoundStatement apply(PreparedStatement statement, List<Column> columns) { Object[] values = Column.getVals(columns); BoundStatement boundStatement = statement.bind(); for (Column col : columns) { // For native protocol V3 or below, all variables must be bound. // With native protocol V4 or above, variables can be left unset, // in which case they will be ignored server side (no tombstones will be generated). if (col.isNull()) { boundStatement.setToNull(col.getColumnName()); } else { boundStatement.set(col.getColumnName(), col.getVal(), CodecRegistry.DEFAULT_INSTANCE.codecFor(col.getVal())); } } return statement.bind(values); } }
@Test(groups = "short") public void should_use_default_codecs_with_prepared_statements_3() { session() .execute( session() .prepare(insertQuery) .bind() .set(0, n_int, Integer.class) .set(1, n_bigint, Long.class) .set(2, n_float, Float.class) .set(3, n_double, Double.class) .set(4, n_varint, BigInteger.class) .set(5, n_decimal, BigDecimal.class)); PreparedStatement ps = session().prepare(selectQuery); ResultSet rows = session().execute(ps.bind().setInt(0, n_int).setLong(1, n_bigint)); Row row = rows.one(); assertRow(row); }
@Test(groups = "short") public void should_work_with_prepared_statements_3() { session().execute(session().prepare(insertQuery).bind().setInt(0, pk).set(1, v, listType)); PreparedStatement ps = session().prepare(selectQuery); ResultSet rows = session().execute(ps.bind().setInt(0, pk)); Row row = rows.one(); assertRow(row); }
@Test(groups = "short") public void should_use_custom_codecs_with_prepared_statements_2() { session() .execute( session() .prepare(insertQuery) .bind() .set(0, new NumberBox<Integer>(n_int), NUMBERBOX_OF_INTEGER_TOKEN) .set(1, new NumberBox<Long>(n_bigint), NUMBERBOX_OF_LONG_TOKEN) .set(2, new NumberBox<Float>(n_float), NUMBERBOX_OF_FLOAT_TOKEN) .set(3, new NumberBox<Double>(n_double), NUMBERBOX_OF_DOUBLE_TOKEN) .set(4, new NumberBox<BigInteger>(n_varint), NUMBERBOX_OF_BIGINTEGER_TOKEN) .set(5, new NumberBox<BigDecimal>(n_decimal), NUMBERBOX_OF_BIGDECIMAL_TOKEN)); PreparedStatement ps = session().prepare(selectQuery); ResultSet rows = session() .execute( ps.bind() .set(0, new NumberBox<Integer>(n_int), NUMBERBOX_OF_INTEGER_TOKEN) .set(1, new NumberBox<Long>(n_bigint), NUMBERBOX_OF_LONG_TOKEN)); Row row = rows.one(); assertRow(row); }
@Test(groups = "short") public void should_use_collection_codecs_with_prepared_statements_3() { session() .execute( session() .prepare(insertQuery) .bind() .setInt(0, n_int) .set(1, l_int, TypeTokens.listOf(Integer.class)) .set(2, l_bigint, TypeTokens.listOf(Long.class)) .set(3, s_float, TypeTokens.setOf(Float.class)) .set(4, s_double, TypeTokens.setOf(Double.class)) .set(5, m_varint, TypeTokens.mapOf(Integer.class, BigInteger.class)) .set(6, m_decimal, TypeTokens.mapOf(Integer.class, BigDecimal.class))); PreparedStatement ps = session().prepare(selectQuery); ResultSet rows = session().execute(ps.bind().setInt(0, n_int)); Row row = rows.one(); assertRow(row); }
@Test(groups = "short") public void should_use_default_codecs_with_prepared_statements_3() { session() .execute( session() .prepare(insertQuery) .bind() .set(0, n_int, Integer.class) .set(1, n_bigint, Long.class) .set(2, n_float, Float.class) .set(3, n_double, Double.class) .set(4, n_varint, BigInteger.class) .set(5, n_decimal, BigDecimal.class)); PreparedStatement ps = session().prepare(selectQuery); ResultSet rows = session().execute(ps.bind().setInt(0, n_int).setLong(1, n_bigint)); Row row = rows.one(); assertRow(row); }
/** * {@inheritDoc} */ @Override public BoundStatement apply(PreparedStatement statement, List<Column> columns) { Object[] values = Column.getVals(columns); BoundStatement boundStatement = statement.bind(); for(Column col : columns) { // For native protocol V3 or below, all variables must be bound. // With native protocol V4 or above, variables can be left unset, // in which case they will be ignored server side (no tombstones will be generated). if(col.isNull()) { boundStatement.setToNull(col.getColumnName()); } else { boundStatement.set(col.getColumnName(), col.getVal(), CodecRegistry.DEFAULT_INSTANCE.codecFor(col.getVal())); } } return statement.bind(values); } }
@Test(groups = "short") public void should_use_custom_codecs_with_built_statements_2() { session() .execute( session() .prepare(insertStmt) .bind() .set(0, new NumberBox<Integer>(n_int), NUMBERBOX_OF_INTEGER_TOKEN) .set(1, new NumberBox<Long>(n_bigint), NUMBERBOX_OF_LONG_TOKEN) .set(2, new NumberBox<Float>(n_float), NUMBERBOX_OF_FLOAT_TOKEN) .set(3, new NumberBox<Double>(n_double), NUMBERBOX_OF_DOUBLE_TOKEN) .set(4, new NumberBox<BigInteger>(n_varint), NUMBERBOX_OF_BIGINTEGER_TOKEN) .set(5, new NumberBox<BigDecimal>(n_decimal), NUMBERBOX_OF_BIGDECIMAL_TOKEN)); PreparedStatement ps = session().prepare(selectStmt); ResultSet rows = session() .execute( ps.bind() .set(0, new NumberBox<Integer>(n_int), NUMBERBOX_OF_INTEGER_TOKEN) .set(1, new NumberBox<Long>(n_bigint), NUMBERBOX_OF_LONG_TOKEN)); Row row = rows.one(); assertRow(row); }
@Test(groups = "short") public void should_use_collection_codecs_with_built_statements() { session() .execute( session() .prepare(insertStmt) .bind() .setInt(0, n_int) .set(1, l_int, TypeTokens.listOf(Integer.class)) .set(2, l_bigint, TypeTokens.listOf(Long.class)) .set(3, s_float, TypeTokens.setOf(Float.class)) .set(4, s_double, TypeTokens.setOf(Double.class)) .set(5, m_varint, TypeTokens.mapOf(Integer.class, BigInteger.class)) .set(6, m_decimal, TypeTokens.mapOf(Integer.class, BigDecimal.class))); PreparedStatement ps = session().prepare(selectStmt); ResultSet rows = session().execute(ps.bind().setInt(0, n_int)); Row row = rows.one(); assertRow(row); }
void setValue(BoundStatement boundStatement, Object arg) { if (paramName == null) { if (codec == null) boundStatement.set(paramIdx, arg, paramType); else boundStatement.set(paramIdx, arg, codec); } else { if (codec == null) boundStatement.set(paramName, arg, paramType); else boundStatement.set(paramName, arg, codec); } } }
@Test(groups = "short") public void should_work_with_built_statements() { session().execute(session().prepare(insertStmt).bind().setInt(0, pk).set(1, v, listType)); PreparedStatement ps = session().prepare(selectStmt); ResultSet rows = session().execute(ps.bind().setInt(0, pk)); Row row = rows.one(); assertRow(row); }
@Test(groups = "short") public void should_use_collection_codecs_with_built_statements() { session() .execute( session() .prepare(insertStmt) .bind() .setInt(0, n_int) .set(1, l_int, TypeTokens.listOf(Integer.class)) .set(2, l_bigint, TypeTokens.listOf(Long.class)) .set(3, s_float, TypeTokens.setOf(Float.class)) .set(4, s_double, TypeTokens.setOf(Double.class)) .set(5, m_varint, TypeTokens.mapOf(Integer.class, BigInteger.class)) .set(6, m_decimal, TypeTokens.mapOf(Integer.class, BigDecimal.class))); PreparedStatement ps = session().prepare(selectStmt); ResultSet rows = session().execute(ps.bind().setInt(0, n_int)); Row row = rows.one(); assertRow(row); }
public CassandraRow result() { if ((partitionKey != null) && (sortKey != null)) { final BoundStatement boundRead = new BoundStatement(preparedRead); boundRead.set( CassandraField.GW_SORT_KEY.getBindMarkerName(), ByteBuffer.wrap(sortKey), ByteBuffer.class); boundRead.set( CassandraField.GW_ADAPTER_ID_KEY.getBindMarkerName(), internalAdapterId, TypeCodec.smallInt()); boundRead.set( CassandraField.GW_PARTITION_ID_KEY.getBindMarkerName(), ByteBuffer.wrap(partitionKey), ByteBuffer.class); try (CloseableIterator<CassandraRow> it = operations.executeQuery(boundRead)) { if (it.hasNext()) { // there should only be one entry with this index return it.next(); } } } return null; } }
@Test(groups = "short") public void should_work_with_prepared_statements_3() { session().execute(session().prepare(insertQuery).bind().setInt(0, pk).set(1, v, listType)); PreparedStatement ps = session().prepare(selectQuery); ResultSet rows = session().execute(ps.bind().setInt(0, pk)); Row row = rows.one(); assertRow(row); }
nanoBuffer.putLong(0, Long.MAX_VALUE - System.nanoTime()); retVal[i] = new BoundStatement(insertionStatement); retVal[i].set( CassandraField.GW_PARTITION_ID_KEY.getBindMarkerName(), ByteBuffer.wrap(partitionKey), ByteBuffer.class); retVal[i].set( CassandraField.GW_ADAPTER_ID_KEY.getBindMarkerName(), row.getAdapterId(), Short.class); retVal[i].set( CassandraField.GW_VALUE_KEY.getBindMarkerName(), ByteBuffer.wrap(DataIndexUtils.serializeDataIndexValue(value, visibilityEnabled)),
@Test(groups = "short") public void should_use_collection_codecs_with_prepared_statements_3() { session() .execute( session() .prepare(insertQuery) .bind() .setInt(0, n_int) .set(1, l_int, TypeTokens.listOf(Integer.class)) .set(2, l_bigint, TypeTokens.listOf(Long.class)) .set(3, s_float, TypeTokens.setOf(Float.class)) .set(4, s_double, TypeTokens.setOf(Double.class)) .set(5, m_varint, TypeTokens.mapOf(Integer.class, BigInteger.class)) .set(6, m_decimal, TypeTokens.mapOf(Integer.class, BigDecimal.class))); PreparedStatement ps = session().prepare(selectQuery); ResultSet rows = session().execute(ps.bind().setInt(0, n_int)); Row row = rows.one(); assertRow(row); }
@Test(groups = "short") public void should_use_custom_codecs_with_prepared_statements_2() { session() .execute( session() .prepare(insertQuery) .bind() .set(0, new NumberBox<Integer>(n_int), NUMBERBOX_OF_INTEGER_TOKEN) .set(1, new NumberBox<Long>(n_bigint), NUMBERBOX_OF_LONG_TOKEN) .set(2, new NumberBox<Float>(n_float), NUMBERBOX_OF_FLOAT_TOKEN) .set(3, new NumberBox<Double>(n_double), NUMBERBOX_OF_DOUBLE_TOKEN) .set(4, new NumberBox<BigInteger>(n_varint), NUMBERBOX_OF_BIGINTEGER_TOKEN) .set(5, new NumberBox<BigDecimal>(n_decimal), NUMBERBOX_OF_BIGDECIMAL_TOKEN)); PreparedStatement ps = session().prepare(selectQuery); ResultSet rows = session() .execute( ps.bind() .set(0, new NumberBox<Integer>(n_int), NUMBERBOX_OF_INTEGER_TOKEN) .set(1, new NumberBox<Long>(n_bigint), NUMBERBOX_OF_LONG_TOKEN)); Row row = rows.one(); assertRow(row); }
@Test(groups = "short") public void should_work_with_built_statements() { session().execute(session().prepare(insertStmt).bind().setInt(0, pk).set(1, v, listType)); PreparedStatement ps = session().prepare(selectStmt); ResultSet rows = session().execute(ps.bind().setInt(0, pk)); Row row = rows.one(); assertRow(row); }
@Test(groups = "short") public void should_use_custom_codecs_with_built_statements_2() { session() .execute( session() .prepare(insertStmt) .bind() .set(0, new NumberBox<Integer>(n_int), NUMBERBOX_OF_INTEGER_TOKEN) .set(1, new NumberBox<Long>(n_bigint), NUMBERBOX_OF_LONG_TOKEN) .set(2, new NumberBox<Float>(n_float), NUMBERBOX_OF_FLOAT_TOKEN) .set(3, new NumberBox<Double>(n_double), NUMBERBOX_OF_DOUBLE_TOKEN) .set(4, new NumberBox<BigInteger>(n_varint), NUMBERBOX_OF_BIGINTEGER_TOKEN) .set(5, new NumberBox<BigDecimal>(n_decimal), NUMBERBOX_OF_BIGDECIMAL_TOKEN)); PreparedStatement ps = session().prepare(selectStmt); ResultSet rows = session() .execute( ps.bind() .set(0, new NumberBox<Integer>(n_int), NUMBERBOX_OF_INTEGER_TOKEN) .set(1, new NumberBox<Long>(n_bigint), NUMBERBOX_OF_LONG_TOKEN)); Row row = rows.one(); assertRow(row); }