Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge v1beta3 #833

Merged
merged 47 commits into from
Apr 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
a77fd34
Update values and keys to v1beta3
Sep 14, 2015
9f40a5f
Default projectId and namespace are empty strings, NullValue and Date…
Sep 14, 2015
660d67b
Merge pull request #161 from ajkannan/update-datastore
ajkannan Sep 19, 2015
e078469
Updates to write-related code for datastore v1beta3 update
Sep 23, 2015
959d67d
cleanup v1beta3 changes and fix LocalGcdHelper bugs
Sep 25, 2015
9463c55
Fix handling of host in DatastoreOptions.java
Oct 1, 2015
4d2fe25
Remove scheme from localhost and check if user-provided host is null/…
Oct 5, 2015
e0aaaba
Fix version in LocalGcdHelper and check for null values when removing…
Oct 5, 2015
843718a
Merge pull request #173 from ajkannan/v1beta3-write-update
ajkannan Oct 5, 2015
c029c37
Update query-related datastore code to v1beta3
Oct 5, 2015
16afb0d
fix distinct and cursor code
Oct 13, 2015
acf2c42
Include cursor workaround, fix distinct in StructuredQuery, and remov…
Oct 15, 2015
0c2f9e9
standardize distinctOn naming
Oct 15, 2015
35ea69a
Add missing case for start_cursor
Oct 16, 2015
af6ab8f
Merge pull request #212 from ajkannan/v1beta3-query-update
aozarov Oct 16, 2015
02a56a8
Don't allow user to set project id or namespace to null
Oct 16, 2015
a98d096
remove extra firstNonNull in KeyFactory
Oct 16, 2015
8245607
Merge pull request #269 from ajkannan/nonnull-projID-namespace
aozarov Oct 16, 2015
f6eeddd
Support GeoPoint value in Datastore v1beta3
Oct 19, 2015
3ccc7ed
Add getters, remove filtering
Oct 20, 2015
d75b0da
rename accessors in geopoint
Oct 20, 2015
241960f
rename geopoint to latlng
Oct 20, 2015
9e4692d
Merge pull request #270 from ajkannan/geopoint-value
aozarov Oct 20, 2015
50a5a66
Query continuation implemented for GqlQuery + tests
Oct 19, 2015
b270c64
Set namespace in Gql's nextQuery and add another batch to tests
Oct 21, 2015
6ffe927
remove changes to structured query's builder and instead use fromPb i…
Oct 21, 2015
b54c501
Merge pull request #273 from ajkannan/gql-pagination
aozarov Oct 22, 2015
bba6925
pull updates from upstream/master into update-datastore branch
Oct 22, 2015
482954f
Merge pull request #277 from ajkannan/pull-updates
aozarov Oct 22, 2015
3d7ea2c
update afterCursor javadoc
Jan 15, 2016
0864393
Merge pull request #555 from ajkannan/add-cursor-after-docs
ajkannan Jan 16, 2016
ec57eb2
Merge changes from upstream/master
Jan 29, 2016
71d91aa
Fixed missed merge conflict
Jan 29, 2016
fbe5a1d
Merge remote-tracking branch 'upstream/master' into update-datastore
Feb 2, 2016
d27d567
Fix ServiceOptions merge bug, remove unnecessary protected modifier f…
Feb 2, 2016
667e606
Merge pull request #598 from ajkannan/update-datastore
aozarov Feb 2, 2016
7e498c1
Remove userinfo scope from DatastoreOptions
Mar 1, 2016
b4bd1b9
Merge pull request #690 from ajkannan/remove-user-info-scope
aozarov Mar 1, 2016
c95e5e7
Allow eventual consistency for Datastore reads
Feb 18, 2016
76e3b3e
Clean up test code and javadoc formatting
Mar 1, 2016
0d794ea
Improve eventual consistency javadoc
Mar 1, 2016
47aae51
Merge pull request #691 from ajkannan/v1beta3-read-consistency
ajkannan Mar 1, 2016
2b52294
Merge conflict resolution.
Mar 29, 2016
1ca9616
Merge pull request #817 from ajkannan/bring-v1beta3-up-to-speed
ajkannan Mar 30, 2016
637860c
Update dependencies
Mar 30, 2016
98c6974
Merge pull request #825 from ajkannan/update-deps
aozarov Mar 31, 2016
bf918e5
Merge remote-tracking branch 'upstream/update-datastore' into merge-v…
Apr 1, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions gcloud-java-datastore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-datastore-protobuf</artifactId>
<version>v1beta2-rev1-4.0.0</version>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>com.google.api-client</groupId>
<artifactId>google-api-client</artifactId>
</exclusion>
</exclusions>
<groupId>com.google.cloud.datastore</groupId>
<artifactId>datastore-v1beta3-protos</artifactId>
<version>1.0.0-beta</version>
</dependency>
<dependency>
<groupId>com.google.cloud.datastore</groupId>
<artifactId>datastore-v1beta3-proto-client</artifactId>
<version>1.0.0-beta</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package com.google.gcloud.datastore;

