public final class SpannerStatementQueryExecutor extends Object
PartTree
parsed method
definitions.Modifier and Type | Method and Description |
---|---|
static StringBuilder |
applySort(org.springframework.data.domain.Sort sort,
StringBuilder sql,
SpannerPersistentEntity<?> persistentEntity) |
static <T> String |
applySortingPagingQueryOptions(Class<T> entityClass,
SpannerPageableQueryOptions options,
String sql,
SpannerMappingContext mappingContext,
boolean fetchInterleaved)
Apply paging and sorting options to a query string.
|
static <T> Statement |
buildQuery(KeySet keySet,
SpannerPersistentEntity<T> persistentEntity,
SpannerCustomConverter writeConverter,
SpannerMappingContext mappingContext)
Builds a query that returns the rows associated with a key set.
|
static <T> Statement |
buildQuery(KeySet keySet,
SpannerPersistentEntity<T> persistentEntity,
SpannerCustomConverter writeConverter,
SpannerMappingContext mappingContext,
String whereClause)
Builds a query that returns the rows associated with a key set with additional SQL-where.
|
static <T> Statement |
buildQuery(KeySet keySet,
SpannerPersistentEntity<T> persistentEntity,
SpannerCustomConverter writeConverter,
SpannerMappingContext mappingContext,
String whereClause,
String index)
Builds a query that returns the rows associated with a key set with additional SQL-where.
|
static Statement |
buildStatementFromSqlWithArgs(String sql,
List<String> tags,
Function<Object,Struct> paramStructConvertFunc,
SpannerCustomConverter spannerCustomConverter,
Object[] params,
Map<String,Parameter> queryMethodParams)
Creates a Cloud Spanner statement.
|
static String |
buildWhere(SpannerPersistentEntity<?> entity)
Builds an SQL where clause for the persistent entity.
|
static <T> List<T> |
executeQuery(Class<T> type,
org.springframework.data.repository.query.parser.PartTree tree,
org.springframework.data.repository.query.ParameterAccessor parameterAccessor,
Parameter[] queryMethodParamsMetadata,
SpannerTemplate spannerTemplate,
SpannerMappingContext spannerMappingContext)
Executes a PartTree-based query.
|
static <A,T> List<A> |
executeQuery(Function<Struct,A> rowFunc,
Class<T> type,
org.springframework.data.repository.query.parser.PartTree tree,
org.springframework.data.repository.query.ParameterAccessor parameterAccessor,
Parameter[] queryMethodParamsMetadata,
SpannerTemplate spannerTemplate,
SpannerMappingContext spannerMappingContext)
Executes a PartTree-based query and applies a custom row-mapping function to the
result.
|
static Statement |
getChildrenRowsQuery(Key parentKey,
SpannerPersistentProperty spannerPersistentProperty,
SpannerCustomConverter writeConverter,
SpannerMappingContext mappingContext)
Gets a
Statement that returns the rows associated with a parent entity. |
static String |
getColumnsStringForSelect(SpannerPersistentEntity<?> spannerPersistentEntity,
SpannerMappingContext mappingContext,
boolean fetchInterleaved) |
public static <T> List<T> executeQuery(Class<T> type, org.springframework.data.repository.query.parser.PartTree tree, org.springframework.data.repository.query.ParameterAccessor parameterAccessor, Parameter[] queryMethodParamsMetadata, SpannerTemplate spannerTemplate, SpannerMappingContext spannerMappingContext)
T
- the type of the underlying entitytype
- the type of the underlying entitytree
- the parsed metadata of the queryparameterAccessor
- the parameters of this specific queryqueryMethodParamsMetadata
- parameter metadata from Query MethodspannerTemplate
- used to execute the queryspannerMappingContext
- used to get metadata about the entity typepublic static <A,T> List<A> executeQuery(Function<Struct,A> rowFunc, Class<T> type, org.springframework.data.repository.query.parser.PartTree tree, org.springframework.data.repository.query.ParameterAccessor parameterAccessor, Parameter[] queryMethodParamsMetadata, SpannerTemplate spannerTemplate, SpannerMappingContext spannerMappingContext)
A
- the type to which to convert Struct paramsT
- the type of the underlying entity on which to queryrowFunc
- the function to apply to each row of the result.type
- the type of the underlying entitytree
- the parsed metadata of the queryparameterAccessor
- the parameters of this specific queryqueryMethodParamsMetadata
- parameter metadata from Query MethodspannerTemplate
- used to execute the queryspannerMappingContext
- used to get metadata about the entity typepublic static <T> String applySortingPagingQueryOptions(Class<T> entityClass, SpannerPageableQueryOptions options, String sql, SpannerMappingContext mappingContext, boolean fetchInterleaved)
T
- the domain type.entityClass
- the domain type whose table is being queried.options
- query options containing the sorting and paging optionssql
- the sql that will be wrapped with sorting and paging options.mappingContext
- a mapping context to convert between Cloud Spanner column names
and underlying property names.fetchInterleaved
- when true
additional subqueries will be added
to fetch eager-Interleaved lists with a single query.
Please note, it doesn't make sense to pass it as true
when the sql
already contains
a complete lists of all eager-Interleaved properties generated by the method getColumnsStringForSelect(com.google.cloud.spring.data.spanner.core.mapping.SpannerPersistentEntity<?>, com.google.cloud.spring.data.spanner.core.mapping.SpannerMappingContext, boolean)
.getColumnsStringForSelect(com.google.cloud.spring.data.spanner.core.mapping.SpannerPersistentEntity<?>, com.google.cloud.spring.data.spanner.core.mapping.SpannerMappingContext, boolean)
public static String buildWhere(SpannerPersistentEntity<?> entity)
entity
- the persistent entity instanceSpannerPersistentEntity.hasWhere()
,
SpannerPersistentEntity.getWhere()
public static Statement getChildrenRowsQuery(Key parentKey, SpannerPersistentProperty spannerPersistentProperty, SpannerCustomConverter writeConverter, SpannerMappingContext mappingContext)
Statement
that returns the rows associated with a parent entity. This function is
intended to be used with parent-child interleaved tables, so that the retrieval of all
child rows having the parent's key values is efficient.parentKey
- the parent key whose children to get.spannerPersistentProperty
- the property with interleaved list of child entries in the parent entity.writeConverter
- a converter to convert key values as needed to bind to the query
statement.mappingContext
- mapping contextpublic static <T> Statement buildQuery(KeySet keySet, SpannerPersistentEntity<T> persistentEntity, SpannerCustomConverter writeConverter, SpannerMappingContext mappingContext)
Where
annotation it will be used to build the query.T
- the type of the persistent entitykeySet
- the key set whose members to get.persistentEntity
- the persistent entity of the table.writeConverter
- a converter to convert key values as needed to bind to the query statement.mappingContext
- mapping contextpublic static <T> Statement buildQuery(KeySet keySet, SpannerPersistentEntity<T> persistentEntity, SpannerCustomConverter writeConverter, SpannerMappingContext mappingContext, String whereClause)
Where
of the persistentEntity
parameter
is ignored, you should pass the SQL-where as a whereClause
parameter.T
- the type of the persistent entitykeySet
- the key set whose members to get.persistentEntity
- the persistent entity of the table.writeConverter
- a converter to convert key values as needed to bind to the query statement.mappingContext
- mapping contextwhereClause
- SQL where clausepublic static <T> Statement buildQuery(KeySet keySet, SpannerPersistentEntity<T> persistentEntity, SpannerCustomConverter writeConverter, SpannerMappingContext mappingContext, String whereClause, String index)
Where
of the persistentEntity
parameter
is ignored, you should pass the SQL-where as a whereClause
parameter.
The secondary index
will be used instead of the table name when the corresponding parameter is not null.T
- the type of the persistent entitykeySet
- the key set whose members to get.persistentEntity
- the persistent entity of the table.writeConverter
- a converter to convert key values as needed to bind to the query statement.mappingContext
- mapping contextwhereClause
- SQL where clauseindex
- the secondary index namepublic static Statement buildStatementFromSqlWithArgs(String sql, List<String> tags, Function<Object,Struct> paramStructConvertFunc, SpannerCustomConverter spannerCustomConverter, Object[] params, Map<String,Parameter> queryMethodParams)
sql
- the SQL string with tags.tags
- the tags that appear in the SQL string.paramStructConvertFunc
- a function to use to convert params to Struct
objects if they cannot be directly mapped to Cloud Spanner supported param types.
If null then this last-attempt conversion is skipped.spannerCustomConverter
- a converter used to convert params that aren't Cloud
Spanner native types. if null
then this conversion is not attempted.params
- the parameters to substitute the tags. The ordering must be the same as
the tags.queryMethodParams
- the parameter metadata from Query Method if available.IllegalArgumentException
- if the number of tags does not match the number of
params, or if a param of an unsupported type is given.public static String getColumnsStringForSelect(SpannerPersistentEntity<?> spannerPersistentEntity, SpannerMappingContext mappingContext, boolean fetchInterleaved)
public static StringBuilder applySort(org.springframework.data.domain.Sort sort, StringBuilder sql, SpannerPersistentEntity<?> persistentEntity)
Copyright © 2021. All rights reserved.