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.
|
ByteBuffer |
getRoutingKey()
Returns the routing key for the query.
|
ByteBuffer[] |
getValues()
The values to use for this statement.
|
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()
Returns the number of values provided for this statement.
|
toString
disableTracing, enableTracing, getConsistencyLevel, getFetchSize, getRetryPolicy, getSerialConsistencyLevel, isIdempotent, isTracing, setConsistencyLevel, 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:
Note that the type of the 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()
getQueryString
in class RegularStatement
public ByteBuffer[] getValues()
RegularStatement
Note: Values for a RegularStatement (i.e. if this method does not return
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(int)
or you use
Cassandra 1.2).
getValues
in class RegularStatement
null
if there is
no such values.SimpleStatement(String, Object...)
public int valuesCount()
This is more efficient than calling getValues()
and getting the length
of the returned array, because getValues()
does some internal conversions.
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()
Unless the routing key has been explicitly set through
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)
This method allows you to manually provide a routing key for this query. It is thus optional since the routing key is only an hint for token aware load balancing policy but is never mandatory.
If the partition key for the query is composite, use the
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()
Unless the keyspace has been explicitly set through 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)
This method allows you to manually provide a keyspace for this query. It is thus optional since the value returned by this method is only an hint for token aware load balancing policy but is never mandatory.
Do note that if the query does not use a fully qualified keyspace, then you do not need to set the keyspace through that method as the currently logged in keyspace will be used.
keyspace
- the name of the keyspace this query operates on.SimpleStatement
object.Statement.getKeyspace()
public SimpleStatement setRoutingKey(ByteBuffer... routingKeyComponents)
See 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()
Copyright © 2012–2015. All rights reserved.