public abstract class Query extends Object implements Serializable
Contract to describe N1QL queries. Queries are formed of a mandatory Statement
and optionally can have other components, as described in each implementation of this.
Also exposes factory methods for different kinds of queries.
Constructor and Description |
---|
Query() |
Modifier and Type | Method and Description |
---|---|
abstract JsonObject |
n1ql()
Convert this query to a full N1QL query in Json form.
|
static ParametrizedQuery |
parametrized(Statement statement,
JsonArray positionalParams)
Create a new query with positionalParameters.
|
static ParametrizedQuery |
parametrized(Statement statement,
JsonArray positionalParams,
QueryParams params)
Create a new query with positionalParameters.
|
static ParametrizedQuery |
parametrized(Statement statement,
JsonObject namedParams)
Create a new query with named parameters.
|
static ParametrizedQuery |
parametrized(Statement statement,
JsonObject namedParams,
QueryParams params)
Create a new query with named parameters.
|
static ParametrizedQuery |
parametrized(String statement,
JsonArray positionalParams)
Create a new query with positionalParameters.
|
static ParametrizedQuery |
parametrized(String statement,
JsonArray positionalParams,
QueryParams params)
Create a new query with positionalParameters.
|
static ParametrizedQuery |
parametrized(String statement,
JsonObject namedParams)
Create a new query with named parameters.
|
static ParametrizedQuery |
parametrized(String statement,
JsonObject namedParams,
QueryParams params)
Create a new query with named parameters.
|
abstract QueryParams |
params()
Returns the
QueryParams representing customization of the N1QL query. |
static PreparedQuery |
prepared(QueryPlan plan)
Create a new prepared query without parameters (the original statement shouldn’t contain parameter placeholders).
|
static PreparedQuery |
prepared(QueryPlan plan,
JsonArray positionalParams)
Create a new prepared query with positionalParameters.
|
static PreparedQuery |
prepared(QueryPlan plan,
JsonArray positionalParams,
QueryParams params)
Create a new prepared query with positionalParameters.
|
static PreparedQuery |
prepared(QueryPlan plan,
JsonObject namedParams)
Create a new prepared query with named parameters.
|
static PreparedQuery |
prepared(QueryPlan plan,
JsonObject namedParams,
QueryParams params)
Create a new prepared query with named parameters.
|
static PreparedQuery |
prepared(QueryPlan plan,
QueryParams params)
Create a new prepared query without parameters (the original statement shouldn’t contain parameter placeholders).
|
static SimpleQuery |
simple(Statement statement)
|
static SimpleQuery |
simple(Statement statement,
QueryParams params)
|
static SimpleQuery |
simple(String statement)
Create a new
Query with a plain raw statement in String form. |
static SimpleQuery |
simple(String statement,
QueryParams params)
|
abstract Statement |
statement()
Returns the
Statement from this query. |
public abstract Statement statement()
Returns the Statement
from this query. Note that this is the only mandatory part of a N1QL query.
public abstract QueryParams params()
Returns the QueryParams
representing customization of the N1QL query.
Note that this is different from named or positional parameters (which relate to the statement).
QueryParams
for this query, null if none.public abstract JsonObject n1ql()
Convert this query to a full N1QL query in Json form.
public static SimpleQuery simple(Statement statement)
statement
- the Statement
to executepublic static SimpleQuery simple(String statement)
Create a new Query
with a plain raw statement in String form.
statement
- the raw statement string to execute (eg. “SELECT * FROM default”).public static SimpleQuery simple(Statement statement, QueryParams params)
statement
- the Statement
to executeparams
- the query parameters
.public static SimpleQuery simple(String statement, QueryParams params)
statement
- the raw statement string to execute (eg. “SELECT * FROM default”).params
- the query parameters
.public static ParametrizedQuery parametrized(Statement statement, JsonArray positionalParams)
Create a new query with positionalParameters. Note that the JsonArray
should not be mutated until n1ql()
is called since it backs the creation of the query string.
statement
- the Statement
to execute (containing positional placeholders)positionalParams
- the values for the positional placeholders in statementpublic static ParametrizedQuery parametrized(Statement statement, JsonObject namedParams)
Create a new query with named parameters. Note that the JsonObject
should not be mutated until n1ql()
is called since it backs the creation of the query string.
statement
- the Statement
to execute (containing named placeholders)namedParams
- the values for the named placeholders in statementpublic static ParametrizedQuery parametrized(Statement statement, JsonArray positionalParams, QueryParams params)
Create a new query with positionalParameters. Note that the JsonArray
should not be mutated until n1ql()
is called since it backs the creation of the query string.
statement
- the Statement
to execute (containing positional placeholders)positionalParams
- the values for the positional placeholders in statementparams
- the query parameters
.public static ParametrizedQuery parametrized(Statement statement, JsonObject namedParams, QueryParams params)
Create a new query with named parameters. Note that the JsonObject
should not be mutated until n1ql()
is called since it backs the creation of the query string.
statement
- the Statement
to execute (containing named placeholders)namedParams
- the values for the named placeholders in statementparams
- the query parameters
.public static ParametrizedQuery parametrized(String statement, JsonArray positionalParams)
Create a new query with positionalParameters. Note that the JsonArray
should not be mutated until n1ql()
is called since it backs the creation of the query string.
statement
- the raw statement to execute (containing positional placeholders)positionalParams
- the values for the positional placeholders in statementpublic static ParametrizedQuery parametrized(String statement, JsonObject namedParams)
Create a new query with named parameters. Note that the JsonObject
should not be mutated until n1ql()
is called since it backs the creation of the query string.
statement
- the raw statement to execute (containing named placeholders)namedParams
- the values for the named placeholders in statementpublic static ParametrizedQuery parametrized(String statement, JsonArray positionalParams, QueryParams params)
Create a new query with positionalParameters. Note that the JsonArray
should not be mutated until n1ql()
is called since it backs the creation of the query string.
statement
- the raw statement to execute (containing positional placeholders)positionalParams
- the values for the positional placeholders in statementparams
- the query parameters
.public static ParametrizedQuery parametrized(String statement, JsonObject namedParams, QueryParams params)
Create a new query with named parameters. Note that the JsonObject
should not be mutated until n1ql()
is called since it backs the creation of the query string.
statement
- the raw statement to execute (containing named placeholders)namedParams
- the values for the named placeholders in statementparams
- the query parameters
.public static PreparedQuery prepared(QueryPlan plan)
Create a new prepared query without parameters (the original statement shouldn’t contain parameter placeholders).
plan
- the prepared QueryPlan
to execute (containing no placeholders).public static PreparedQuery prepared(QueryPlan plan, JsonArray positionalParams)
Create a new prepared query with positionalParameters. Note that the JsonArray
should not be mutated until n1ql()
is called since it backs the creation of the query string.
plan
- the prepared QueryPlan
to execute (containing positional placeholders).positionalParams
- the values for the positional placeholders in statement.public static PreparedQuery prepared(QueryPlan plan, JsonObject namedParams)
Create a new prepared query with named parameters. Note that the JsonObject
should not be mutated until n1ql()
is called since it backs the creation of the query string.
plan
- the prepared QueryPlan
to execute (containing named placeholders).namedParams
- the values for the named placeholders in statement.public static PreparedQuery prepared(QueryPlan plan, QueryParams params)
Create a new prepared query without parameters (the original statement shouldn’t contain parameter placeholders).
plan
- the prepared QueryPlan
to execute (containing no placeholders).params
- the query parameters
.public static PreparedQuery prepared(QueryPlan plan, JsonArray positionalParams, QueryParams params)
Create a new prepared query with positionalParameters. Note that the JsonArray
should not be mutated until n1ql()
is called since it backs the creation of the query string.
plan
- the prepared QueryPlan
to execute (containing positional placeholders).positionalParams
- the values for the positional placeholders in statement.params
- the query parameters
.public static PreparedQuery prepared(QueryPlan plan, JsonObject namedParams, QueryParams params)
Create a new prepared query with named parameters. Note that the JsonObject
should not be mutated until n1ql()
is called since it backs the creation of the query string.
plan
- the prepared QueryPlan
to execute (containing named placeholders).namedParams
- the values for the named placeholders in statement.params
- the query parameters
.Copyright © 2014 Couchbase, Inc.