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

Update values and keys to v1beta3 #161

Merged
merged 2 commits into from
Sep 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 20 additions & 0 deletions gcloud-java-datastore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,32 @@
<artifactId>gcloud-java-pom</artifactId>
<version>0.0.8-SNAPSHOT</version>
</parent>
<repositories>
<repository>
<id>sonatype-snapshots</id>
<name>sonatype-snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>gcloud-java-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.cloud.datastore</groupId>
<artifactId>datastore-v1beta3-protos</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.cloud.datastore</groupId>
<artifactId>datastore-v1beta3-proto-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-datastore-protobuf</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ protected DatastoreV1.Mutation.Builder toMutationPb() {
mutationPb.addUpsert(entity.toPb());
}
for (Key key : toDelete()) {
mutationPb.addDelete(key.toPb());
// TODO(ajaykannan): fix me!
//mutationPb.addDelete(key.toPb());
}
return mutationPb;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,13 @@ private B self() {
protected B fill(DatastoreV1.Entity entityPb) {
Map<String, Value<?>> copiedProperties = Maps.newHashMap();
for (DatastoreV1.Property property : entityPb.getPropertyList()) {
copiedProperties.put(property.getName(), Value.fromPb(property.getValue()));
// TODO(ajaykannan): fix me!
//copiedProperties.put(property.getName(), Value.fromPb(property.getValue()));
}
properties(copiedProperties);
if (entityPb.hasKey()) {
key((K) IncompleteKey.fromPb(entityPb.getKey()));
// TODO(ajaykannan): fix me!
//key((K) IncompleteKey.fromPb(entityPb.getKey()));
}
return self();
}
Expand Down Expand Up @@ -389,11 +391,13 @@ protected final DatastoreV1.Entity toPb() {
for (Map.Entry<String, Value<?>> entry : properties.entrySet()) {
DatastoreV1.Property.Builder propertyPb = DatastoreV1.Property.newBuilder();
propertyPb.setName(entry.getKey());
propertyPb.setValue(entry.getValue().toPb());
// TODO(ajaykannan): fix me!
//propertyPb.setValue(entry.getValue().toPb());
entityPb.addProperty(propertyPb.build());
}
if (key != null) {
entityPb.setKey(key.toPb());
// TODO(ajaykannan): fix me!
//entityPb.setKey(key.toPb());
}
return entityPb.build();
}
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.
*/
abstract class BaseKey extends Serializable<DatastoreV1.Key> {
abstract class BaseKey extends Serializable<com.google.datastore.v1beta3.Key> {

private static final long serialVersionUID = -4671243265877410635L;

Expand All @@ -41,8 +40,8 @@ abstract class BaseKey extends Serializable<DatastoreV1.Key> {

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 @@ -172,20 +171,15 @@ public boolean equals(Object obj) {
}

@Override
protected 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());
}
protected 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 @@ -43,7 +43,9 @@ 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);
// TODO(ajaykannan): fix me!
//return Key.fromPb(keyPb);
return Key.builder(null).build(); // TODO(ajaykannan): fix me!
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package com.google.gcloud.datastore;

import static com.google.api.services.datastore.DatastoreV1.Value.BLOB_VALUE_FIELD_NUMBER;

import com.google.api.services.datastore.DatastoreV1;
import static com.google.datastore.v1beta3.Value.BLOB_VALUE_FIELD_NUMBER;

public final class BlobValue extends Value<Blob> {

Expand All @@ -40,12 +38,12 @@ public Builder newBuilder(Blob value) {
}

@Override
protected Blob getValue(DatastoreV1.Value from) {
protected Blob getValue(com.google.datastore.v1beta3.Value from) {
return new Blob(from.getBlobValue());
}

@Override
protected void setValue(BlobValue from, DatastoreV1.Value.Builder to) {
protected void setValue(BlobValue from, com.google.datastore.v1beta3.Value.Builder to) {
to.setBlobValue(from.get().byteString());
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package com.google.gcloud.datastore;

import static com.google.api.services.datastore.DatastoreV1.Value.BOOLEAN_VALUE_FIELD_NUMBER;

import com.google.api.services.datastore.DatastoreV1;
import static com.google.datastore.v1beta3.Value.BOOLEAN_VALUE_FIELD_NUMBER;

public final class BooleanValue extends Value<Boolean> {

Expand All @@ -40,12 +38,12 @@ public Builder newBuilder(Boolean value) {
}

@Override
protected Boolean getValue(DatastoreV1.Value from) {
protected Boolean getValue(com.google.datastore.v1beta3.Value from) {
return from.getBooleanValue();
}

@Override
protected void setValue(BooleanValue from, DatastoreV1.Value.Builder to) {
protected void setValue(BooleanValue from, com.google.datastore.v1beta3.Value.Builder to) {
to.setBooleanValue(from.get());
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,14 @@ public List<Key> allocateId(IncompleteKey... keys) {
}
DatastoreV1.AllocateIdsRequest.Builder requestPb = DatastoreV1.AllocateIdsRequest.newBuilder();
for (IncompleteKey key : keys) {
requestPb.addKey(trimNameOrId(key).toPb());
// TODO(ajaykannan): fix me!
//requestPb.addKey(trimNameOrId(key).toPb());
}
DatastoreV1.AllocateIdsResponse responsePb = allocateIds(requestPb.build());
ImmutableList.Builder<Key> keyList = ImmutableList.builder();
for (DatastoreV1.Key keyPb : responsePb.getKeyList()) {
keyList.add(Key.fromPb(keyPb));
// TODO(ajaykannan): fix me!
// keyList.add(Key.fromPb(keyPb));
}
return keyList.build();
}
Expand Down Expand Up @@ -193,7 +195,8 @@ public List<Entity> add(FullEntity<?>... entities) {
if (completeEntity != null) {
responseBuilder.add(completeEntity);
} else {
responseBuilder.add(Entity.builder(Key.fromPb(allocatedKeys.next()), entity).build());
// TODO(ajaykannan): fix me!
//responseBuilder.add(Entity.builder(Key.fromPb(allocatedKeys.next()), entity).build());
}
}
return responseBuilder.build();
Expand Down Expand Up @@ -223,7 +226,8 @@ Iterator<Entity> get(DatastoreV1.ReadOptions readOptionsPb, final Key... keys) {
requestPb.setReadOptions(readOptionsPb);
}
for (Key k : Sets.newLinkedHashSet(Arrays.asList(keys))) {
requestPb.addKey(k.toPb());
// TODO(ajaykannan): fix me!
//requestPb.addKey(k.toPb());
}
return new ResultsIterator(requestPb);
}
Expand Down Expand Up @@ -310,7 +314,8 @@ public void delete(Key... keys) {
DatastoreV1.Mutation.Builder mutationPb = DatastoreV1.Mutation.newBuilder();
Set<Key> dedupKeys = new LinkedHashSet<>(Arrays.asList(keys));
for (Key key : dedupKeys) {
mutationPb.addDelete(key.toPb());
// TODO(ajaykannan): fix me!
//mutationPb.addDelete(key.toPb());
}
commitMutation(mutationPb);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import static com.google.common.base.Preconditions.checkNotNull;

import com.google.api.services.datastore.DatastoreV1;
import com.google.api.services.datastore.DatastoreV1.Value;
import com.google.protobuf.InvalidProtocolBufferException;

import org.joda.time.format.ISODateTimeFormat;
Expand All @@ -34,7 +32,7 @@
* @see <a href="https://cloud.google.com/datastore/docs/concepts/entities">Google Cloud Datastore

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

* Entities, Properties, and Keys</a>
*/
public final class DateTime extends Serializable<DatastoreV1.Value>
public final class DateTime extends Serializable<com.google.protobuf.Timestamp>
implements Comparable<DateTime> {

private static final long serialVersionUID = 7343324797621228378L;
Expand Down Expand Up @@ -98,12 +96,23 @@ public static DateTime copyFrom(Calendar calendar) {
}

@Override
protected Value toPb() {
return DatastoreV1.Value.newBuilder().setIntegerValue(timestampMicroseconds).build();
protected com.google.protobuf.Timestamp toPb() {
return microsecondsToTimestampPb(timestampMicroseconds);
}

@Override
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
return new DateTime(DatastoreV1.Value.parseFrom(bytesPb).getIntegerValue());
return new DateTime(timestampPbToMicroseconds(
com.google.protobuf.Timestamp.parseFrom(bytesPb)));
}

protected static long timestampPbToMicroseconds(com.google.protobuf.Timestamp timestampPb) {
return timestampPb.getSeconds() * 1000000 + timestampPb.getNanos() / 1000;
}

protected static com.google.protobuf.Timestamp microsecondsToTimestampPb(long microseconds) {
long seconds = microseconds / 1000000;
int nanos = (int) (microseconds % 1000000) * 1000;
return com.google.protobuf.Timestamp.newBuilder().setSeconds(seconds).setNanos(nanos).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package com.google.gcloud.datastore;

import static com.google.api.services.datastore.DatastoreV1.Value.TIMESTAMP_MICROSECONDS_VALUE_FIELD_NUMBER;

import com.google.api.services.datastore.DatastoreV1;
import static com.google.datastore.v1beta3.Value.TIMESTAMP_VALUE_FIELD_NUMBER;

public final class DateTimeValue extends Value<DateTime> {

Expand All @@ -31,7 +29,7 @@ public final class DateTimeValue extends Value<DateTime> {

@Override
public int getProtoFieldId() {
return TIMESTAMP_MICROSECONDS_VALUE_FIELD_NUMBER;
return TIMESTAMP_VALUE_FIELD_NUMBER;
}

@Override
Expand All @@ -40,13 +38,14 @@ public Builder newBuilder(DateTime value) {
}

@Override
protected DateTime getValue(DatastoreV1.Value from) {
return new DateTime(from.getTimestampMicrosecondsValue());
protected DateTime getValue(com.google.datastore.v1beta3.Value from) {
return new DateTime(DateTime.timestampPbToMicroseconds(from.getTimestampValue()));
}

@Override
protected void setValue(DateTimeValue from, DatastoreV1.Value.Builder to) {
to.setTimestampMicrosecondsValue(from.get().timestampMicroseconds());
protected void setValue(DateTimeValue from, com.google.datastore.v1beta3.Value.Builder to) {
to.setTimestampValue(DateTime.microsecondsToTimestampPb(from.get()
.timestampMicroseconds()));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package com.google.gcloud.datastore;

import static com.google.api.services.datastore.DatastoreV1.Value.DOUBLE_VALUE_FIELD_NUMBER;

import com.google.api.services.datastore.DatastoreV1;
import static com.google.datastore.v1beta3.Value.DOUBLE_VALUE_FIELD_NUMBER;

public final class DoubleValue extends Value<Double> {

Expand All @@ -40,12 +38,12 @@ public Builder newBuilder(Double value) {
}

@Override
protected Double getValue(DatastoreV1.Value from) {
protected Double getValue(com.google.datastore.v1beta3.Value from) {
return from.getDoubleValue();
}

@Override
protected void setValue(DoubleValue from, DatastoreV1.Value.Builder to) {
protected void setValue(DoubleValue from, com.google.datastore.v1beta3.Value.Builder to) {
to.setDoubleValue(from.get());
}
};
Expand Down
Loading