Skip to content

Commit 9c840d6

Browse files
authored
Merge pull request #1240 from mziccard/datastore-serializable
Remove Datastore's Serializable class and related changes
2 parents 470d948 + 5f7d381 commit 9c840d6

39 files changed

Lines changed: 182 additions & 322 deletions

google-cloud-datastore/src/main/java/com/google/cloud/datastore/BaseEntity.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,11 @@
2828
import static com.google.cloud.datastore.NullValue.of;
2929
import static com.google.cloud.datastore.StringValue.of;
3030

31+
import com.google.common.base.MoreObjects;
3132
import com.google.common.collect.ImmutableSortedMap;
3233
import com.google.common.collect.Maps;
33-
import com.google.protobuf.InvalidProtocolBufferException;
3434

35+
import java.io.Serializable;
3536
import java.util.HashMap;
3637
import java.util.LinkedList;
3738
import java.util.List;
@@ -49,12 +50,10 @@
4950
* @see <a href="https://cloud.google.com/datastore/docs/concepts/entities">Google Cloud Datastore
5051
* Entities, Properties, and Keys</a>
5152
*/
52-
public abstract class BaseEntity<K extends IncompleteKey>
53-
extends Serializable<com.google.datastore.v1.Entity> {
53+
public abstract class BaseEntity<K extends IncompleteKey> implements Serializable {
5454

55-
private static final long serialVersionUID = 8175618724683792766L;
56-
57-
private final transient ImmutableSortedMap<String, Value<?>> properties;
55+
private static final long serialVersionUID = -9070588108769487081L;
56+
private final ImmutableSortedMap<String, Value<?>> properties;
5857
private final K key;
5958

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

461+
@Override
462+
public String toString() {
463+
return MoreObjects.toStringHelper(this)
464+
.add("key", key)
465+
.add("properties", properties)
466+
.toString();
467+
}
468+
462469
@Override
463470
public int hashCode() {
464471
return Objects.hash(key, properties);
@@ -643,16 +650,6 @@ ImmutableSortedMap<String, Value<?>> properties() {
643650
return properties;
644651
}
645652

646-
@Override
647-
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
648-
Builder<?, ?> builder = emptyBuilder();
649-
builder.fill(com.google.datastore.v1.Entity.parseFrom(bytesPb));
650-
return builder.build();
651-
}
652-
653-
protected abstract Builder<?, ?> emptyBuilder();
654-
655-
@Override
656653
final com.google.datastore.v1.Entity toPb() {
657654
com.google.datastore.v1.Entity.Builder entityPb = com.google.datastore.v1.Entity.newBuilder();
658655
Map<String, com.google.datastore.v1.Value> propertiesPb = entityPb.getMutableProperties();

google-cloud-datastore/src/main/java/com/google/cloud/datastore/BaseKey.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,25 @@
2020
import static com.google.cloud.datastore.Validator.validateKind;
2121
import static com.google.cloud.datastore.Validator.validateNamespace;
2222

23+
import com.google.common.base.MoreObjects;
2324
import com.google.common.base.Preconditions;
2425
import com.google.common.collect.ImmutableList;
2526

27+
import java.io.Serializable;
2628
import java.util.LinkedList;
2729
import java.util.List;
2830
import java.util.Objects;
2931

3032
/**
3133
* Base class for keys.
3234
*/
33-
public abstract class BaseKey extends Serializable<com.google.datastore.v1.Key> {
35+
public abstract class BaseKey implements Serializable {
3436

35-
private static final long serialVersionUID = -4671243265877410635L;
37+
private static final long serialVersionUID = -5897863400209818325L;
3638

37-
private final transient String projectId;
38-
private final transient String namespace;
39-
private final transient ImmutableList<PathElement> path;
39+
private final String projectId;
40+
private final String namespace;
41+
private final ImmutableList<PathElement> path;
4042

4143
/**
4244
* Base class for key builders.
@@ -158,6 +160,15 @@ public String kind() {
158160

159161
abstract BaseKey parent();
160162

163+
@Override
164+
public String toString() {
165+
return MoreObjects.toStringHelper(this)
166+
.add("projectId", projectId)
167+
.add("namespace", namespace)
168+
.add("path", path)
169+
.toString();
170+
}
171+
161172
@Override
162173
public int hashCode() {
163174
return Objects.hash(projectId(), namespace(), path());
@@ -177,7 +188,6 @@ public boolean equals(Object obj) {
177188
&& Objects.equals(path(), other.path());
178189
}
179190

180-
@Override
181191
com.google.datastore.v1.Key toPb() {
182192
com.google.datastore.v1.Key.Builder keyPb = com.google.datastore.v1.Key.newBuilder();
183193
com.google.datastore.v1.PartitionId.Builder partitionIdPb =

google-cloud-datastore/src/main/java/com/google/cloud/datastore/Blob.java

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
import com.google.common.base.MoreObjects;
2222
import com.google.common.base.MoreObjects.ToStringHelper;
2323
import com.google.protobuf.ByteString;
24-
import com.google.protobuf.InvalidProtocolBufferException;
2524

2625
import java.io.BufferedInputStream;
2726
import java.io.ByteArrayOutputStream;
2827
import java.io.IOException;
2928
import java.io.InputStream;
29+
import java.io.Serializable;
3030
import java.nio.ByteBuffer;
3131

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

41-
private static final long serialVersionUID = 3835421019618247721L;
41+
private static final long serialVersionUID = 7311366042557240313L;
4242

43-
private final transient ByteString byteString;
43+
private final ByteString byteString;
4444

4545
Blob(ByteString byteString) {
4646
this.byteString = checkNotNull(byteString);
@@ -144,13 +144,7 @@ public static Blob copyFrom(InputStream input) throws IOException {
144144
return copyFrom(bytes.toByteArray());
145145
}
146146

147-
@Override
148147
com.google.datastore.v1.Value toPb() {
149148
return com.google.datastore.v1.Value.newBuilder().setBlobValue(byteString).build();
150149
}
151-
152-
@Override
153-
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
154-
return new Blob(com.google.datastore.v1.Value.parseFrom(bytesPb).getBlobValue());
155-
}
156150
}

google-cloud-datastore/src/main/java/com/google/cloud/datastore/BlobValue.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public final class BlobValue extends Value<Blob> {
2525
static final BaseMarshaller<Blob, BlobValue, Builder> MARSHALLER =
2626
new BaseMarshaller<Blob, BlobValue, Builder>() {
2727

28-
private static final long serialVersionUID = -823515687083612387L;
28+
private static final long serialVersionUID = -739627441374592171L;
2929

3030
@Override
3131
public int getProtoFieldId() {

google-cloud-datastore/src/main/java/com/google/cloud/datastore/BooleanValue.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
public final class BooleanValue extends Value<Boolean> {
2222

23-
private static final long serialVersionUID = -542649497897250340L;
23+
private static final long serialVersionUID = -6692551696100439451L;
2424

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

28-
private static final long serialVersionUID = 7080467411349092522L;
28+
private static final long serialVersionUID = 5178009712526977429L;
2929

3030
@Override
3131
public int getProtoFieldId() {

google-cloud-datastore/src/main/java/com/google/cloud/datastore/Cursor.java

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,18 @@
2222
import com.google.common.base.MoreObjects.ToStringHelper;
2323
import com.google.common.io.BaseEncoding;
2424
import com.google.protobuf.ByteString;
25-
import com.google.protobuf.InvalidProtocolBufferException;
25+
26+
import java.io.Serializable;
2627

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

33-
private static final long serialVersionUID = -1423744878777486541L;
34+
private static final long serialVersionUID = 4688656124180503551L;
3435

35-
private final transient ByteString byteString;
36+
private final ByteString byteString;
3637

3738
Cursor(ByteString byteString) {
3839
this.byteString = byteString;
@@ -84,17 +85,7 @@ public static Cursor copyFrom(byte[] bytes) {
8485
return new Cursor(ByteString.copyFrom(checkNotNull(bytes)));
8586
}
8687

87-
@Override
8888
com.google.datastore.v1.Value toPb() {
8989
return com.google.datastore.v1.Value.newBuilder().setBlobValue(byteString).build();
9090
}
91-
92-
@Override
93-
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
94-
return fromPb(com.google.datastore.v1.Value.parseFrom(bytesPb));
95-
}
96-
97-
static Cursor fromPb(com.google.datastore.v1.Value valuePb) {
98-
return new Cursor(valuePb.getBlobValue());
99-
}
10091
}

google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreBatchWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ interface DatastoreBatchWriter extends DatastoreWriter {
6060
/**
6161
* {@inheritDoc}
6262
* This operation will also remove from this batch any prior writes for entities with the same
63-
* keys
63+
* keys.
6464
*
6565
* @throws DatastoreException if not active
6666
*/

google-cloud-datastore/src/main/java/com/google/cloud/datastore/DateTime.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818

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

21-
import com.google.protobuf.InvalidProtocolBufferException;
22-
2321
import org.joda.time.format.ISODateTimeFormat;
2422

23+
import java.io.Serializable;
2524
import java.util.Calendar;
2625
import java.util.Date;
2726

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

38-
private static final long serialVersionUID = 7343324797621228378L;
36+
private static final long serialVersionUID = 5152143600571559844L;
3937

40-
private final transient long timestampMicroseconds;
38+
private final long timestampMicroseconds;
4139

4240
DateTime(long timestampMicroseconds) {
4341
this.timestampMicroseconds = timestampMicroseconds;
@@ -95,17 +93,10 @@ public static DateTime copyFrom(Calendar calendar) {
9593
return copyFrom(calendar.getTime());
9694
}
9795

98-
@Override
9996
com.google.protobuf.Timestamp toPb() {
10097
return microsecondsToTimestampPb(timestampMicroseconds);
10198
}
10299

103-
@Override
104-
Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
105-
return new DateTime(timestampPbToMicroseconds(
106-
com.google.protobuf.Timestamp.parseFrom(bytesPb)));
107-
}
108-
109100
static long timestampPbToMicroseconds(com.google.protobuf.Timestamp timestampPb) {
110101
return timestampPb.getSeconds() * 1000000 + timestampPb.getNanos() / 1000;
111102
}

google-cloud-datastore/src/main/java/com/google/cloud/datastore/DateTimeValue.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
public final class DateTimeValue extends Value<DateTime> {
2222

23-
private static final long serialVersionUID = -5096238337676649540L;
23+
private static final long serialVersionUID = -8502433575902990648L;
2424

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

28-
private static final long serialVersionUID = -5695812592049332840L;
28+
private static final long serialVersionUID = -5789520029958113745L;
2929

3030
@Override
3131
public int getProtoFieldId() {

google-cloud-datastore/src/main/java/com/google/cloud/datastore/DoubleValue.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020

2121
public final class DoubleValue extends Value<Double> {
2222

23-
private static final long serialVersionUID = -5096238337676649540L;
23+
private static final long serialVersionUID = -6282769624277370453L;
2424

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

28-
private static final long serialVersionUID = 3935522813529400538L;
28+
private static final long serialVersionUID = -48735616199736169L;
2929

3030
@Override
3131
public int getProtoFieldId() {

0 commit comments

Comments
 (0)