// We don't let the user change the fetchSize globally if the proto v1 is used, so we just need to
// check for the case of a per-statement override
if (fetchSize <= 0)
fetchSize = -1;
else if (fetchSize != Integer.MAX_VALUE)
throw new UnsupportedFeatureException(protoVersion, "Paging is not supported");
} else if (fetchSize <= 0) {
fetchSize = configuration().getQueryOptions().getFetchSize();
}
if (fetchSize == Integer.MAX_VALUE)
fetchSize = -1;
if (statement instanceof RegularStatement) {
RegularStatement rs = (RegularStatement)statement;
// It saddens me that we special case for the query builder here, but for now this is simpler.
// We could provide a general API in RegularStatement instead at some point but it's unclear what's
// the cleanest way to do that is right now (and it's probably not really that useful anyway).
if (protoVersion == ProtocolVersion.V1 && rs instanceof com.datastax.driver.core.querybuilder.BuiltStatement)
((com.datastax.driver.core.querybuilder.BuiltStatement)rs).setForceNoValues(true);
ByteBuffer[] rawValues = rs.getValues(protoVersion);
if (protoVersion == ProtocolVersion.V1 && rawValues != null)
throw new UnsupportedFeatureException(protoVersion, "Binary values are not supported");
List<ByteBuffer> values = rawValues == null ? Collections.<ByteBuffer>emptyList() : Arrays.asList(rawValues);
String qString = rs.getQueryString();
Requests.QueryProtocolOptions options = new Requests.QueryProtocolOptions(cl, values, false,
fetchSize, pagingState, scl, defaultTimestamp);
return new Requests.Query(qString, options);
} else if (statement instanceof BoundStatement) {
BoundStatement bs = (BoundStatement)statement;
bs.ensureAllSet();
boolean skipMetadata = protoVersion != ProtocolVersion.V1 && bs.statement.getPreparedId().resultSetMetadata != null;
Requests.QueryProtocolOptions options = new Requests.QueryProtocolOptions(cl, Arrays.asList(bs.wrapper.values), skipMetadata,
fetchSize, pagingState, scl, defaultTimestamp);
return new Requests.Execute(bs.statement.getPreparedId().id, options);
} else {
assert statement instanceof BatchStatement : statement;
assert pagingState == null;
if (protoVersion == ProtocolVersion.V1)
throw new UnsupportedFeatureException(protoVersion, "Protocol level batching is not supported");
BatchStatement bs = (BatchStatement)statement;
bs.ensureAllSet();
BatchStatement.IdAndValues idAndVals = bs.getIdAndValues(protoVersion);
Requests.BatchProtocolOptions options = new Requests.BatchProtocolOptions(cl, scl, defaultTimestamp);