Search in sources :

Example 71 with ResultSet

use of com.google.cloud.spanner.ResultSet in project spring-cloud-gcp by spring-cloud.

the class SpannerTemplate method query.

@Override
public <A> List<A> query(Function<Struct, A> rowFunc, Statement statement, SpannerQueryOptions options) {
    ArrayList<A> result = new ArrayList<>();
    try (ResultSet resultSet = executeQuery(statement, options)) {
        while (resultSet.next()) {
            result.add(rowFunc.apply(resultSet.getCurrentRowAsStruct()));
        }
    }
    maybeEmitEvent(new AfterQueryEvent(result, statement, options));
    return result;
}
Also used : AfterQueryEvent(org.springframework.cloud.gcp.data.spanner.core.mapping.event.AfterQueryEvent) ArrayList(java.util.ArrayList) ResultSet(com.google.cloud.spanner.ResultSet)

Aggregations

ResultSet (com.google.cloud.spanner.ResultSet)71 Test (org.junit.Test)25 Statement (com.google.cloud.spanner.Statement)15 Struct (com.google.cloud.spanner.Struct)12 ArrayList (java.util.ArrayList)12 KeySet (com.google.cloud.spanner.KeySet)11 IntegrationTest (com.google.cloud.spanner.IntegrationTest)10 ReadContext (com.google.cloud.spanner.ReadContext)10 DatabaseClient (com.google.cloud.spanner.DatabaseClient)8 BatchReadOnlyTransaction (com.google.cloud.spanner.BatchReadOnlyTransaction)5 Mutation (com.google.cloud.spanner.Mutation)5 Partition (com.google.cloud.spanner.Partition)5 ReadOnlyTransaction (com.google.cloud.spanner.ReadOnlyTransaction)5 HashMap (java.util.HashMap)5 Key (com.google.cloud.spanner.Key)4 ReadOption (com.google.cloud.spanner.Options.ReadOption)4 Spanner (com.google.cloud.spanner.Spanner)4 SpannerOptions (com.google.cloud.spanner.SpannerOptions)4 TransactionContext (com.google.cloud.spanner.TransactionContext)4 Joiner (com.google.common.base.Joiner)4