Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
import static com.google.cloud.datastore.NullValue.of;
import static com.google.cloud.datastore.StringValue.of;

import com.google.common.base.MoreObjects;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.Maps;
import com.google.protobuf.InvalidProtocolBufferException;

import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
Expand All @@ -49,12 +50,10 @@
* @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<com.google.datastore.v1.Entity> {
public abstract class BaseEntity<K extends IncompleteKey> implements Serializable {

private static final long serialVersionUID = 8175618724683792766L;

private final transient ImmutableSortedMap<String, Value<?>> properties;
private static final long serialVersionUID = -9070588108769487081L;
private final ImmutableSortedMap<String, Value<?>> properties;
private final K key;

public abstract static class Builder<K extends IncompleteKey, B extends Builder<K, B>> {
Expand Down Expand Up @@ -459,6 +458,14 @@ public B setNull(String name) {
this.properties = from.properties;
}

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("key", key)
.add("properties", properties)
.toString();
}

@Override
public int hashCode() {
return Objects.hash(key, properties);
Expand Down Expand Up @@ -643,16 +650,6 @@ ImmutableSortedMap<String, Value<?>> properties() {
return properties;
}

@Override
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
Builder<?, ?> builder = emptyBuilder();
builder.fill(com.google.datastore.v1.Entity.parseFrom(bytesPb));
return builder.build();
}

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

@Override
final com.google.datastore.v1.Entity toPb() {
com.google.datastore.v1.Entity.Builder entityPb = com.google.datastore.v1.Entity.newBuilder();
Map<String, com.google.datastore.v1.Value> propertiesPb = entityPb.getMutableProperties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@
import static com.google.cloud.datastore.Validator.validateKind;
import static com.google.cloud.datastore.Validator.validateNamespace;

import com.google.common.base.MoreObjects;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;

import java.io.Serializable;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

/**
* Base class for keys.
*/
public abstract class BaseKey extends Serializable<com.google.datastore.v1.Key> {
public abstract class BaseKey implements Serializable {

private static final long serialVersionUID = -4671243265877410635L;
private static final long serialVersionUID = -5897863400209818325L;

private final transient String projectId;
private final transient String namespace;
private final transient ImmutableList<PathElement> path;
private final String projectId;
private final String namespace;
private final ImmutableList<PathElement> path;

/**
* Base class for key builders.
Expand Down Expand Up @@ -158,6 +160,15 @@ public String kind() {

abstract BaseKey parent();

@Override
public String toString() {
return MoreObjects.toStringHelper(this)
.add("projectId", projectId)
.add("namespace", namespace)
.add("path", path)
.toString();
}

@Override
public int hashCode() {
return Objects.hash(projectId(), namespace(), path());
Expand All @@ -177,7 +188,6 @@ public boolean equals(Object obj) {
&& Objects.equals(path(), other.path());
}

@Override
com.google.datastore.v1.Key toPb() {
com.google.datastore.v1.Key.Builder keyPb = com.google.datastore.v1.Key.newBuilder();
com.google.datastore.v1.PartitionId.Builder partitionIdPb =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
import com.google.common.base.MoreObjects;
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.nio.ByteBuffer;

/**
Expand All @@ -36,11 +36,11 @@
* @see <a href="https://cloud.google.com/datastore/docs/concepts/entities">
* Google Cloud Datastore Entities, Properties, and Keys</a>
*/
public final class Blob extends Serializable<com.google.datastore.v1.Value> {
public final class Blob implements Serializable {

private static final long serialVersionUID = 3835421019618247721L;
private static final long serialVersionUID = 7311366042557240313L;

private final transient ByteString byteString;
private final ByteString byteString;

Blob(ByteString byteString) {
this.byteString = checkNotNull(byteString);
Expand Down Expand Up @@ -144,13 +144,7 @@ public static Blob copyFrom(InputStream input) throws IOException {
return copyFrom(bytes.toByteArray());
}

@Override
com.google.datastore.v1.Value toPb() {
return com.google.datastore.v1.Value.newBuilder().setBlobValue(byteString).build();
}

@Override
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
return new Blob(com.google.datastore.v1.Value.parseFrom(bytesPb).getBlobValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public final class BlobValue extends Value<Blob> {
static final BaseMarshaller<Blob, BlobValue, Builder> MARSHALLER =
new BaseMarshaller<Blob, BlobValue, Builder>() {

private static final long serialVersionUID = -823515687083612387L;
private static final long serialVersionUID = -739627441374592171L;

@Override
public int getProtoFieldId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

public final class BooleanValue extends Value<Boolean> {

private static final long serialVersionUID = -542649497897250340L;
private static final long serialVersionUID = -6692551696100439451L;

static final BaseMarshaller<Boolean, BooleanValue, Builder> MARSHALLER =
new BaseMarshaller<Boolean, BooleanValue, Builder>() {

private static final long serialVersionUID = 7080467411349092522L;
private static final long serialVersionUID = 5178009712526977429L;

@Override
public int getProtoFieldId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,18 @@
import com.google.common.base.MoreObjects.ToStringHelper;
import com.google.common.io.BaseEncoding;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;

This comment was marked as spam.

import java.io.Serializable;

/**
* A Google Cloud Datastore cursor.
* The cursor can be used to as a starting point or an ending point for a {@link Query}
*/
public final class Cursor extends Serializable<com.google.datastore.v1.Value> {
public final class Cursor implements Serializable {

This comment was marked as spam.

This comment was marked as spam.


private static final long serialVersionUID = -1423744878777486541L;
private static final long serialVersionUID = 4688656124180503551L;

private final transient ByteString byteString;
private final ByteString byteString;

Cursor(ByteString byteString) {
this.byteString = byteString;
Expand Down Expand Up @@ -84,17 +85,7 @@ public static Cursor copyFrom(byte[] bytes) {
return new Cursor(ByteString.copyFrom(checkNotNull(bytes)));
}

@Override
com.google.datastore.v1.Value toPb() {
return com.google.datastore.v1.Value.newBuilder().setBlobValue(byteString).build();
}

@Override
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
return fromPb(com.google.datastore.v1.Value.parseFrom(bytesPb));
}

static Cursor fromPb(com.google.datastore.v1.Value valuePb) {
return new Cursor(valuePb.getBlobValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ interface DatastoreBatchWriter extends DatastoreWriter {
/**
* {@inheritDoc}
* This operation will also remove from this batch any prior writes for entities with the same
* keys
* keys.
*
* @throws DatastoreException if not active
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@

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

import com.google.protobuf.InvalidProtocolBufferException;

import org.joda.time.format.ISODateTimeFormat;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;

Expand All @@ -32,12 +31,11 @@
* @see <a href="https://cloud.google.com/datastore/docs/concepts/entities">Google Cloud Datastore
* Entities, Properties, and Keys</a>
*/
public final class DateTime extends Serializable<com.google.protobuf.Timestamp>
implements Comparable<DateTime> {
public final class DateTime implements Comparable<DateTime>, Serializable {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.


private static final long serialVersionUID = 7343324797621228378L;
private static final long serialVersionUID = 5152143600571559844L;

private final transient long timestampMicroseconds;
private final long timestampMicroseconds;

DateTime(long timestampMicroseconds) {
this.timestampMicroseconds = timestampMicroseconds;
Expand Down Expand Up @@ -95,17 +93,10 @@ public static DateTime copyFrom(Calendar calendar) {
return copyFrom(calendar.getTime());
}

@Override
com.google.protobuf.Timestamp toPb() {
return microsecondsToTimestampPb(timestampMicroseconds);
}

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

static long timestampPbToMicroseconds(com.google.protobuf.Timestamp timestampPb) {
return timestampPb.getSeconds() * 1000000 + timestampPb.getNanos() / 1000;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

public final class DateTimeValue extends Value<DateTime> {

private static final long serialVersionUID = -5096238337676649540L;
private static final long serialVersionUID = -8502433575902990648L;

static final BaseMarshaller<DateTime, DateTimeValue, Builder> MARSHALLER =
new BaseMarshaller<DateTime, DateTimeValue, Builder>() {

private static final long serialVersionUID = -5695812592049332840L;
private static final long serialVersionUID = -5789520029958113745L;

@Override
public int getProtoFieldId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

public final class DoubleValue extends Value<Double> {

private static final long serialVersionUID = -5096238337676649540L;
private static final long serialVersionUID = -6282769624277370453L;

static final BaseMarshaller<Double, DoubleValue, Builder> MARSHALLER =
new BaseMarshaller<Double, DoubleValue, Builder>() {

private static final long serialVersionUID = 3935522813529400538L;
private static final long serialVersionUID = -48735616199736169L;

@Override
public int getProtoFieldId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*/
public final class Entity extends FullEntity<Key> {

private static final long serialVersionUID = 432961565733066915L;
private static final long serialVersionUID = 2312315289215899118L;

public static final class Builder extends BaseEntity.Builder<Key, Builder> {

Expand Down Expand Up @@ -68,11 +68,6 @@ public Entity build() {
Preconditions.checkArgument(from.key() != null);
}

@Override
protected BaseEntity.Builder<Key, Builder> emptyBuilder() {
return new Builder();
}

static Entity convert(FullEntity<Key> from) {
if (from instanceof Entity) {
return (Entity) from;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
public final class EntityQuery extends StructuredQuery<Entity> {

private static final long serialVersionUID = 2990565454831019471L;
private static final long serialVersionUID = -4748310327736758820L;

/**
* A {@code EntityQuery} builder for queries that return {@link Entity} results.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

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

private static final long serialVersionUID = -5461475706792576395L;
private static final long serialVersionUID = 2231420223179039760L;

static final BaseMarshaller<FullEntity<?>, EntityValue, Builder> MARSHALLER =
new BaseMarshaller<FullEntity<?>, EntityValue, Builder>() {

private static final long serialVersionUID = 2355075086076070931L;
private static final long serialVersionUID = 7349141367266671632L;

@Override
public int getProtoFieldId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*/
public class FullEntity<K extends IncompleteKey> extends BaseEntity<K> {

private static final long serialVersionUID = 432961565733066915L;
private static final long serialVersionUID = -2075539363782670624L;

public static class Builder<K extends IncompleteKey> extends BaseEntity.Builder<K, Builder<K>> {

Expand Down Expand Up @@ -51,11 +51,6 @@ public FullEntity<K> build() {
super(from);
}

@Override
protected BaseEntity.Builder<K, ?> emptyBuilder() {
return new Builder<K>();
}

public static Builder<IncompleteKey> builder() {
return new Builder<>();
}
Expand Down
Loading