Search in sources :

Example 1 with StructAccessor

use of org.springframework.cloud.gcp.data.spanner.core.convert.StructAccessor in project spring-cloud-gcp by spring-cloud.

the class SqlSpannerQuery method executeReadSql.

private List executeReadSql(Pageable pageable, Sort sort, QueryTagValue queryTagValue) {
    SpannerPageableQueryOptions spannerQueryOptions = new SpannerPageableQueryOptions().setAllowPartialRead(true);
    if (sort != null && sort.isSorted()) {
        spannerQueryOptions.setSort(sort);
    }
    if (pageable != null && pageable.isPaged()) {
        spannerQueryOptions.setOffset(pageable.getOffset()).setLimit(pageable.getPageSize());
    }
    final Class<?> returnedType = getReturnedType();
    final SpannerPersistentEntity<?> entity = returnedType == null ? null : this.spannerMappingContext.getPersistentEntity(returnedType);
    queryTagValue.sql = SpannerStatementQueryExecutor.applySortingPagingQueryOptions(this.entityType, spannerQueryOptions, queryTagValue.sql, this.spannerMappingContext, entity != null && entity.hasEagerlyLoadedProperties());
    Statement statement = buildStatementFromQueryAndTags(queryTagValue);
    return (getReturnedSimpleConvertableItemType() != null) ? this.spannerTemplate.query((struct) -> new StructAccessor(struct).getSingleValue(0), statement, spannerQueryOptions) : this.spannerTemplate.query(this.entityType, statement, spannerQueryOptions);
}
Also used : Param(org.springframework.data.repository.query.Param) Arrays(java.util.Arrays) SpannerDataException(org.springframework.cloud.gcp.data.spanner.core.mapping.SpannerDataException) ParserContext(org.springframework.expression.ParserContext) LiteralExpression(org.springframework.expression.common.LiteralExpression) HashMap(java.util.HashMap) Parameters(org.springframework.data.repository.query.Parameters) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) QueryMethodEvaluationContextProvider(org.springframework.data.repository.query.QueryMethodEvaluationContextProvider) Matcher(java.util.regex.Matcher) CompositeStringExpression(org.springframework.expression.common.CompositeStringExpression) Map(java.util.Map) Parameter(org.springframework.data.repository.query.Parameter) StreamSupport(java.util.stream.StreamSupport) SpannerTemplate(org.springframework.cloud.gcp.data.spanner.core.SpannerTemplate) Pageable(org.springframework.data.domain.Pageable) Sort(org.springframework.data.domain.Sort) SpannerPersistentEntity(org.springframework.cloud.gcp.data.spanner.core.mapping.SpannerPersistentEntity) SpannerMappingContext(org.springframework.cloud.gcp.data.spanner.core.mapping.SpannerMappingContext) Builder(com.google.cloud.spanner.Struct.Builder) SpannerPageableQueryOptions(org.springframework.cloud.gcp.data.spanner.core.SpannerPageableQueryOptions) ParametersParameterAccessor(org.springframework.data.repository.query.ParametersParameterAccessor) ParameterAccessor(org.springframework.data.repository.query.ParameterAccessor) StructAccessor(org.springframework.cloud.gcp.data.spanner.core.convert.StructAccessor) Set(java.util.Set) EvaluationContext(org.springframework.expression.EvaluationContext) Statement(com.google.cloud.spanner.Statement) List(java.util.List) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Struct(com.google.cloud.spanner.Struct) Expression(org.springframework.expression.Expression) Optional(java.util.Optional) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) Pattern(java.util.regex.Pattern) Collections(java.util.Collections) StringUtils(org.springframework.util.StringUtils) StructAccessor(org.springframework.cloud.gcp.data.spanner.core.convert.StructAccessor) Statement(com.google.cloud.spanner.Statement) SpannerPageableQueryOptions(org.springframework.cloud.gcp.data.spanner.core.SpannerPageableQueryOptions)

Aggregations

Statement (com.google.cloud.spanner.Statement)1 Struct (com.google.cloud.spanner.Struct)1 Builder (com.google.cloud.spanner.Struct.Builder)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 StreamSupport (java.util.stream.StreamSupport)1 SpannerPageableQueryOptions (org.springframework.cloud.gcp.data.spanner.core.SpannerPageableQueryOptions)1 SpannerTemplate (org.springframework.cloud.gcp.data.spanner.core.SpannerTemplate)1 StructAccessor (org.springframework.cloud.gcp.data.spanner.core.convert.StructAccessor)1 SpannerDataException (org.springframework.cloud.gcp.data.spanner.core.mapping.SpannerDataException)1