Class Delete.Where
- java.lang.Object
-
- com.datastax.driver.core.Statement
-
- com.datastax.driver.core.RegularStatement
-
- com.datastax.driver.core.querybuilder.BuiltStatement
-
- com.datastax.driver.core.querybuilder.Delete.Where
-
- Enclosing class:
- Delete
public static class Delete.Where extends BuiltStatement
The WHERE clause of a DELETE statement.
-
-
Field Summary
-
Fields inherited from class com.datastax.driver.core.Statement
idempotent, NULL_PAYLOAD_VALUE
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Delete.Whereand(Clause clause)Adds the provided clause to this WHERE clause.StatementdisableTracing()Disables tracing for this query.StatementenableTracing()Enables tracing for this query.ConsistencyLevelgetConsistencyLevel()The consistency level for this query.StringgetKeyspace()Returns the keyspace this query operates on.StringgetQueryString(CodecRegistry codecRegistry)Returns the query string for this statement.RetryPolicygetRetryPolicy()Returns the retry policy sets for this query, if any.ByteBuffergetRoutingKey(ProtocolVersion protocolVersion, CodecRegistry codecRegistry)Returns the routing key (in binary raw form) to use for token aware routing of this query.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.DeleteifExists()Sets the 'IF EXISTS' option for the DELETE statement this WHERE clause is part of.booleanisTracing()Returns whether tracing is enabled for this query or not.Delete.ConditionsonlyIf(Clause condition)Adds a condition to the DELETE statement this WHERE clause is part of.StatementsetConsistencyLevel(ConsistencyLevel consistency)Sets the consistency level for the query.RegularStatementsetForceNoValues(boolean forceNoValues)Allows to force this builder to not generate values (through itsgetValues()method).StatementsetRetryPolicy(RetryPolicy policy)Sets the retry policy to use for this query.StringtoString()Returns this statement as a CQL query string.Delete.Optionsusing(Using using)Adds an option to the DELETE statement this WHERE clause is part of.-
Methods inherited from class com.datastax.driver.core.querybuilder.BuiltStatement
escapeId, getNamedValues, getObject, getObject, hasValues, isIdempotent, usesNamedValues
-
Methods inherited from class com.datastax.driver.core.RegularStatement
getQueryString, requestSizeInBytes
-
Methods inherited from class com.datastax.driver.core.Statement
getDefaultTimestamp, getFetchSize, getHost, getLastHost, getNowInSeconds, getOutgoingPayload, getPartitioner, getReadTimeoutMillis, getSerialConsistencyLevel, isBatchIdempotent, isLWT, setDefaultTimestamp, setFetchSize, setHost, setIdempotent, setLastHost, setNowInSeconds, setOutgoingPayload, setPagingState, setPagingState, setPagingStateUnsafe, setReadTimeoutMillis, setSerialConsistencyLevel
-
-
-
-
Method Detail
-
and
public Delete.Where and(Clause clause)
Adds the provided clause to this WHERE clause.- Parameters:
clause- the clause to add.- Returns:
- this WHERE clause.
-
using
public Delete.Options using(Using using)
Adds an option to the DELETE statement this WHERE clause is part of.- Parameters:
using- the using clause to add.- Returns:
- the options of the DELETE statement this WHERE clause is part of.
-
ifExists
public Delete ifExists()
Sets the 'IF EXISTS' option for the DELETE statement this WHERE clause is part of.A delete with that option will report whether the statement actually resulted in data being deleted. The existence check and deletion are done transactionally in the sense that if multiple clients attempt to delete a given row with this option, then at most one may succeed.
Please keep in mind that using this option has a non negligible performance impact and should be avoided when possible.
- Returns:
- the DELETE statement this WHERE clause is part of.
-
onlyIf
public Delete.Conditions onlyIf(Clause condition)
Adds a condition to the DELETE statement this WHERE clause is part of.- Parameters:
condition- the condition to add.- Returns:
- the conditions for the DELETE statement this WHERE clause is part of.
-
getQueryString
public String getQueryString(CodecRegistry codecRegistry)
Description copied from class:RegularStatementReturns 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.
- Overrides:
getQueryStringin classBuiltStatement- 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-argRegularStatement.getQueryString()depending on the type of statement this is called on.- Returns:
- a valid CQL query string.
- See Also:
RegularStatement.getQueryString()
-
getRoutingKey
public ByteBuffer getRoutingKey(ProtocolVersion protocolVersion, CodecRegistry codecRegistry)
Description copied from class:StatementReturns the routing key (in binary raw form) to use for token aware routing of this query.The routing key is optional in that implementers are free to return
null. The routing key is an hint used for token-aware routing (seeTokenAwarePolicy), and if provided should correspond to the binary value for the query partition key. However, not providing a routing key never causes a query to fail and if the load balancing policy used is not token aware, then the routing key can be safely ignored.- Overrides:
getRoutingKeyin classBuiltStatement- Parameters:
protocolVersion- the protocol version that will be used if the actual implementation needs to serialize something to compute the key.codecRegistry- the codec registry that will be used if the actual implementation needs to serialize something to compute this key.- Returns:
- the routing key for this query or
null.
-
getKeyspace
public String getKeyspace()
Description copied from class:StatementReturns the keyspace this query operates on.Note that not all query specify on which keyspace they operate on, and so this method can always return
null. Firstly, some queries do not operate inside a keyspace: keyspace creation,USEqueries, user creation, etc. Secondly, even query that operate within a keyspace do not have to specify said keyspace directly, in which case the currently logged in keyspace (the one set through aUSEquery (or through the use ofCluster.connect(String))). Lastly, as for the routing key, this keyspace information is only a hint for token-aware routing (since replica placement depend on the replication strategy in use which is a per-keyspace property) and having this method returnnull(or even a bogus keyspace name) will never cause the query to fail.- Overrides:
getKeyspacein classBuiltStatement- Returns:
- the keyspace this query operate on if relevant or
null.
-
setForceNoValues
public RegularStatement setForceNoValues(boolean forceNoValues)
Description copied from class:BuiltStatementAllows to force this builder to not generate values (through itsgetValues()method).By default (and unless the protocol version 1 is in use, see below) and for performance reasons, the query builder will not serialize all values provided to strings. This means that
BuiltStatement.getQueryString(CodecRegistry)may return a query string with bind markers (where and when is at the discretion of the builder) andBuiltStatement.getValues(com.datastax.driver.core.ProtocolVersion, com.datastax.driver.core.CodecRegistry)will return the binary values for those markers. This method allows to force the builder to not generate binary values but rather to inline them all in the query string. In practice, this means that if you callsetForceNoValues(true), you are guaranteed thatgetValues()will returnnulland that the string returned bygetQueryString()will contain no other bind markers than the ones specified by the user.If the native protocol version 1 is in use, the driver will default to not generating values since those are not supported by that version of the protocol. In practice, the driver will automatically call this method with
trueas argument prior to execution. Hence, calling this method when the protocol version 1 is in use is basically a no-op.Note that this method is mainly useful for debugging purpose. In general, the default behavior should be the correct and most efficient one.
- Overrides:
setForceNoValuesin classBuiltStatement- Parameters:
forceNoValues- whether or not this builder may generate values.- Returns:
- this statement.
-
setConsistencyLevel
public Statement setConsistencyLevel(ConsistencyLevel consistency)
Description copied from class:StatementSets the consistency level for the query.- Overrides:
setConsistencyLevelin classStatement- Parameters:
consistency- the consistency level to set.- Returns:
- this
Statementobject.
-
getConsistencyLevel
public ConsistencyLevel getConsistencyLevel()
Description copied from class:StatementThe consistency level for this query.- Overrides:
getConsistencyLevelin classStatement- Returns:
- the consistency level for this query, or
nullif no consistency level has been specified (throughsetConsistencyLevel). In the latter case, the default consistency level will be used.
-
enableTracing
public Statement enableTracing()
Description copied from class:StatementEnables tracing for this query.By default (that is unless you call this method), tracing is not enabled.
- Overrides:
enableTracingin classStatement- Returns:
- this
Statementobject.
-
disableTracing
public Statement disableTracing()
Description copied from class:StatementDisables tracing for this query.- Overrides:
disableTracingin classStatement- Returns:
- this
Statementobject.
-
isTracing
public boolean isTracing()
Description copied from class:StatementReturns whether tracing is enabled for this query or not.
-
setRetryPolicy
public Statement setRetryPolicy(RetryPolicy policy)
Description copied from class:StatementSets the retry policy to use for this query.The default retry policy, if this method is not called, is the one returned by
Policies.getRetryPolicy()in the cluster configuration. This method is thus only useful in case you want to punctually override the default policy for this request.- Overrides:
setRetryPolicyin classStatement- Parameters:
policy- the retry policy to use for this query.- Returns:
- this
Statementobject.
-
getRetryPolicy
public RetryPolicy getRetryPolicy()
Description copied from class:StatementReturns the retry policy sets for this query, if any.- Overrides:
getRetryPolicyin classStatement- Returns:
- the retry policy sets specifically for this query or
nullif no query specific retry policy has been set throughStatement.setRetryPolicy(com.datastax.driver.core.policies.RetryPolicy)(in which case the Cluster retry policy will apply if necessary).
-
getValues
public ByteBuffer[] getValues(ProtocolVersion protocolVersion, CodecRegistry codecRegistry)
Description copied from class:RegularStatementThe 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,
RegularStatement.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).- Overrides:
getValuesin classBuiltStatement- 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.- See Also:
SimpleStatement(String, Object...)
-
hasValues
public boolean hasValues()
Description copied from class:RegularStatementWhether or not this statement has values, that is ifgetValueswill returnnullor not.This method calls
RegularStatement.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.
- Overrides:
hasValuesin classRegularStatement- Returns:
falseifRegularStatement.getValues(com.datastax.driver.core.ProtocolVersion, com.datastax.driver.core.CodecRegistry)returnsnull,trueotherwise.
- for a
-
toString
public String toString()
Description copied from class:RegularStatementReturns 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
RegularStatement.getQueryString()for more information.- Overrides:
toStringin classBuiltStatement- Returns:
- this statement as a CQL query string.
- See Also:
RegularStatement.getQueryString()
-
-