Class 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 mandatory Statement 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 Detail

      • N1qlQuery

        public N1qlQuery()
    • Method Detail

      • statement

        public abstract Statement statement()
        Returns the Statement 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 the N1qlParams 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​(String statement)
        Create a new N1qlQuery with a plain raw statement in String form.
        Parameters:
        statement - the raw statement string to execute (eg. "SELECT * FROM default").
      • parameterized

        public static ParameterizedN1qlQuery parameterized​(Statement statement,
                                                           JsonArray positionalParams)
        Create a new query with positional parameters. Note that the JsonArray should not be mutated until n1ql() 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 the simple(Statement) vs the positional parameterized(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 the N1qlParams) can provide better performance even when the actual arguments change at execution time.
        Parameters:
        statement - the Statement 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 the JsonObject should not be mutated until n1ql() 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 the simple(Statement) vs the named parameterized(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 the N1qlParams) can provide better performance even when the actual arguments change at execution time.
        Parameters:
        statement - the Statement 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 the JsonArray should not be mutated until n1ql() 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 the simple(Statement) vs the positional parameterized(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 the N1qlParams) can provide better performance even when the actual arguments change at execution time.
        Parameters:
        statement - the Statement to execute (containing positional placeholders)
        positionalParams - the values for the positional placeholders in statement
        params - the query parameters.
      • parameterized

        public static ParameterizedN1qlQuery parameterized​(Statement statement,
                                                           JsonObject namedParams,
                                                           N1qlParams 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. Named parameters have the form of `$name`, where the `name` represents the unique name. The following two examples are equivalent and compare the simple(Statement) vs the named parameterized(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 the N1qlParams) can provide better performance even when the actual arguments change at execution time.
        Parameters:
        statement - the Statement to execute (containing named placeholders)
        namedParams - the values for the named placeholders in statement
        params - the query parameters.
      • parameterized

        public static ParameterizedN1qlQuery parameterized​(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. Positional parameters have the form of `$n`, where the `n` represents the position, starting with 1. The following two examples are equivalent and compare the simple(Statement) vs the positional parameterized(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 the N1qlParams) 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 the JsonObject should not be mutated until n1ql() 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 the simple(Statement) vs the named parameterized(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 the N1qlParams) 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 the JsonArray should not be mutated until n1ql() 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 the simple(Statement) vs the positional parameterized(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 the N1qlParams) 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
        params - the query parameters.
      • parameterized

        public static ParameterizedN1qlQuery parameterized​(String statement,
                                                           JsonObject namedParams,
                                                           N1qlParams 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. Named parameters have the form of `$name`, where the `name` represents the unique name. The following two examples are equivalent and compare the simple(Statement) vs the named parameterized(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 the N1qlParams) 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
        params - the query parameters.