Java Code Examples for com.datastax.driver.core.BoundStatement#set()

The following examples show how to use com.datastax.driver.core.BoundStatement#set() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: geowave   File: RowRead.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source Project: geowave   File: BatchedRangeRead.java    License: Apache License 2.0 5 votes vote down vote up
public CloseableIterator<T> results() {
  final List<BoundStatement> statements = new ArrayList<>();
  for (final SinglePartitionQueryRanges r : ranges) {
    final byte[] partitionKey = CassandraUtils.getCassandraSafePartitionKey(r.getPartitionKey());
    for (final ByteArrayRange range : r.getSortKeyRanges()) {
      final BoundStatement boundRead = new BoundStatement(preparedRead);
      final byte[] start = range.getStart() != null ? range.getStart() : new byte[0];
      final byte[] end =
          range.getEnd() != null ? range.getEndAsNextPrefix()
              : new byte[] {
                  (byte) 0xFF,
                  (byte) 0xFF,
                  (byte) 0xFF,
                  (byte) 0xFF,
                  (byte) 0xFF,
                  (byte) 0xFF,
                  (byte) 0xFF};
      boundRead.set(
          CassandraField.GW_SORT_KEY.getLowerBoundBindMarkerName(),
          ByteBuffer.wrap(start),
          ByteBuffer.class);

      boundRead.set(
          CassandraField.GW_SORT_KEY.getUpperBoundBindMarkerName(),
          ByteBuffer.wrap(end),
          ByteBuffer.class);
      boundRead.set(
          CassandraField.GW_PARTITION_ID_KEY.getBindMarkerName(),
          ByteBuffer.wrap(partitionKey),
          ByteBuffer.class);

      boundRead.set(
          CassandraField.GW_ADAPTER_ID_KEY.getBindMarkerName(),
          Arrays.asList(ArrayUtils.toObject(adapterIds)),
          TypeCodec.list(TypeCodec.smallInt()));
      statements.add(boundRead);
    }
  }
  return executeQueryAsync(statements.toArray(new BoundStatement[] {}));
}