public class SimpleStatement extends RegularStatement
RegularStatement
implementation built directly from a query
string.idempotent
Constructor and Description |
---|
SimpleStatement(String query)
Creates a new
SimpleStatement with the provided query string (and no values). |
SimpleStatement(String query,
Object... values)
Creates a new
SimpleStatement with the provided query string and values. |
Modifier and Type | Method and Description |
---|---|
String |
getKeyspace()
Returns the keyspace this query operates on.
|
Object |
getObject(int i)
Returns the
i th value as the Java type matching its CQL type. |
String |
getQueryString()
Returns the query string for this statement.
|
ByteBuffer |
getRoutingKey()
Returns the routing key for the query.
|
ByteBuffer[] |
getValues(ProtocolVersion protocolVersion)
The values to use for this statement.
|
boolean |
hasValues()
Whether or not this statement has values, that is if
getValues
will return null or not. |
SimpleStatement |
setKeyspace(String keyspace)
Sets the keyspace this query operates on.
|
SimpleStatement |
setRoutingKey(ByteBuffer... routingKeyComponents)
Sets the routing key for this query.
|
SimpleStatement |
setRoutingKey(ByteBuffer routingKey)
Sets the routing key for this query.
|
int |
valuesCount()
The number of values for this statement, that is the size of the array
that will be returned by
getValues . |
getValues, getValues, toString
disableTracing, enableTracing, getConsistencyLevel, getDefaultTimestamp, getFetchSize, getRetryPolicy, getSerialConsistencyLevel, isIdempotent, isTracing, setConsistencyLevel, setDefaultTimestamp, setFetchSize, setIdempotent, setPagingState, setPagingStateUnsafe, setRetryPolicy, setSerialConsistencyLevel
public SimpleStatement(String query)
SimpleStatement
with the provided query string (and no values).query
- the query string.public SimpleStatement(String query, Object... values)
SimpleStatement
with the provided query string and values.
This version of SimpleStatement is useful when you do not want to execute a
query only once (and thus do not want to resort to prepared statement), but
do not want to convert all column values to string (typically, if you have blob
values, encoding them to a hexadecimal string is not very efficient). In
that case, you can provide a query string with bind marker to this constructor
along with the values for those bind variables. When executed, the server will
prepare the provided, bind the provided values to that prepare statement and
execute the resulting statement. Thus,
session.execute(new SimpleStatement(query, value1, value2, value3));is functionally equivalent to
PreparedStatement ps = session.prepare(query); session.execute(ps.bind(value1, value2, value3));except that the former version:
values
provided to this method will
not be validated by the driver as is done by BoundStatement.bind(java.lang.Object...)
since
query
is not parsed (and hence the driver cannot know what those value
should be). If too much or too little values are provided or if a value is not
a valid one for the variable it is bound to, an
InvalidQueryException
will be thrown
by Cassandra at execution time. An IllegalArgumentException
may be
thrown by this constructor however if one of the value does not correspond to
any CQL3 type (for instance, if it is a custom class).query
- the query string.values
- values required for the execution of query
.IllegalArgumentException
- if the number of values is greater than 65535.public String getQueryString()
RegularStatement
Statement
objects.
For example, Statement
objects carry numerous protocol-level
settings, such as the consistency level
to use,
or the idempotence flag
, among others.
None of these settings will be included in the resulting query string.
Similarly, if values have been set on this statement because
it has bind markers, these values will not appear in the resulting query string.
Note: the consistency level was conveyed at CQL level in older versions
of the CQL grammar, but since CASSANDRA-4734
it is now a protocol-level setting and consequently does not appear in the query string.getQueryString
in class RegularStatement
public ByteBuffer[] getValues(ProtocolVersion protocolVersion)
RegularStatement
null
) are not supported with the native protocol version 1: you
will get an UnsupportedProtocolVersionException
when submitting
one if version 1 of the protocol is in use (i.e. if you've force version
1 through Cluster.Builder.withProtocolVersion(com.datastax.driver.core.ProtocolVersion)
or you use
Cassandra 1.2).getValues
in class RegularStatement
protocolVersion
- the protocol version in which the returned values
must be serialized for.null
if there is
no such values.SimpleStatement(String, Object...)
public int valuesCount()
getValues
.public boolean hasValues()
RegularStatement
getValues
will return null
or not.hasValues
in class RegularStatement
false
if RegularStatement.getValues(com.datastax.driver.core.ProtocolVersion)
returns null
, true
otherwise.public Object getObject(int i)
i
th value as the Java type matching its CQL type.i
- the index to retrieve.i
th value of this statement.IllegalStateException
- if this statement does not have values.IndexOutOfBoundsException
- if i
is not a valid index for this object.public ByteBuffer getRoutingKey()
setRoutingKey(java.nio.ByteBuffer)
, this method will return null
to
avoid having to parse the query string to retrieve the partition key.getRoutingKey
in class Statement
setRoutingKey(java.nio.ByteBuffer)
if such a key
was set, null
otherwise.Statement.getRoutingKey()
public SimpleStatement setRoutingKey(ByteBuffer routingKey)
setRoutingKey(ByteBuffer...)
method instead to build the
routing key.routingKey
- the raw (binary) value to use as routing key.SimpleStatement
object.Statement.getRoutingKey()
public String getKeyspace()
setKeyspace(java.lang.String)
,
this method will return null
to avoid having to parse the query
string.getKeyspace
in class Statement
setKeyspace(java.lang.String)
if such keyspace was
set, null
otherwise.Statement.getKeyspace()
public SimpleStatement setKeyspace(String keyspace)
keyspace
- the name of the keyspace this query operates on.SimpleStatement
object.Statement.getKeyspace()
public SimpleStatement setRoutingKey(ByteBuffer... routingKeyComponents)
setRoutingKey(ByteBuffer)
for more information. This
method is a variant for when the query partition key is composite and
thus the routing key must be built from multiple values.routingKeyComponents
- the raw (binary) values to compose to obtain
the routing key.SimpleStatement
object.Statement.getRoutingKey()