import com.google.api.services.datastore.DatastoreV1;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -88,9 +88,7 @@ public final List<Entity> add(FullEntity<?>... entities) {
for (FullEntity<?> entity : entities) {
IncompleteKey key = entity.key();
Preconditions.checkArgument(key != null, "Entity must have a key");
if (key instanceof Key) {
addInternal((FullEntity<Key>) entity);
} else {
if (!(key instanceof Key)) {
incompleteKeys.add(key);
}
}
Expand All @@ -104,6 +102,7 @@ public final List<Entity> add(FullEntity<?>... entities) {
List<Entity> answer = Lists.newArrayListWithExpectedSize(entities.length);
for (FullEntity<?> entity : entities) {
if (entity.key() instanceof Key) {
addInternal((FullEntity<Key>) entity);
answer.add(Entity.convert((FullEntity<Key>) entity));
} else {
Entity entityWithAllocatedId = Entity.builder(allocated.next(), entity).build();
Expand Down Expand Up @@ -199,24 +198,30 @@ protected DatastoreException newInvalidRequest(String msg, Object... params) {
return DatastoreException.throwInvalidRequest(String.format(msg, params));
}

DatastoreV1.Mutation.Builder toMutationPb() {
DatastoreV1.Mutation.Builder mutationPb = DatastoreV1.Mutation.newBuilder();
protected List<com.google.datastore.v1beta3.Mutation> toMutationPbList() {
List<com.google.datastore.v1beta3.Mutation> mutationsPb =
new ArrayList<>();
for (FullEntity<IncompleteKey> entity : toAddAutoId()) {
mutationPb.addInsertAutoId(entity.toPb());
mutationsPb.add(
com.google.datastore.v1beta3.Mutation.newBuilder().setInsert(entity.toPb()).build());
}
for (FullEntity<Key> entity : toAdd().values()) {
mutationPb.addInsert(entity.toPb());
mutationsPb.add(
com.google.datastore.v1beta3.Mutation.newBuilder().setInsert(entity.toPb()).build());
}
for (FullEntity<Key> entity : toUpdate().values()) {
mutationPb.addUpdate(entity.toPb());
mutationsPb.add(
com.google.datastore.v1beta3.Mutation.newBuilder().setUpdate(entity.toPb()).build());
}
for (FullEntity<Key> entity : toPut().values()) {
mutationPb.addUpsert(entity.toPb());
mutationsPb.add(
com.google.datastore.v1beta3.Mutation.newBuilder().setUpsert(entity.toPb()).build());
}
for (Key key : toDelete()) {
mutationPb.addDelete(key.toPb());
mutationsPb.add(
com.google.datastore.v1beta3.Mutation.newBuilder().setDelete(key.toPb()).build());
}
return mutationPb;
return mutationsPb;
}

protected abstract Datastore datastore();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
import static com.google.gcloud.datastore.DoubleValue.of;
import static com.google.gcloud.datastore.EntityValue.of;
import static com.google.gcloud.datastore.KeyValue.of;
import static com.google.gcloud.datastore.LatLngValue.of;
import static com.google.gcloud.datastore.ListValue.of;
import static com.google.gcloud.datastore.LongValue.of;
import static com.google.gcloud.datastore.NullValue.of;
import static com.google.gcloud.datastore.StringValue.of;

import com.google.api.services.datastore.DatastoreV1;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Maps;
import com.google.protobuf.InvalidProtocolBufferException;
Expand All @@ -49,7 +49,8 @@
* @see <a href="https://cloud.google.com/datastore/docs/concepts/entities">Google Cloud Datastore
* Entities, Properties, and Keys</a>
*/
public abstract class BaseEntity<K extends IncompleteKey> extends Serializable<DatastoreV1.Entity> {
public abstract class BaseEntity<K extends IncompleteKey>
extends Serializable<com.google.datastore.v1beta3.Entity> {

private static final long serialVersionUID = 8175618724683792766L;

Expand Down Expand Up @@ -91,10 +92,11 @@ private B self() {
}

@SuppressWarnings("unchecked")
B fill(DatastoreV1.Entity entityPb) {
B fill(com.google.datastore.v1beta3.Entity entityPb) {
Map<String, Value<?>> copiedProperties = Maps.newHashMap();
for (DatastoreV1.Property property : entityPb.getPropertyList()) {
copiedProperties.put(property.getName(), Value.fromPb(property.getValue()));
for (Map.Entry<String, com.google.datastore.v1beta3.Value> entry :
entityPb.getProperties().entrySet()) {
copiedProperties.put(entry.getKey(), Value.fromPb(entry.getValue()));
}
properties(copiedProperties);
if (entityPb.hasKey()) {
Expand Down Expand Up @@ -290,6 +292,36 @@ public B set(String name, DateTime first, DateTime second, DateTime... others) {
return self();
}

/**
* Sets a property of type {@link LatLng}.
*
* @param name name of the property
* @param value value associated with the property
*/
public B set(String name, LatLng value) {
properties.put(name, of(value));
return self();
}

/**
* Sets a list property containing elements of type {@link LatLng}.
*
* @param name name of the property
* @param first the first {@link LatLng} in the list
* @param second the second {@link LatLng} in the list
* @param others other {@link LatLng}s in the list
*/
public B set(String name, LatLng first, LatLng second, LatLng... others) {
List<LatLngValue> values = new LinkedList<>();
values.add(of(first));
values.add(of(second));
for (LatLng other : others) {
values.add(of(other));
}
properties.put(name, of(values));
return self();
}

/**
* Sets a property of type {@link KeyValue}.
*
Expand Down Expand Up @@ -545,6 +577,17 @@ public DateTime getDateTime(String name) {
return ((Value<DateTime>) getValue(name)).get();
}

/**
* Returns the property value as a LatLng.
*
* @throws DatastoreException if not such property.
* @throws ClassCastException if value is not a LatLng.
*/
@SuppressWarnings("unchecked")
public LatLng getLatLng(String name) {
return ((Value<LatLng>) getValue(name)).get();
}

/**
* Returns the property value as a Key.
*
Expand Down Expand Up @@ -603,20 +646,19 @@ ImmutableSortedMap<String, Value<?>> properties() {
@Override
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
Builder<?, ?> builder = emptyBuilder();
builder.fill(DatastoreV1.Entity.parseFrom(bytesPb));
builder.fill(com.google.datastore.v1beta3.Entity.parseFrom(bytesPb));
return builder.build();
}

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

@Override
final DatastoreV1.Entity toPb() {
DatastoreV1.Entity.Builder entityPb = DatastoreV1.Entity.newBuilder();
final com.google.datastore.v1beta3.Entity toPb() {
com.google.datastore.v1beta3.Entity.Builder entityPb =
com.google.datastore.v1beta3.Entity.newBuilder();
Map<String, com.google.datastore.v1beta3.Value> propertiesPb = entityPb.getMutableProperties();
for (Map.Entry<String, Value<?>> entry : properties.entrySet()) {
DatastoreV1.Property.Builder propertyPb = DatastoreV1.Property.newBuilder();
propertyPb.setName(entry.getKey());
propertyPb.setValue(entry.getValue().toPb());
entityPb.addProperty(propertyPb.build());
propertiesPb.put(entry.getKey(), entry.getValue().toPb());
}
if (key != null) {
entityPb.setKey(key.toPb());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static com.google.gcloud.datastore.Validator.validateKind;
import static com.google.gcloud.datastore.Validator.validateNamespace;

import com.google.api.services.datastore.DatastoreV1;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;

Expand All @@ -31,7 +30,7 @@
/**
* Base class for keys.
*/
public abstract class BaseKey extends Serializable<DatastoreV1.Key> {
public abstract class BaseKey extends Serializable<com.google.datastore.v1beta3.Key> {

private static final long serialVersionUID = -4671243265877410635L;

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

String projectId;
String namespace;
String projectId = "";
String namespace = "";
String kind;
final List<PathElement> ancestors;

Expand Down Expand Up @@ -179,20 +178,15 @@ public boolean equals(Object obj) {
}

@Override
DatastoreV1.Key toPb() {
DatastoreV1.Key.Builder keyPb = DatastoreV1.Key.newBuilder();
DatastoreV1.PartitionId.Builder partitionIdPb = DatastoreV1.PartitionId.newBuilder();
if (projectId != null) {
partitionIdPb.setDatasetId(projectId);
}
if (namespace != null) {
partitionIdPb.setNamespace(namespace);
}
if (partitionIdPb.hasDatasetId() || partitionIdPb.hasNamespace()) {
keyPb.setPartitionId(partitionIdPb.build());
}
com.google.datastore.v1beta3.Key toPb() {
com.google.datastore.v1beta3.Key.Builder keyPb = com.google.datastore.v1beta3.Key.newBuilder();
com.google.datastore.v1beta3.PartitionId.Builder partitionIdPb =
com.google.datastore.v1beta3.PartitionId.newBuilder();
partitionIdPb.setProjectId(projectId);
partitionIdPb.setNamespaceId(namespace);
keyPb.setPartitionId(partitionIdPb.build());
for (PathElement pathEntry : path) {
keyPb.addPathElement(pathEntry.toPb());
keyPb.addPath(pathEntry.toPb());
}
return keyPb.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,63 +16,53 @@

package com.google.gcloud.datastore;

import com.google.api.services.datastore.DatastoreV1;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import com.google.gcloud.datastore.BatchOption.ForceWrites;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;


class BatchImpl extends BaseDatastoreBatchWriter implements Batch {

private final DatastoreImpl datastore;
private final boolean force;

static class ResponseImpl implements Batch.Response {

private final DatastoreV1.CommitResponse response;
private final com.google.datastore.v1beta3.CommitResponse response;
private final int numAutoAllocatedIds;

ResponseImpl(DatastoreV1.CommitResponse response) {
ResponseImpl(com.google.datastore.v1beta3.CommitResponse response, int numAutoAllocatedIds) {
this.response = response;
this.numAutoAllocatedIds = numAutoAllocatedIds;
}

@Override
public List<Key> generatedKeys() {
return Lists.transform(response.getMutationResult().getInsertAutoIdKeyList(),
new Function<DatastoreV1.Key, Key>() {
@Override public Key apply(DatastoreV1.Key keyPb) {
return Key.fromPb(keyPb);
}
});
Iterator<com.google.datastore.v1beta3.MutationResult> results =
response.getMutationResultsList().iterator();
List<Key> generated = new ArrayList<>(numAutoAllocatedIds);
for (int i = 0; i < numAutoAllocatedIds; i++) {
generated.add(Key.fromPb(results.next().getKey()));
}
return generated;
}
}

BatchImpl(DatastoreImpl datastore, BatchOption... options) {
BatchImpl(DatastoreImpl datastore) {
super("batch");
this.datastore = datastore;
Map<Class<? extends BatchOption>, BatchOption> optionsMap = BatchOption.asImmutableMap(options);
if (optionsMap.containsKey(ForceWrites.class)) {
force = ((ForceWrites) optionsMap.get(ForceWrites.class)).force();
} else {
force = datastore.options().force();
}
}

@Override
public Batch.Response submit() {
validateActive();
DatastoreV1.Mutation.Builder mutationPb = toMutationPb();
if (force) {
mutationPb.setForce(force);
}
DatastoreV1.CommitRequest.Builder requestPb = DatastoreV1.CommitRequest.newBuilder();
requestPb.setMode(DatastoreV1.CommitRequest.Mode.NON_TRANSACTIONAL);
requestPb.setMutation(mutationPb);
DatastoreV1.CommitResponse responsePb = datastore.commit(requestPb.build());
List<com.google.datastore.v1beta3.Mutation> mutationsPb = toMutationPbList();
com.google.datastore.v1beta3.CommitRequest.Builder requestPb =
com.google.datastore.v1beta3.CommitRequest.newBuilder();
requestPb.setMode(com.google.datastore.v1beta3.CommitRequest.Mode.NON_TRANSACTIONAL);
requestPb.addAllMutations(mutationsPb);
com.google.datastore.v1beta3.CommitResponse responsePb = datastore.commit(requestPb.build());
deactivate();
return new ResponseImpl(responsePb);
return new ResponseImpl(responsePb, toAddAutoId().size());
}

@Override
Expand Down
Loading