public class Insert extends RegularStatement
Modifier and Type | Class and Description |
---|---|
static class |
Insert.Options
The options of an INSERT statement.
|
Modifier and Type | Method and Description |
---|---|
String |
getKeyspace()
Returns the keyspace this query operates on.
|
String |
getQueryString()
Returns the query string for this statement.
|
ByteBuffer |
getRoutingKey()
Returns the routing key (in binary raw form) to use for token aware
routing of this query.
|
ByteBuffer[] |
getValues()
The values to use for this statement.
|
Insert |
ifNotExists()
Sets the 'IF NOT EXISTS' option for this INSERT statement.
|
RegularStatement |
setForceNoValues(boolean forceNoValues)
Allows to force this builder to not generate values (through its
getValues() method). |
String |
toString() |
Insert.Options |
using(Using using)
Adds a new options for this INSERT statement.
|
Insert |
value(String name,
Object value)
Adds a column/value pair to the values inserted by this INSERT statement.
|
Insert |
values(String[] names,
Object[] values)
Adds multiple column/value pairs to the values inserted by this INSERT statement.
|
disableTracing, enableTracing, getConsistencyLevel, getFetchSize, getRetryPolicy, getSerialConsistencyLevel, isTracing, setConsistencyLevel, setFetchSize, setRetryPolicy, setSerialConsistencyLevel
public Insert value(String name, Object value)
name
- the name of the column to insert/update.value
- the value to insert/update for name
.public Insert values(String[] names, Object[] values)
names
- a list of column names to insert/update.values
- a list of values to insert/update. The i
th
value in values
will be inserted for the i
th column
in names
.IllegalArgumentException
- if names.length != values.length
.public Insert.Options using(Using using)
using
- the option to add.public Insert ifNotExists()
An insert with that option will not succeed unless the row does not exist at the time the insertion is execution. The existence check and insertions are done transactionally in the sense that if multiple clients attempt to create 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.
public String getQueryString()
RegularStatement
getQueryString
in class RegularStatement
public ByteBuffer getRoutingKey()
Statement
The routing key is optional in that implementers are free to
return null
. The routing key is an hint used for token-aware routing (see
TokenAwarePolicy
), 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.
getRoutingKey
in class Statement
null
.public String getKeyspace()
Statement
Note that not all query specify on which keyspace they operate on, and
so this method can always reutrn null
. Firstly, some queries do
not operate inside a keyspace: keyspace creation, USE
queries,
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 a USE
query
(or through the use of Cluster.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
return null
(or even a bogus keyspace name) will never cause the
query to fail.
getKeyspace
in class Statement
null
.public ByteBuffer[] getValues()
RegularStatement
getValues
in class RegularStatement
null
if there is
no such values.SimpleStatement.SimpleStatement(String, Object...)
public String toString()
toString
in class RegularStatement
public RegularStatement setForceNoValues(boolean forceNoValues)
getValues()
method).
By default and for performance reasons, the query builder will not
serialize all values provided to strings. This means that the
getQueryString()
may return a query string with bind markers
(where and when is at the discretion of the builder) and getValues()
will return the binary values for those markers. This method allows to force
the builder to not generate binary values but rather to serialize them
all in the query string. In practice, this means that if you call
setForceNoValues(true)
, you are guarateed that getValues()
will return null
and that the string returned by getQueryString()
will contain no other bind markers than the one inputed by the user.
Note that this method is mainly useful for debugging purpose. In general, the default behavior should be the correct and most efficient one.
forceNoValues
- whether or not this builder may generate values.Copyright © 2013. All rights reserved.