public abstract class RegularStatement extends Statement
This class represents a query string along with query options (and optionally binary values,
see getValues
). It can be extended but SimpleStatement
is provided as a simple
implementation to build a RegularStatement
directly from its query string.
idempotent, NULL_PAYLOAD_VALUE
Modifier | Constructor and Description |
---|---|
protected |
RegularStatement()
Creates a new RegularStatement.
|
Modifier and Type | Method and Description |
---|---|
String |
getKeyspace()
Returns the keyspace this query operates on.
|
abstract Map<String,ByteBuffer> |
getNamedValues(ProtocolVersion protocolVersion,
CodecRegistry codecRegistry)
The named values to use for this statement.
|
String |
getQueryString()
Returns the query string for this statement.
|
abstract String |
getQueryString(CodecRegistry codecRegistry)
Returns the query string for this statement.
|
Token |
getRoutingToken()
Returns the routing token to use for token aware routing of this query.
|
abstract ByteBuffer[] |
getValues(ProtocolVersion protocolVersion,
CodecRegistry codecRegistry)
The positional values to use for this statement.
|
boolean |
hasValues()
Whether or not this statement has values, that is if
getValues will return null
or not. |
abstract boolean |
hasValues(CodecRegistry codecRegistry)
Whether or not this statement has values, that is if
getValues will return null
or not. |
int |
requestSizeInBytes(ProtocolVersion protocolVersion,
CodecRegistry codecRegistry)
Returns the number of bytes required to encode this statement.
|
RegularStatement |
setRoutingToken(Token routingToken)
Sets a routing token for this statement.
|
String |
toString()
Returns this statement as a CQL query string.
|
abstract boolean |
usesNamedValues()
Whether this statement uses named values.
|
disableTracing, enableTracing, executingAs, getConsistencyLevel, getDefaultTimestamp, getFetchSize, getHost, getOutgoingPayload, getReadTimeoutMillis, getRetryPolicy, getRoutingKey, getSerialConsistencyLevel, isBatchIdempotent, isIdempotent, isTracing, setConsistencyLevel, setDefaultTimestamp, setFetchSize, setHost, setIdempotent, setOutgoingPayload, setPagingState, setPagingState, setPagingStateUnsafe, setReadTimeoutMillis, setRetryPolicy, setSerialConsistencyLevel
public abstract String getQueryString(CodecRegistry codecRegistry)
It is important to note that the query string is merely a CQL representation of this
statement, but it does not convey all the information stored in 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.
codecRegistry
- the codec registry that will be used if the actual implementation needs to
serialize Java objects in the process of generating the query. Note that it might be
possible to use the no-arg getQueryString()
depending on the type of statement
this is called on.getQueryString()
public String getQueryString()
This method calls getQueryString(CodecRegistry)
with CodecRegistry.DEFAULT_INSTANCE
. Whether you should use this or the other variant depends on
the type of statement this is called on:
SimpleStatement
or SchemaStatement
, the codec registry isn't
actually needed, so it's always safe to use this method;
BuiltStatement
you can use this method if you use no custom codecs, or if
your custom codecs are registered with the default registry. Otherwise, use the other
method and provide the registry that contains your codecs (see BuiltStatement
for
more explanations on why this is so);
BatchStatement
, use the first rule if it contains no built statements, or
the second rule otherwise.
public abstract ByteBuffer[] getValues(ProtocolVersion protocolVersion, CodecRegistry codecRegistry)
A statement can use either positional or named values, but not both. So if this method
returns a non-null result, getNamedValues(ProtocolVersion, CodecRegistry)
will return
null
.
Values for a RegularStatement (i.e. if either 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 forced version 1 through Cluster.Builder.withProtocolVersion(com.datastax.driver.core.ProtocolVersion)
or you use
Cassandra 1.2).
protocolVersion
- the protocol version that will be used to serialize the values.codecRegistry
- the codec registry that will be used to serialize the values.InvalidTypeException
- if one of the values is not of a type that can be serialized to a
CQL3 typeSimpleStatement.SimpleStatement(String, Object...)
public abstract Map<String,ByteBuffer> getNamedValues(ProtocolVersion protocolVersion, CodecRegistry codecRegistry)
A statement can use either positional or named values, but not both. So if this method
returns a non-null result, getValues(ProtocolVersion, CodecRegistry)
will return
null
.
Values for a RegularStatement (i.e. if either 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 forced version 1 through Cluster.Builder.withProtocolVersion(com.datastax.driver.core.ProtocolVersion)
or you use
Cassandra 1.2).
protocolVersion
- the protocol version that will be used to serialize the values.codecRegistry
- the codec registry that will be used to serialize the values.InvalidTypeException
- if one of the values is not of a type that can be serialized to a
CQL3 typeSimpleStatement.SimpleStatement(String, Map)
public abstract boolean hasValues(CodecRegistry codecRegistry)
getValues
will return null
or not.codecRegistry
- the codec registry that will be used if the actual implementation needs to
serialize Java objects in the process of determining if the query has values. Note that it
might be possible to use the no-arg hasValues()
depending on the type of statement
this is called on.false
if both getValues(ProtocolVersion, CodecRegistry)
and getNamedValues(ProtocolVersion, CodecRegistry)
return null
, true
otherwise.hasValues()
public abstract boolean usesNamedValues()
false
if getNamedValues(ProtocolVersion, CodecRegistry)
returns null
, true
otherwise.public boolean hasValues()
getValues
will return null
or not.
This method calls hasValues(CodecRegistry)
with ProtocolVersion.NEWEST_SUPPORTED
. Whether you should use this or the other variant depends on
the type of statement this is called on:
SimpleStatement
or SchemaStatement
, the codec registry isn't
actually needed, so it's always safe to use this method;
BuiltStatement
you can use this method if you use no custom codecs, or if
your custom codecs are registered with the default registry. Otherwise, use the other
method and provide the registry that contains your codecs (see BuiltStatement
for
more explanations on why this is so);
BatchStatement
, use the first rule if it contains no built statements, or
the second rule otherwise.
false
if getValues(com.datastax.driver.core.ProtocolVersion, com.datastax.driver.core.CodecRegistry)
returns null
, true
otherwise.public Token getRoutingToken()
Statement
This is similar to Statement.getRoutingKey(ProtocolVersion, CodecRegistry)
, except that the
key is already hashed. A typical use case would be analytics clients wishing to optimize a
query by splitting it into chunks, each targeted to a direct replica. Such clients could call
Metadata.getTokenRanges()
to get a description of the ring, and then issue a separate
query with the end token of each range. Unlike the routing key, the routing token is never
computed automatically.
If both the routing key and token are defined, the token is used in priority.
getRoutingToken
in class Statement
null
.public RegularStatement setRoutingToken(Token routingToken)
getRoutingToken()
public String getKeyspace()
Unless the keyspace has been explicitly set through a means such as SimpleStatement.setKeyspace(java.lang.String)
, this method will return null
to avoid having to parse the
query string.
Note: This returns the internal representation of the keyspace. In the typical case, the internal representation is equivalent to the CQL representation. However, if you are using a keyspace that requires the use of quotes in CQL (a quoted identifier), i.e.: "MyKS", this method will return the unquoted representation instead, i.e. MyKS.
getKeyspace
in class Statement
null
otherwise.Statement.getKeyspace()
public int requestSizeInBytes(ProtocolVersion protocolVersion, CodecRegistry codecRegistry)
Statement
The calculated size may be overestimated by a few bytes, but is never underestimated. If the size cannot be calculated, this method returns -1.
Note that the returned value is not cached, but instead recomputed at every method call.
requestSizeInBytes
in class Statement
public String toString()
It is important to note that the query string is merely a CQL representation of this
statement, but it does not convey all the information stored in Statement
objects.
See the javadocs of getQueryString()
for more information.
toString
in class Object
getQueryString()
Copyright © 2012–2018. All rights reserved.