Skip to content

Commit

Permalink
Default projectId and namespace are empty strings, along with other m…
Browse files Browse the repository at this point in the history
…inor edits
  • Loading branch information
Ajay Kannan committed Sep 16, 2015
1 parent a77fd34 commit 701939d
Show file tree
Hide file tree
Showing 21 changed files with 64 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ protected DatastoreV1.Mutation.Builder toMutationPb() {
mutationPb.addUpsert(entity.toPb());
}
for (Key key : toDelete()) {
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
// 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,12 +93,12 @@ private B self() {
protected B fill(DatastoreV1.Entity entityPb) {
Map<String, Value<?>> copiedProperties = Maps.newHashMap();
for (DatastoreV1.Property property : entityPb.getPropertyList()) {
// TODO(ajaykannan): Uncomment when possible in datastore v1beta3 transition
// TODO(ajaykannan): fix me!
//copiedProperties.put(property.getName(), Value.fromPb(property.getValue()));
}
properties(copiedProperties);
if (entityPb.hasKey()) {
// TODO(ajaykannan): Uncomment when possible in datastore v1beta3 transition
// TODO(ajaykannan): fix me!
//key((K) IncompleteKey.fromPb(entityPb.getKey()));
}
return self();
Expand Down Expand Up @@ -391,12 +391,12 @@ protected final DatastoreV1.Entity toPb() {
for (Map.Entry<String, Value<?>> entry : properties.entrySet()) {
DatastoreV1.Property.Builder propertyPb = DatastoreV1.Property.newBuilder();
propertyPb.setName(entry.getKey());
// TODO(ajaykannan): Uncomment when possible in datastore v1beta3 transition
// TODO(ajaykannan): fix me!
//propertyPb.setValue(entry.getValue().toPb());
entityPb.addProperty(propertyPb.build());
}
if (key != null) {
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
// 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 @@ -21,7 +21,6 @@
import static com.google.gcloud.datastore.Validator.validateNamespace;

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

import java.util.LinkedList;
Expand All @@ -41,8 +40,8 @@ abstract class BaseKey extends Serializable<com.google.datastore.v1beta3.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 @@ -176,15 +175,9 @@ 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)) {
partitionIdPb.setProjectId(projectId);
}
if (!Strings.isNullOrEmpty(namespace)) {
partitionIdPb.setNamespaceId(namespace);
}
if (!partitionIdPb.getProjectId().isEmpty() || !partitionIdPb.getNamespaceId().isEmpty()) {
keyPb.setPartitionId(partitionIdPb.build());
}
partitionIdPb.setProjectId(projectId);
partitionIdPb.setNamespaceId(namespace);
keyPb.setPartitionId(partitionIdPb.build());
for (PathElement pathEntry : path) {
keyPb.addPath(pathEntry.toPb());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public List<Key> generatedKeys() {
return Lists.transform(response.getMutationResult().getInsertAutoIdKeyList(),
new Function<DatastoreV1.Key, Key>() {
@Override public Key apply(DatastoreV1.Key keyPb) {
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
// TODO(ajaykannan): fix me!
//return Key.fromPb(keyPb);
return Key.builder(null).build(); // TODO(ajaykannan): remove this line when possible
return Key.builder(null).build(); // TODO(ajaykannan): fix me!
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,13 @@ public List<Key> allocateId(IncompleteKey... keys) {
}
DatastoreV1.AllocateIdsRequest.Builder requestPb = DatastoreV1.AllocateIdsRequest.newBuilder();
for (IncompleteKey key : keys) {
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
// 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()) {
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
// TODO(ajaykannan): fix me!
// keyList.add(Key.fromPb(keyPb));
}
return keyList.build();
Expand Down Expand Up @@ -195,7 +195,7 @@ public List<Entity> add(FullEntity<?>... entities) {
if (completeEntity != null) {
responseBuilder.add(completeEntity);
} else {
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
// TODO(ajaykannan): fix me!
//responseBuilder.add(Entity.builder(Key.fromPb(allocatedKeys.next()), entity).build());
}
}
Expand Down Expand Up @@ -226,7 +226,7 @@ Iterator<Entity> get(DatastoreV1.ReadOptions readOptionsPb, final Key... keys) {
requestPb.setReadOptions(readOptionsPb);
}
for (Key k : Sets.newLinkedHashSet(Arrays.asList(keys))) {
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
// TODO(ajaykannan): fix me!
//requestPb.addKey(k.toPb());
}
return new ResultsIterator(requestPb);
Expand Down Expand Up @@ -314,7 +314,7 @@ public void delete(Key... keys) {
DatastoreV1.Mutation.Builder mutationPb = DatastoreV1.Mutation.newBuilder();
Set<Key> dedupKeys = new LinkedHashSet<>(Arrays.asList(keys));
for (Key key : dedupKeys) {
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
// TODO(ajaykannan): fix me!
//mutationPb.addDelete(key.toPb());
}
commitMutation(mutationPb);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
* @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.datastore.v1beta3.Value>
public final class DateTime extends Serializable<com.google.protobuf.Timestamp>
implements Comparable<DateTime> {

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

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

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

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

public final class DoubleValue extends Value<Double> {

private static final long serialVersionUID = -5096238337676649540L;
Expand All @@ -43,7 +41,7 @@ public Builder newBuilder(Double value) {
protected Double getValue(com.google.datastore.v1beta3.Value from) {
return from.getDoubleValue();
}

@Override
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 @@ -39,14 +39,14 @@ public Builder newBuilder(FullEntity<?> value) {

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

@Override
protected void setValue(EntityValue from, com.google.datastore.v1beta3.Value.Builder to) {
// TODO(ajaykannan): uncomment this line when possible in datastore v1beta3 transition
// TODO(ajaykannan): fix me!
//to.setEntityValue(from.get().toPb());
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ protected DatastoreV1.GqlQueryArg toPb() {
argPb.setCursor(cursor.byteString());
}
if (value != null) {
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
// TODO(ajaykannan): fix me!
//argPb.setValue(value.toPb());
}
return argPb.build();
Expand All @@ -151,9 +151,9 @@ static Binding fromPb(DatastoreV1.GqlQueryArg argPb) {
if (argPb.hasCursor()) {
return new Binding(name, new Cursor(argPb.getCursor()));
}
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
// TODO(ajaykannan): fix me!
//return new Binding(name, Value.fromPb(argPb.getValue()));
return new Binding(name, new Cursor(null)); // TODO(ajaykannan): remove this line when possible
return new Binding(name, new Cursor(null)); // TODO(ajaykannan): fix me!
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,12 @@ protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {
}

static IncompleteKey fromPb(com.google.datastore.v1beta3.Key keyPb) {
String projectId = null;
String namespace = null;
String projectId = "";
String namespace = "";
if (keyPb.hasPartitionId()) {
com.google.datastore.v1beta3.PartitionId partitionIdPb = keyPb.getPartitionId();
projectId = partitionIdPb.getProjectId();
if (projectId.isEmpty()) {
projectId = null;
}
namespace = partitionIdPb.getNamespaceId();
if (namespace.isEmpty()) {
namespace = null;
}
}
List<com.google.datastore.v1beta3.Key.PathElement> pathElementsPb = keyPb.getPathList();
Preconditions.checkArgument(!pathElementsPb.isEmpty(), "Path must not be empty");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public boolean equals(Object obj) {

@Override
protected com.google.datastore.v1beta3.Key.PathElement toPb() {
com.google.datastore.v1beta3.Key.PathElement.Builder pathElementPb = com.google.datastore.v1beta3.Key.PathElement.newBuilder();
com.google.datastore.v1beta3.Key.PathElement.Builder pathElementPb =
com.google.datastore.v1beta3.Key.PathElement.newBuilder();
pathElementPb.setKind(kind);
if (id != null) {
pathElementPb.setId(id);
Expand All @@ -103,15 +104,14 @@ protected Object fromPb(byte[] bytesPb) throws InvalidProtocolBufferException {

static PathElement fromPb(com.google.datastore.v1beta3.Key.PathElement pathElementPb) {
String kind = pathElementPb.getKind();
if (pathElementPb.getIdTypeCase() ==
com.google.datastore.v1beta3.Key.PathElement.IdTypeCase.ID) {
return of(kind, pathElementPb.getId());
switch (pathElementPb.getIdTypeCase()) {
case ID:
return of(kind, pathElementPb.getId());
case NAME:
return of(kind, pathElementPb.getName());
default:
return of(kind);
}
if (pathElementPb.getIdTypeCase() ==
com.google.datastore.v1beta3.Key.PathElement.IdTypeCase.NAME) {
return of(kind, pathElementPb.getName());
}
return of(kind);
}

static PathElement of(String kind) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public abstract static class ResultType<V> implements java.io.Serializable {
if (!entityPb.hasKey()) {
return null;
}
//TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
//TODO(ajaykannan): fix me!
//return Key.fromPb(entityPb.getKey());
}
return ProjectionEntity.fromPb(entityPb);
Expand All @@ -89,9 +89,9 @@ public abstract static class ResultType<V> implements java.io.Serializable {
private static final long serialVersionUID = -8514289244104446252L;

@Override protected Key convert(DatastoreV1.Entity entityPb) {
//TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
//TODO(ajaykannan): fix me!
//return Key.fromPb(entityPb.getKey());
return Key.builder(null).build(); // TODO(ajaykannan): remove this line when possible
return Key.builder(null).build(); // TODO(ajaykannan): fix me!
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ private PropertyFilter(String property, Operator operator, Value<?> value) {
public static PropertyFilter fromPb(DatastoreV1.PropertyFilter propertyFilterPb) {
String property = propertyFilterPb.getProperty().getName();
Operator operator = Operator.fromPb(propertyFilterPb.getOperator());
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
// TODO(ajaykannan): fix me!
//Value<?> value = Value.fromPb(propertyFilterPb.getValue());
//return new PropertyFilter(property, operator, value);
return new PropertyFilter(property, operator, null); // TODO(ajaykannan): remove this line when possible
return new PropertyFilter(property, operator, null); // TODO(ajaykannan): fix me!
}

@Override
Expand Down Expand Up @@ -437,7 +437,7 @@ protected DatastoreV1.Filter toPb() {
propertyFilterPb.getPropertyBuilder().setName(property);
propertyFilterPb.setOperator(operator.toPb());
if (value != null) {
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
// TODO(ajaykannan): fix me!
//propertyFilterPb.setValue(value.toPb());
}
return filterPb.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ public List<Key> generatedKeys() {
return Lists.transform(response.getMutationResult().getInsertAutoIdKeyList(),
new Function<DatastoreV1.Key, Key>() {
@Override public Key apply(DatastoreV1.Key keyPb) {
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
// TODO(ajaykannan): fix me!
//return Key.fromPb(keyPb);
return Key.builder(null).build(); //: TODO(ajaykannan) remove this placeholder line
return Key.builder(null).build(); // TODO(ajaykannan): fix me!
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ static String validateDatabase(String projectId) {
}

static String validateNamespace(String namespace) {
if (namespace != null) {
checkArgument(!namespace.isEmpty(), "namespace must not be an empty string");
if (namespace != null && !namespace.isEmpty()) {
checkArgument(namespace.length() <= MAX_NAMESPACE_LENGTH,
"namespace must not contain more than 100 characters");
checkArgument(NAMESPACE_PATTERN.matcher(namespace).matches(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public final boolean excludeFromIndexes() {
}

@Deprecated
public final int meaning() {
final int meaning() {
return meaning;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public enum ValueType {
*/
RAW_VALUE(RawValue.MARSHALLER);

/**
* TODO(ajaykannan): add GEO_POINT_VALUE
* Will represent a geolocation value in latitude/longitude
*/

private static final ImmutableMap<Integer, ValueType> DESCRIPTOR_TO_TYPE_MAP;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public void testPutWhenNotActive() throws Exception {

@Test
public void testDelete() throws Exception {
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
// TODO(ajaykannan): fix me!
DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder()
//.addDelete(KEY1.toPb())
//.addDelete(KEY2.toPb())
Expand All @@ -285,7 +285,7 @@ public void testDelete() throws Exception {

@Test
public void testDeleteAfterAdd() throws Exception {
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
// TODO(ajaykannan): fix me!
DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder()
.addInsertAutoId(INCOMPLETE_ENTITY_1.toPb())
//.addDelete(KEY1.toPb())
Expand All @@ -298,7 +298,7 @@ public void testDeleteAfterAdd() throws Exception {

@Test
public void testDeleteAfterUpdate() throws Exception {
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
// TODO(ajaykannan): fix me!
DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder()
//.addDelete(KEY1.toPb())
.build();
Expand All @@ -309,7 +309,7 @@ public void testDeleteAfterUpdate() throws Exception {

@Test
public void testDeleteAfterPut() throws Exception {
// TODO(ajaykannan): uncomment when possible in datastore v1beta3 transition
// TODO(ajaykannan): fix me!
DatastoreV1.Mutation pb = DatastoreV1.Mutation.newBuilder()
//.addDelete(KEY1.toPb())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public void testBadDatasetInSetter() throws Exception {
public void testNamespace() throws Exception {
Builder builder = new Builder("ds", "k");
BaseKey key = builder.build();
assertNull(key.namespace());
assertTrue(key.namespace() != null);
assertTrue(key.namespace().length() == 0);
key = builder.namespace("ns").build();
assertEquals("ns", key.namespace());
}
Expand Down
Loading

0 comments on commit 701939d

Please sign in to comment.