Package com.couchbase.client.java.query
Class N1qlQuery
- java.lang.Object
-
- com.couchbase.client.java.query.N1qlQuery
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
AbstractN1qlQuery
public abstract class N1qlQuery extends Object implements Serializable
Contract to describe N1QL queries. Queries are formed of a mandatoryStatement
and optionally can have other components, as described in each implementation of this. Also exposes factory methods for different kinds of queries.- Since:
- 2.1
- Author:
- Simon Baslé
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description N1qlQuery()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract JsonObject
n1ql()
Convert this query to a full N1QL query in Json form.static ParameterizedN1qlQuery
parameterized(Statement statement, JsonArray positionalParams)
Create a new query with positional parameters.static ParameterizedN1qlQuery
parameterized(Statement statement, JsonArray positionalParams, N1qlParams params)
Create a new query with positionalParameters.static ParameterizedN1qlQuery
parameterized(Statement statement, JsonObject namedParams)
Create a new query with named parameters.static ParameterizedN1qlQuery
parameterized(Statement statement, JsonObject namedParams, N1qlParams params)
Create a new query with named parameters.static ParameterizedN1qlQuery
parameterized(String statement, JsonArray positionalParams)
Create a new query with positionalParameters.static ParameterizedN1qlQuery
parameterized(String statement, JsonArray positionalParams, N1qlParams params)
Create a new query with positionalParameters.static ParameterizedN1qlQuery
parameterized(String statement, JsonObject namedParams)
Create a new query with named parameters.static ParameterizedN1qlQuery
parameterized(String statement, JsonObject namedParams, N1qlParams params)
Create a new query with named parameters.abstract N1qlParams
params()
Returns theN1qlParams
representing customization of the N1QL query.static SimpleN1qlQuery
simple(Statement statement)
static SimpleN1qlQuery
simple(Statement statement, N1qlParams params)
static SimpleN1qlQuery
simple(String statement)
Create a newN1qlQuery
with a plain raw statement in String form.static SimpleN1qlQuery
simple(String statement, N1qlParams params)
abstract Statement
statement()
Returns theStatement
from this query.
-
-
-
Method Detail
-
statement
public abstract Statement statement()
Returns theStatement
from this query. Note that this is the only mandatory part of a N1QL query.- Returns:
- the statement that forms the base of this query
-
params
public abstract N1qlParams params()
Returns theN1qlParams
representing customization of the N1QL query. Note that this is different from named or positional parameters (which relate to the statement).- Returns:
- the
N1qlParams
for this query, null if none.
-
n1ql
public abstract JsonObject n1ql()
Convert this query to a full N1QL query in Json form.- Returns:
- the json representation of this query (including all relevant parameters)
-
simple
public static SimpleN1qlQuery simple(Statement statement)
- Parameters:
statement
- theStatement
to execute
-
simple
public static SimpleN1qlQuery simple(String statement)
Create a newN1qlQuery
with a plain raw statement in String form.- Parameters:
statement
- the raw statement string to execute (eg. "SELECT * FROM default").
-
simple
public static SimpleN1qlQuery simple(Statement statement, N1qlParams params)
- Parameters:
statement
- theStatement
to executeparams
- thequery parameters
.
-
simple
public static SimpleN1qlQuery simple(String statement, N1qlParams params)
- Parameters:
statement
- the raw statement string to execute (eg. "SELECT * FROM default").params
- thequery parameters
.
-
parameterized
public static ParameterizedN1qlQuery parameterized(Statement statement, JsonArray positionalParams)
Create a new query with positional parameters. Note that theJsonArray
should not be mutated untiln1ql()
is called since it backs the creation of the query string. Positional parameters have the form of `$n`, where the `n` represents the position, starting with 1. The following two examples are equivalent and compare thesimple(Statement)
vs the positionalparameterized(Statement, JsonArray)
approach: Simple: ``` N1qlQuery.simple("SELECT * FROM `travel-sample` WHERE type = 'airline' and name like 'A%'") ``` Positional Params: ``` N1qlQuery.parameterized( "SELECT * FROM `travel-sample` WHERE type = $1 and name like $2", JsonArray.from("airline", "A%") ) ``` Using parameterized statements combined with non-adhoc queries (which is configurable through theN1qlParams
) can provide better performance even when the actual arguments change at execution time.- Parameters:
statement
- theStatement
to execute (containing positional placeholders)positionalParams
- the values for the positional placeholders in statement
-
parameterized
public static ParameterizedN1qlQuery parameterized(Statement statement, JsonObject namedParams)
Create a new query with named parameters. Note that theJsonObject
should not be mutated untiln1ql()
is called since it backs the creation of the query string. Named parameters have the form of `$name`, where the `name` represents the unique name. The following two examples are equivalent and compare thesimple(Statement)
vs the namedparameterized(Statement, JsonObject)
approach: Simple: ``` N1qlQuery.simple("SELECT * FROM `travel-sample` WHERE type = 'airline' and name like 'A%'") ``` Named Params: ``` N1qlQuery.parameterized( "SELECT * FROM `travel-sample` WHERE type = $type and name like $name", JsonObject.create() .put("type", "airline") .put("name", "A%") ) ``` Using parameterized statements combined with non-adhoc queries (which is configurable through theN1qlParams
) can provide better performance even when the actual arguments change at execution time.- Parameters:
statement
- theStatement
to execute (containing named placeholders)namedParams
- the values for the named placeholders in statement
-
parameterized
public static ParameterizedN1qlQuery parameterized(Statement statement, JsonArray positionalParams, N1qlParams params)
Create a new query with positionalParameters. Note that theJsonArray
should not be mutated untiln1ql()
is called since it backs the creation of the query string. Positional parameters have the form of `$n`, where the `n` represents the position, starting with 1. The following two examples are equivalent and compare thesimple(Statement)
vs the positionalparameterized(Statement, JsonArray)
approach: Simple: ``` N1qlQuery.simple("SELECT * FROM `travel-sample` WHERE type = 'airline' and name like 'A%'") ``` Positional Params: ``` N1qlQuery.parameterized( "SELECT * FROM `travel-sample` WHERE type = $1 and name like $2", JsonArray.from("airline", "A%") ) ``` Using parameterized statements combined with non-adhoc queries (which is configurable through theN1qlParams
) can provide better performance even when the actual arguments change at execution time.- Parameters:
statement
- theStatement
to execute (containing positional placeholders)positionalParams
- the values for the positional placeholders in statementparams
- thequery parameters
.
-
parameterized
public static ParameterizedN1qlQuery parameterized(Statement statement, JsonObject namedParams, N1qlParams params)
Create a new query with named parameters. Note that theJsonObject
should not be mutated untiln1ql()
is called since it backs the creation of the query string. Named parameters have the form of `$name`, where the `name` represents the unique name. The following two examples are equivalent and compare thesimple(Statement)
vs the namedparameterized(Statement, JsonObject)
approach: Simple: ``` N1qlQuery.simple("SELECT * FROM `travel-sample` WHERE type = 'airline' and name like 'A%'") ``` Named Params: ``` N1qlQuery.parameterized( "SELECT * FROM `travel-sample` WHERE type = $type and name like $name", JsonObject.create() .put("type", "airline") .put("name", "A%") ) ``` Using parameterized statements combined with non-adhoc queries (which is configurable through theN1qlParams
) can provide better performance even when the actual arguments change at execution time.- Parameters:
statement
- theStatement
to execute (containing named placeholders)namedParams
- the values for the named placeholders in statementparams
- thequery parameters
.
-
parameterized
public static ParameterizedN1qlQuery parameterized(String statement, JsonArray positionalParams)
Create a new query with positionalParameters. Note that theJsonArray
should not be mutated untiln1ql()
is called since it backs the creation of the query string. Positional parameters have the form of `$n`, where the `n` represents the position, starting with 1. The following two examples are equivalent and compare thesimple(Statement)
vs the positionalparameterized(Statement, JsonArray)
approach: Simple: ``` N1qlQuery.simple("SELECT * FROM `travel-sample` WHERE type = 'airline' and name like 'A%'") ``` Positional Params: ``` N1qlQuery.parameterized( "SELECT * FROM `travel-sample` WHERE type = $1 and name like $2", JsonArray.from("airline", "A%") ) ``` Using parameterized statements combined with non-adhoc queries (which is configurable through theN1qlParams
) can provide better performance even when the actual arguments change at execution time.- Parameters:
statement
- the raw statement to execute (containing positional placeholders)positionalParams
- the values for the positional placeholders in statement
-
parameterized
public static ParameterizedN1qlQuery parameterized(String statement, JsonObject namedParams)
Create a new query with named parameters. Note that theJsonObject
should not be mutated untiln1ql()
is called since it backs the creation of the query string. Named parameters have the form of `$name`, where the `name` represents the unique name. The following two examples are equivalent and compare thesimple(Statement)
vs the namedparameterized(Statement, JsonObject)
approach: Simple: ``` N1qlQuery.simple("SELECT * FROM `travel-sample` WHERE type = 'airline' and name like 'A%'") ``` Named Params: ``` N1qlQuery.parameterized( "SELECT * FROM `travel-sample` WHERE type = $type and name like $name", JsonObject.create() .put("type", "airline") .put("name", "A%") ) ``` Using parameterized statements combined with non-adhoc queries (which is configurable through theN1qlParams
) can provide better performance even when the actual arguments change at execution time.- Parameters:
statement
- the raw statement to execute (containing named placeholders)namedParams
- the values for the named placeholders in statement
-
parameterized
public static ParameterizedN1qlQuery parameterized(String statement, JsonArray positionalParams, N1qlParams params)
Create a new query with positionalParameters. Note that theJsonArray
should not be mutated untiln1ql()
is called since it backs the creation of the query string. Positional parameters have the form of `$n`, where the `n` represents the position, starting with 1. The following two examples are equivalent and compare thesimple(Statement)
vs the positionalparameterized(Statement, JsonArray)
approach: Simple: ``` N1qlQuery.simple("SELECT * FROM `travel-sample` WHERE type = 'airline' and name like 'A%'") ``` Positional Params: ``` N1qlQuery.parameterized( "SELECT * FROM `travel-sample` WHERE type = $1 and name like $2", JsonArray.from("airline", "A%") ) ``` Using parameterized statements combined with non-adhoc queries (which is configurable through theN1qlParams
) can provide better performance even when the actual arguments change at execution time.- Parameters:
statement
- the raw statement to execute (containing positional placeholders)positionalParams
- the values for the positional placeholders in statementparams
- thequery parameters
.
-
parameterized
public static ParameterizedN1qlQuery parameterized(String statement, JsonObject namedParams, N1qlParams params)
Create a new query with named parameters. Note that theJsonObject
should not be mutated untiln1ql()
is called since it backs the creation of the query string. Named parameters have the form of `$name`, where the `name` represents the unique name. The following two examples are equivalent and compare thesimple(Statement)
vs the namedparameterized(Statement, JsonObject)
approach: Simple: ``` N1qlQuery.simple("SELECT * FROM `travel-sample` WHERE type = 'airline' and name like 'A%'") ``` Named Params: ``` N1qlQuery.parameterized( "SELECT * FROM `travel-sample` WHERE type = $type and name like $name", JsonObject.create() .put("type", "airline") .put("name", "A%") ) ``` Using parameterized statements combined with non-adhoc queries (which is configurable through theN1qlParams
) can provide better performance even when the actual arguments change at execution time.- Parameters:
statement
- the raw statement to execute (containing named placeholders)namedParams
- the values for the named placeholders in statementparams
- thequery parameters
.
-
-