Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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): uncomment when possible in datastore v1beta3 transition
//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): Uncomment when possible in datastore v1beta3 transition
//copiedProperties.put(property.getName(), Value.fromPb(property.getValue()));
}
properties(copiedProperties);
if (entityPb.hasKey()) {
key((K) IncompleteKey.fromPb(entityPb.getKey()));
// TODO(ajaykannan): Uncomment when possible in datastore v1beta3 transition
//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): Uncomment when possible in datastore v1beta3 transition
//propertyPb.setValue(entry.getValue().toPb());
entityPb.addProperty(propertyPb.build());
}
if (key != null) {
entityPb.setKey(key.toPb());
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
//entityPb.setKey(key.toPb());
}
return entityPb.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
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.base.Strings;
import com.google.common.collect.ImmutableList;

import java.util.LinkedList;
Expand All @@ -31,7 +31,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 Down Expand Up @@ -172,20 +172,21 @@ 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);
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();
if (!Strings.isNullOrEmpty(projectId)) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

partitionIdPb.setProjectId(projectId);
}
if (namespace != null) {
partitionIdPb.setNamespace(namespace);
if (!Strings.isNullOrEmpty(namespace)) {
partitionIdPb.setNamespaceId(namespace);
}
if (partitionIdPb.hasDatasetId() || partitionIdPb.hasNamespace()) {
if (!partitionIdPb.getProjectId().isEmpty() || !partitionIdPb.getNamespaceId().isEmpty()) {
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): uncomment when possible in datastore v1beta3 transition
//return Key.fromPb(keyPb);
return Key.builder(null).build(); // TODO(ajaykannan): remove this line when possible
}
});
}
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): uncomment when possible in datastore v1beta3 transition
//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): uncomment when possible in datastore v1beta3 transition
// 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): uncomment when possible in datastore v1beta3 transition
//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): uncomment when possible in datastore v1beta3 transition
//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): uncomment when possible in datastore v1beta3 transition
//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.datastore.v1beta3.Value>

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

implements Comparable<DateTime> {

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

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

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

protected static long timestampPbToMicroseconds(com.google.protobuf.Timestamp timestampPb) {
return timestampPb.getSeconds() * 10^6 + timestampPb.getNanos() / 10^3;
}

protected static com.google.protobuf.Timestamp microsecondsToTimestampPb(long microseconds) {
long seconds = microseconds / 10^6;
int nanos = (int) (microseconds % 10^6) * 10^3;
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,7 +16,7 @@

package com.google.gcloud.datastore;

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

import com.google.api.services.datastore.DatastoreV1;

Expand All @@ -40,12 +40,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();
}

This comment was marked as spam.

@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
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

package com.google.gcloud.datastore;

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

import com.google.api.services.datastore.DatastoreV1;
import com.google.common.base.Preconditions;
import static com.google.datastore.v1beta3.Value.ENTITY_VALUE_FIELD_NUMBER;

public class EntityValue extends Value<FullEntity<?>> {

Expand All @@ -41,13 +38,16 @@ public Builder newBuilder(FullEntity<?> value) {
}

@Override
protected FullEntity<?> getValue(DatastoreV1.Value from) {
return FullEntity.fromPb(from.getEntityValue());
protected FullEntity<?> getValue(com.google.datastore.v1beta3.Value from) {
// TODO(ajaykannan): uncomment this line when possible in datastore v1beta3 transition
//return FullEntity.fromPb(from.getEntityValue());
return null; // TODO(ajaykannan): remove this line when possible
}

@Override
protected void setValue(EntityValue from, DatastoreV1.Value.Builder to) {
to.setEntityValue(from.get().toPb());
protected void setValue(EntityValue from, com.google.datastore.v1beta3.Value.Builder to) {
// TODO(ajaykannan): uncomment this line when possible in datastore v1beta3 transition
//to.setEntityValue(from.get().toPb());
}
};

Expand All @@ -57,13 +57,6 @@ private Builder() {
super(ValueType.ENTITY);
}

@Override
public Builder indexed(boolean indexed) {
// see issue #25
Preconditions.checkArgument(!indexed, "EntityValue can't be indexed");
return super.indexed(indexed);
}

@Override
public EntityValue build() {
return new EntityValue(this);
Expand All @@ -88,6 +81,6 @@ public static EntityValue of(FullEntity<?> entity) {
}

public static Builder builder(FullEntity<?> entity) {
return new Builder().set(entity).indexed(false);
return new Builder().set(entity);
}
}
Loading