Class RegularStatement
- java.lang.Object
-
- com.datastax.driver.core.Statement
-
- com.datastax.driver.core.RegularStatement
-
- Direct Known Subclasses:
BuiltStatement,SchemaStatement,SimpleStatement
public abstract class RegularStatement extends Statement
A regular (non-prepared and non batched) CQL statement.This class represents a query string along with query options (and optionally binary values, see
getValues). It can be extended butSimpleStatementis provided as a simple implementation to build aRegularStatementdirectly from its query string.
-
-
Field Summary
-
Fields inherited from class com.datastax.driver.core.Statement
idempotent, NULL_PAYLOAD_VALUE
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedRegularStatement()Creates a new RegularStatement.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract Map<String,ByteBuffer>getNamedValues(ProtocolVersion protocolVersion, CodecRegistry codecRegistry)The named values to use for this statement.StringgetQueryString()Returns the query string for this statement.abstract StringgetQueryString(CodecRegistry codecRegistry)Returns the query string for this statement.abstract ByteBuffer[]getValues(ProtocolVersion protocolVersion, CodecRegistry codecRegistry)The positional values to use for this statement.booleanhasValues()Whether or not this statement has values, that is ifgetValueswill returnnullor not.abstract booleanhasValues(CodecRegistry codecRegistry)Whether or not this statement has values, that is ifgetValueswill returnnullor not.intrequestSizeInBytes(ProtocolVersion protocolVersion, CodecRegistry codecRegistry)Returns the number of bytes required to encode this statement.StringtoString()Returns this statement as a CQL query string.abstract booleanusesNamedValues()Whether this statement uses named values.-
Methods inherited from class com.datastax.driver.core.Statement
disableTracing, enableTracing, getConsistencyLevel, getDefaultTimestamp, getFetchSize, getHost, getKeyspace, getLastHost, getNowInSeconds, getOutgoingPayload, getPartitioner, getReadTimeoutMillis, getRetryPolicy, getRoutingKey, getSerialConsistencyLevel, isBatchIdempotent, isIdempotent, isLWT, isTracing, setConsistencyLevel, setDefaultTimestamp, setFetchSize, setHost, setIdempotent, setLastHost, setNowInSeconds, setOutgoingPayload, setPagingState, setPagingState, setPagingStateUnsafe, setReadTimeoutMillis, setRetryPolicy, setSerialConsistencyLevel
-
-
-
-
Method Detail
-
getQueryString
public abstract String getQueryString(CodecRegistry codecRegistry)
Returns the query string for this statement.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
Statementobjects.For example,
Statementobjects carry numerous protocol-level settings, such as theconsistency levelto use, or theidempotence 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.
- Parameters:
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-arggetQueryString()depending on the type of statement this is called on.- Returns:
- a valid CQL query string.
- See Also:
getQueryString()
-
getQueryString
public String getQueryString()
Returns the query string for this statement.This method calls
getQueryString(CodecRegistry)withCodecRegistry.DEFAULT_INSTANCE. Whether you should use this or the other variant depends on the type of statement this is called on:- for a
SimpleStatementorSchemaStatement, the codec registry isn't actually needed, so it's always safe to use this method; - for a
BuiltStatementyou 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 (seeBuiltStatementfor more explanations on why this is so); - for a
BatchStatement, use the first rule if it contains no built statements, or the second rule otherwise.
- Returns:
- a valid CQL query string.
- for a
-
getValues
public abstract ByteBuffer[] getValues(ProtocolVersion protocolVersion, CodecRegistry codecRegistry)
The positional values to use for this statement.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 returnnull.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 anUnsupportedProtocolVersionExceptionwhen submitting one if version 1 of the protocol is in use (i.e. if you've forced version 1 throughCluster.Builder.withProtocolVersion(com.datastax.driver.core.ProtocolVersion)or you use Cassandra 1.2).- Parameters:
protocolVersion- the protocol version that will be used to serialize the values.codecRegistry- the codec registry that will be used to serialize the values.- Throws:
InvalidTypeException- if one of the values is not of a type that can be serialized to a CQL3 type- See Also:
SimpleStatement(String, Object...)
-
getNamedValues
public abstract Map<String,ByteBuffer> getNamedValues(ProtocolVersion protocolVersion, CodecRegistry codecRegistry)
The named values to use for this statement.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 returnnull.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 anUnsupportedProtocolVersionExceptionwhen submitting one if version 1 of the protocol is in use (i.e. if you've forced version 1 throughCluster.Builder.withProtocolVersion(com.datastax.driver.core.ProtocolVersion)or you use Cassandra 1.2).- Parameters:
protocolVersion- the protocol version that will be used to serialize the values.codecRegistry- the codec registry that will be used to serialize the values.- Returns:
- the named values.
- Throws:
InvalidTypeException- if one of the values is not of a type that can be serialized to a CQL3 type- See Also:
SimpleStatement(String, Map)
-
hasValues
public abstract boolean hasValues(CodecRegistry codecRegistry)
Whether or not this statement has values, that is ifgetValueswill returnnullor not.- Parameters:
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-arghasValues()depending on the type of statement this is called on.- Returns:
falseif bothgetValues(ProtocolVersion, CodecRegistry)andgetNamedValues(ProtocolVersion, CodecRegistry)returnnull,trueotherwise.- See Also:
hasValues()
-
usesNamedValues
public abstract boolean usesNamedValues()
Whether this statement uses named values.- Returns:
falseifgetNamedValues(ProtocolVersion, CodecRegistry)returnsnull,trueotherwise.
-
hasValues
public boolean hasValues()
Whether or not this statement has values, that is ifgetValueswill returnnullor not.This method calls
hasValues(CodecRegistry)withProtocolVersion.NEWEST_SUPPORTED. Whether you should use this or the other variant depends on the type of statement this is called on:- for a
SimpleStatementorSchemaStatement, the codec registry isn't actually needed, so it's always safe to use this method; - for a
BuiltStatementyou 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 (seeBuiltStatementfor more explanations on why this is so); - for a
BatchStatement, use the first rule if it contains no built statements, or the second rule otherwise.
- Returns:
falseifgetValues(com.datastax.driver.core.ProtocolVersion, com.datastax.driver.core.CodecRegistry)returnsnull,trueotherwise.
- for a
-
requestSizeInBytes
public int requestSizeInBytes(ProtocolVersion protocolVersion, CodecRegistry codecRegistry)
Description copied from class:StatementReturns the number of bytes required to encode this 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.
- Overrides:
requestSizeInBytesin classStatement- Returns:
- the number of bytes required to encode this statement.
-
toString
public String toString()
Returns this statement as a CQL query string.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
Statementobjects.See the javadocs of
getQueryString()for more information.- Overrides:
toStringin classObject- Returns:
- this statement as a CQL query string.
- See Also:
getQueryString()
-
-