Skip to content

Commit 9f40a5f

Browse files
author
Ajay Kannan
committed
Default projectId and namespace are empty strings, NullValue and DateTime are fixed, along with other minor edits
1 parent a77fd34 commit 9f40a5f

26 files changed

+125
-125
lines changed

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BaseDatastoreBatchWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ protected DatastoreV1.Mutation.Builder toMutationPb() {
214214
mutationPb.addUpsert(entity.toPb());
215215
}
216216
for (Key key : toDelete()) {
217-
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
217+
// TODO(ajaykannan): fix me!
218218
//mutationPb.addDelete(key.toPb());
219219
}
220220
return mutationPb;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ private B self() {
9393
protected B fill(DatastoreV1.Entity entityPb) {
9494
Map<String, Value<?>> copiedProperties = Maps.newHashMap();
9595
for (DatastoreV1.Property property : entityPb.getPropertyList()) {
96-
// TODO(ajaykannan): Uncomment when possible in datastore v1beta3 transition
96+
// TODO(ajaykannan): fix me!
9797
//copiedProperties.put(property.getName(), Value.fromPb(property.getValue()));
9898
}
9999
properties(copiedProperties);
100100
if (entityPb.hasKey()) {
101-
// TODO(ajaykannan): Uncomment when possible in datastore v1beta3 transition
101+
// TODO(ajaykannan): fix me!
102102
//key((K) IncompleteKey.fromPb(entityPb.getKey()));
103103
}
104104
return self();
@@ -391,12 +391,12 @@ protected final DatastoreV1.Entity toPb() {
391391
for (Map.Entry<String, Value<?>> entry : properties.entrySet()) {
392392
DatastoreV1.Property.Builder propertyPb = DatastoreV1.Property.newBuilder();
393393
propertyPb.setName(entry.getKey());
394-
// TODO(ajaykannan): Uncomment when possible in datastore v1beta3 transition
394+
// TODO(ajaykannan): fix me!
395395
//propertyPb.setValue(entry.getValue().toPb());
396396
entityPb.addProperty(propertyPb.build());
397397
}
398398
if (key != null) {
399-
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
399+
// TODO(ajaykannan): fix me!
400400
//entityPb.setKey(key.toPb());
401401
}
402402
return entityPb.build();

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import static com.google.gcloud.datastore.Validator.validateNamespace;
2222

2323
import com.google.common.base.Preconditions;
24-
import com.google.common.base.Strings;
2524
import com.google.common.collect.ImmutableList;
2625

2726
import java.util.LinkedList;
@@ -41,8 +40,8 @@ abstract class BaseKey extends Serializable<com.google.datastore.v1beta3.Key> {
4140

4241
abstract static class Builder<B extends Builder<B>> {
4342

44-
String projectId;
45-
String namespace;
43+
String projectId = "";
44+
String namespace = "";
4645
String kind;
4746
final List<PathElement> ancestors;
4847

@@ -176,15 +175,9 @@ protected com.google.datastore.v1beta3.Key toPb() {
176175
com.google.datastore.v1beta3.Key.Builder keyPb = com.google.datastore.v1beta3.Key.newBuilder();
177176
com.google.datastore.v1beta3.PartitionId.Builder partitionIdPb =
178177
com.google.datastore.v1beta3.PartitionId.newBuilder();
179-
if (!Strings.isNullOrEmpty(projectId)) {
180-
partitionIdPb.setProjectId(projectId);
181-
}
182-
if (!Strings.isNullOrEmpty(namespace)) {
183-
partitionIdPb.setNamespaceId(namespace);
184-
}
185-
if (!partitionIdPb.getProjectId().isEmpty() || !partitionIdPb.getNamespaceId().isEmpty()) {
186-
keyPb.setPartitionId(partitionIdPb.build());
187-
}
178+
partitionIdPb.setProjectId(projectId);
179+
partitionIdPb.setNamespaceId(namespace);
180+
keyPb.setPartitionId(partitionIdPb.build());
188181
for (PathElement pathEntry : path) {
189182
keyPb.addPath(pathEntry.toPb());
190183
}

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/BatchImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public List<Key> generatedKeys() {
4343
return Lists.transform(response.getMutationResult().getInsertAutoIdKeyList(),
4444
new Function<DatastoreV1.Key, Key>() {
4545
@Override public Key apply(DatastoreV1.Key keyPb) {
46-
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
46+
// TODO(ajaykannan): fix me!
4747
//return Key.fromPb(keyPb);
48-
return Key.builder(null).build(); // TODO(ajaykannan): remove this line when possible
48+
return Key.builder(null).build(); // TODO(ajaykannan): fix me!
4949
}
5050
});
5151
}

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/DatastoreImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,13 +126,13 @@ public List<Key> allocateId(IncompleteKey... keys) {
126126
}
127127
DatastoreV1.AllocateIdsRequest.Builder requestPb = DatastoreV1.AllocateIdsRequest.newBuilder();
128128
for (IncompleteKey key : keys) {
129-
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
129+
// TODO(ajaykannan): fix me!
130130
//requestPb.addKey(trimNameOrId(key).toPb());
131131
}
132132
DatastoreV1.AllocateIdsResponse responsePb = allocateIds(requestPb.build());
133133
ImmutableList.Builder<Key> keyList = ImmutableList.builder();
134134
for (DatastoreV1.Key keyPb : responsePb.getKeyList()) {
135-
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
135+
// TODO(ajaykannan): fix me!
136136
// keyList.add(Key.fromPb(keyPb));
137137
}
138138
return keyList.build();
@@ -195,7 +195,7 @@ public List<Entity> add(FullEntity<?>... entities) {
195195
if (completeEntity != null) {
196196
responseBuilder.add(completeEntity);
197197
} else {
198-
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
198+
// TODO(ajaykannan): fix me!
199199
//responseBuilder.add(Entity.builder(Key.fromPb(allocatedKeys.next()), entity).build());
200200
}
201201
}
@@ -226,7 +226,7 @@ Iterator<Entity> get(DatastoreV1.ReadOptions readOptionsPb, final Key... keys) {
226226
requestPb.setReadOptions(readOptionsPb);
227227
}
228228
for (Key k : Sets.newLinkedHashSet(Arrays.asList(keys))) {
229-
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
229+
// TODO(ajaykannan): fix me!
230230
//requestPb.addKey(k.toPb());
231231
}
232232
return new ResultsIterator(requestPb);
@@ -314,7 +314,7 @@ public void delete(Key... keys) {
314314
DatastoreV1.Mutation.Builder mutationPb = DatastoreV1.Mutation.newBuilder();
315315
Set<Key> dedupKeys = new LinkedHashSet<>(Arrays.asList(keys));
316316
for (Key key : dedupKeys) {
317-
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
317+
// TODO(ajaykannan): fix me!
318318
//mutationPb.addDelete(key.toPb());
319319
}
320320
commitMutation(mutationPb);

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
* @see <a href="https://cloud.google.com/datastore/docs/concepts/entities">Google Cloud Datastore
3333
* Entities, Properties, and Keys</a>
3434
*/
35-
public final class DateTime extends Serializable<com.google.datastore.v1beta3.Value>
35+
public final class DateTime extends Serializable<com.google.protobuf.Timestamp>
3636
implements Comparable<DateTime> {
3737

3838
private static final long serialVersionUID = 7343324797621228378L;
@@ -96,24 +96,23 @@ public static DateTime copyFrom(Calendar calendar) {
9696
}
9797

9898
@Override
99-
protected com.google.datastore.v1beta3.Value toPb() {
100-
return com.google.datastore.v1beta3.Value.newBuilder()
101-
.setTimestampValue(microsecondsToTimestampPb(timestampMicroseconds)).build();
99+
protected com.google.protobuf.Timestamp toPb() {
100+
return microsecondsToTimestampPb(timestampMicroseconds);
102101
}
103102

104103
@Override
105104
protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
106-
return new DateTime(timestampPbToMicroseconds(com.google.datastore.v1beta3.Value
107-
.parseFrom(bytesPb).getTimestampValue()));
105+
return new DateTime(timestampPbToMicroseconds(
106+
com.google.protobuf.Timestamp.parseFrom(bytesPb)));
108107
}
109108

110109
protected static long timestampPbToMicroseconds(com.google.protobuf.Timestamp timestampPb) {
111-
return timestampPb.getSeconds() * 10^6 + timestampPb.getNanos() / 10^3;
110+
return timestampPb.getSeconds() * 1000000 + timestampPb.getNanos() / 1000;
112111
}
113112

114113
protected static com.google.protobuf.Timestamp microsecondsToTimestampPb(long microseconds) {
115-
long seconds = microseconds / 10^6;
116-
int nanos = (int) (microseconds % 10^6) * 10^3;
114+
long seconds = microseconds / 1000000;
115+
int nanos = (int) (microseconds % 1000000) * 1000;
117116
return com.google.protobuf.Timestamp.newBuilder().setSeconds(seconds).setNanos(nanos).build();
118117
}
119118
}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
import static com.google.datastore.v1beta3.Value.DOUBLE_VALUE_FIELD_NUMBER;
2020

21-
import com.google.api.services.datastore.DatastoreV1;
22-
2321
public final class DoubleValue extends Value<Double> {
2422

2523
private static final long serialVersionUID = -5096238337676649540L;
@@ -43,7 +41,7 @@ public Builder newBuilder(Double value) {
4341
protected Double getValue(com.google.datastore.v1beta3.Value from) {
4442
return from.getDoubleValue();
4543
}
46-
44+
4745
@Override
4846
protected void setValue(DoubleValue from, com.google.datastore.v1beta3.Value.Builder to) {
4947
to.setDoubleValue(from.get());

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/EntityValue.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ public Builder newBuilder(FullEntity<?> value) {
3939

4040
@Override
4141
protected FullEntity<?> getValue(com.google.datastore.v1beta3.Value from) {
42-
// TODO(ajaykannan): uncomment this line when possible in datastore v1beta3 transition
42+
// TODO(ajaykannan): fix me!
4343
//return FullEntity.fromPb(from.getEntityValue());
44-
return null; // TODO(ajaykannan): remove this line when possible
44+
return null; // TODO(ajaykannan): fix me!
4545
}
4646

4747
@Override
4848
protected void setValue(EntityValue from, com.google.datastore.v1beta3.Value.Builder to) {
49-
// TODO(ajaykannan): uncomment this line when possible in datastore v1beta3 transition
49+
// TODO(ajaykannan): fix me!
5050
//to.setEntityValue(from.get().toPb());
5151
}
5252
};

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/GqlQuery.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ protected DatastoreV1.GqlQueryArg toPb() {
135135
argPb.setCursor(cursor.byteString());
136136
}
137137
if (value != null) {
138-
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
138+
// TODO(ajaykannan): fix me!
139139
//argPb.setValue(value.toPb());
140140
}
141141
return argPb.build();
@@ -151,9 +151,9 @@ static Binding fromPb(DatastoreV1.GqlQueryArg argPb) {
151151
if (argPb.hasCursor()) {
152152
return new Binding(name, new Cursor(argPb.getCursor()));
153153
}
154-
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
154+
// TODO(ajaykannan): fix me!
155155
//return new Binding(name, Value.fromPb(argPb.getValue()));
156-
return new Binding(name, new Cursor(null)); // TODO(ajaykannan): remove this line when possible
156+
return new Binding(name, new Cursor(null)); // TODO(ajaykannan): fix me!
157157
}
158158
}
159159

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/IncompleteKey.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,12 @@ protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
5858
}
5959

6060
static IncompleteKey fromPb(com.google.datastore.v1beta3.Key keyPb) {
61-
String projectId = null;
62-
String namespace = null;
61+
String projectId = "";
62+
String namespace = "";
6363
if (keyPb.hasPartitionId()) {
6464
com.google.datastore.v1beta3.PartitionId partitionIdPb = keyPb.getPartitionId();
6565
projectId = partitionIdPb.getProjectId();
66-
if (projectId.isEmpty()) {
67-
projectId = null;
68-
}
6966
namespace = partitionIdPb.getNamespaceId();
70-
if (namespace.isEmpty()) {
71-
namespace = null;
72-
}
7367
}
7468
List<com.google.datastore.v1beta3.Key.PathElement> pathElementsPb = keyPb.getPathList();
7569
Preconditions.checkArgument(!pathElementsPb.isEmpty(), "Path must not be empty");

0 commit comments

Comments
 (0)