statement.setBytes(paramIndex, (ByteBuffer) typeCodec.parse(paramValue));
@Override protected ResultSetFuture newFuture() { return factory.session.executeAsync( factory .preparedStatement .bind() .setLong("trace_id", input.trace_id()) .setBytesUnsafe("ts", factory.timestampCodec.serialize(input.ts())) .setString("span_name", input.span_name()) .setBytes("span", ByteBuffer.wrap(input.span()))); }
@Test(groups = "short") public void should_truncate_blob_parameter_when_max_length_exceeded_bound_statements() throws Exception { // given normal.setLevel(TRACE); queryLogger = QueryLogger.builder().withMaxParameterValueLength(6).build(); cluster().register(queryLogger); // when String query = "UPDATE test SET c_blob = ? WHERE pk = ?"; PreparedStatement ps = session().prepare(query); BoundStatement bs = ps.bind(); bs.setBytes("c_blob", ByteBuffer.wrap(Bytes.toArray(Lists.newArrayList(1, 2, 3)))); bs.setInt("pk", 42); session().execute(bs); // then String line = normalAppender.waitAndGet(10000); assertThat(line) .contains("Query completed normally") .contains(ipOfNode(1)) .contains("c_blob:0x0102" + TRUNCATED_OUTPUT) .doesNotContain("0x010203"); }
@Override protected ResultSetFuture newFuture() { ByteBuffer annotation = CassandraUtil.toByteBuffer(input.annotation()); Statement bound = factory .preparedStatement .bind() .setBytes("annotation", annotation) .setBytesUnsafe("start_ts", factory.timestampCodec.serialize(input.start_ts())) .setBytesUnsafe("end_ts", factory.timestampCodec.serialize(input.end_ts())) .setInt("limit_", input.limit_()) .setFetchSize(Integer.MAX_VALUE); // NOTE in the new driver, we also set this to limit return factory.session.executeAsync(bound); }
@Override public QueryBinder<ENTITY> setBytes(int i, ByteBuffer v) { for (BoundStatement statement : statements.values()) { statement.setBytes(i, v); } return this; }
random.nextBytes(b); ByteBuffer in = ByteBuffer.wrap(b); stmt.setBytes("col" + c, in);
@Override public BoundStatement bindPartitionKey(BoundStatement bound, String partitionKey) { try { return bound.setInt("bucket", RAND.nextInt(bucketCount)) .setBytes("annotation", toByteBuffer(partitionKey)); } catch (CharacterCodingException e) { throw new IllegalArgumentException(e); } }
@Override public BoundStatement bindPartitionKey(BoundStatement bound, String partitionKey) { return bound .setInt("bucket", RAND.nextInt(bucketCount)) .setBytes("annotation", toByteBuffer(partitionKey)); }
public void setBytes(int parameterIndex, byte[] bytes) throws SQLException { checkNotClosed(); checkIndex(parameterIndex); this.statement.setBytes(parameterIndex-1, ByteBuffer.wrap(bytes)); //bindValues.put(parameterIndex, bytes == null ? null : ByteBuffer.wrap(bytes)); }
@Override public QueryBinder<ENTITY> setBytes(String name, ByteBuffer v) { for (BoundStatement statement : statements.values()) { if (statement.preparedStatement().getVariables().contains(name)) { statement.setBytes(name, v); } } return this; }
public ListenableFuture<Void> storeDependencies(long epochDayMillis, ByteBuffer dependencies) { Date startFlooredToDay = new Date(epochDayMillis); try { BoundStatement bound = insertDependencies.bind() .setTimestamp("day", startFlooredToDay) .setBytes("dependencies", dependencies); if (LOG.isDebugEnabled()) { LOG.debug(debugInsertDependencies(startFlooredToDay, dependencies)); } return Futures.transform(session.executeAsync(bound), resultSetToVoidFunction); } catch (RuntimeException ex) { LOG.error("failed " + debugInsertDependencies(startFlooredToDay, dependencies), ex); return Futures.immediateFailedFuture(ex); } }
ListenableFuture<?> storeDependencies(long epochDayMillis, ByteBuffer dependencies) { Date startFlooredToDay = new Date(epochDayMillis); try { BoundStatement bound = CassandraUtil.bindWithName(insertDependencies, "insert-dependencies") .setTimestamp("day", startFlooredToDay) .setBytes("dependencies", dependencies); return session.executeAsync(bound); } catch (RuntimeException ex) { return Futures.immediateFailedFuture(ex); } } }
private Mono<Integer> writePart(ByteBuffer data, BlobId blobId, int position) { return cassandraAsyncExecutor.executeVoidReactor( insertPart.bind() .setString(BlobTable.ID, blobId.asString()) .setInt(BlobParts.CHUNK_NUMBER, position) .setBytes(BlobParts.DATA, data)) .then(Mono.just(position)); }
@Test public void visit_BlobValueAcceptCalled_ShouldCallSetString() { // Arrange BlobValue value = new BlobValue(ANY_NAME, ANY_STRING.getBytes()); ValueBinder binder = new ValueBinder(bound); // Act value.accept(binder); // Assert verify(bound) .setBytes( 0, (ByteBuffer) ByteBuffer.allocate(ANY_STRING.length()).put(ANY_STRING.getBytes()).flip()); }
private BoundStatement addColumnUpdate(PreparedStatement prepState, boolean valueIsBinary, String key, DColumn column) { BoundStatement boundState = prepState.bind(); boundState.setString(0, key); boundState.setString(1, column.getName()); if (valueIsBinary) { boundState.setBytes(2, ByteBuffer.wrap(column.getRawValue())); } else { boundState.setString(2, column.getValue()); } return boundState; } // addColumnUpdate
private BoundStatement addColumnUpdate(String tableName, String key, DColumn column, boolean isBinaryValue) { PreparedStatement prepState = m_dbservice.getPreparedUpdate(Update.INSERT_ROW, tableName); BoundStatement boundState = prepState.bind(); boundState.setString(0, key); boundState.setString(1, column.getName()); if (isBinaryValue) { boundState.setBytes(2, ByteBuffer.wrap(column.getRawValue())); } else { boundState.setString(2, column.getValue()); } return boundState; }
public CompletableFuture<Void> storeAttachment(Attachment attachment) throws IOException { return cassandraAsyncExecutor.executeVoid( insertStatement.bind() .setString(ID, attachment.getAttachmentId().getId()) .setLong(SIZE, attachment.getSize()) .setString(TYPE, attachment.getType()) .setBytes(PAYLOAD, ByteBuffer.wrap(attachment.getBytes()))); }
@Override public EntryList getSlice(final KeySliceQuery query, final StoreTransaction txh) throws BackendException { final Future<EntryList> result = Future.fromJavaFuture( this.executorService, this.session.executeAsync(this.getSlice.bind() .setBytes(KEY_BINDING, query.getKey().asByteBuffer()) .setBytes(SLICE_START_BINDING, query.getSliceStart().asByteBuffer()) .setBytes(SLICE_END_BINDING, query.getSliceEnd().asByteBuffer()) .setInt(LIMIT_BINDING, query.getLimit()) .setConsistencyLevel(getTransaction(txh).getReadConsistencyLevel()))) .map(resultSet -> fromResultSet(resultSet, this.getter)); interruptibleWait(result); return result.getValue().get().getOrElseThrow(EXCEPTION_MAPPER); }
@Override public KeyIterator getKeys(final SliceQuery query, final StoreTransaction txh) throws BackendException { if (this.storeManager.getFeatures().hasOrderedScan()) { throw new PermanentBackendException("This operation is only allowed when a random partitioner (md5 or murmur3) is used."); } return Try.of(() -> new CQLResultSetKeyIterator( query, this.getter, this.session.execute(this.getKeysAll.bind() .setBytes(SLICE_START_BINDING, query.getSliceStart().asByteBuffer()) .setBytes(SLICE_END_BINDING, query.getSliceEnd().asByteBuffer()) .setFetchSize(this.storeManager.getPageSize()) .setConsistencyLevel(getTransaction(txh).getReadConsistencyLevel())))) .getOrElseThrow(EXCEPTION_MAPPER); } }