public class QueryBuilder extends Object
Constructor and Description |
---|
QueryBuilder() |
Modifier and Type | Method and Description |
---|---|
static Term |
add(Term left,
Term right)
The sum of two terms, as in
WHERE k = left + right . |
static BindMarker |
bindMarker()
Creates an anonymous bind marker, which appears as
? in the generated CQL. |
static BindMarker |
bindMarker(CqlIdentifier id)
Creates a named bind marker, which appears as
:id in the generated CQL. |
static BindMarker |
bindMarker(String name)
Shortcut for
bindMarker(CqlIdentifier.fromCql(name)) |
static Term |
currentDate()
A call to the built-in
currentDate function as a term. |
static Term |
currentTime()
A call to the built-in
currentTime function as a term. |
static Term |
currentTimestamp()
A call to the built-in
currentTimestamp function as a term. |
static Term |
currentTimeUuid()
A call to the built-in
currentTimeUuid function as a term. |
static DeleteSelection |
deleteFrom(CqlIdentifier table)
Starts a DELETE query for an unqualified table.
|
static DeleteSelection |
deleteFrom(CqlIdentifier keyspace,
CqlIdentifier table)
Starts a DELETE query for a qualified table.
|
static DeleteSelection |
deleteFrom(String table)
Shortcut for
deleteFrom(CqlIdentifier.fromCql(table)) |
static DeleteSelection |
deleteFrom(String keyspace,
String table)
|
static Term |
divide(Term left,
Term right)
The quotient of two terms, as in
WHERE k = left / right . |
static Term |
function(CqlIdentifier keyspaceId,
CqlIdentifier functionId,
Iterable<Term> arguments)
A function call as a term, as in
WHERE k = ks.f(arguments) . |
static Term |
function(CqlIdentifier keyspaceId,
CqlIdentifier functionId,
Term... arguments)
Var-arg equivalent of
function(CqlIdentifier, CqlIdentifier, Iterable) . |
static Term |
function(CqlIdentifier functionId,
Iterable<Term> arguments)
A function call as a term, as in
WHERE k = f(arguments) . |
static Term |
function(CqlIdentifier functionId,
Term... arguments)
Var-arg equivalent of
function(CqlIdentifier, Iterable) . |
static Term |
function(String functionName,
Iterable<Term> arguments)
Shortcut for
function(CqlIdentifier.fromCql(functionName), arguments) . |
static Term |
function(String keyspaceName,
String functionName,
Iterable<Term> arguments)
|
static Term |
function(String keyspaceName,
String functionName,
Term... arguments)
|
static Term |
function(String functionName,
Term... arguments)
Shortcut for
function(CqlIdentifier.fromCql(functionName), arguments) . |
static InsertInto |
insertInto(CqlIdentifier table)
Starts an INSERT query for an unqualified table.
|
static InsertInto |
insertInto(CqlIdentifier keyspace,
CqlIdentifier table)
Starts an INSERT query for a qualified table.
|
static InsertInto |
insertInto(String table)
Shortcut for
insertInto(CqlIdentifier.fromCql(table)) . |
static InsertInto |
insertInto(String keyspace,
String table)
|
static Literal |
literal(Object value)
A literal term, as in
WHERE k = 1 . |
static Literal |
literal(Object value,
CodecRegistry codecRegistry)
A literal term, as in
WHERE k = 1 . |
static <T> Literal |
literal(T value,
TypeCodec<T> codec)
A literal term, as in
WHERE k = 1 . |
static Term |
maxTimeUuid(Term argument)
A call to the built-in
maxTimeUuid function as a term. |
static Term |
minTimeUuid(Term argument)
A call to the built-in
minTimeUuid function as a term. |
static Term |
multiply(Term left,
Term right)
The product of two terms, as in
WHERE k = left * right . |
static Term |
negate(Term argument)
The opposite of a term, as in
WHERE k = -argument . |
static Term |
now()
A call to the built-in
now function as a term. |
static Raw |
raw(String raw)
A raw CQL snippet.
|
static Term |
remainder(Term left,
Term right)
The remainder of two terms, as in
WHERE k = left % right . |
static SelectFrom |
selectFrom(CqlIdentifier table)
Starts a SELECT query for an unqualified table.
|
static SelectFrom |
selectFrom(CqlIdentifier keyspace,
CqlIdentifier table)
Starts a SELECT query for a qualified table.
|
static SelectFrom |
selectFrom(String table)
Shortcut for
selectFrom(CqlIdentifier.fromCql(table)) |
static SelectFrom |
selectFrom(String keyspace,
String table)
|
static Term |
subtract(Term left,
Term right)
The difference of two terms, as in
WHERE k = left - right . |
static Term |
toDate(Term argument)
A call to the built-in
toDate function as a term. |
static Term |
toTimestamp(Term argument)
A call to the built-in
toTimestamp function as a term. |
static Term |
toUnixTimestamp(Term argument)
A call to the built-in
toUnixTimestamp function as a term. |
static Truncate |
truncate(CqlIdentifier table)
Creates a new
TRUNCATE query. |
static Truncate |
truncate(CqlIdentifier keyspace,
CqlIdentifier table)
Creates a new
TRUNCATE query. |
static Truncate |
truncate(String table)
Creates a new
TRUNCATE query. |
static Truncate |
truncate(String keyspace,
String table)
Creates a new
TRUNCATE query. |
static Term |
tuple(Iterable<? extends Term> components)
An ordered set of anonymous terms, as in
WHERE (a, b) = (1, 2) (on the right-hand
side). |
static Term |
tuple(Term... components)
Var-arg equivalent of
tuple(Iterable) . |
static Term |
typeHint(Term term,
DataType targetType)
Provides a type hint for an expression, as in
WHERE k = (double)1/3 . |
static UserDefinedType |
udt(CqlIdentifier name)
Shortcut to reference a UDT in methods that use a
DataType , such as typeHint(Term, DataType) and Selector.cast(Selector, DataType) . |
static UserDefinedType |
udt(String name)
Shortcut for
udt(CqlIdentifier.fromCql(name)) . |
static UpdateStart |
update(CqlIdentifier table)
Starts an UPDATE query for an unqualified table.
|
static UpdateStart |
update(CqlIdentifier keyspace,
CqlIdentifier table)
Starts an UPDATE query for a qualified table.
|
static UpdateStart |
update(String table)
Shortcut for
update(CqlIdentifier.fromCql(table)) |
static UpdateStart |
update(String keyspace,
String table)
|
@NonNull public static SelectFrom selectFrom(@Nullable CqlIdentifier keyspace, @NonNull CqlIdentifier table)
@NonNull public static SelectFrom selectFrom(@Nullable String keyspace, @NonNull String table)
@NonNull public static SelectFrom selectFrom(@NonNull CqlIdentifier table)
@NonNull public static SelectFrom selectFrom(@NonNull String table)
selectFrom(CqlIdentifier.fromCql(table))
@NonNull public static InsertInto insertInto(@Nullable CqlIdentifier keyspace, @NonNull CqlIdentifier table)
@NonNull public static InsertInto insertInto(@Nullable String keyspace, @NonNull String table)
@NonNull public static InsertInto insertInto(@NonNull CqlIdentifier table)
@NonNull public static InsertInto insertInto(@NonNull String table)
insertInto(CqlIdentifier.fromCql(table))
.@NonNull public static UpdateStart update(@Nullable CqlIdentifier keyspace, @NonNull CqlIdentifier table)
@NonNull public static UpdateStart update(@Nullable String keyspace, @NonNull String table)
@NonNull public static UpdateStart update(@NonNull CqlIdentifier table)
@NonNull public static UpdateStart update(@NonNull String table)
update(CqlIdentifier.fromCql(table))
@NonNull public static DeleteSelection deleteFrom(@Nullable CqlIdentifier keyspace, @NonNull CqlIdentifier table)
@NonNull public static DeleteSelection deleteFrom(@Nullable String keyspace, @NonNull String table)
@NonNull public static DeleteSelection deleteFrom(@NonNull CqlIdentifier table)
@NonNull public static DeleteSelection deleteFrom(@NonNull String table)
deleteFrom(CqlIdentifier.fromCql(table))
@NonNull public static Term tuple(@NonNull Iterable<? extends Term> components)
WHERE (a, b) = (1, 2)
(on the right-hand
side).
For example, this can be used as the right operand of Relation.columns(String...)
.
@NonNull public static Term tuple(@NonNull Term... components)
tuple(Iterable)
.@NonNull public static Term add(@NonNull Term left, @NonNull Term right)
WHERE k = left + right
.@NonNull public static Term subtract(@NonNull Term left, @NonNull Term right)
WHERE k = left - right
.@NonNull public static Term multiply(@NonNull Term left, @NonNull Term right)
WHERE k = left * right
.@NonNull public static Term divide(@NonNull Term left, @NonNull Term right)
WHERE k = left / right
.@NonNull public static Term remainder(@NonNull Term left, @NonNull Term right)
WHERE k = left % right
.@NonNull public static Term negate(@NonNull Term argument)
WHERE k = -argument
.@NonNull public static Term function(@NonNull CqlIdentifier functionId, @NonNull Iterable<Term> arguments)
WHERE k = f(arguments)
.@NonNull public static Term function(@NonNull CqlIdentifier functionId, @NonNull Term... arguments)
function(CqlIdentifier, Iterable)
.@NonNull public static Term function(@NonNull String functionName, @NonNull Iterable<Term> arguments)
function(CqlIdentifier.fromCql(functionName), arguments)
.@NonNull public static Term function(@NonNull String functionName, @NonNull Term... arguments)
function(CqlIdentifier.fromCql(functionName), arguments)
.@NonNull public static Term function(@Nullable CqlIdentifier keyspaceId, @NonNull CqlIdentifier functionId, @NonNull Iterable<Term> arguments)
WHERE k = ks.f(arguments)
.@NonNull public static Term function(@Nullable CqlIdentifier keyspaceId, @NonNull CqlIdentifier functionId, @NonNull Term... arguments)
function(CqlIdentifier, CqlIdentifier, Iterable)
.@NonNull public static Term function(@Nullable String keyspaceName, @NonNull String functionName, @NonNull Iterable<Term> arguments)
@NonNull public static Term function(@Nullable String keyspaceName, @NonNull String functionName, @NonNull Term... arguments)
@NonNull public static Term typeHint(@NonNull Term term, @NonNull DataType targetType)
WHERE k = (double)1/3
.
To create the data type, use the constants and static methods in DataTypes
, or
udt(CqlIdentifier)
.
@NonNull public static Term now()
now
function as a term.@NonNull public static Term currentTimestamp()
currentTimestamp
function as a term.@NonNull public static Term currentDate()
currentDate
function as a term.@NonNull public static Term currentTime()
currentTime
function as a term.@NonNull public static Term currentTimeUuid()
currentTimeUuid
function as a term.@NonNull public static Term minTimeUuid(@NonNull Term argument)
minTimeUuid
function as a term.@NonNull public static Term maxTimeUuid(@NonNull Term argument)
maxTimeUuid
function as a term.@NonNull public static Term toDate(@NonNull Term argument)
toDate
function as a term.@NonNull public static Term toTimestamp(@NonNull Term argument)
toTimestamp
function as a term.@NonNull public static Term toUnixTimestamp(@NonNull Term argument)
toUnixTimestamp
function as a term.@NonNull public static Literal literal(@Nullable Object value)
WHERE k = 1
.
This method can process any type for which there is a default Java to CQL mapping, namely:
primitive types (Integer=>int, Long=>bigint, String=>text, etc.
), and collections,
tuples, and user defined types thereof.
A null argument will be rendered as NULL
.
For custom mappings, use literal(Object, CodecRegistry)
or literal(Object,
TypeCodec)
.
CodecNotFoundException
- if there is no default CQL mapping for the Java type of value
.@NonNull public static Literal literal(@Nullable Object value, @NonNull CodecRegistry codecRegistry)
WHERE k = 1
.
This is an alternative to literal(Object)
for custom type mappings. The provided
registry should contain a codec that can format the value. Typically, this will be your
session's registry, which is accessible via session.getContext().getCodecRegistry()
.
CodecNotFoundException
- if codecRegistry
does not contain any codec that can
handle value
.AttachmentPoint.getCodecRegistry()
@NonNull public static <T> Literal literal(@Nullable T value, @Nullable TypeCodec<T> codec)
WHERE k = 1
.
This is an alternative to literal(Object)
for custom type mappings. The value will
be turned into a string with TypeCodec.format(Object)
, and inlined in the query.
@NonNull public static Raw raw(@NonNull String raw)
The contents will be appended to the query as-is, without any syntax checking or escaping. This method should be used with caution, as it's possible to generate invalid CQL that will fail at execution time; on the other hand, it can be used as a workaround to handle new CQL features that are not yet covered by the query builder.
@NonNull public static BindMarker bindMarker()
?
in the generated CQL.@NonNull public static BindMarker bindMarker(@Nullable CqlIdentifier id)
:id
in the generated CQL.@NonNull public static BindMarker bindMarker(@Nullable String name)
bindMarker(CqlIdentifier.fromCql(name))
@NonNull public static UserDefinedType udt(@NonNull CqlIdentifier name)
DataType
, such as typeHint(Term, DataType)
and Selector.cast(Selector, DataType)
.@NonNull public static UserDefinedType udt(@NonNull String name)
udt(CqlIdentifier.fromCql(name))
.public static Truncate truncate(@NonNull CqlIdentifier table)
TRUNCATE
query.table
- the name of the table to truncate.public static Truncate truncate(@NonNull String table)
TRUNCATE
query.
This is a shortcut for truncate(CqlIdentifier.fromCql(table))
.
table
- the name of the table to truncate.public static Truncate truncate(@Nullable CqlIdentifier keyspace, @NonNull CqlIdentifier table)
TRUNCATE
query.keyspace
- the name of the keyspace to use.table
- the name of the table to truncate.public static Truncate truncate(@Nullable String keyspace, @NonNull String table)
TRUNCATE
query.
This is a shortcut for truncate(CqlIdentifier.fromCql(keyspace), CqlIdentifier.fromCql(table))
.
keyspace
- the name of the keyspace to use.table
- the name of the table to truncate.Copyright © 2017–2019. All rights reserved.