public class StringN1qlBasedQuery extends AbstractN1qlBasedQuery
RepositoryQuery
for Couchbase, based on N1QL and a String statement.
The statement can contain positional placeholders (eg. name = $1
) that will map to the
method's parameters, in the same order.
The statement can also contain SpEL expressions enclosed in #{
and }
.
There are couchbase-provided variables included for the bucket namespace
,
the ID and CAS fields
necessary for entity reconstruction
or a shortcut that covers SELECT AND FROM clauses
,
along with a variable for WHERE clause filtering
of the correct entity.Modifier and Type | Class and Description |
---|---|
static class |
StringN1qlBasedQuery.N1qlSpelValues
This class is exposed to SpEL parsing through the variable
# . |
Modifier and Type | Field and Description |
---|---|
static String |
SPEL_BUCKET
Use this variable in a SpEL expression in a
@Query
annotation's inline statement. |
static String |
SPEL_DELETE
Use this variable in a SpEL expression in a
@Query
annotation's inline statement. |
static String |
SPEL_ENTITY
Use this variable in a SpEL expression in a
@Query
annotation's inline statement. |
static String |
SPEL_FILTER
Use this variable in a SpEL expression in a
@Query
annotation's inline statement WHERE clause. |
static String |
SPEL_PREFIX |
static String |
SPEL_RETURNING
Use this variable in a SpEL expression in a
@Query
annotation's inline statement. |
static String |
SPEL_SELECT_FROM_CLAUSE
Use this variable in a SpEL expression in a
@Query
annotation's inline statement. |
queryMethod
Constructor and Description |
---|
StringN1qlBasedQuery(String statement,
CouchbaseQueryMethod queryMethod,
CouchbaseOperations couchbaseOperations,
org.springframework.expression.spel.standard.SpelExpressionParser spelParser,
org.springframework.data.repository.query.EvaluationContextProvider evaluationContextProvider) |
Modifier and Type | Method and Description |
---|---|
static StringN1qlBasedQuery.N1qlSpelValues |
createN1qlSpelValues(String bucketName,
String typeField,
Class<?> typeValue,
boolean isCount) |
protected static String |
doParse(String statement,
org.springframework.expression.spel.standard.SpelExpressionParser parser,
org.springframework.expression.EvaluationContext evaluationContext,
StringN1qlBasedQuery.N1qlSpelValues n1qlSpelValues) |
protected com.couchbase.client.java.query.Statement |
getCount(org.springframework.data.repository.query.ParameterAccessor accessor,
Object[] runtimeParameters)
The statement for a count() query.
|
protected com.couchbase.client.java.document.json.JsonValue |
getPlaceholderValues(org.springframework.data.repository.query.ParameterAccessor accessor) |
com.couchbase.client.java.query.Statement |
getStatement(org.springframework.data.repository.query.ParameterAccessor accessor,
Object[] runtimeParameters,
org.springframework.data.repository.query.ReturnedType returnedType) |
protected String |
getTypeField() |
protected Class<?> |
getTypeValue() |
protected String |
parseSpel(String statement,
boolean isCount,
Object[] runtimeParameters)
Parse the statement to detect SPEL blocks (delimited by
#{ and } )
and replace said expression blocks with their corresponding values. |
protected boolean |
useGeneratedCountQuery() |
buildQuery, execute, executeCollection, executeDependingOnType, executeEntity, executePaged, executeSingleProjection, executeSliced, executeStream, getCouchbaseOperations, getQueryMethod
public static final String SPEL_PREFIX
public static final String SPEL_SELECT_FROM_CLAUSE
@Query
annotation's inline statement. This will be replaced by the correct SELECT x FROM y
clause needed
for entity mapping. Eg. "#{} WHERE test = true"
.
Note this only makes sense once, as the beginning of the statement.public static final String SPEL_BUCKET
@Query
annotation's inline statement. This will be replaced by the (escaped) bucket name corresponding to the repository's
entity. Eg. "SELECT * FROM #{} LIMIT 3"
.public static final String SPEL_ENTITY
@Query
annotation's inline statement. This will be replaced by the fields allowing to construct the repository's entity
(SELECT clause). Eg. "SELECT #{} FROM test"
.public static final String SPEL_FILTER
@Query
annotation's inline statement WHERE clause. This will be replaced by the expression allowing to only select
documents matching the entity's class. Eg. "SELECT * FROM test WHERE test = true AND #{}"
.public static final String SPEL_DELETE
@Query
annotation's inline statement. This will be replaced by the correct delete
expression needed
Eg. "#{} WHERE test = true"
.
Note this only makes sense once, as the beginning of the statement.public static final String SPEL_RETURNING
@Query
annotation's inline statement. This will be replaced by the correct returning
clause needed
for entity mapping. Eg. "#{} WHERE test = true"
.
Note this only makes sense once, as the beginning of the statement.public StringN1qlBasedQuery(String statement, CouchbaseQueryMethod queryMethod, CouchbaseOperations couchbaseOperations, org.springframework.expression.spel.standard.SpelExpressionParser spelParser, org.springframework.data.repository.query.EvaluationContextProvider evaluationContextProvider)
protected String getTypeField()
protected Class<?> getTypeValue()
public static StringN1qlBasedQuery.N1qlSpelValues createN1qlSpelValues(String bucketName, String typeField, Class<?> typeValue, boolean isCount)
protected String parseSpel(String statement, boolean isCount, Object[] runtimeParameters)
#{
and }
)
and replace said expression blocks with their corresponding values.statement
- the full statement into which SpEL expressions should be parsed and replaced.runtimeParameters
- the parameters passed into the method at runtime.protected static String doParse(String statement, org.springframework.expression.spel.standard.SpelExpressionParser parser, org.springframework.expression.EvaluationContext evaluationContext, StringN1qlBasedQuery.N1qlSpelValues n1qlSpelValues)
protected com.couchbase.client.java.document.json.JsonValue getPlaceholderValues(org.springframework.data.repository.query.ParameterAccessor accessor)
getPlaceholderValues
in class AbstractN1qlBasedQuery
public com.couchbase.client.java.query.Statement getStatement(org.springframework.data.repository.query.ParameterAccessor accessor, Object[] runtimeParameters, org.springframework.data.repository.query.ReturnedType returnedType)
getStatement
in class AbstractN1qlBasedQuery
protected com.couchbase.client.java.query.Statement getCount(org.springframework.data.repository.query.ParameterAccessor accessor, Object[] runtimeParameters)
AbstractN1qlBasedQuery
CountFragment.COUNT_ALIAS
.getCount
in class AbstractN1qlBasedQuery
CountFragment
protected boolean useGeneratedCountQuery()
useGeneratedCountQuery
in class AbstractN1qlBasedQuery
count statement
should also be used when
the return type of the QueryMethod is a primitive type.Copyright © 2011–2017 Pivotal Software, Inc.. All rights reserved.