|
20 | 20 | import com.google.common.base.Preconditions;
|
21 | 21 | import com.google.common.collect.AbstractIterator;
|
22 | 22 | import com.google.common.collect.ImmutableList;
|
| 23 | +import com.google.common.collect.Iterables; |
23 | 24 | import com.google.common.collect.Sets;
|
| 25 | +import com.google.datastore.v1beta3.ReadOptions.ReadConsistency; |
24 | 26 | import com.google.gcloud.BaseService;
|
25 | 27 | import com.google.gcloud.RetryHelper;
|
26 | 28 | import com.google.gcloud.RetryHelper.RetryHelperException;
|
27 | 29 | import com.google.gcloud.RetryParams;
|
| 30 | +import com.google.gcloud.datastore.ReadOption.EventualConsistency; |
28 | 31 | import com.google.gcloud.spi.DatastoreRpc;
|
29 | 32 | import com.google.protobuf.ByteString;
|
30 | 33 |
|
@@ -70,6 +73,11 @@ public <T> QueryResults<T> run(Query<T> query) {
|
70 | 73 | return run(null, query);
|
71 | 74 | }
|
72 | 75 |
|
| 76 | + @Override |
| 77 | + public <T> QueryResults<T> run(Query<T> query, ReadOption... options) { |
| 78 | + return run(toReadOptionsPb(options), query); |
| 79 | + } |
| 80 | + |
73 | 81 | <T> QueryResults<T> run(com.google.datastore.v1beta3.ReadOptions readOptionsPb, Query<T> query) {
|
74 | 82 | return new QueryResultsImpl<>(this, readOptionsPb, query);
|
75 | 83 | }
|
@@ -185,16 +193,47 @@ public Entity get(Key key) {
|
185 | 193 | return DatastoreHelper.get(this, key);
|
186 | 194 | }
|
187 | 195 |
|
| 196 | + @Override |
| 197 | + public Entity get(Key key, ReadOption... options) { |
| 198 | + return DatastoreHelper.get(this, key, options); |
| 199 | + } |
| 200 | + |
188 | 201 | @Override
|
189 | 202 | public Iterator<Entity> get(Key... keys) {
|
190 | 203 | return get(null, keys);
|
191 | 204 | }
|
192 | 205 |
|
| 206 | + @Override |
| 207 | + public Iterator<Entity> get(Iterable<Key> keys, ReadOption... options) { |
| 208 | + return get(toReadOptionsPb(options), Iterables.toArray(keys, Key.class)); |
| 209 | + } |
| 210 | + |
| 211 | + private static com.google.datastore.v1beta3.ReadOptions toReadOptionsPb(ReadOption... options) { |
| 212 | + com.google.datastore.v1beta3.ReadOptions readOptionsPb = null; |
| 213 | + if (options != null) { |
| 214 | + Map<Class<? extends ReadOption>, ReadOption> optionsMap = ReadOption.asImmutableMap(options); |
| 215 | + EventualConsistency eventualConsistency = |
| 216 | + (EventualConsistency) optionsMap.get(EventualConsistency.class); |
| 217 | + if (eventualConsistency != null) { |
| 218 | + readOptionsPb = |
| 219 | + com.google.datastore.v1beta3.ReadOptions.newBuilder() |
| 220 | + .setReadConsistency(ReadConsistency.EVENTUAL) |
| 221 | + .build(); |
| 222 | + } |
| 223 | + } |
| 224 | + return readOptionsPb; |
| 225 | + } |
| 226 | + |
193 | 227 | @Override
|
194 | 228 | public List<Entity> fetch(Key... keys) {
|
195 | 229 | return DatastoreHelper.fetch(this, keys);
|
196 | 230 | }
|
197 | 231 |
|
| 232 | + @Override |
| 233 | + public List<Entity> fetch(Iterable<Key> keys, ReadOption... options) { |
| 234 | + return DatastoreHelper.fetch(this, Iterables.toArray(keys, Key.class), options); |
| 235 | + } |
| 236 | + |
198 | 237 | Iterator<Entity> get(com.google.datastore.v1beta3.ReadOptions readOptionsPb, final Key... keys) {
|
199 | 238 | if (keys.length == 0) {
|
200 | 239 | return Collections.emptyIterator();
|
|
0 commit comments