Skip to content

Commit c120b68

Browse files
committed
Merge pull request #68 from aozarov/temp1
adding an option to page from ListResult
2 parents 2cd8108 + 57c4242 commit c120b68

9 files changed

Lines changed: 160 additions & 55 deletions

File tree

src/main/java/com/google/gcloud/ServiceOptions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ public AuthCredentials authCredentials() {
283283
}
284284

285285
public RetryParams retryParams() {
286-
return retryParams;
286+
return retryParams != null ? retryParams : RetryParams.noRetries();
287287
}
288288

289289
public ServiceRpcFactory<R, O> serviceRpcFactory() {

src/main/java/com/google/gcloud/datastore/DatastoreServiceOptions.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class DatastoreServiceOptions extends ServiceOptions<DatastoreRpc, Datast
4444
private final String namespace;
4545
private final boolean force;
4646
private final boolean normalizeDataset;
47+
private transient DatastoreRpc datastoreRpc;
4748

4849
public static class Builder extends
4950
ServiceOptions.Builder<DatastoreRpc, DatastoreServiceOptions, Builder> {
@@ -178,10 +179,15 @@ public boolean equals(Object obj) {
178179
}
179180

180181
DatastoreRpc datastoreRpc() {
182+
if (datastoreRpc != null) {
183+
return datastoreRpc;
184+
}
181185
if (serviceRpcFactory() != null) {
182-
return serviceRpcFactory().create(this);
186+
datastoreRpc = serviceRpcFactory().create(this);
187+
} else {
188+
datastoreRpc = ServiceRpcProvider.datastore(this);
183189
}
184-
return ServiceRpcProvider.datastore(this);
190+
return datastoreRpc;
185191
}
186192

187193
public static DatastoreServiceOptions defaultInstance() {

src/main/java/com/google/gcloud/storage/BatchRequest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ public boolean equals(Object obj) {
9696
&& Objects.equals(toGet, other.toGet);
9797
}
9898

99-
Map<Blob, Iterable<BlobSourceOption>> toDelete() {
99+
public Map<Blob, Iterable<BlobSourceOption>> toDelete() {
100100
return toDelete;
101101
}
102102

103-
Map<Blob, Iterable<BlobTargetOption>> toUpdate() {
103+
public Map<Blob, Iterable<BlobTargetOption>> toUpdate() {
104104
return toUpdate;
105105
}
106106

107-
Map<Blob, Iterable<BlobSourceOption>> toGet() {
107+
public Map<Blob, Iterable<BlobSourceOption>> toGet() {
108108
return toGet;
109109
}
110110

src/main/java/com/google/gcloud/storage/BatchResponse.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public static class Result<T extends Serializable> implements Serializable {
4343
private final StorageServiceException exception;
4444

4545

46-
Result(T value) {
46+
public Result(T value) {
4747
this.value = value;
4848
this.exception = null;
4949
}
5050

51-
Result(StorageServiceException exception) {
51+
public Result(StorageServiceException exception) {
5252
this.exception = exception;
5353
this.value = null;
5454
}
@@ -112,7 +112,7 @@ static <T extends Serializable> Result<T> empty() {
112112
}
113113
}
114114

115-
BatchResponse(List<Result<Boolean>> deleteResult, List<Result<Blob>> updateResult,
115+
public BatchResponse(List<Result<Boolean>> deleteResult, List<Result<Blob>> updateResult,
116116
List<Result<Blob>> getResult) {
117117
this.deleteResult = ImmutableList.copyOf(deleteResult);
118118
this.updateResult = ImmutableList.copyOf(updateResult);

src/main/java/com/google/gcloud/storage/ListResult.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,35 @@ public final class ListResult<T extends Serializable> implements Iterable<T>, Se
3131

3232
private final String cursor;
3333
private final Iterable<T> results;
34+
private final NextPageFetcher<T> pageFetcher;
3435

35-
ListResult(String cursor, Iterable<T> results) {
36+
interface NextPageFetcher<T extends Serializable> extends Serializable {
37+
ListResult<T> nextPage();
38+
}
39+
40+
public ListResult(NextPageFetcher<T> pageFetcher, String cursor, Iterable<T> results) {
41+
this.pageFetcher = pageFetcher;
3642
this.cursor = cursor;
3743
this.results = results;
3844
}
3945

46+
/**
47+
* Returns the cursor for the nextPage or {@code null} if no more results.
48+
*/
4049
public String nextPageCursor() {
4150
return cursor;
4251
}
4352

53+
/**
54+
* Returns the results of the nextPage or {@code null} if no more result.
55+
*/
56+
public ListResult<T> nextPage() {
57+
if (cursor == null || pageFetcher == null) {
58+
return null;
59+
}
60+
return pageFetcher.nextPage();
61+
}
62+
4463
@Override
4564
public Iterator<T> iterator() {
4665
return results == null ? Collections.<T>emptyIterator() : results.iterator();

0 commit comments

Comments
 (0)