Class N1qlUtils
java.lang.Object
org.springframework.data.couchbase.repository.query.support.N1qlUtils
Utility class to deal with constructing well formed N1QL queries around Spring Data entities, so that the framework
can use N1QL to find such entities (eg. restrict the bucket search to a particular type).
- Author:
- Simon Baslé, Subhashni Balakrishnan, Mark Paluch, Michael Reiche
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Converter<? super CouchbasePersistentProperty,String> A converter that can be used to extract thefieldName, eg. when one wants a path fromPersistentPropertyPath.toDotPath(Converter)made of escaped field names. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic N1QLQuerybuildQuery(N1QLExpression expression, com.couchbase.client.java.json.JsonValue queryPlaceholderValues, com.couchbase.client.java.query.QueryScanConsistency scanConsistency) Creates N1QLQuery object from the statement, query placeholder values and scan consistencystatic <T> N1QLExpressioncreateCountQueryForEntity(String bucketName, CouchbaseConverter converter, CouchbaseEntityInformation<T, String> entityInformation) Creates a full N1QL query that counts total number of the given entity in the bucket.static N1QLExpressioncreateReturningExpressionForDelete(String bucketName) Creates the returning clause for N1ql deletes with all attributes of the entity and meta informationstatic N1QLExpressioncreateSelectClauseForEntity(String bucketName) Produce aN1QLExpressionthat corresponds to the SELECT clause for looking for Spring Data entities stored in Couchbase.static N1QLExpressioncreateSelectClauseForEntity(String bucketName, ReturnedType returnedType, CouchbaseConverter converter) Produce aN1QLExpressionthat corresponds to the SELECT clause for looking for Spring Data entities stored in Couchbase.static N1QLExpressioncreateSelectFromForEntity(String bucketName) Produce aN1QLExpressionthat corresponds to the SELECT...FROM clauses for looking for Spring Data entities stored in Couchbase.static N1QLExpression[]createSort(Sort sort) Create a N1QLN1QLExpressionout of a Spring DataSort.static N1QLExpressioncreateWhereFilterForEntity(N1QLExpression baseWhereCriteria, CouchbaseConverter converter, EntityMetadata<?> entityInformation) Produces anN1QLExpressionthat can serve as a WHERE clause criteria to only select documents in a bucket that matches a particular Spring Data entity (as given by theEntityMetadataparameter).static N1QLExpressionescapedBucket(String bucketName) Escape the given bucketName and produce anN1QLExpression.static StringGiven aPersistentPropertyPathofCouchbasePersistentProperty(seegetPathWithAlternativeFieldNames(CouchbaseConverter, PropertyPath)), obtain a String representation of the path, separated with dots and using alternative field names.getPathWithAlternativeFieldNames(CouchbaseConverter converter, PropertyPath property) Given a commonPropertyPath, returns the correspondingPersistentPropertyPathofCouchbasePersistentPropertywhich will allow to discover alternative naming for fields.
-
Field Details
-
FIELD_NAME_ESCAPED
A converter that can be used to extract thefieldName, eg. when one wants a path fromPersistentPropertyPath.toDotPath(Converter)made of escaped field names.
-
-
Constructor Details
-
N1qlUtils
public N1qlUtils()
-
-
Method Details
-
escapedBucket
Escape the given bucketName and produce anN1QLExpression. -
createSelectClauseForEntity
public static N1QLExpression createSelectClauseForEntity(String bucketName, ReturnedType returnedType, CouchbaseConverter converter) Produce aN1QLExpressionthat corresponds to the SELECT clause for looking for Spring Data entities stored in Couchbase. Notably it will select the content of the document AND its id and cas and use custom construction of query if required.- Parameters:
bucketName- the bucket that stores the entity documents (will be escaped).returnedType- Returned type projection information from result processor.converter- couchbase converter- Returns:
- the needed SELECT clause of the statement.
-
createReturningExpressionForDelete
Creates the returning clause for N1ql deletes with all attributes of the entity and meta information- Parameters:
bucketName- the bucket that stores the entity documents (will be escaped).- Returns:
- the needed returning clause of the statement.
-
createSelectClauseForEntity
Produce aN1QLExpressionthat corresponds to the SELECT clause for looking for Spring Data entities stored in Couchbase. Notably it will select the content of the document AND its id and cas.- Parameters:
bucketName- the bucket that stores the entity documents (will be escaped).- Returns:
- the needed SELECT clause of the statement.
-
createSelectFromForEntity
Produce aN1QLExpressionthat corresponds to the SELECT...FROM clauses for looking for Spring Data entities stored in Couchbase. Notably it will select the content of the document AND its id and cas FROM the given bucket.- Parameters:
bucketName- the bucket that stores the entity documents (will be escaped).- Returns:
- the needed SELECT...FROM clauses of the statement.
-
createWhereFilterForEntity
public static N1QLExpression createWhereFilterForEntity(N1QLExpression baseWhereCriteria, CouchbaseConverter converter, EntityMetadata<?> entityInformation) Produces anN1QLExpressionthat can serve as a WHERE clause criteria to only select documents in a bucket that matches a particular Spring Data entity (as given by theEntityMetadataparameter).- Parameters:
baseWhereCriteria- the other criteria of the WHERE clause, or null if none.converter- theCouchbaseConvertergiving the attribute storing the type information can be extracted.entityInformation- the expected type information.- Returns:
- an
N1QLExpressionto be used as a WHERE clause, that additionally restricts on the given type.
-
getPathWithAlternativeFieldNames
public static PersistentPropertyPath<CouchbasePersistentProperty> getPathWithAlternativeFieldNames(CouchbaseConverter converter, PropertyPath property) Given a commonPropertyPath, returns the correspondingPersistentPropertyPathofCouchbasePersistentPropertywhich will allow to discover alternative naming for fields. -
getDottedPathWithAlternativeFieldNames
public static String getDottedPathWithAlternativeFieldNames(PersistentPropertyPath<CouchbasePersistentProperty> path) Given aPersistentPropertyPathofCouchbasePersistentProperty(seegetPathWithAlternativeFieldNames(CouchbaseConverter, PropertyPath)), obtain a String representation of the path, separated with dots and using alternative field names. -
createSort
Create a N1QLN1QLExpressionout of a Spring DataSort. Note that the later must use alternative field names as declared by theFieldannotation on the entity, if any. -
createCountQueryForEntity
public static <T> N1QLExpression createCountQueryForEntity(String bucketName, CouchbaseConverter converter, CouchbaseEntityInformation<T, String> entityInformation) Creates a full N1QL query that counts total number of the given entity in the bucket.- Parameters:
bucketName- the name of the bucket where data is stored (will be escaped).converter- theCouchbaseConvertergiving the attribute storing the type information can be extracted.entityInformation- the counted entity type.- Returns:
- the N1QL query that counts number of documents matching this entity type.
-
buildQuery
public static N1QLQuery buildQuery(N1QLExpression expression, com.couchbase.client.java.json.JsonValue queryPlaceholderValues, com.couchbase.client.java.query.QueryScanConsistency scanConsistency) Creates N1QLQuery object from the statement, query placeholder values and scan consistency- Parameters:
expression- AN1QLExpressionrepresenting the query to executequeryPlaceholderValues- The positional or named parameters needed for the queryscanConsistency- TheQueryScanConsistencyto be used.- Returns:
- A
N1QLQueryto be executed.
-