Skip to content

Commit 742ba7a

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 2751 b: refs/heads/update-datastore c: ec57eb2 h: refs/heads/master i: 2749: af5727a 2747: d2cb3ab 2743: 34daff6 2735: 2f1c385 2719: 4b960db 2687: 6a172f8
1 parent 7b6839f commit 742ba7a

76 files changed

Lines changed: 1532 additions & 1455 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/gh-pages: 4e0561bb4504bf647db669a14417b2b2c87ba45d
55
refs/heads/bigquery: 762fa5830e6c398c0396177e3e7fd243bd62cfc3
66
refs/heads/pubsub-alpha: 1a0e970f265af871e02274085b9662b3fe29058b
77
refs/heads/resource-manager: ebf4adc5ee835cd2086c4ac5b4e78d01a5a005a7
8-
refs/heads/update-datastore: 44a1533df7f7a4c3a4ed86503d03d98e6794c094
8+
refs/heads/update-datastore: ec57eb2cab88a6e5fd195e3889e4c95bfb8068fe
99
refs/tags/0.0.9: 22f1839238f66c39e67ed4dfdcd273b1ae2e8444
1010
refs/tags/v0.0.10: 207ebd2a3472fddee69fe1298eb90429e3306efd
1111
refs/tags/v0.0.11: ffbfba48a6426ff63c08ff2117e58681f251fbf2

branches/update-datastore/gcloud-java-core/src/main/java/com/google/gcloud/ServiceOptions.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static com.google.common.base.MoreObjects.firstNonNull;
2020
import static com.google.common.base.Preconditions.checkArgument;
21+
import static com.google.common.base.Preconditions.checkNotNull;
2122
import static java.nio.charset.StandardCharsets.UTF_8;
2223

