Skip to content

Commit 9e1e505

Browse files
committed
fixed merge conflicts
1 parent 18ef800 commit 9e1e505

File tree

1 file changed

+34
-0
lines changed
  • google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner

1 file changed

+34
-0
lines changed

google-cloud-clients/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SpannerImpl.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@
2525

2626
import com.google.api.client.util.BackOff;
2727
import com.google.api.client.util.ExponentialBackOff;
28+
import com.google.api.gax.paging.Page;
2829
import com.google.api.pathtemplate.PathTemplate;
2930
import com.google.cloud.BaseService;
31+
import com.google.cloud.PageImpl;
32+
import com.google.cloud.PageImpl.NextPageFetcher;
3033
import com.google.cloud.Timestamp;
3134
import com.google.cloud.spanner.AbstractReadContext.MultiUseReadOnlyTransaction;
3235
import com.google.cloud.spanner.AbstractReadContext.SingleReadContext;
3336
import com.google.cloud.spanner.AbstractReadContext.SingleUseReadOnlyTransaction;
3437
import com.google.cloud.spanner.spi.v1.SpannerRpc;
38+
import com.google.cloud.spanner.spi.v1.SpannerRpc.Paginated;
3539
import com.google.common.annotations.VisibleForTesting;
3640
import com.google.common.base.Preconditions;
3741
import com.google.common.base.Throwables;
@@ -374,6 +378,36 @@ private static <T extends Message> T unpack(Any response, Class<T> clazz)
374378
}
375379
}
376380

381+
abstract static class PageFetcher<S, T> implements NextPageFetcher<S> {
382+
private String nextPageToken;
383+
384+
@Override
385+
public Page<S> getNextPage() {
386+
Paginated<T> nextPage =
387+
runWithRetries(
388+
new Callable<Paginated<T>>() {
389+
@Override
390+
public Paginated<T> call() {
391+
return getNextPage(nextPageToken);
392+
}
393+
});
394+
this.nextPageToken = nextPage.getNextPageToken();
395+
List<S> results = new ArrayList<>();
396+
for (T proto : nextPage.getResults()) {
397+
results.add(fromProto(proto));
398+
}
399+
return new PageImpl<S>(this, nextPageToken, results);
400+
}
401+
402+
void setNextPageToken(String nextPageToken) {
403+
this.nextPageToken = nextPageToken;
404+
}
405+
406+
abstract Paginated<T> getNextPage(@Nullable String nextPageToken);
407+
408+
abstract S fromProto(T proto);
409+
}
410+
377411
class SessionImpl implements Session {
378412
private final String name;
379413
private SessionTransaction activeTransaction;

0 commit comments

Comments
 (0)