|
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; |
26 | 25 | import static com.google.gcloud.datastore.ListValue.of; |
27 | 26 | import static com.google.gcloud.datastore.LongValue.of; |
28 | 27 | import static com.google.gcloud.datastore.NullValue.of; |
29 | 28 | import static com.google.gcloud.datastore.StringValue.of; |
30 | 29 |
|
| 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; |
|
49 | 49 | * @see <a href="https://cloud.google.com/datastore/docs/concepts/entities">Google Cloud Datastore |
50 | 50 | * Entities, Properties, and Keys</a> |
51 | 51 | */ |
52 | | -public abstract class BaseEntity<K extends IncompleteKey> |
53 | | - extends Serializable<com.google.datastore.v1beta3.Entity> { |
| 52 | +public abstract class BaseEntity<K extends IncompleteKey> extends Serializable<DatastoreV1.Entity> { |
54 | 53 |
|
55 | 54 | private static final long serialVersionUID = 8175618724683792766L; |
56 | 55 |
|
@@ -92,11 +91,10 @@ private B self() { |
92 | 91 | } |
93 | 92 |
|
94 | 93 | @SuppressWarnings("unchecked") |
95 | | - B fill(com.google.datastore.v1beta3.Entity entityPb) { |
| 94 | + B fill(DatastoreV1.Entity entityPb) { |
96 | 95 | Map<String, Value<?>> copiedProperties = Maps.newHashMap(); |
97 | | - for (Map.Entry<String, com.google.datastore.v1beta3.Value> entry : |
98 | | - entityPb.getProperties().entrySet()) { |
99 | | - copiedProperties.put(entry.getKey(), Value.fromPb(entry.getValue())); |
| 96 | + for (DatastoreV1.Property property : entityPb.getPropertyList()) { |
| 97 | + copiedProperties.put(property.getName(), Value.fromPb(property.getValue())); |
100 | 98 | } |
101 | 99 | properties(copiedProperties); |
102 | 100 | if (entityPb.hasKey()) { |
@@ -292,36 +290,6 @@ public B set(String name, DateTime first, DateTime second, DateTime... others) { |
292 | 290 | return self(); |
293 | 291 | } |
294 | 292 |
|
295 | | - /** |
296 | | - * Sets a property of type {@link LatLng}. |
297 | | - * |
298 | | - * @param name name of the property |
299 | | - * @param value value associated with the property |
300 | | - */ |
301 | | - public B set(String name, LatLng value) { |
302 | | - properties.put(name, of(value)); |
303 | | - return self(); |
304 | | - } |
305 | | - |
306 | | - /** |
307 | | - * Sets a list property containing elements of type {@link LatLng}. |
308 | | - * |
309 | | - * @param name name of the property |
310 | | - * @param first the first {@link LatLng} in the list |
311 | | - * @param second the second {@link LatLng} in the list |
312 | | - * @param others other {@link LatLng}s in the list |
313 | | - */ |
314 | | - public B set(String name, LatLng first, LatLng second, LatLng... others) { |
315 | | - List<LatLngValue> values = new LinkedList<>(); |
316 | | - values.add(of(first)); |
317 | | - values.add(of(second)); |
318 | | - for (LatLng other : others) { |
319 | | - values.add(of(other)); |
320 | | - } |
321 | | - properties.put(name, of(values)); |
322 | | - return self(); |
323 | | - } |
324 | | - |
325 | 293 | /** |
326 | 294 | * Sets a property of type {@link KeyValue}. |
327 | 295 | * |
@@ -577,17 +545,6 @@ public DateTime getDateTime(String name) { |
577 | 545 | return ((Value<DateTime>) getValue(name)).get(); |
578 | 546 | } |
579 | 547 |
|
580 | | - /** |
581 | | - * Returns the property value as a LatLng. |
582 | | - * |
583 | | - * @throws DatastoreException if not such property. |
584 | | - * @throws ClassCastException if value is not a LatLng. |
585 | | - */ |
586 | | - @SuppressWarnings("unchecked") |
587 | | - public LatLng getLatLng(String name) { |
588 | | - return ((Value<LatLng>) getValue(name)).get(); |
589 | | - } |
590 | | - |
591 | 548 | /** |
592 | 549 | * Returns the property value as a Key. |
593 | 550 | * |
@@ -646,19 +603,20 @@ ImmutableSortedMap<String, Value<?>> properties() { |
646 | 603 | @Override |
647 | 604 | Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException { |
648 | 605 | Builder<?, ?> builder = emptyBuilder(); |
649 | | - builder.fill(com.google.datastore.v1beta3.Entity.parseFrom(bytesPb)); |
| 606 | + builder.fill(DatastoreV1.Entity.parseFrom(bytesPb)); |
650 | 607 | return builder.build(); |
651 | 608 | } |
652 | 609 |
|
653 | 610 | protected abstract Builder<?, ?> emptyBuilder(); |
654 | 611 |
|
655 | 612 | @Override |
656 | | - final com.google.datastore.v1beta3.Entity toPb() { |
657 | | - com.google.datastore.v1beta3.Entity.Builder entityPb = |
658 | | - com.google.datastore.v1beta3.Entity.newBuilder(); |
659 | | - Map<String, com.google.datastore.v1beta3.Value> propertiesPb = entityPb.getMutableProperties(); |
| 613 | + final DatastoreV1.Entity toPb() { |
| 614 | + DatastoreV1.Entity.Builder entityPb = DatastoreV1.Entity.newBuilder(); |
660 | 615 | for (Map.Entry<String, Value<?>> entry : properties.entrySet()) { |
661 | | - propertiesPb.put(entry.getKey(), entry.getValue().toPb()); |
| 616 | + DatastoreV1.Property.Builder propertyPb = DatastoreV1.Property.newBuilder(); |
| 617 | + propertyPb.setName(entry.getKey()); |
| 618 | + propertyPb.setValue(entry.getValue().toPb()); |
| 619 | + entityPb.addProperty(propertyPb.build()); |
662 | 620 | } |
663 | 621 | if (key != null) { |
664 | 622 | entityPb.setKey(key.toPb()); |
|
0 commit comments