2324
import com.google.api.client.extensions.appengine.http.UrlFetchTransport;
@@ -228,7 +229,8 @@ public B clock(Clock clock) {
228229
* @return the builder
229230
*/
230231
public B projectId(String projectId) {
231-
this.projectId = projectId;
232+
this.projectId =
233+
checkNotNull(projectId, "Project ID cannot be set to null. Leave unset for default.");
232234
return self();
233235
}
234236

branches/update-datastore/gcloud-java-datastore/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@
1313
<artifactId>gcloud-java-pom</artifactId>
1414
<version>0.1.4-SNAPSHOT</version>
1515
</parent>
16+
<repositories>
17+
<repository>
18+
<id>sonatype-snapshots</id>
19+
<name>sonatype-snapshots</name>
20+
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
21+
<snapshots>
22+
<enabled>true</enabled>
23+
</snapshots>
24+
</repository>
25+
</repositories>
1626
<properties>
1727
<site.installationModule>gcloud-java-datastore</site.installationModule>
1828
</properties>
@@ -22,6 +32,16 @@
2232
<artifactId>gcloud-java-core</artifactId>
2333
<version>${project.version}</version>
2434
</dependency>
35+
<dependency>
36+
<groupId>com.google.cloud.datastore</groupId>
37+
<artifactId>datastore-v1beta3-protos</artifactId>
38+
<version>0.0.1-SNAPSHOT</version>
39+
</dependency>
40+
<dependency>
41+
<groupId>com.google.cloud.datastore</groupId>
42+
<artifactId>datastore-v1beta3-proto-client</artifactId>
43+
<version>0.0.1-SNAPSHOT</version>
44+
</dependency>
2545
<dependency>
2646
<groupId>com.google.apis</groupId>
2747
<artifactId>google-api-services-datastore-protobuf</artifactId>

branches/update-datastore/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BaseDatastoreBatchWriter.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
package com.google.gcloud.datastore;
1818

19-
import com.google.api.services.datastore.DatastoreV1;
2019
import com.google.common.base.Preconditions;
2120
import com.google.common.collect.Iterables;
2221
import com.google.common.collect.Lists;
2322

23+
import java.util.ArrayList;
2424
import java.util.Collections;
2525
import java.util.Iterator;
2626
import java.util.LinkedHashMap;
@@ -88,9 +88,7 @@ public final List<Entity> add(FullEntity<?>... entities) {
8888
for (FullEntity<?> entity : entities) {
8989
IncompleteKey key = entity.key();
9090
Preconditions.checkArgument(key != null, "Entity must have a key");
91-
if (key instanceof Key) {
92-
addInternal((FullEntity<Key>) entity);
93-
} else {
91+
if (!(key instanceof Key)) {
9492
incompleteKeys.add(key);
9593
}
9694
}
@@ -104,6 +102,7 @@ public final List<Entity> add(FullEntity<?>... entities) {
104102
List<Entity> answer = Lists.newArrayListWithExpectedSize(entities.length);
105103
for (FullEntity<?> entity : entities) {
106104
if (entity.key() instanceof Key) {
105+
addInternal((FullEntity<Key>) entity);
107106
answer.add(Entity.convert((FullEntity<Key>) entity));
108107
} else {
109108
Entity entityWithAllocatedId = Entity.builder(allocated.next(), entity).build();
@@ -199,24 +198,30 @@ protected DatastoreException newInvalidRequest(String msg, Object... params) {
199198
return DatastoreException.throwInvalidRequest(String.format(msg, params));
200199
}
201200

202-
DatastoreV1.Mutation.Builder toMutationPb() {
203-
DatastoreV1.Mutation.Builder mutationPb = DatastoreV1.Mutation.newBuilder();
201+
protected List<com.google.datastore.v1beta3.Mutation> toMutationPbList() {
202+
List<com.google.datastore.v1beta3.Mutation> mutationsPb =
203+
new ArrayList<>();
204204
for (FullEntity<IncompleteKey> entity : toAddAutoId()) {
205-
mutationPb.addInsertAutoId(entity.toPb());
205+
mutationsPb.add(
206+
com.google.datastore.v1beta3.Mutation.newBuilder().setInsert(entity.toPb()).build());
206207
}
207208
for (FullEntity<Key> entity : toAdd().values()) {
208-
mutationPb.addInsert(entity.toPb());
209+
mutationsPb.add(
210+
com.google.datastore.v1beta3.Mutation.newBuilder().setInsert(entity.toPb()).build());
209211
}
210212
for (FullEntity<Key> entity : toUpdate().values()) {
211-
mutationPb.addUpdate(entity.toPb());
213+
mutationsPb.add(
214+
com.google.datastore.v1beta3.Mutation.newBuilder().setUpdate(entity.toPb()).build());
212215
}
213216
for (FullEntity<Key> entity : toPut().values()) {
214-
mutationPb.addUpsert(entity.toPb());
217+
mutationsPb.add(
218+
com.google.datastore.v1beta3.Mutation.newBuilder().setUpsert(entity.toPb()).build());
215219
}
216220
for (Key key : toDelete()) {
217-
mutationPb.addDelete(key.toPb());
221+
mutationsPb.add(
222+
com.google.datastore.v1beta3.Mutation.newBuilder().setDelete(key.toPb()).build());
218223
}
219-
return mutationPb;
224+
return mutationsPb;
220225
}
221226

222227
protected abstract Datastore datastore();

branches/update-datastore/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BaseEntity.java

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import static com.google.gcloud.datastore.DoubleValue.of;
2323
import static com.google.gcloud.datastore.EntityValue.of;
2424
import static com.google.gcloud.datastore.KeyValue.of;
25+
import static com.google.gcloud.datastore.LatLngValue.of;
2526
import static com.google.gcloud.datastore.ListValue.of;
2627
import static com.google.gcloud.datastore.LongValue.of;
2728
import static com.google.gcloud.datastore.NullValue.of;
2829
import static com.google.gcloud.datastore.StringValue.of;
2930

30-
import com.google.api.services.datastore.DatastoreV1;
3131
import com.google.common.collect.ImmutableSortedMap;
3232
import com.google.common.collect.Maps;
3333
import com.google.protobuf.InvalidProtocolBufferException;
@@ -48,7 +48,8 @@
4848
* @see <a href="https://cloud.google.com/datastore/docs/concepts/entities">Google Cloud Datastore
4949
* Entities, Properties, and Keys</a>
5050
*/
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> {
5253

5354
private static final long serialVersionUID = 8175618724683792766L;
5455

@@ -90,10 +91,11 @@ private B self() {
9091
}
9192

9293
@SuppressWarnings("unchecked")
93-
B fill(DatastoreV1.Entity entityPb) {
94+
B fill(com.google.datastore.v1beta3.Entity entityPb) {
9495
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()));
9799
}
98100
properties(copiedProperties);
99101
if (entityPb.hasKey()) {
@@ -158,6 +160,11 @@ public B set(String name, DateTime value) {
158160
return self();
159161
}
160162

163+
public B set(String name, LatLng value) {
164+
properties.put(name, of(value));
165+
return self();
166+
}
167+
161168
public B set(String name, Key value) {
162169
properties.put(name, of(value));
163170
return self();
@@ -319,6 +326,17 @@ public DateTime getDateTime(String name) {
319326
return ((Value<DateTime>) getValue(name)).get();
320327
}
321328

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+
322340
/**
323341
* Returns the property value as a Key.
324342
*
@@ -377,20 +395,19 @@ ImmutableSortedMap<String, Value<?>> properties() {
377395
@Override
378396
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
379397
Builder<?, ?> builder = emptyBuilder();
380-
builder.fill(DatastoreV1.Entity.parseFrom(bytesPb));
398+
builder.fill(com.google.datastore.v1beta3.Entity.parseFrom(bytesPb));
381399
return builder.build();
382400
}
383401

384402
protected abstract Builder<?, ?> emptyBuilder();
385403

386404
@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();
389409
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());
394411
}
395412
if (key != null) {
396413
entityPb.setKey(key.toPb());

branches/update-datastore/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BaseKey.java

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import static com.google.gcloud.datastore.Validator.validateKind;
2121
import static com.google.gcloud.datastore.Validator.validateNamespace;
2222

23-
import com.google.api.services.datastore.DatastoreV1;
2423
import com.google.common.base.Preconditions;
2524
import com.google.common.collect.ImmutableList;
2625

@@ -31,7 +30,7 @@
3130
/**
3231
* Base class for keys.
3332
*/
34-
public abstract class BaseKey extends Serializable<DatastoreV1.Key> {
33+
public abstract class BaseKey extends Serializable<com.google.datastore.v1beta3.Key> {
3534

3635
private static final long serialVersionUID = -4671243265877410635L;
3736

@@ -46,8 +45,8 @@ public abstract class BaseKey extends Serializable<DatastoreV1.Key> {
4645
*/
4746
protected abstract static class Builder<B extends Builder<B>> {
4847

49-
String projectId;
50-
String namespace;
48+
String projectId = "";
49+
String namespace = "";
5150
String kind;
5251
final List<PathElement> ancestors;
5352

@@ -177,20 +176,15 @@ public boolean equals(Object obj) {
177176
}
178177

179178
@Override
180-
DatastoreV1.Key toPb() {
181-
DatastoreV1.Key.Builder keyPb = DatastoreV1.Key.newBuilder();
182-
DatastoreV1.PartitionId.Builder partitionIdPb = DatastoreV1.PartitionId.newBuilder();
183-
if (projectId != null) {
184-
partitionIdPb.setDatasetId(projectId);
185-
}
186-
if (namespace != null) {
187-
partitionIdPb.setNamespace(namespace);
188-
}
189-
if (partitionIdPb.hasDatasetId() || partitionIdPb.hasNamespace()) {
190-
keyPb.setPartitionId(partitionIdPb.build());
191-
}
179+
com.google.datastore.v1beta3.Key toPb() {
180+
com.google.datastore.v1beta3.Key.Builder keyPb = com.google.datastore.v1beta3.Key.newBuilder();
181+
com.google.datastore.v1beta3.PartitionId.Builder partitionIdPb =
182+
com.google.datastore.v1beta3.PartitionId.newBuilder();
183+
partitionIdPb.setProjectId(projectId);
184+
partitionIdPb.setNamespaceId(namespace);
185+
keyPb.setPartitionId(partitionIdPb.build());
192186
for (PathElement pathEntry : path) {
193-
keyPb.addPathElement(pathEntry.toPb());
187+
keyPb.addPath(pathEntry.toPb());
194188
}
195189
return keyPb.build();
196190
}

branches/update-datastore/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BatchImpl.java

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,63 +16,53 @@
1616

1717
package com.google.gcloud.datastore;
1818

19-
import com.google.api.services.datastore.DatastoreV1;
20-
import com.google.common.base.Function;
21-
import com.google.common.collect.Lists;
22-
import com.google.gcloud.datastore.BatchOption.ForceWrites;
23-
19+
import java.util.ArrayList;
20+
import java.util.Iterator;
2421
import java.util.List;
25-
import java.util.Map;
2622

2723

2824
class BatchImpl extends BaseDatastoreBatchWriter implements Batch {
2925

3026
private final DatastoreImpl datastore;
31-
private final boolean force;
3227

3328
static class ResponseImpl implements Batch.Response {
3429

35-
private final DatastoreV1.CommitResponse response;
30+
private final com.google.datastore.v1beta3.CommitResponse response;
31+
private final int numAutoAllocatedIds;
3632

37-
ResponseImpl(DatastoreV1.CommitResponse response) {
33+
ResponseImpl(com.google.datastore.v1beta3.CommitResponse response, int numAutoAllocatedIds) {
3834
this.response = response;
35+
this.numAutoAllocatedIds = numAutoAllocatedIds;
3936
}
4037

4138
@Override
4239
public List<Key> generatedKeys() {
43-
return Lists.transform(response.getMutationResult().getInsertAutoIdKeyList(),
44-
new Function<DatastoreV1.Key, Key>() {
45-
@Override public Key apply(DatastoreV1.Key keyPb) {
46-
return Key.fromPb(keyPb);
47-
}
48-
});
40+
Iterator<com.google.datastore.v1beta3.MutationResult> results =
41+
response.getMutationResultsList().iterator();
42+
List<Key> generated = new ArrayList<>(numAutoAllocatedIds);
43+
for (int i = 0; i < numAutoAllocatedIds; i++) {
44+
generated.add(Key.fromPb(results.next().getKey()));
45+
}
46+
return generated;
4947
}
5048
}
5149

52-
BatchImpl(DatastoreImpl datastore, BatchOption... options) {
50+
BatchImpl(DatastoreImpl datastore) {
5351
super("batch");
5452
this.datastore = datastore;
55-
Map<Class<? extends BatchOption>, BatchOption> optionsMap = BatchOption.asImmutableMap(options);
56-
if (optionsMap.containsKey(ForceWrites.class)) {
57-
force = ((ForceWrites) optionsMap.get(ForceWrites.class)).force();
58-
} else {
59-
force = datastore.options().force();
60-
}
6153
}
6254

6355
@Override
6456
public Batch.Response submit() {
6557
validateActive();
66-
DatastoreV1.Mutation.Builder mutationPb = toMutationPb();
67-
if (force) {
68-
mutationPb.setForce(force);
69-
}
70-
DatastoreV1.CommitRequest.Builder requestPb = DatastoreV1.CommitRequest.newBuilder();
71-
requestPb.setMode(DatastoreV1.CommitRequest.Mode.NON_TRANSACTIONAL);
72-
requestPb.setMutation(mutationPb);
73-
DatastoreV1.CommitResponse responsePb = datastore.commit(requestPb.build());
58+
List<com.google.datastore.v1beta3.Mutation> mutationsPb = toMutationPbList();
59+
com.google.datastore.v1beta3.CommitRequest.Builder requestPb =
60+
com.google.datastore.v1beta3.CommitRequest.newBuilder();
61+
requestPb.setMode(com.google.datastore.v1beta3.CommitRequest.Mode.NON_TRANSACTIONAL);
62+
requestPb.addAllMutations(mutationsPb);
63+
com.google.datastore.v1beta3.CommitResponse responsePb = datastore.commit(requestPb.build());
7464
deactivate();
75-
return new ResponseImpl(responsePb);
65+
return new ResponseImpl(responsePb, toAddAutoId().size());
7666
}
7767

7868
@Override

0 commit comments

Comments
 (0)