|
22 | 22 | import static com.google.gcloud.datastore.DoubleValue.of; |
23 | 23 | import static com.google.gcloud.datastore.EntityValue.of; |
24 | 24 | import static com.google.gcloud.datastore.KeyValue.of; |
| 25 | +import static com.google.gcloud.datastore.LatLngValue.of; |
25 | 26 | import static com.google.gcloud.datastore.ListValue.of; |
26 | 27 | import static com.google.gcloud.datastore.LongValue.of; |
27 | 28 | import static com.google.gcloud.datastore.NullValue.of; |
28 | 29 | import static com.google.gcloud.datastore.StringValue.of; |
29 | 30 |
|
30 | | -import com.google.api.services.datastore.DatastoreV1; |
31 | 31 | import com.google.common.collect.ImmutableSortedMap; |
32 | 32 | import com.google.common.collect.Maps; |
33 | 33 | import com.google.protobuf.InvalidProtocolBufferException; |
|
48 | 48 | * @see <a href="https://cloud.google.com/datastore/docs/concepts/entities">Google Cloud Datastore |
49 | 49 | * Entities, Properties, and Keys</a> |
50 | 50 | */ |
51 | | -public abstract class BaseEntity<K extends IncompleteKey> extends Serializable<DatastoreV1.Entity> { |
| 51 | +public abstract class BaseEntity<K extends IncompleteKey> |
| 52 | + extends Serializable<com.google.datastore.v1beta3.Entity> { |
52 | 53 |
|
53 | 54 | private static final long serialVersionUID = 8175618724683792766L; |
54 | 55 |
|
@@ -90,10 +91,11 @@ private B self() { |
90 | 91 | } |
91 | 92 |
|
92 | 93 | @SuppressWarnings("unchecked") |
93 | | - B fill(DatastoreV1.Entity entityPb) { |
| 94 | + B fill(com.google.datastore.v1beta3.Entity entityPb) { |
94 | 95 | Map<String, Value<?>> copiedProperties = Maps.newHashMap(); |
95 | | - for (DatastoreV1.Property property : entityPb.getPropertyList()) { |
96 | | - copiedProperties.put(property.getName(), Value.fromPb(property.getValue())); |
| 96 | + for (Map.Entry<String, com.google.datastore.v1beta3.Value> entry : |
| 97 | + entityPb.getProperties().entrySet()) { |
| 98 | + copiedProperties.put(entry.getKey(), Value.fromPb(entry.getValue())); |
97 | 99 | } |
98 | 100 | properties(copiedProperties); |
99 | 101 | if (entityPb.hasKey()) { |
@@ -158,6 +160,11 @@ public B set(String name, DateTime value) { |
158 | 160 | return self(); |
159 | 161 | } |
160 | 162 |
|
| 163 | + public B set(String name, LatLng value) { |
| 164 | + properties.put(name, of(value)); |
| 165 | + return self(); |
| 166 | + } |
| 167 | + |
161 | 168 | public B set(String name, Key value) { |
162 | 169 | properties.put(name, of(value)); |
163 | 170 | return self(); |
@@ -319,6 +326,17 @@ public DateTime getDateTime(String name) { |
319 | 326 | return ((Value<DateTime>) getValue(name)).get(); |
320 | 327 | } |
321 | 328 |
|
| 329 | + /** |
| 330 | + * Returns the property value as a LatLng. |
| 331 | + * |
| 332 | + * @throws DatastoreException if not such property. |
| 333 | + * @throws ClassCastException if value is not a LatLng. |
| 334 | + */ |
| 335 | + @SuppressWarnings("unchecked") |
| 336 | + public LatLng getLatLng(String name) { |
| 337 | + return ((Value<LatLng>) getValue(name)).get(); |
| 338 | + } |
| 339 | + |
322 | 340 | /** |
323 | 341 | * Returns the property value as a Key. |
324 | 342 | * |
@@ -377,20 +395,19 @@ ImmutableSortedMap<String, Value<?>> properties() { |
377 | 395 | @Override |
378 | 396 | Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException { |
379 | 397 | Builder<?, ?> builder = emptyBuilder(); |
380 | | - builder.fill(DatastoreV1.Entity.parseFrom(bytesPb)); |
| 398 | + builder.fill(com.google.datastore.v1beta3.Entity.parseFrom(bytesPb)); |
381 | 399 | return builder.build(); |
382 | 400 | } |
383 | 401 |
|
384 | 402 | protected abstract Builder<?, ?> emptyBuilder(); |
385 | 403 |
|
386 | 404 | @Override |
387 | | - final DatastoreV1.Entity toPb() { |
388 | | - DatastoreV1.Entity.Builder entityPb = DatastoreV1.Entity.newBuilder(); |
| 405 | + final com.google.datastore.v1beta3.Entity toPb() { |
| 406 | + com.google.datastore.v1beta3.Entity.Builder entityPb = |
| 407 | + com.google.datastore.v1beta3.Entity.newBuilder(); |
| 408 | + Map<String, com.google.datastore.v1beta3.Value> propertiesPb = entityPb.getMutableProperties(); |
389 | 409 | for (Map.Entry<String, Value<?>> entry : properties.entrySet()) { |
390 | | - DatastoreV1.Property.Builder propertyPb = DatastoreV1.Property.newBuilder(); |
391 | | - propertyPb.setName(entry.getKey()); |
392 | | - propertyPb.setValue(entry.getValue().toPb()); |
393 | | - entityPb.addProperty(propertyPb.build()); |
| 410 | + propertiesPb.put(entry.getKey(), entry.getValue().toPb()); |
394 | 411 | } |
395 | 412 | if (key != null) { |
396 | 413 | entityPb.setKey(key.toPb()); |
|
0 commit comments