public class Insert extends BuiltStatement
INSERT
statement.Modifier and Type | Class and Description |
---|---|
static class |
Insert.Options
The options of an
INSERT statement. |
idempotent, NULL_PAYLOAD_VALUE
Modifier and Type | Method and Description |
---|---|
Insert |
defaultNull()
Appends a
DEFAULT NULL clause to this {@code INSERT INTO ... |
Insert |
defaultUnset()
Appends a
DEFAULT UNSET clause to this {@code INSERT INTO ... |
Insert |
ifNotExists()
Sets the 'IF NOT EXISTS' option for this
INSERT statement. |
Insert |
json(Object json)
Inserts the provided object, using the {@code INSERT INTO ...
|
Insert.Options |
using()
Returns the options for this
INSERT statement. |
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(List<String> names,
List<Object> values)
Adds multiple column/value pairs 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.
|
escapeId, getKeyspace, getNamedValues, getObject, getObject, getQueryString, getRoutingKey, getValues, hasValues, isIdempotent, setForceNoValues, setKeyspace, toString, usesNamedValues
getQueryString, getRoutingToken, hasValues, requestSizeInBytes, setRoutingToken
disableTracing, enableTracing, executingAs, getConsistencyLevel, getDefaultTimestamp, getFetchSize, getOutgoingPayload, getReadTimeoutMillis, getRetryPolicy, getSerialConsistencyLevel, isBatchIdempotent, isTracing, setConsistencyLevel, setDefaultTimestamp, setFetchSize, setIdempotent, setOutgoingPayload, setPagingState, setPagingState, setPagingStateUnsafe, setReadTimeoutMillis, setRetryPolicy, setSerialConsistencyLevel
public Insert value(String name, Object value)
INSERT
statement.name
- the name of the column to insert/update.value
- the value to insert/update for name
.INSERT
statement.IllegalStateException
- if this method is called and the json(Object)
method has been called before, because it's not possible
to mix INSERT JSON
syntax with regular INSERT
syntax.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
.IllegalStateException
- if this method is called and the json(Object)
method has been called before, because it's not possible
to mix INSERT JSON
syntax with regular INSERT
syntax.public Insert values(List<String> names, List<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.size() != values.size()
.IllegalStateException
- if this method is called and the json(Object)
method has been called before, because it's not possible
to mix INSERT JSON
syntax with regular INSERT
syntax.public Insert json(Object json)
INSERT INTO ... JSON
syntax introduced
in Cassandra 2.2.
With INSERT statements, the new JSON
keyword can be used to enable inserting a JSON
structure as a single row.
The provided object can be of the following types:
SELECT JSON
statement on the same table.
Note that it is not possible to insert function calls nor bind markers in a JSON string.bind marker
. In this case, the statement is meant to be prepared
and no JSON string will be appended to the query string, only a bind marker for the whole JSON parameter.codec
is registered with the
CodecRegistry
in use. This allows the usage of JSON libraries, such
as the Java API for JSON processing,
the popular Jackson library, or
Google's Gson library, for instance.insertInto("mytable").json("{\"\\\"myKey\\\"\": 0, \"value\": 0}");This will produce the following CQL:
INSERT INTO mytable JSON '{"\"myKey\"": 0, "value": 0}';
foo"'bar
should be inserted in the JSON string
as "foo\"''bar"
.
NULL
value
(which will result in a tombstone being created).json
- the JSON string, or a bind marker, or a JSON object handled by a specific codec
.IllegalStateException
- if this method is called and any of the value
or values
methods have been called before, because it's not possible
to mix INSERT JSON
syntax with regular INSERT
syntax.public Insert defaultUnset()
DEFAULT UNSET
clause to this INSERT INTO ... JSON
statement.
Support for DEFAULT UNSET
has been introduced in Cassandra 3.10.INSERT
statement.IllegalStateException
- if this method is called and any of the value
or values
methods have been called before, because it's not possible
to mix INSERT JSON
syntax with regular INSERT
syntax.public Insert defaultNull()
DEFAULT NULL
clause to this INSERT INTO ... JSON
statement.
Support for DEFAULT NULL
has been introduced in Cassandra 3.10.INSERT
statement.IllegalStateException
- if this method is called and any of the value
or values
methods have been called before, because it's not possible
to mix INSERT JSON
syntax with regular INSERT
syntax.public Insert.Options using(Using using)
INSERT
statement.using
- the option to add.INSERT
statement.public Insert.Options using()
INSERT
statement.
Chain this with Insert.Options.and(Using)
to add options.INSERT
statement.public Insert ifNotExists()
INSERT
statement.
An insert with that option will not succeed unless the row does not
exist at the time the insertion is executed. 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.
This will configure the statement as non-idempotent, see Statement.isIdempotent()
for more information.INSERT
statement.Copyright © 2012–2018. All rights reserved.