diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BaseDatastoreBatchWriter.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BaseDatastoreBatchWriter.java index e91bef5842d0..206c5d30679c 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BaseDatastoreBatchWriter.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BaseDatastoreBatchWriter.java @@ -52,7 +52,7 @@ protected BaseDatastoreBatchWriter(String name) { public final void addWithDeferredIdAllocation(FullEntity... entities) { validateActive(); for (FullEntity entity : entities) { - IncompleteKey key = entity.key(); + IncompleteKey key = entity.getKey(); Preconditions.checkArgument(key != null, "Entity must have a key"); if (key instanceof Key) { addInternal((FullEntity) entity); @@ -63,10 +63,10 @@ public final void addWithDeferredIdAllocation(FullEntity... entities) { } private void addInternal(FullEntity entity) { - Key key = entity.key(); + Key key = entity.getKey(); if (toAdd.containsKey(key) || toUpdate.containsKey(key) || toPut.containsKey(key)) { throw newInvalidRequest("Entity with the key %s was already added or updated in this %s", - entity.key(), name); + entity.getKey(), name); } if (toDelete.remove(key)) { toPut.put(key, entity); @@ -86,7 +86,7 @@ public final List add(FullEntity... entities) { validateActive(); List incompleteKeys = Lists.newArrayListWithExpectedSize(entities.length); for (FullEntity entity : entities) { - IncompleteKey key = entity.key(); + IncompleteKey key = entity.getKey(); Preconditions.checkArgument(key != null, "Entity must have a key"); if (!(key instanceof Key)) { incompleteKeys.add(key); @@ -95,17 +95,17 @@ public final List add(FullEntity... entities) { Iterator allocated; if (!incompleteKeys.isEmpty()) { IncompleteKey[] toAllocate = Iterables.toArray(incompleteKeys, IncompleteKey.class); - allocated = datastore().allocateId(toAllocate).iterator(); + allocated = getDatastore().allocateId(toAllocate).iterator(); } else { allocated = Collections.emptyIterator(); } List answer = Lists.newArrayListWithExpectedSize(entities.length); for (FullEntity entity : entities) { - if (entity.key() instanceof Key) { + if (entity.getKey() instanceof Key) { addInternal((FullEntity) entity); answer.add(Entity.convert((FullEntity) entity)); } else { - Entity entityWithAllocatedId = Entity.builder(allocated.next(), entity).build(); + Entity entityWithAllocatedId = Entity.newBuilder(allocated.next(), entity).build(); addInternal(entityWithAllocatedId); answer.add(entityWithAllocatedId); } @@ -118,10 +118,10 @@ public final List add(FullEntity... entities) { public final void update(Entity... entities) { validateActive(); for (Entity entity : entities) { - Key key = entity.key(); + Key key = entity.getKey(); if (toDelete.contains(key)) { throw newInvalidRequest("Entity with the key %s was already deleted in this %s", - entity.key(), name); + entity.getKey(), name); } if (toAdd.remove(key) != null || toPut.containsKey(key)) { toPut.put(key, entity); @@ -132,7 +132,7 @@ public final void update(Entity... entities) { } private void putInternal(FullEntity entity) { - Key key = entity.key(); + Key key = entity.getKey(); toAdd.remove(key); toUpdate.remove(key); toDelete.remove(key); @@ -149,7 +149,7 @@ public final Entity put(FullEntity entity) { public final void putWithDeferredIdAllocation(FullEntity... entities) { validateActive(); for (FullEntity entity : entities) { - IncompleteKey key = entity.key(); + IncompleteKey key = entity.getKey(); Preconditions.checkArgument(key != null, "Entity must have a key"); if (key instanceof Key) { putInternal(Entity.convert((FullEntity) entity)); @@ -165,7 +165,7 @@ public final List put(FullEntity... entities) { validateActive(); List incompleteKeys = Lists.newArrayListWithExpectedSize(entities.length); for (FullEntity entity : entities) { - IncompleteKey key = entity.key(); + IncompleteKey key = entity.getKey(); Preconditions.checkArgument(key != null, "Entity must have a key"); if (!(key instanceof Key)) { incompleteKeys.add(key); @@ -174,17 +174,17 @@ public final List put(FullEntity... entities) { Iterator allocated; if (!incompleteKeys.isEmpty()) { IncompleteKey[] toAllocate = Iterables.toArray(incompleteKeys, IncompleteKey.class); - allocated = datastore().allocateId(toAllocate).iterator(); + allocated = getDatastore().allocateId(toAllocate).iterator(); } else { allocated = Collections.emptyIterator(); } List answer = Lists.newArrayListWithExpectedSize(entities.length); for (FullEntity entity : entities) { - if (entity.key() instanceof Key) { + if (entity.getKey() instanceof Key) { putInternal((FullEntity) entity); answer.add(Entity.convert((FullEntity) entity)); } else { - Entity entityWithAllocatedId = Entity.builder(allocated.next(), entity).build(); + Entity entityWithAllocatedId = Entity.newBuilder(allocated.next(), entity).build(); putInternal(entityWithAllocatedId); answer.add(entityWithAllocatedId); } @@ -204,11 +204,17 @@ public final void delete(Key... keys) { } @Override + @Deprecated public boolean active() { return active; } - protected String name() { + @Override + public boolean isActive() { + return active; + } + + protected String getName() { return name; } @@ -270,5 +276,8 @@ protected List toMutationPbList() { return mutationsPb; } + @Deprecated protected abstract Datastore datastore(); + + protected abstract Datastore getDatastore(); } diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BaseEntity.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BaseEntity.java index b4aa57efec7a..c4e4c558381e 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BaseEntity.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BaseEntity.java @@ -65,7 +65,7 @@ public abstract static class Builder entity) { @@ -73,15 +73,15 @@ public abstract static class Builder entity) { - key(key); - properties(entity.properties); + setKey(key); + setProperties(entity.properties); } protected K key() { return key; } - protected Map> properties() { + protected Map> setProperties() { return properties; } @@ -94,26 +94,38 @@ private B self() { B fill(com.google.datastore.v1.Entity entityPb) { Map> copiedProperties = Maps.newHashMap(); for (Map.Entry entry : - entityPb.getProperties().entrySet()) { + entityPb.getPropertiesMap().entrySet()) { copiedProperties.put(entry.getKey(), Value.fromPb(entry.getValue())); } - properties(copiedProperties); + setProperties(copiedProperties); if (entityPb.hasKey()) { - key((K) IncompleteKey.fromPb(entityPb.getKey())); + setKey((K) IncompleteKey.fromPb(entityPb.getKey())); } return self(); } - protected B properties(Map> properties) { + protected B setProperties(Map> properties) { this.properties.putAll(properties); return self(); } + /** + * Sets the key for the entity. + */ + @Deprecated public B key(K key) { this.key = key; return self(); } + /** + * Sets the key for the entity. + */ + public B setKey(K key) { + this.key = key; + return self(); + } + /** * Clears all the properties. */ @@ -401,7 +413,7 @@ public B set(String name, List> values) { * @param others other values in the list */ public B set(String name, Value first, Value second, Value... others) { - properties.put(name, ListValue.builder().addValue(first).addValue(second, others).build()); + properties.put(name, ListValue.newBuilder().addValue(first).addValue(second, others).build()); return self(); } @@ -454,7 +466,7 @@ public B setNull(String name) { } BaseEntity(BaseEntity from) { - this.key = from.key(); + this.key = from.getKey(); this.properties = from.properties; } @@ -494,10 +506,18 @@ public boolean hasKey() { /** * Returns the associated key or null if it does not have one. */ + @Deprecated public K key() { return key; } + /** + * Returns the associated key or null if it does not have one. + */ + public K getKey() { + return key; + } + /** * Returns {@code true} if the entity contains a property with the given {@code name}. */ @@ -642,19 +662,26 @@ public Blob getBlob(String name) { /** * Returns the properties name. */ + @Deprecated public Set names() { return properties.keySet(); } - ImmutableSortedMap> properties() { + /** + * Returns the properties name. + */ + public Set getNames() { + return properties.keySet(); + } + + ImmutableSortedMap> getProperties() { return properties; } final com.google.datastore.v1.Entity toPb() { com.google.datastore.v1.Entity.Builder entityPb = com.google.datastore.v1.Entity.newBuilder(); - Map propertiesPb = entityPb.getMutableProperties(); for (Map.Entry> entry : properties.entrySet()) { - propertiesPb.put(entry.getKey(), entry.getValue().toPb()); + entityPb.putProperties(entry.getKey(), entry.getValue().toPb()); } if (key != null) { entityPb.setKey(key.toPb()); diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BaseKey.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BaseKey.java index 9623c46b7c63..4d59ed3c5ce3 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BaseKey.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BaseKey.java @@ -65,9 +65,9 @@ protected abstract static class Builder> { } Builder(BaseKey copyFrom) { - projectId = copyFrom.projectId(); - namespace = copyFrom.namespace(); - ancestors = new LinkedList<>(copyFrom.ancestors()); + projectId = copyFrom.getProjectId(); + namespace = copyFrom.getNamespace(); + ancestors = new LinkedList<>(copyFrom.getAncestors()); kind = copyFrom.kind(); } @@ -76,16 +76,44 @@ B self() { return (B) this; } + /** + * Adds an ancestor for this key. + */ + @Deprecated public B ancestors(PathElement ancestor) { Preconditions.checkState(ancestors.size() < MAX_PATH, "path can have at most 100 elements"); ancestors.add(ancestor); return self(); } + /** + * Adds an ancestor for this key. + */ + public B addAncestor(PathElement ancestor) { + Preconditions.checkState(ancestors.size() < MAX_PATH, "path can have at most 100 elements"); + ancestors.add(ancestor); + return self(); + } + + /** + * Adds an ancestor to the key. + */ + @Deprecated public B ancestors(PathElement ancestor, PathElement... other) { - return ancestors(ImmutableList.builder().add(ancestor).add(other).build()); + return addAncestors(ImmutableList.builder().add(ancestor).add(other).build()); + } + + /** + * Adds the provided ancestors to the key. + */ + public B addAncestors(PathElement ancestor, PathElement... other) { + return addAncestors(ImmutableList.builder().add(ancestor).add(other).build()); } + /** + * Adds the provided ancestors to the key. + */ + @Deprecated public B ancestors(Iterable ancestors) { ImmutableList list = ImmutableList.copyOf(ancestors); Preconditions.checkState(this.ancestors.size() + list.size() < MAX_PATH, @@ -94,21 +122,68 @@ public B ancestors(Iterable ancestors) { return self(); } + /** + * Adds the provided ancestors to the key. + */ + public B addAncestors(Iterable ancestors) { + ImmutableList list = ImmutableList.copyOf(ancestors); + Preconditions.checkState(this.ancestors.size() + list.size() < MAX_PATH, + "path can have at most 100 elements"); + this.ancestors.addAll(list); + return self(); + } + + /** + * Sets the kind of the key. + */ + @Deprecated public B kind(String kind) { this.kind = validateKind(kind); return self(); } + /** + * Sets the kind of the key. + */ + public B setKind(String kind) { + this.kind = validateKind(kind); + return self(); + } + + /** + * Sets the project ID of the key. + */ + @Deprecated public B projectId(String projectId) { this.projectId = validateDatabase(projectId); return self(); } + /** + * Sets the project ID of the key. + */ + public B setProjectId(String projectId) { + this.projectId = validateDatabase(projectId); + return self(); + } + + /** + * Sets the namespace of the key. + */ + @Deprecated public B namespace(String namespace) { this.namespace = validateNamespace(namespace); return self(); } + /** + * Sets the namespace of the key. + */ + public B setNamespace(String namespace) { + this.namespace = validateNamespace(namespace); + return self(); + } + protected abstract BaseKey build(); } @@ -122,44 +197,87 @@ public B namespace(String namespace) { /** * Returns the key's projectId. */ + @Deprecated public String projectId() { return projectId; } + /** + * Returns the key's projectId. + */ + public String getProjectId() { + return projectId; + } + /** * Returns the key's namespace or {@code null} if not provided. */ + @Deprecated public String namespace() { return namespace; } + /** + * Returns the key's namespace or {@code null} if not provided. + */ + public String getNamespace() { + return namespace; + } + /** * Returns an immutable list with the key's ancestors. */ + @Deprecated public List ancestors() { - return path().subList(0, path().size() - 1); + return getPath().subList(0, getPath().size() - 1); + } + + /** + * Returns an immutable list with the key's ancestors. + */ + public List getAncestors() { + return getPath().subList(0, getPath().size() - 1); } /** * Returns an immutable list of the key's path (ancestors + self). */ + @Deprecated List path() { return path; } - PathElement leaf() { - return path().get(path().size() - 1); + /** + * Returns an immutable list of the key's path (ancestors + self). + */ + List getPath() { + return path; + } + + PathElement getLeaf() { + return getPath().get(getPath().size() - 1); } /** * Returns the key's kind. */ + @Deprecated public String kind() { - return leaf().kind(); + return getLeaf().kind(); } + /** + * Returns the key's kind. + */ + public String getKind() { + return getLeaf().kind(); + } + + @Deprecated abstract BaseKey parent(); + abstract BaseKey getParent(); + @Override public String toString() { return MoreObjects.toStringHelper(this) @@ -171,7 +289,7 @@ public String toString() { @Override public int hashCode() { - return Objects.hash(projectId(), namespace(), path()); + return Objects.hash(getProjectId(), getNamespace(), getPath()); } @Override @@ -183,9 +301,9 @@ public boolean equals(Object obj) { return false; } BaseKey other = (BaseKey) obj; - return Objects.equals(projectId(), other.projectId()) - && Objects.equals(namespace(), other.namespace()) - && Objects.equals(path(), other.path()); + return Objects.equals(getProjectId(), other.getProjectId()) + && Objects.equals(getNamespace(), other.getNamespace()) + && Objects.equals(getPath(), other.getPath()); } com.google.datastore.v1.Key toPb() { diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Batch.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Batch.java index dbe6f86c4b99..184fd0831cc9 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Batch.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Batch.java @@ -26,9 +26,9 @@ *
 {@code
  * Entity entity1 = datastore.get(key1);
  * Batch batch = datastore.newBatch();
- * Entity entity2 = Entity.builder(key2).set("name", "John").build();
- * entity1 = Entity.builder(entity1).clear().setNull("bla").build();
- * Entity entity3 = Entity.builder(key3).set("title", "title").build();
+ * Entity entity2 = Entity.newBuilder(key2).set("name", "John").build();
+ * entity1 = Entity.newBuilder(entity1).clear().setNull("bla").build();
+ * Entity entity3 = Entity.newBuilder(key3).set("title", "title").build();
  * batch.update(entity1);
  * batch.add(entity2, entity3);
  * batch.submit();
@@ -37,7 +37,16 @@
 public interface Batch extends DatastoreBatchWriter {
 
   interface Response {
+    /**
+     * Returns a list of keys generated by a batch.
+     */
+    @Deprecated
     List generatedKeys();
+
+    /**
+     * Returns a list of keys generated by a batch.
+     */
+    List getGeneratedKeys();
   }
 
   /**
@@ -50,5 +59,11 @@ interface Response {
   /**
    * Returns the batch associated {@link Datastore}.
    */
+  @Deprecated
   Datastore datastore();
+
+  /**
+   * Returns the batch associated {@link Datastore}.
+   */
+  Datastore getDatastore();
 }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BatchImpl.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BatchImpl.java
index f61c0ae846d4..3ca05bc92ad3 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BatchImpl.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BatchImpl.java
@@ -35,6 +35,7 @@ static class ResponseImpl implements Batch.Response {
     }
 
     @Override
+    @Deprecated
     public List generatedKeys() {
       Iterator results =
           response.getMutationResultsList().iterator();
@@ -44,6 +45,17 @@ public List generatedKeys() {
       }
       return generated;
     }
+
+    @Override
+    public List getGeneratedKeys() {
+      Iterator results =
+          response.getMutationResultsList().iterator();
+      List generated = new ArrayList<>(numAutoAllocatedIds);
+      for (int i = 0; i < numAutoAllocatedIds; i++) {
+        generated.add(Key.fromPb(results.next().getKey()));
+      }
+      return generated;
+    }
   }
 
   BatchImpl(DatastoreImpl datastore) {
@@ -65,7 +77,13 @@ public Batch.Response submit() {
   }
 
   @Override
+  @Deprecated
   public Datastore datastore() {
     return datastore;
   }
+
+  @Override
+  public Datastore getDatastore() {
+    return datastore;
+  }
 }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Blob.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Blob.java
index 22fac0a5d09f..325e5d2ec8cf 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Blob.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Blob.java
@@ -72,10 +72,18 @@ public boolean equals(Object obj) {
   /**
    * Returns the size of this blob.
    */
+  @Deprecated
   public int length() {
     return byteString.size();
   }
 
+  /**
+   * Returns the size of this blob.
+   */
+  public int getLength() {
+    return byteString.size();
+  }
+
   /**
    * Returns a copy as byte array.
    */
@@ -119,10 +127,10 @@ public void copyTo(ByteBuffer target) {
    * @throws IndexOutOfBoundsException if an offset or size is negative or too large
    */
   public void copyTo(byte[] target) {
-    byteString.copyTo(target, 0, 0, length());
+    byteString.copyTo(target, 0, 0, getLength());
   }
 
-  ByteString byteString() {
+  ByteString getByteString() {
     return byteString;
   }
 
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BlobValue.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BlobValue.java
index 5f2243e36447..7fd37da3d0af 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BlobValue.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BlobValue.java
@@ -34,7 +34,7 @@ public int getProtoFieldId() {
 
         @Override
         public Builder newBuilder(Blob value) {
-          return builder(value);
+          return BlobValue.newBuilder(value);
         }
 
         @Override
@@ -44,7 +44,7 @@ protected Blob getValue(com.google.datastore.v1.Value from) {
 
         @Override
         protected void setValue(BlobValue from, com.google.datastore.v1.Value.Builder to) {
-          to.setBlobValue(from.get().byteString());
+          to.setBlobValue(from.get().getByteString());
         }
       };
 
@@ -61,7 +61,7 @@ public BlobValue build() {
   }
 
   public BlobValue(Blob blob) {
-    this(builder(blob));
+    this(newBuilder(blob));
   }
 
   private BlobValue(Builder builder) {
@@ -77,7 +77,12 @@ public static BlobValue of(Blob blob) {
     return new BlobValue(blob);
   }
 
+  @Deprecated
   public static Builder builder(Blob blob) {
     return new Builder().set(blob);
   }
+
+  public static Builder newBuilder(Blob blob) {
+    return new Builder().set(blob);
+  }
 }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BooleanValue.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BooleanValue.java
index 9fb930e6d5a5..c011ccd7b838 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BooleanValue.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/BooleanValue.java
@@ -34,7 +34,7 @@ public int getProtoFieldId() {
 
         @Override
         public Builder newBuilder(Boolean value) {
-          return builder(value);
+          return BooleanValue.newBuilder(value);
         }
 
         @Override
@@ -61,7 +61,7 @@ public BooleanValue build() {
   }
 
   public BooleanValue(boolean value) {
-    this(builder(value));
+    this(newBuilder(value));
   }
 
   private BooleanValue(Builder builder) {
@@ -77,7 +77,12 @@ public static BooleanValue of(boolean value) {
     return new BooleanValue(value);
   }
 
+  @Deprecated
   public static Builder builder(boolean value) {
     return new Builder().set(value);
   }
+
+  public static Builder newBuilder(boolean value) {
+    return new Builder().set(value);
+  }
 }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Cursor.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Cursor.java
index f0fdf0e07212..9a60cb83944a 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Cursor.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Cursor.java
@@ -59,7 +59,7 @@ public String toString() {
     return toStringHelper.add("bytes", stBuilder.toString()).toString();
   }
 
-  ByteString byteString() {
+  ByteString getByteString() {
     return byteString;
   }
 
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreBatchWriter.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreBatchWriter.java
index 32559ebb58d0..0900243569e8 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreBatchWriter.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreBatchWriter.java
@@ -89,5 +89,11 @@ interface DatastoreBatchWriter extends DatastoreWriter {
   /**
    * Returns {@code true} if still active (write operations were not sent to the Datastore).
    */
+  @Deprecated
   boolean active();
+
+  /**
+   * Returns {@code true} if still active (write operations were not sent to the Datastore).
+   */
+  boolean isActive();
 }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreHelper.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreHelper.java
index 655b1722b1ca..957839cf4301 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreHelper.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreHelper.java
@@ -79,7 +79,7 @@ private static List compileEntities(Key[] keys, Iterator entitie
     Map map = Maps.newHashMapWithExpectedSize(keys.length);
     while (entities.hasNext()) {
       Entity entity = entities.next();
-      map.put(entity.key(), entity);
+      map.put(entity.getKey(), entity);
     }
     List list = new ArrayList<>(keys.length);
     for (Key key : keys) {
@@ -99,7 +99,7 @@ static  T runInTransaction(Datastore datastore, Datastore.TransactionCallable
       transaction.rollback();
       throw DatastoreException.propagateUserException(ex);
     } finally {
-      if (transaction.active()) {
+      if (transaction.isActive()) {
         transaction.rollback();
       }
     }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreImpl.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreImpl.java
index 842e5f2eb5c3..892d397935df 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreImpl.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DatastoreImpl.java
@@ -139,7 +139,7 @@ public com.google.datastore.v1.AllocateIdsResponse call()
 
   private IncompleteKey trimNameOrId(IncompleteKey key) {
     if (key instanceof Key) {
-      return IncompleteKey.builder(key).build();
+      return IncompleteKey.newBuilder(key).build();
     }
     return key;
   }
@@ -159,13 +159,13 @@ public List add(FullEntity... entities) {
     Map completeEntities = new LinkedHashMap<>();
     for (FullEntity entity : entities) {
       Entity completeEntity = null;
-      if (entity.key() instanceof Key) {
+      if (entity.getKey() instanceof Key) {
         completeEntity = Entity.convert((FullEntity) entity);
       }
       if (completeEntity != null) {
-        if (completeEntities.put(completeEntity.key(), completeEntity) != null) {
+        if (completeEntities.put(completeEntity.getKey(), completeEntity) != null) {
           throw DatastoreException.throwInvalidRequest(
-            "Duplicate entity with the key %s", entity.key());
+            "Duplicate entity with the key %s", entity.getKey());
         }
       } else {
         Preconditions.checkArgument(entity.hasKey(), "Entity %s is missing a key", entity);
@@ -178,13 +178,13 @@ public List add(FullEntity... entities) {
         commitResponse.getMutationResultsList().iterator();
     ImmutableList.Builder responseBuilder = ImmutableList.builder();
     for (FullEntity entity : entities) {
-      Entity completeEntity = completeEntities.get(entity.key());
+      Entity completeEntity = completeEntities.get(entity.getKey());
       if (completeEntity != null) {
         responseBuilder.add(completeEntity);
         mutationResults.next();
       } else {
         responseBuilder.add(
-            Entity.builder(Key.fromPb(mutationResults.next().getKey()), entity).build());
+            Entity.newBuilder(Key.fromPb(mutationResults.next().getKey()), entity).build());
       }
     }
     return responseBuilder.build();
@@ -300,7 +300,7 @@ public void update(Entity... entities) {
       List mutationsPb = new ArrayList<>();
       Map dedupEntities = new LinkedHashMap<>();
       for (Entity entity : entities) {
-        dedupEntities.put(entity.key(), entity);
+        dedupEntities.put(entity.getKey(), entity);
       }
       for (Entity entity : dedupEntities.values()) {
         mutationsPb.add(
@@ -325,9 +325,9 @@ public List put(FullEntity... entities) {
     Map dedupEntities = new LinkedHashMap<>();
     for (FullEntity entity : entities) {
       Preconditions.checkArgument(entity.hasKey(), "Entity %s is missing a key", entity);
-      if (entity.key() instanceof Key) {
+      if (entity.getKey() instanceof Key) {
         Entity completeEntity = Entity.convert((FullEntity) entity);
-        dedupEntities.put(completeEntity.key(), completeEntity);
+        dedupEntities.put(completeEntity.getKey(), completeEntity);
       } else {
         mutationsPb.add(
             com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build());
@@ -342,12 +342,12 @@ public List put(FullEntity... entities) {
         commitResponse.getMutationResultsList().iterator();
     ImmutableList.Builder responseBuilder = ImmutableList.builder();
     for (FullEntity entity : entities) {
-      Entity completeEntity = dedupEntities.get(entity.key());
+      Entity completeEntity = dedupEntities.get(entity.getKey());
       if (completeEntity != null) {
         responseBuilder.add(completeEntity);
       } else {
         responseBuilder.add(
-            Entity.builder(Key.fromPb(mutationResults.next().getKey()), entity).build());
+            Entity.newBuilder(Key.fromPb(mutationResults.next().getKey()), entity).build());
       }
     }
     return responseBuilder.build();
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DateTime.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DateTime.java
index dee2558275bb..84be14e5b9a9 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DateTime.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DateTime.java
@@ -43,7 +43,7 @@ public final class DateTime implements Comparable, Serializable {
 
   @Override
   public String toString() {
-    return ISODateTimeFormat.dateTime().print(timestampMillis());
+    return ISODateTimeFormat.dateTime().print(getTimestampMillis());
   }
 
   @Override
@@ -63,21 +63,43 @@ public boolean equals(Object obj) {
             && timestampMicroseconds == ((DateTime) obj).timestampMicroseconds);
   }
 
+  /**
+   * Returns the value of this timestamp in microseconds.
+   */
+  @Deprecated
   public long timestampMicroseconds() {
     return timestampMicroseconds;
   }
 
+  /**
+   * Returns the value of this timestamp in microseconds.
+   */
+  public long getTimestampMicroseconds() {
+    return timestampMicroseconds;
+  }
+
+  /**
+   * Returns the value of this timestamp in milliseconds.
+   */
+  @Deprecated
   public long timestampMillis() {
     return timestampMicroseconds / 1000L;
   }
 
+  /**
+   * Returns the value of this timestamp in milliseconds.
+   */
+  public long getTimestampMillis() {
+    return timestampMicroseconds / 1000L;
+  }
+
   public Date toDate() {
-    return new Date(timestampMillis());
+    return new Date(getTimestampMillis());
   }
 
   public Calendar toCalendar() {
     Calendar cal = Calendar.getInstance();
-    cal.setTimeInMillis(timestampMillis());
+    cal.setTimeInMillis(getTimestampMillis());
     return cal;
   }
 
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DateTimeValue.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DateTimeValue.java
index 534328f6c0d5..b7789bf42f3b 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DateTimeValue.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DateTimeValue.java
@@ -34,7 +34,7 @@ public int getProtoFieldId() {
 
         @Override
         public Builder newBuilder(DateTime value) {
-          return builder(value);
+          return DateTimeValue.newBuilder(value);
         }
 
         @Override
@@ -45,7 +45,7 @@ protected DateTime getValue(com.google.datastore.v1.Value from) {
         @Override
         protected void setValue(DateTimeValue from, com.google.datastore.v1.Value.Builder to) {
           to.setTimestampValue(DateTime.microsecondsToTimestampPb(from.get()
-              .timestampMicroseconds()));
+              .getTimestampMicroseconds()));
         }
       };
 
@@ -62,7 +62,7 @@ public DateTimeValue build() {
   }
 
   public DateTimeValue(DateTime dateTime) {
-    this(builder(dateTime));
+    this(newBuilder(dateTime));
   }
 
   private DateTimeValue(Builder builder) {
@@ -78,7 +78,12 @@ public static DateTimeValue of(DateTime dateTime) {
     return new DateTimeValue(dateTime);
   }
 
+  @Deprecated
   public static Builder builder(DateTime dateTime) {
     return new Builder().set(dateTime);
   }
+
+  public static Builder newBuilder(DateTime dateTime) {
+    return new Builder().set(dateTime);
+  }
 }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DoubleValue.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DoubleValue.java
index d2afa2e2ccc5..6e17883f1cab 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DoubleValue.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/DoubleValue.java
@@ -34,7 +34,7 @@ public int getProtoFieldId() {
 
         @Override
         public Builder newBuilder(Double value) {
-          return builder(value);
+          return DoubleValue.newBuilder(value);
         }
 
         @Override
@@ -61,7 +61,7 @@ public DoubleValue build() {
   }
 
   public DoubleValue(double value) {
-    this(builder(value));
+    this(newBuilder(value));
   }
 
   private DoubleValue(Builder builder) {
@@ -77,7 +77,12 @@ public static DoubleValue of(double value) {
     return new DoubleValue(value);
   }
 
+  @Deprecated
   public static Builder builder(double value) {
     return new Builder().set(value);
   }
+
+  public static Builder newBuilder(double value) {
+    return new Builder().set(value);
+  }
 }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Entity.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Entity.java
index 25e71541115c..69f7dc61a781 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Entity.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Entity.java
@@ -42,13 +42,20 @@ private Builder(Entity entity) {
     }
 
     private Builder(Key key, FullEntity entity) {
-      properties(entity.properties());
-      key(key);
+      setProperties(entity.getProperties());
+      setKey(key);
     }
 
     @Override
+    @Deprecated
     public Builder key(Key key) {
-      super.key(checkNotNull(key));
+      super.setKey(checkNotNull(key));
+      return this;
+    }
+
+    @Override
+    public Builder setKey(Key key) {
+      super.setKey(checkNotNull(key));
       return this;
     }
 
@@ -65,7 +72,7 @@ public Entity build() {
 
   Entity(FullEntity from) {
     super(from);
-    Preconditions.checkArgument(from.key() != null);
+    Preconditions.checkArgument(from.getKey() != null);
   }
 
   static Entity convert(FullEntity from) {
@@ -75,18 +82,33 @@ static Entity convert(FullEntity from) {
     return new Entity(from);
   }
 
+  @Deprecated
   public static Builder builder(Key key) {
     return new Builder(key);
   }
 
+  public static Builder newBuilder(Key key) {
+    return new Builder(key);
+  }
+
+  @Deprecated
   public static Builder builder(Entity copyFrom) {
     return new Builder(copyFrom);
   }
 
+  public static Builder newBuilder(Entity copyFrom) {
+    return new Builder(copyFrom);
+  }
+
+  @Deprecated
   public static Builder builder(Key key, FullEntity copyFrom) {
     return new Builder(key, copyFrom);
   }
 
+  public static Builder newBuilder(Key key, FullEntity copyFrom) {
+    return new Builder(key, copyFrom);
+  }
+
   static Entity fromPb(com.google.datastore.v1.Entity entityPb) {
     return new Builder().fill(entityPb).build();
   }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/EntityValue.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/EntityValue.java
index be7daace342e..11aa1fb8f378 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/EntityValue.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/EntityValue.java
@@ -34,7 +34,7 @@ public int getProtoFieldId() {
 
         @Override
         public Builder newBuilder(FullEntity value) {
-          return builder(value);
+          return EntityValue.newBuilder(value);
         }
 
         @Override
@@ -61,7 +61,7 @@ public EntityValue build() {
   }
 
   public EntityValue(FullEntity entity) {
-    this(builder(entity));
+    this(newBuilder(entity));
   }
 
   private EntityValue(Builder builder) {
@@ -77,7 +77,12 @@ public static EntityValue of(FullEntity entity) {
     return new EntityValue(entity);
   }
 
+  @Deprecated
   public static Builder builder(FullEntity entity) {
     return new Builder().set(entity);
   }
+
+  public static Builder newBuilder(FullEntity entity) {
+    return new Builder().set(entity);
+  }
 }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/FullEntity.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/FullEntity.java
index a2871876a775..aa7ef3ce6ef8 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/FullEntity.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/FullEntity.java
@@ -51,18 +51,33 @@ public FullEntity build() {
     super(from);
   }
 
+  @Deprecated
   public static Builder builder() {
     return new Builder<>();
   }
 
+  public static Builder newBuilder() {
+    return new Builder<>();
+  }
+
+  @Deprecated
   public static  Builder builder(K key) {
     return new Builder<>(key);
   }
 
+  public static  Builder newBuilder(K key) {
+    return new Builder<>(key);
+  }
+
+  @Deprecated
   public static  Builder builder(FullEntity copyFrom) {
     return new Builder<>(copyFrom);
   }
 
+  public static  Builder newBuilder(FullEntity copyFrom) {
+    return new Builder<>(copyFrom);
+  }
+
   static FullEntity fromPb(com.google.datastore.v1.Entity entityPb) {
     return new Builder<>().fill(entityPb).build();
   }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/GqlQuery.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/GqlQuery.java
index 6409356cf33e..4627d0d55a70 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/GqlQuery.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/GqlQuery.java
@@ -44,7 +44,7 @@
  * 

When the type of the results is known the preferred usage would be: *

 {@code
  * Query query =
- *     Query.gqlQueryBuilder(Query.ResultType.ENTITY, "select * from kind").build();
+ *     Query.newGqlQueryBuilder(Query.ResultType.ENTITY, "select * from kind").build();
  * QueryResults results = datastore.run(query);
  * while (results.hasNext()) {
  *   Entity entity = results.next();
@@ -54,9 +54,9 @@
  *
  * 

When the type of the results is unknown you can use this approach: *

 {@code
- * Query query = Query.gqlQueryBuilder("select __key__ from kind").build();
+ * Query query = Query.newGqlQueryBuilder("select __key__ from kind").build();
  * QueryResults results = datastore.run(query);
- * if (Key.class.isAssignableFrom(results.resultClass())) {
+ * if (Key.class.isAssignableFrom(results.getResultClass())) {
  *   QueryResults keys = (QueryResults) results;
  *   while (keys.hasNext()) {
  *     Key key = keys.next();
@@ -94,7 +94,7 @@ static final class Binding implements Serializable {
       cursor = null;
     }
 
-    Object cursorOrValue() {
+    Object getCursorOrValue() {
       return MoreObjects.firstNonNull(cursor, value);
     }
 
@@ -124,7 +124,7 @@ com.google.datastore.v1.GqlQueryParameter toPb() {
       com.google.datastore.v1.GqlQueryParameter.Builder argPb =
           com.google.datastore.v1.GqlQueryParameter.newBuilder();
       if (cursor != null) {
-        argPb.setCursor(cursor.byteString());
+        argPb.setCursor(cursor.getByteString());
       }
       if (value != null) {
         argPb.setValue(value.toPb());
@@ -161,21 +161,59 @@ public static final class Builder {
       queryString = checkNotNull(query);
     }
 
+    /**
+     * Sets the GQL query string.
+     */
+    @Deprecated
     public Builder query(String query) {
       queryString = checkNotNull(query);
       return this;
     }
 
+    /**
+     * Sets the GQL query.
+     */
+    public Builder setQuery(String query) {
+      queryString = checkNotNull(query);
+      return this;
+    }
+
+    /**
+     * Sets the namespace for the GQL query.
+     */
+    @Deprecated
     public Builder namespace(String namespace) {
       this.namespace = validateNamespace(namespace);
       return this;
     }
 
+    /**
+     * Sets the namespace for the GQL query.
+     */
+    public Builder setNamespace(String namespace) {
+      this.namespace = validateNamespace(namespace);
+      return this;
+    }
+
+    /**
+     * Sets whether the query string can contain literals.  When {@code false}, the query string
+     * must not contain any literals and instead must bind all values.
+     */
+    @Deprecated
     public Builder allowLiteral(boolean allowLiteral) {
       this.allowLiteral = allowLiteral;
       return this;
     }
 
+    /**
+     * Sets whether the query string can contain literals.  When {@code false}, the query string
+     * must not contain any literals and instead must bind all values.
+     */
+    public Builder setAllowLiteral(boolean allowLiteral) {
+      this.allowLiteral = allowLiteral;
+      return this;
+    }
+
     public Builder clearBindings() {
       namedBindings.clear();
       positionalBindings.clear();
@@ -304,21 +342,57 @@ private GqlQuery(Builder builder) {
     positionalBindings = ImmutableList.copyOf(builder.positionalBindings);
   }
 
+  /**
+   * Returns the query string for this query.
+   */
+  @Deprecated
   public String queryString() {
     return queryString;
   }
 
+  /**
+   * Returns the query string for this query.
+   */
+  public String getQueryString() {
+    return queryString;
+  }
+
+  /**
+   * Returns whether the query string can contain literals.  When {@code false}, the query string
+   * must not contain any literals and instead must bind all values.
+   */
+  @Deprecated
   public boolean allowLiteral() {
     return allowLiteral;
   }
 
+  /**
+   * Returns whether the query string can contain literals.  When {@code false}, the query string
+   * must not contain any literals and instead must bind all values.
+   */
+  public boolean getAllowLiteral() {
+    return allowLiteral;
+  }
+
   /**
    * Returns an immutable map of named bindings.
    */
+  @Deprecated
   public Map namedBindings() {
     ImmutableMap.Builder builder = ImmutableSortedMap.naturalOrder();
     for (Map.Entry binding : namedBindings.entrySet()) {
-      builder.put(binding.getKey(), binding.getValue().cursorOrValue());
+      builder.put(binding.getKey(), binding.getValue().getCursorOrValue());
+    }
+    return builder.build();
+  }
+
+  /**
+   * Returns an immutable map of named bindings.
+   */
+  public Map getNamedBindings() {
+    ImmutableMap.Builder builder = ImmutableSortedMap.naturalOrder();
+    for (Map.Entry binding : namedBindings.entrySet()) {
+      builder.put(binding.getKey(), binding.getValue().getCursorOrValue());
     }
     return builder.build();
   }
@@ -326,10 +400,22 @@ public Map namedBindings() {
   /**
    * Returns an immutable list of positional bindings (using original order).
    */
+  @Deprecated
   public List numberArgs() {
     ImmutableList.Builder builder = ImmutableList.builder();
     for (Binding binding : positionalBindings) {
-      builder.add(binding.cursorOrValue());
+      builder.add(binding.getCursorOrValue());
+    }
+    return builder.build();
+  }
+
+  /**
+   * Returns an immutable list of positional bindings (using original order).
+   */
+  public List getNumberArgs() {
+    ImmutableList.Builder builder = ImmutableList.builder();
+    for (Binding binding : positionalBindings) {
+      builder.add(binding.getCursorOrValue());
     }
     return builder.build();
   }
@@ -370,10 +456,8 @@ com.google.datastore.v1.GqlQuery toPb() {
         com.google.datastore.v1.GqlQuery.newBuilder();
     queryPb.setQueryString(queryString);
     queryPb.setAllowLiterals(allowLiteral);
-    Map namedBindingsPb =
-        queryPb.getMutableNamedBindings();
     for (Map.Entry entry : namedBindings.entrySet()) {
-      namedBindingsPb.put(entry.getKey(), entry.getValue().toPb());
+      queryPb.putNamedBindings(entry.getKey(), entry.getValue().toPb());
     }
     for (Binding argument : positionalBindings) {
       queryPb.addPositionalBindings(argument.toPb());
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/IncompleteKey.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/IncompleteKey.java
index 53039f77aea5..d786f17f8aa1 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/IncompleteKey.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/IncompleteKey.java
@@ -67,7 +67,7 @@ static IncompleteKey fromPb(com.google.datastore.v1.Key keyPb) {
     }
     ImmutableList path = pathBuilder.build();
     PathElement leaf = path.get(path.size() - 1);
-    if (leaf.nameOrId() != null) {
+    if (leaf.getNameOrId() != null) {
       return new Key(projectId, namespace, path);
     }
     return new IncompleteKey(projectId, namespace, path);
@@ -77,34 +77,77 @@ static IncompleteKey fromPb(com.google.datastore.v1.Key keyPb) {
    * Returns the key's parent.
    */
   @Override
+  @Deprecated
   public Key parent() {
-    List ancestors = ancestors();
+    List ancestors = getAncestors();
     if (ancestors.isEmpty()) {
       return null;
     }
     PathElement parent = ancestors.get(ancestors.size() - 1);
     Key.Builder keyBuilder;
     if (parent.hasName()) {
-      keyBuilder = Key.builder(projectId(), parent.kind(), parent.name());
+      keyBuilder = Key.newBuilder(getProjectId(), parent.kind(), parent.name());
     } else {
-      keyBuilder = Key.builder(projectId(), parent.kind(), parent.id());
+      keyBuilder = Key.newBuilder(getProjectId(), parent.kind(), parent.id());
     }
-    String namespace = namespace();
+    String namespace = getNamespace();
     if (namespace != null) {
-      keyBuilder.namespace(namespace);
+      keyBuilder.setNamespace(namespace);
     }
-    return keyBuilder.ancestors(ancestors.subList(0, ancestors.size() - 1)).build();
+    return keyBuilder.addAncestors(ancestors.subList(0, ancestors.size() - 1)).build();
   }
 
+  /**
+   * Returns the key's parent.
+   */
+  @Override
+  public Key getParent() {
+    List ancestors = getAncestors();
+    if (ancestors.isEmpty()) {
+      return null;
+    }
+    PathElement parent = ancestors.get(ancestors.size() - 1);
+    Key.Builder keyBuilder;
+    if (parent.hasName()) {
+      keyBuilder = Key.newBuilder(getProjectId(), parent.kind(), parent.name());
+    } else {
+      keyBuilder = Key.newBuilder(getProjectId(), parent.kind(), parent.id());
+    }
+    String namespace = getNamespace();
+    if (namespace != null) {
+      keyBuilder.setNamespace(namespace);
+    }
+    return keyBuilder.addAncestors(ancestors.subList(0, ancestors.size() - 1)).build();
+  }
+
+  @Deprecated
   public static Builder builder(String projectId, String kind) {
     return new Builder(projectId, kind);
   }
 
+  public static Builder newBuilder(String projectId, String kind) {
+    return new Builder(projectId, kind);
+  }
+
+  @Deprecated
   public static Builder builder(IncompleteKey copyFrom) {
     return new Builder(copyFrom);
   }
 
+  public static Builder newBuilder(IncompleteKey copyFrom) {
+    return new Builder(copyFrom);
+  }
+
+  @Deprecated
   public static Builder builder(Key parent, String kind) {
-    return builder(parent.projectId(), kind).namespace(parent.namespace()).ancestors(parent.path());
+    return newBuilder(parent.getProjectId(), kind)
+        .setNamespace(parent.getNamespace())
+        .addAncestors(parent.getPath());
+  }
+
+  public static Builder newBuilder(Key parent, String kind) {
+    return newBuilder(parent.getProjectId(), kind)
+        .setNamespace(parent.getNamespace())
+        .addAncestors(parent.getPath());
   }
 }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Key.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Key.java
index 9f7e5d602070..18d579b11cab 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Key.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Key.java
@@ -66,24 +66,50 @@ private Builder(IncompleteKey copyFrom, long id) {
     private Builder(Key copyFrom) {
       super(copyFrom);
       if (copyFrom.hasId()) {
-        id = copyFrom.id();
+        id = copyFrom.getId();
       } else {
-        name = copyFrom.name();
+        name = copyFrom.getName();
       }
     }
 
+    /**
+     * Sets the name of this key.
+     */
+    @Deprecated
     public Builder name(String name) {
       this.name = name;
       id = null;
       return this;
     }
 
+    /**
+     * Sets the name of this key.
+     */
+    public Builder setName(String name) {
+      this.name = name;
+      id = null;
+      return this;
+    }
+
+    /**
+     * Sets the ID of this key.
+     */
+    @Deprecated
     public Builder id(long id) {
       this.id = id;
       name = null;
       return this;
     }
 
+    /**
+     * Sets the ID of this key.
+     */
+    public Builder setId(long id) {
+      this.id = id;
+      name = null;
+      return this;
+    }
+
     @Override
     public Key build() {
       ImmutableList.Builder pathBuilder =
@@ -99,37 +125,60 @@ public Key build() {
 
   Key(String projectId, String namespace, ImmutableList path) {
     super(projectId, namespace, path);
-    Preconditions.checkArgument(nameOrId() != null);
+    Preconditions.checkArgument(getNameOrId() != null);
   }
 
   public boolean hasId() {
-    return leaf().hasId();
+    return getLeaf().hasId();
   }
 
   /**
    * Returns the key's id or {@code null} if it has a name instead.
    */
+  @Deprecated
   public Long id() {
-    return leaf().id();
+    return getLeaf().id();
+  }
+
+  /**
+   * Returns the key's id or {@code null} if it has a name instead.
+   */
+  public Long getId() {
+    return getLeaf().id();
   }
 
   public boolean hasName() {
-    return leaf().hasName();
+    return getLeaf().hasName();
   }
 
   /**
    * Returns the key's name or {@code null} if it has an id instead.
    */
+  @Deprecated
   public String name() {
-    return leaf().name();
+    return getLeaf().name();
+  }
+
+  /**
+   * Returns the key's name or {@code null} if it has an id instead.
+   */
+  public String getName() {
+    return getLeaf().name();
   }
 
   /**
-   * Returns the key's id (as {@link Long}) or name (as {@link String}).
-   * Never {@code null}.
+   * Returns the key's ID (as {@link Long}) or name (as {@link String}). Never {@code null}.
    */
+  @Deprecated
   public Object nameOrId() {
-    return leaf().nameOrId();
+    return getLeaf().getNameOrId();
+  }
+
+  /**
+   * Returns the key's ID (as {@link Long}) or name (as {@link String}). Never {@code null}.
+   */
+  public Object getNameOrId() {
+    return getLeaf().getNameOrId();
   }
 
   /**
@@ -167,45 +216,84 @@ static Key fromPb(com.google.datastore.v1.Key keyPb) {
     return (Key) key;
   }
 
+  @Deprecated
   public static Builder builder(String projectId, String kind, String name) {
     return new Builder(projectId, kind, name);
   }
 
+  public static Builder newBuilder(String projectId, String kind, String name) {
+    return new Builder(projectId, kind, name);
+  }
+
+  @Deprecated
   public static Builder builder(String projectId, String kind, long id) {
     return new Builder(projectId, kind, id);
   }
 
+  public static Builder newBuilder(String projectId, String kind, long id) {
+    return new Builder(projectId, kind, id);
+  }
+
+  @Deprecated
   public static Builder builder(Key copyFrom) {
     return new Builder(copyFrom);
   }
 
+  public static Builder newBuilder(Key copyFrom) {
+    return new Builder(copyFrom);
+  }
+
+  @Deprecated
   public static Builder builder(IncompleteKey copyFrom, String name) {
     return new Builder(copyFrom, name);
   }
 
+  public static Builder newBuilder(IncompleteKey copyFrom, String name) {
+    return new Builder(copyFrom, name);
+  }
+
+  @Deprecated
   public static Builder builder(IncompleteKey copyFrom, long id) {
     return new Builder(copyFrom, id);
   }
 
+  public static Builder newBuilder(IncompleteKey copyFrom, long id) {
+    return new Builder(copyFrom, id);
+  }
+
+  @Deprecated
   public static Builder builder(Key parent, String kind, String name) {
-    Builder builder = builder(parent.projectId(), kind, name);
+    Builder builder = newBuilder(parent.getProjectId(), kind, name);
     addParentToBuilder(parent, builder);
     return builder;
   }
 
+  public static Builder newBuilder(Key parent, String kind, String name) {
+    Builder builder = newBuilder(parent.getProjectId(), kind, name);
+    addParentToBuilder(parent, builder);
+    return builder;
+  }
+
+  @Deprecated
   public static Builder builder(Key parent, String kind, long id) {
-    Builder builder = builder(parent.projectId(), kind, id);
+    Builder builder = newBuilder(parent.getProjectId(), kind, id);
+    addParentToBuilder(parent, builder);
+    return builder;
+  }
+
+  public static Builder newBuilder(Key parent, String kind, long id) {
+    Builder builder = newBuilder(parent.getProjectId(), kind, id);
     addParentToBuilder(parent, builder);
     return builder;
   }
 
   private static void addParentToBuilder(Key parent, Builder builder) {
-    builder.namespace(parent.namespace());
-    builder.ancestors(parent.ancestors());
+    builder.setNamespace(parent.getNamespace());
+    builder.addAncestors(parent.getAncestors());
     if (parent.hasId()) {
-      builder.ancestors(PathElement.of(parent.kind(), parent.id()));
+      builder.addAncestors(PathElement.of(parent.kind(), parent.getId()));
     } else {
-      builder.ancestors(PathElement.of(parent.kind(), parent.name()));
+      builder.addAncestors(PathElement.of(parent.kind(), parent.getName()));
     }
   }
 }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/KeyFactory.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/KeyFactory.java
index f7fc17448a6d..80d48ca3bf37 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/KeyFactory.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/KeyFactory.java
@@ -33,7 +33,7 @@ public KeyFactory(String projectId) {
 
   public KeyFactory(String projectId, String namespace) {
     super(projectId);
-    namespace(namespace);
+    setNamespace(namespace);
     this.pi = projectId;
     this.ns = namespace;
   }
@@ -61,8 +61,8 @@ public Key newKey(long id) {
    * @return {@code this} for chaining
    */
   public KeyFactory reset() {
-    projectId(pi);
-    namespace(ns);
+    setProjectId(pi);
+    setNamespace(ns);
     kind = null;
     ancestors.clear();
     return this;
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/KeyValue.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/KeyValue.java
index aedf9e914b45..63599d180f8a 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/KeyValue.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/KeyValue.java
@@ -34,7 +34,7 @@ public int getProtoFieldId() {
 
         @Override
         public Builder newBuilder(Key key) {
-          return builder(key);
+          return KeyValue.newBuilder(key);
         }
 
         @Override
@@ -61,7 +61,7 @@ public KeyValue build() {
   }
 
   public KeyValue(Key key) {
-    this(builder(key));
+    this(newBuilder(key));
   }
 
   private KeyValue(Builder builder) {
@@ -77,7 +77,12 @@ public static KeyValue of(Key key) {
     return new KeyValue(key);
   }
 
+  @Deprecated
   public static Builder builder(Key key) {
     return new Builder().set(key);
   }
+
+  public static Builder newBuilder(Key key) {
+    return new Builder().set(key);
+  }
 }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/LatLng.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/LatLng.java
index e2407225032b..8bfb5e979d06 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/LatLng.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/LatLng.java
@@ -45,14 +45,36 @@ public final class LatLng implements Serializable {
     this.longitude = longitude;
   }
 
+  /**
+   * Returns the latitude.
+   */
+  @Deprecated
   public double latitude() {
     return latitude;
   }
 
+  /**
+   * Returns the latitude.
+   */
+  public double getLatitude() {
+    return latitude;
+  }
+
+  /**
+   * Returns the longitude.
+   */
+  @Deprecated
   public double longitude() {
     return longitude;
   }
 
+  /**
+   * Returns the longitude.
+   */
+  public double getLongitude() {
+    return longitude;
+  }
+
   @Override
   public String toString() {
     return Double.toString(latitude) + ", " + Double.toString(longitude);
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/LatLngValue.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/LatLngValue.java
index 1a4eac8b6b1d..58f6c335ea7d 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/LatLngValue.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/LatLngValue.java
@@ -34,7 +34,7 @@ public int getProtoFieldId() {
 
         @Override
         public Builder newBuilder(LatLng value) {
-          return builder(value);
+          return LatLngValue.newBuilder(value);
         }
 
         @Override
@@ -62,7 +62,7 @@ public LatLngValue build() {
   }
 
   public LatLngValue(LatLng value) {
-    this(builder(value));
+    this(newBuilder(value));
   }
 
   private LatLngValue(Builder builder) {
@@ -78,7 +78,12 @@ public static LatLngValue of(LatLng value) {
     return new LatLngValue(value);
   }
 
+  @Deprecated
   public static Builder builder(LatLng value) {
     return new Builder().set(value);
   }
+
+  public static Builder newBuilder(LatLng value) {
+    return new Builder().set(value);
+  }
 }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ListValue.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ListValue.java
index 92191f980c3f..8907d20e8ed4 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ListValue.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ListValue.java
@@ -43,7 +43,7 @@ public int getProtoFieldId() {
 
         @Override
         public Builder newBuilder(List> values) {
-          return builder().set(values);
+          return ListValue.newBuilder().set(values);
         }
 
         @Override
@@ -77,7 +77,7 @@ private Builder() {
 
     private void addValueHelper(Value value) {
       // see datastore.proto definition for list_value
-      Preconditions.checkArgument(value.type() != ValueType.LIST, "Cannot contain another list");
+      Preconditions.checkArgument(value.getType() != ValueType.LIST, "Cannot contain another list");
       listBuilder.add(value);
     }
 
@@ -221,7 +221,7 @@ public ListValue build() {
   }
 
   public ListValue(List> values) {
-    this(builder().set(values));
+    this(newBuilder().set(values));
   }
 
   public ListValue(Value first, Value... other) {
@@ -258,69 +258,77 @@ public static ListValue of(Value first, Value... other) {
    * Creates a {@code ListValue} object given a number of string values.
    */
   public static ListValue of(String first, String... other) {
-    return builder().addValue(first, other).build();
+    return newBuilder().addValue(first, other).build();
   }
 
   /**
    * Creates a {@code ListValue} object given a number of long values.
    */
   public static ListValue of(long first, long... other) {
-    return builder().addValue(first, other).build();
+    return newBuilder().addValue(first, other).build();
   }
 
   /**
    * Creates a {@code ListValue} object given a number of double values.
    */
   public static ListValue of(double first, double... other) {
-    return builder().addValue(first, other).build();
+    return newBuilder().addValue(first, other).build();
   }
 
   /**
    * Creates a {@code ListValue} object given a number of boolean values.
    */
   public static ListValue of(boolean first, boolean... other) {
-    return builder().addValue(first, other).build();
+    return newBuilder().addValue(first, other).build();
   }
 
   /**
    * Creates a {@code ListValue} object given a number of {@code DateTime} values.
    */
   public static ListValue of(DateTime first, DateTime... other) {
-    return builder().addValue(first, other).build();
+    return newBuilder().addValue(first, other).build();
   }
 
   /**
    * Creates a {@code ListValue} object given a number of {@code LatLng} values.
    */
   public static ListValue of(LatLng first, LatLng... other) {
-    return builder().addValue(first, other).build();
+    return newBuilder().addValue(first, other).build();
   }
 
   /**
    * Creates a {@code ListValue} object given a number of {@code Key} values.
    */
   public static ListValue of(Key first, Key... other) {
-    return builder().addValue(first, other).build();
+    return newBuilder().addValue(first, other).build();
   }
 
   /**
    * Creates a {@code ListValue} object given a number of {@code FullEntity} values.
    */
   public static ListValue of(FullEntity first, FullEntity... other) {
-    return builder().addValue(first, other).build();
+    return newBuilder().addValue(first, other).build();
   }
 
   /**
    * Creates a {@code ListValue} object given a number of {@code Blob} values.
    */
   public static ListValue of(Blob first, Blob... other) {
-    return builder().addValue(first, other).build();
+    return newBuilder().addValue(first, other).build();
   }
 
   /**
    * Returns a builder for {@code ListValue} objects.
    */
+  @Deprecated
   public static Builder builder() {
     return new Builder();
   }
+
+  /**
+   * Returns a builder for {@code ListValue} objects.
+   */
+  public static Builder newBuilder() {
+    return new Builder();
+  }
 }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/LongValue.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/LongValue.java
index 1a1011f5f1b1..934046b5f16e 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/LongValue.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/LongValue.java
@@ -34,7 +34,7 @@ public int getProtoFieldId() {
 
         @Override
         public Builder newBuilder(Long value) {
-          return builder(value);
+          return LongValue.newBuilder(value);
         }
 
         @Override
@@ -61,7 +61,7 @@ public LongValue build() {
   }
 
   public LongValue(long value) {
-    this(builder(value));
+    this(newBuilder(value));
   }
 
   private LongValue(Builder builder) {
@@ -77,7 +77,12 @@ public static LongValue of(long value) {
     return new LongValue(value);
   }
 
+  @Deprecated
   public static Builder builder(long value) {
     return new Builder().set(value);
   }
+
+  public static Builder newBuilder(long value) {
+    return new Builder().set(value);
+  }
 }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/NullValue.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/NullValue.java
index b94415b74736..81945b8acea0 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/NullValue.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/NullValue.java
@@ -30,7 +30,7 @@ public final class NullValue extends Value {
 
         @Override
         public Builder newBuilder(Void value) {
-          return builder();
+          return NullValue.newBuilder();
         }
 
         @Override
@@ -69,7 +69,7 @@ public Builder set(Void value) {
   }
 
   public NullValue() {
-    this(builder());
+    this(newBuilder());
   }
 
   private NullValue(Builder builder) {
@@ -85,7 +85,12 @@ public static NullValue of() {
     return new NullValue();
   }
 
+  @Deprecated
   public static Builder builder() {
     return new Builder();
   }
+
+  public static Builder newBuilder() {
+    return new Builder();
+  }
 }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/PathElement.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/PathElement.java
index da564d6e868e..7fcd170a6dea 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/PathElement.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/PathElement.java
@@ -42,30 +42,76 @@ private PathElement(String kind, String name, Long id) {
     this.id = id;
   }
 
+  /**
+   * Returns the kind of this path element.
+   */
+  @Deprecated
   public String kind() {
     return kind;
   }
 
+  /**
+   * Returns the kind of this path element.
+   */
+  public String getKind() {
+    return kind;
+  }
+
   public boolean hasId() {
     return id != null;
   }
 
+  /**
+   * Returns the ID of this path element.
+   */
+  @Deprecated
   public Long id() {
     return id;
   }
 
+  /**
+   * Returns the ID of this path element.
+   */
+  public Long getId() {
+    return id;
+  }
+
   public boolean hasName() {
     return name != null;
   }
 
+  /**
+   * Returns the name of this path element.
+   */
+  @Deprecated
   public String name() {
     return name;
   }
 
+  /**
+   * Returns the name of this path element.
+   */
+  public String getName() {
+    return name;
+  }
+
+  /**
+   * Returns the path element's ID (as {@link Long}) or name (as {@link String}). Never
+   * {@code null}.
+   */
+  @Deprecated
   public Object nameOrId() {
     return id == null ? name : id;
   }
 
+  /**
+   * Returns the path element's ID (as {@link Long}) or name (as {@link String}). Never
+   * {@code null}.
+   */
+  public Object getNameOrId() {
+    return id == null ? name : id;
+  }
+
   @Override
   public String toString() {
     return MoreObjects.toStringHelper(this)
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ProjectionEntity.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ProjectionEntity.java
index 2468fc837c8a..2572010eb174 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ProjectionEntity.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ProjectionEntity.java
@@ -75,7 +75,12 @@ static ProjectionEntity fromPb(com.google.datastore.v1.Entity entityPb) {
     return new Builder().fill(entityPb).build();
   }
 
+  @Deprecated
   public static Builder builder(ProjectionEntity copyFrom) {
     return new Builder(copyFrom);
   }
+
+  public static Builder newBuilder(ProjectionEntity copyFrom) {
+    return new Builder(copyFrom);
+  }
 }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ProjectionEntityQuery.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ProjectionEntityQuery.java
index e28fcf3a0b4b..1b7acf85dc3d 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ProjectionEntityQuery.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ProjectionEntityQuery.java
@@ -54,8 +54,18 @@ public Builder clearProjection() {
      * Sets the query's projection clause (clearing any previously specified Projection settings).
      */
     @Override
+    @Deprecated
     public Builder projection(String projection, String... others) {
-      super.projection(projection, others);
+      super.setProjection(projection, others);
+      return this;
+    }
+
+    /**
+     * Sets the query's projection clause (clearing any previously specified Projection settings).
+     */
+    @Override
+    public Builder setProjection(String projection, String... others) {
+      super.setProjection(projection, others);
       return this;
     }
 
@@ -78,11 +88,21 @@ public Builder clearDistinctOn() {
     }
 
     /**
-     * Sets the query's group by clause (clearing any previously specified GroupBy settings).
+     * Sets the query's distinct on clause (clearing any previously specified distinct on settings).
      */
     @Override
+    @Deprecated
     public Builder distinctOn(String property, String... others) {
-      super.distinctOn(property, others);
+      super.setDistinctOn(property, others);
+      return this;
+    }
+
+    /**
+     * Sets the query's distinct on clause (clearing any previously specified distinct on settings).
+     */
+    @Override
+    public Builder setDistinctOn(String property, String... others) {
+      super.setDistinctOn(property, others);
       return this;
     }
 
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Query.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Query.java
index 02197684928a..cb80178c6839 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Query.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Query.java
@@ -62,7 +62,7 @@ public abstract static class ResultType implements Serializable {
 
       @Override
       Object convert(com.google.datastore.v1.Entity entityPb) {
-        if (entityPb.getProperties().isEmpty()) {
+        if (entityPb.getPropertiesMap().isEmpty()) {
           if (!entityPb.hasKey()) {
             return null;
           }
@@ -193,8 +193,27 @@ ToStringHelper toStringHelper() {
    *
    * @see GQL Reference
    */
+  @Deprecated
   public static GqlQuery.Builder gqlQueryBuilder(String gql) {
-    return gqlQueryBuilder(ResultType.UNKNOWN, gql);
+    return newGqlQueryBuilder(ResultType.UNKNOWN, gql);
+  }
+
+  /**
+   * Returns a new {@link GqlQuery} builder.
+   *
+   * 

Example of creating and running a GQL query. + *

 {@code
+   * String kind = "my_kind";
+   * String gqlQuery = "select * from " + kind;
+   * Query query = Query.gqlQueryBuilder(gqlQuery).build();
+   * QueryResults results = datastore.run(query);
+   * // Use results
+   * }
+ * + * @see GQL Reference + */ + public static GqlQuery.Builder newGqlQueryBuilder(String gql) { + return newGqlQueryBuilder(ResultType.UNKNOWN, gql); } /** @@ -211,10 +230,29 @@ public static GqlQuery.Builder gqlQueryBuilder(String gql) { * * @see GQL Reference */ + @Deprecated public static GqlQuery.Builder gqlQueryBuilder(ResultType resultType, String gql) { return new GqlQuery.Builder<>(resultType, gql); } + /** + * Returns a new {@link GqlQuery} builder. + * + *

Example of creating and running a typed GQL query. + *

 {@code
+   * String kind = "my_kind";
+   * String gqlQuery = "select * from " + kind;
+   * Query query = Query.gqlQueryBuilder(Query.ResultType.ENTITY, gqlQuery).build();
+   * QueryResults results = datastore.run(query);
+   * // Use results
+   * }
+ * + * @see GQL Reference + */ + public static GqlQuery.Builder newGqlQueryBuilder(ResultType resultType, String gql) { + return new GqlQuery.Builder<>(resultType, gql); + } + /** * Returns a new {@link StructuredQuery} builder for full (complete entities) queries. * @@ -227,10 +265,27 @@ public static GqlQuery.Builder gqlQueryBuilder(ResultType resultType, * } * */ + @Deprecated public static EntityQuery.Builder entityQueryBuilder() { return new EntityQuery.Builder(); } + /** + * Returns a new {@link StructuredQuery} builder for full (complete entities) queries. + * + *

Example of creating and running an entity query. + *

 {@code
+   * String kind = "my_kind";
+   * Query query = Query.entityQueryBuilder().kind(kind).build();
+   * QueryResults results = datastore.run(query);
+   * // Use results
+   * }
+ * + */ + public static EntityQuery.Builder newEntityQueryBuilder() { + return new EntityQuery.Builder(); + } + /** * Returns a new {@link StructuredQuery} builder for key only queries. * @@ -243,10 +298,27 @@ public static EntityQuery.Builder entityQueryBuilder() { * } * */ + @Deprecated public static KeyQuery.Builder keyQueryBuilder() { return new KeyQuery.Builder(); } + /** + * Returns a new {@link StructuredQuery} builder for key only queries. + * + *

Example of creating and running a key query. + *

 {@code
+   * String kind = "my_kind";
+   * Query query = Query.keyQueryBuilder().kind(kind).build();
+   * QueryResults results = datastore.run(query);
+   * // Use results
+   * }
+ * + */ + public static KeyQuery.Builder newKeyQueryBuilder() { + return new KeyQuery.Builder(); + } + /** * Returns a new {@link StructuredQuery} builder for projection queries. * @@ -263,7 +335,28 @@ public static KeyQuery.Builder keyQueryBuilder() { * } * */ + @Deprecated public static ProjectionEntityQuery.Builder projectionEntityQueryBuilder() { return new ProjectionEntityQuery.Builder(); } + + /** + * Returns a new {@link StructuredQuery} builder for projection queries. + * + *

Example of creating and running a projection entity query. + *

 {@code
+   * String kind = "my_kind";
+   * String property = "my_property";
+   * Query query = Query.projectionEntityQueryBuilder()
+   *     .kind(kind)
+   *     .addProjection(property)
+   *     .build();
+   * QueryResults results = datastore.run(query);
+   * // Use results
+   * }
+ * + */ + public static ProjectionEntityQuery.Builder newProjectionEntityQueryBuilder() { + return new ProjectionEntityQuery.Builder(); + } } diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/QueryResults.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/QueryResults.java index a907ddcad6b9..9e50dc464abe 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/QueryResults.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/QueryResults.java @@ -33,8 +33,14 @@ public interface QueryResults extends Iterator { /** * Returns the actual class of the result's values. */ + @Deprecated Class resultClass(); + /** + * Returns the actual class of the result's values. + */ + Class getResultClass(); + /** * Returns the Cursor for the point after the value returned in the last {@link #next} call. This * cursor can be used to issue subsequent queries (with the same constraints) that may return @@ -42,15 +48,35 @@ public interface QueryResults extends Iterator { * *

A simple use case: *

 {@code
-   * Query query = Query.entityQueryBuilder()
-   *     .kind("Person")
-   *     .filter(PropertyFilter.eq("favoriteFood", "pizza"))
+   * Query query = Query.newEntityQueryBuilder()
+   *     .setKind("Person")
+   *     .setFilter(PropertyFilter.eq("favoriteFood", "pizza"))
    *     .build();
    * QueryResults results = datastore.run(query);
    * // Consume some results (using results.next()) and do any other actions as necessary.
-   * query = query.toBuilder().startCursor(results.cursorAfter()).build();
+   * query = query.toBuilder().setStartCursor(results.getCursorAfter()).build();
    * results = datastore.run(query); // now we will iterate over all entities not yet consumed
    * }
*/ + @Deprecated Cursor cursorAfter(); + + /** + * Returns the Cursor for the point after the value returned in the last {@link #next} call. This + * cursor can be used to issue subsequent queries (with the same constraints) that may return + * additional results. + * + *

A simple use case: + *

 {@code
+   * Query query = Query.newEntityQueryBuilder()
+   *     .setKind("Person")
+   *     .setFilter(PropertyFilter.eq("favoriteFood", "pizza"))
+   *     .build();
+   * QueryResults results = datastore.run(query);
+   * // Consume some results (using results.next()) and do any other actions as necessary.
+   * query = query.toBuilder().setStartCursor(results.getCursorAfter()).build();
+   * results = datastore.run(query); // now we will iterate over all entities not yet consumed
+   * }
+ */ + Cursor getCursorAfter(); } diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/QueryResultsImpl.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/QueryResultsImpl.java index f23ff846a652..66e007e86039 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/QueryResultsImpl.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/QueryResultsImpl.java @@ -104,12 +104,24 @@ protected T computeNext() { } @Override + @Deprecated public Class resultClass() { return actualResultType.resultClass(); } @Override + public Class getResultClass() { + return actualResultType.resultClass(); + } + + @Override + @Deprecated public Cursor cursorAfter() { return new Cursor(cursor); } + + @Override + public Cursor getCursorAfter() { + return new Cursor(cursor); + } } diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/RawValue.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/RawValue.java index 35510df76d10..01c762323767 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/RawValue.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/RawValue.java @@ -27,7 +27,7 @@ public final class RawValue extends Value { @Override public Builder newBuilder(com.google.datastore.v1.Value value) { - return builder(value); + return RawValue.newBuilder(value); } @Override @@ -65,7 +65,7 @@ private RawValue(Builder builder) { } RawValue(com.google.datastore.v1.Value valuePb) { - this(builder(valuePb)); + this(newBuilder(valuePb)); } @Override @@ -77,10 +77,10 @@ static RawValue of(com.google.datastore.v1.Value valuePb) { return new RawValue(valuePb); } - static Builder builder(com.google.datastore.v1.Value valuePb) { + static Builder newBuilder(com.google.datastore.v1.Value valuePb) { Builder builder = new Builder(); - builder.excludeFromIndexes(valuePb.getExcludeFromIndexes()); - builder.meaning(valuePb.getMeaning()); + builder.setExcludeFromIndexes(valuePb.getExcludeFromIndexes()); + builder.setMeaning(valuePb.getMeaning()); builder.set(valuePb); return builder; } diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/StringValue.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/StringValue.java index bb90aada37f3..4891630e0c20 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/StringValue.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/StringValue.java @@ -34,7 +34,7 @@ public int getProtoFieldId() { @Override public Builder newBuilder(String value) { - return builder(value); + return StringValue.newBuilder(value); } @Override @@ -61,7 +61,7 @@ public StringValue build() { } public StringValue(String value) { - this(builder(value)); + this(newBuilder(value)); } private StringValue(Builder builder) { @@ -77,7 +77,12 @@ public static StringValue of(String value) { return new StringValue(value); } + @Deprecated public static Builder builder(String value) { return new Builder().set(value); } + + public static Builder newBuilder(String value) { + return new Builder().set(value); + } } diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/StructuredQuery.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/StructuredQuery.java index 6d3c6fd19e83..a185a9681527 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/StructuredQuery.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/StructuredQuery.java @@ -45,7 +45,7 @@ * *

A simple query that returns all entities for a specific kind *

 {@code
- * Query query = Query.entityQueryBuilder().kind(kind).build();
+ * Query query = Query.newEntityQueryBuilder().setKind(kind).build();
  * QueryResults results = datastore.run(query);
  * while (results.hasNext()) {
  *   Entity entity = results.next();
@@ -55,7 +55,7 @@
  *
  * 

A simple key-only query of all entities for a specific kind *

 {@code
- * Query keyOnlyQuery =  Query.keyQueryBuilder().kind(KIND1).build();
+ * Query keyOnlyQuery =  Query.newKeyQueryBuilder().setKind(KIND1).build();
  * QueryResults results = datastore.run(keyOnlyQuery);
  * ...
  * }
@@ -63,13 +63,13 @@ *

A less trivial example of a projection query that returns the first 10 results * of "age" and "name" properties (sorted and grouped by "age") with an age greater than 18 *

 {@code
- * Query query = Query.projectionEntityQueryBuilder()
- *     .kind(kind)
- *     .projection(Projection.property("age"), Projection.first("name"))
- *     .filter(PropertyFilter.gt("age", 18))
- *     .groupBy("age")
- *     .orderBy(OrderBy.asc("age"))
- *     .limit(10)
+ * Query query = Query.newProjectionEntityQueryBuilder()
+ *     .setKind(kind)
+ *     .setProjection(Projection.property("age"), Projection.first("name"))
+ *     .setFilter(PropertyFilter.gt("age", 18))
+ *     .setGroupBy("age")
+ *     .setOrderBy(OrderBy.asc("age"))
+ *     .setLimit(10)
  *     .build();
  * QueryResults results = datastore.run(query);
  * ...
@@ -497,14 +497,36 @@ public boolean equals(Object obj) {
           && direction == other.direction;
     }
 
+    /**
+     * Returns the property according to which the query result should be ordered.
+     */
+    @Deprecated
     public String property() {
       return property;
     }
 
+    /**
+     * Returns the property according to which the query result should be ordered.
+     */
+    public String getProperty() {
+      return property;
+    }
+
+    /**
+     * Returns the order's direction.
+     */
+    @Deprecated
     public Direction direction() {
       return direction;
     }
 
+    /**
+     * Returns the order's direction.
+     */
+    public Direction getDirection() {
+      return direction;
+    }
+
     com.google.datastore.v1.PropertyOrder toPb() {
       return com.google.datastore.v1.PropertyOrder.newBuilder()
           .setDirection(direction.toPb())
@@ -534,27 +556,97 @@ static OrderBy fromPb(com.google.datastore.v1.PropertyOrder propertyOrderPb) {
    * @param  the type of result the query returns.
    */
   public interface Builder {
+
+    /**
+     * Sets the namespace for the query.
+     */
+    @Deprecated
     Builder namespace(String namespace);
 
+    /**
+     * Sets the namespace for the query.
+     */
+    Builder setNamespace(String namespace);
+
+    /**
+     * Sets the kind for the query.
+     */
+    @Deprecated
     Builder kind(String kind);
 
+    /**
+     * Sets the kind for the query.
+     */
+    Builder setKind(String kind);
+
+    /**
+     * Sets the start cursor for the query.
+     */
+    @Deprecated
     Builder startCursor(Cursor startCursor);
 
+    /**
+     * Sets the start cursor for the query.
+     */
+    Builder setStartCursor(Cursor startCursor);
+
+    /**
+     * Sets the end cursor for the query.
+     */
+    @Deprecated
     Builder endCursor(Cursor endCursor);
 
+    /**
+     * Sets the end cursor for the query.
+     */
+    Builder setEndCursor(Cursor endCursor);
+
+    /**
+     * Sets the offset for the query.
+     */
+    @Deprecated
     Builder offset(int offset);
 
+    /**
+     * Sets the offset for the query.
+     */
+    Builder setOffset(int offset);
+
+    /**
+     * Sets the limit for the query.
+     */
+    @Deprecated
     Builder limit(Integer limit);
 
+    /**
+     * Sets the limit for the query.
+     */
+    Builder setLimit(Integer limit);
+
+    /**
+     * Sets a filter for the query.
+     */
+    @Deprecated
     Builder filter(Filter filter);
 
+    Builder setFilter(Filter filter);
+
+    /**
+     * Clears any previously specified order by settings.
+     */
     Builder clearOrderBy();
 
     /**
-     * Sets the query's order by clause (clearing any previously specified OrderBy settings).
+     * Sets the query's order by clause (clearing any previously specified order by settings).
      */
+    @Deprecated
     Builder orderBy(OrderBy orderBy, OrderBy... others);
 
+    /**
+     * Sets the query's order by clause (clearing any previously specified order by settings).
+     */
+    Builder setOrderBy(OrderBy orderBy, OrderBy... others);
+
     /**
      * Adds settings to the existing order by clause.
      */
@@ -607,30 +699,59 @@ B self() {
     }
 
     @Override
+    @Deprecated
     public B namespace(String namespace) {
       this.namespace = namespace;
       return self();
     }
 
     @Override
+    public B setNamespace(String namespace) {
+      this.namespace = namespace;
+      return self();
+    }
+
+    @Override
+    @Deprecated
     public B kind(String kind) {
       this.kind = kind;
       return self();
     }
 
     @Override
+    public B setKind(String kind) {
+      this.kind = kind;
+      return self();
+    }
+
+    @Override
+    @Deprecated
     public B startCursor(Cursor startCursor) {
       this.startCursor = startCursor;
       return self();
     }
 
     @Override
+    public B setStartCursor(Cursor startCursor) {
+      this.startCursor = startCursor;
+      return self();
+    }
+
+    @Override
+    @Deprecated
     public B endCursor(Cursor endCursor) {
       this.endCursor = endCursor;
       return self();
     }
 
     @Override
+    public B setEndCursor(Cursor endCursor) {
+      this.endCursor = endCursor;
+      return self();
+    }
+
+    @Override
+    @Deprecated
     public B offset(int offset) {
       Preconditions.checkArgument(offset >= 0, "offset must not be negative");
       this.offset = offset;
@@ -638,6 +759,14 @@ public B offset(int offset) {
     }
 
     @Override
+    public B setOffset(int offset) {
+      Preconditions.checkArgument(offset >= 0, "offset must not be negative");
+      this.offset = offset;
+      return self();
+    }
+
+    @Override
+    @Deprecated
     public B limit(Integer limit) {
       Preconditions.checkArgument(limit == null || limit > 0, "limit must be positive");
       this.limit = limit;
@@ -645,11 +774,25 @@ public B limit(Integer limit) {
     }
 
     @Override
+    public B setLimit(Integer limit) {
+      Preconditions.checkArgument(limit == null || limit > 0, "limit must be positive");
+      this.limit = limit;
+      return self();
+    }
+
+    @Override
+    @Deprecated
     public B filter(Filter filter) {
       this.filter = filter;
       return self();
     }
 
+    @Override
+    public B setFilter(Filter filter) {
+      this.filter = filter;
+      return self();
+    }
+
     @Override
     public B clearOrderBy() {
       orderBy.clear();
@@ -657,12 +800,20 @@ public B clearOrderBy() {
     }
 
     @Override
+    @Deprecated
     public B orderBy(OrderBy orderBy, OrderBy... others) {
       clearOrderBy();
       addOrderBy(orderBy, others);
       return self();
     }
 
+    @Override
+    public B setOrderBy(OrderBy orderBy, OrderBy... others) {
+      clearOrderBy();
+      addOrderBy(orderBy, others);
+      return self();
+    }
+
     @Override
     public B addOrderBy(OrderBy orderBy, OrderBy... others) {
       this.orderBy.add(orderBy);
@@ -675,12 +826,19 @@ B clearProjection() {
       return self();
     }
 
+    @Deprecated
     B projection(String projection, String... others) {
       clearProjection();
       addProjection(projection, others);
       return self();
     }
 
+    B setProjection(String projection, String... others) {
+      clearProjection();
+      addProjection(projection, others);
+      return self();
+    }
+
     B addProjection(String projection, String... others) {
       this.projection.add(projection);
       Collections.addAll(this.projection, others);
@@ -692,12 +850,19 @@ B clearDistinctOn() {
       return self();
     }
 
+    @Deprecated
     B distinctOn(String property, String... others) {
       clearDistinctOn();
       addDistinctOn(property, others);
       return self();
     }
 
+    B setDistinctOn(String property, String... others) {
+      clearDistinctOn();
+      addDistinctOn(property, others);
+      return self();
+    }
+
     B addDistinctOn(String property, String... others) {
       this.distinctOn.add(property);
       Collections.addAll(this.distinctOn, others);
@@ -706,22 +871,22 @@ B addDistinctOn(String property, String... others) {
 
     B mergeFrom(com.google.datastore.v1.Query queryPb) {
       if (queryPb.getKindCount() > 0) {
-        kind(queryPb.getKind(0).getName());
+        setKind(queryPb.getKind(0).getName());
       }
       if (!queryPb.getStartCursor().isEmpty()) {
-        startCursor(new Cursor(queryPb.getStartCursor()));
+        setStartCursor(new Cursor(queryPb.getStartCursor()));
       }
       if (!queryPb.getEndCursor().isEmpty()) {
-        endCursor(new Cursor(queryPb.getEndCursor()));
+        setEndCursor(new Cursor(queryPb.getEndCursor()));
       }
-      offset(queryPb.getOffset());
+      setOffset(queryPb.getOffset());
       if (queryPb.hasLimit()) {
-        limit(queryPb.getLimit().getValue());
+        setLimit(queryPb.getLimit().getValue());
       }
       if (queryPb.hasFilter()) {
         Filter currFilter = Filter.fromPb(queryPb.getFilter());
         if (currFilter != null) {
-          filter(currFilter);
+          setFilter(currFilter);
         }
       }
       for (com.google.datastore.v1.PropertyOrder orderByPb : queryPb.getOrderList()) {
@@ -793,46 +958,145 @@ public boolean equals(Object obj) {
 
   }
 
+  /**
+   * Returns the kind for this query.
+   */
+  @Deprecated
   public String kind() {
     return kind;
   }
 
-  boolean keyOnly() {
+  /**
+   * Returns the kind for this query.
+   */
+  public String getKind() {
+    return kind;
+  }
+
+  boolean isKeyOnly() {
     return projection.size() == 1 && KEY_PROPERTY_NAME.equals(projection.get(0));
   }
 
+  /**
+   * Returns the projection for this query.
+   */
+  @Deprecated
   public List projection() {
     return projection;
   }
 
+  /**
+   * Returns the projection for this query.
+   */
+  public List getProjection() {
+    return projection;
+  }
+
+  /**
+   * Returns the filter for this query.
+   */
+  @Deprecated
   public Filter filter() {
     return filter;
   }
 
+  /**
+   * Returns the filter for this query.
+   */
+  public Filter getFilter() {
+    return filter;
+  }
+
+  /**
+   * Returns the distinct on clause for this query.
+   */
+  @Deprecated
   public List distinctOn() {
     return distinctOn;
   }
 
+  /**
+   * Returns the distinct on clause for this query.
+   */
+  public List getDistinctOn() {
+    return distinctOn;
+  }
+
+  /**
+   * Returns the order by clause for this query.
+   */
+  @Deprecated
   public ImmutableList orderBy() {
     return orderBy;
   }
 
+  /**
+   * Returns the order by clause for this query.
+   */
+  public ImmutableList getOrderBy() {
+    return orderBy;
+  }
+
+  /**
+   * Returns the start cursor for this query.
+   */
+  @Deprecated
   public Cursor startCursor() {
     return startCursor;
   }
 
+  /**
+   * Returns the start cursor for this query.
+   */
+  public Cursor getStartCursor() {
+    return startCursor;
+  }
+
+  /**
+   * Returns the end cursor for this query.
+   */
+  @Deprecated
   public Cursor endCursor() {
     return endCursor;
   }
 
+  /**
+   * Returns the end cursor for this query.
+   */
+  public Cursor getEndCursor() {
+    return endCursor;
+  }
+
+  /**
+   * Returns the offset for this query.
+   */
+  @Deprecated
   public int offset() {
     return offset;
   }
 
+  /**
+   * Returns the offset for this query.
+   */
+  public int getOffset() {
+    return offset;
+  }
+
+  /**
+   * Returns the limit for this query.
+   */
+  @Deprecated
   public Integer limit() {
     return limit;
   }
 
+  /**
+   * Returns the limit for this query.
+   */
+  public Integer getLimit() {
+    return limit;
+  }
+
   public abstract Builder toBuilder();
 
   @Override
@@ -843,13 +1107,13 @@ void populatePb(com.google.datastore.v1.RunQueryRequest.Builder requestPb) {
   @Override
   StructuredQuery nextQuery(com.google.datastore.v1.RunQueryResponse responsePb) {
     Builder builder = toBuilder();
-    builder.startCursor(new Cursor(responsePb.getBatch().getEndCursor()));
+    builder.setStartCursor(new Cursor(responsePb.getBatch().getEndCursor()));
     if (offset > 0 && responsePb.getBatch().getSkippedResults() < offset) {
-      builder.offset(offset - responsePb.getBatch().getSkippedResults());
+      builder.setOffset(offset - responsePb.getBatch().getSkippedResults());
     } else {
-      builder.offset(0);
+      builder.setOffset(0);
       if (limit != null) {
-        builder.limit(limit - responsePb.getBatch().getEntityResultsCount());
+        builder.setLimit(limit - responsePb.getBatch().getEntityResultsCount());
       }
     }
     return builder.build();
@@ -861,10 +1125,10 @@ com.google.datastore.v1.Query toPb() {
       queryPb.addKindBuilder().setName(kind);
     }
     if (startCursor != null) {
-      queryPb.setStartCursor(startCursor.byteString());
+      queryPb.setStartCursor(startCursor.getByteString());
     }
     if (endCursor != null) {
-      queryPb.setEndCursor(endCursor.byteString());
+      queryPb.setEndCursor(endCursor.getByteString());
     }
     if (offset > 0) {
       queryPb.setOffset(offset);
@@ -903,6 +1167,6 @@ static  StructuredQuery fromPb(ResultType resultType, String namespace,
     } else {
       builder = new ProjectionEntityQuery.Builder();
     }
-    return (StructuredQuery) builder.namespace(namespace).mergeFrom(queryPb).build();
+    return (StructuredQuery) builder.setNamespace(namespace).mergeFrom(queryPb).build();
   }
 }
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Transaction.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Transaction.java
index fd629bf0294b..b2e378d4ab54 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Transaction.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Transaction.java
@@ -35,13 +35,16 @@
  *   Entity entity = transaction.get(key);
  *   if (!entity.contains("last_name") || entity.isNull("last_name")) {
  *     String[] name = entity.getString("name").split(" ");
- *     entity = Entity.builder(entity).remove("name").set("first_name", name[0])
- *         .set("last_name", name[1]).build();
+ *     entity = Entity.newBuilder(entity)
+ *         .remove("name")
+ *         .set("first_name", name[0])
+ *         .set("last_name", name[1])
+ *         .build();
  *     transaction.update(entity);
  *     transaction.commit();
  *   }
  * } finally {
- *   if (transaction.active()) {
+ *   if (transaction.isActive()) {
  *     transaction.rollback();
  *   }
  * }
@@ -54,7 +57,17 @@
 public interface Transaction extends DatastoreBatchWriter, DatastoreReaderWriter {
 
   interface Response {
+    /**
+     * Returns a list of keys generated by a transaction.
+     */
+    @Deprecated
     List generatedKeys();
+
+    /**
+     * Returns a list of keys generated by a transaction.
+     */
+    @Deprecated
+    List getGeneratedKeys();
   }
 
   /**
@@ -231,10 +244,45 @@ interface Response {
    *
    */
   @Override
+  @Deprecated
   boolean active();
 
+  /**
+   * Returns {@code true} if the transaction is still active (was not committed or rolledback).
+   *
+   * 

Example of verifying if a transaction is active. + *

 {@code
+   * // create an entity
+   * KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+   * Key key = datastore.allocateId(keyFactory.newKey());
+   * Entity entity = Entity.builder(key).set("description", "active()").build();
+   * // calling transaction.active() now would return true
+   * try {
+   *   // add the entity and commit
+   *   transaction.put(entity);
+   *   transaction.commit();
+   * } finally {
+   *   // if committing succeeded
+   *   // then transaction.active() will be false
+   *   if (transaction.active()) {
+   *     // otherwise it's true and we need to rollback
+   *     transaction.rollback();
+   *   }
+   * }
+   * }
+ * + */ + @Override + boolean isActive(); + /** * Returns the transaction associated {@link Datastore}. */ + @Deprecated Datastore datastore(); + + /** + * Returns the transaction associated {@link Datastore}. + */ + Datastore getDatastore(); } diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/TransactionImpl.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/TransactionImpl.java index 8b398cb68cff..8c227f0c8ebd 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/TransactionImpl.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/TransactionImpl.java @@ -39,6 +39,7 @@ static class ResponseImpl implements Transaction.Response { } @Override + @Deprecated public List generatedKeys() { Iterator results = response.getMutationResultsList().iterator(); @@ -48,6 +49,17 @@ public List generatedKeys() { } return generated; } + + @Override + public List getGeneratedKeys() { + Iterator results = + response.getMutationResultsList().iterator(); + List generated = new ArrayList<>(numAutoAllocatedIds); + for (int i = 0; i < numAutoAllocatedIds; i++) { + generated.add(Key.fromPb(results.next().getKey())); + } + return generated; + } } TransactionImpl(DatastoreImpl datastore) { @@ -116,4 +128,9 @@ public void rollback() { public Datastore datastore() { return datastore; } + + @Override + public Datastore getDatastore() { + return datastore; + } } diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Value.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Value.java index 00f2c2fa64ce..e33ab137c733 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Value.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Value.java @@ -95,22 +95,36 @@ public ValueType getValueType() { @Override public B mergeFrom(P other) { excludeFromIndexes = other.excludeFromIndexes(); - meaning = other.meaning(); + meaning = other.getMeaning(); set(other.get()); return self(); } @Override + @Deprecated public boolean getExcludeFromIndexes() { return excludeFromIndexes; } @Override + public boolean excludeFromIndexes() { + return excludeFromIndexes; + } + + @Override + @Deprecated public B excludeFromIndexes(boolean excludeFromIndexes) { this.excludeFromIndexes = excludeFromIndexes; return self(); } + @Override + public B setExcludeFromIndexes(boolean excludeFromIndexes) { + this.excludeFromIndexes = excludeFromIndexes; + return self(); + } + + @Deprecated @Override public int getMeaning() { @@ -124,6 +138,13 @@ public B meaning(int meaning) { return self(); } + @Deprecated + @Override + public B setMeaning(int meaning) { + this.meaning = meaning; + return self(); + } + @Override public V get() { return value; @@ -152,10 +173,24 @@

, B extends BaseBuilder> Value(ValueBuilder value = builder.get(); } + /** + * Returns the type of this value. + */ + @Deprecated public final ValueType type() { return valueType; } + /** + * Returns the type of this value. + */ + public final ValueType getType() { + return valueType; + } + + /** + * Returns whether this value should be excluded from indexes. + */ public final boolean excludeFromIndexes() { return excludeFromIndexes; } @@ -165,6 +200,11 @@ final int meaning() { return meaning; } + @Deprecated + final int getMeaning() { + return meaning; + } + public final V get() { return value; } @@ -204,7 +244,7 @@ public boolean equals(Object obj) { @SuppressWarnings("unchecked") com.google.datastore.v1.Value toPb() { - return type().getMarshaller().toProto(this); + return getType().getMarshaller().toProto(this); } static Value fromPb(com.google.datastore.v1.Value proto) { diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ValueBuilder.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ValueBuilder.java index 0328d4a0637b..7a8065b54523 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ValueBuilder.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/ValueBuilder.java @@ -29,10 +29,16 @@ public interface ValueBuilder, B extends ValueBuilder, B extends ValueBuilder. *

 {@code
  * Datastore datastore = DatastoreOptions.defaultInstance().service();
- * KeyFactory keyFactory = datastore.newKeyFactory().kind("keyKind");
+ * KeyFactory keyFactory = datastore.newKeyFactory().setKind("keyKind");
  * Key key = keyFactory.newKey("keyName");
- * Entity entity = Entity.builder(key)
+ * Entity entity = Entity.newBuilder(key)
  *     .set("name", "John Doe")
  *     .set("age", 30)
  *     .set("access_time", DateTime.now())
@@ -39,12 +39,12 @@
  * UpdateEntity.java.
  * 
 {@code
  * Datastore datastore = DatastoreOptions.defaultInstance().service();
- * KeyFactory keyFactory = datastore.newKeyFactory().kind("keyKind");
+ * KeyFactory keyFactory = datastore.newKeyFactory().setKind("keyKind");
  * Key key = keyFactory.newKey("keyName");
  * Entity entity = datastore.get(key);
  * if (entity != null) {
  *   System.out.println("Updating access_time for " + entity.getString("name"));
- *   entity = Entity.builder(entity)
+ *   entity = Entity.newBuilder(entity)
  *       .set("access_time", DateTime.now())
  *       .build();
  *   datastore.update(entity);
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/LocalDatastoreHelper.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/LocalDatastoreHelper.java
index b8dbb6008fb0..c112479356e8 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/LocalDatastoreHelper.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/LocalDatastoreHelper.java
@@ -648,32 +648,66 @@ private DatastoreOptions.Builder optionsBuilder() {
    * Returns a {@link DatastoreOptions} instance that sets the host to use the Datastore emulator on
    * localhost.
    */
+  @Deprecated
   public DatastoreOptions options() {
     return optionsBuilder().build();
   }
 
+  /**
+   * Returns a {@link DatastoreOptions} instance that sets the host to use the Datastore emulator on
+   * localhost.
+   */
+  public DatastoreOptions getOptions() {
+    return optionsBuilder().build();
+  }
+
   /**
    * Returns a {@link DatastoreOptions} instance that sets the host to use the Datastore emulator on
    * localhost. The default namespace is set to {@code namespace}.
    */
+  @Deprecated
   public DatastoreOptions options(String namespace) {
     return optionsBuilder().namespace(namespace).build();
   }
 
+  /**
+   * Returns a {@link DatastoreOptions} instance that sets the host to use the Datastore emulator on
+   * localhost. The default namespace is set to {@code namespace}.
+   */
+  public DatastoreOptions getOptions(String namespace) {
+    return optionsBuilder().namespace(namespace).build();
+  }
+
   /**
    * Returns the project ID associated with this local Datastore emulator.
    */
+  @Deprecated
   public String projectId() {
     return projectId;
   }
 
+  /**
+   * Returns the project ID associated with this local Datastore emulator.
+   */
+  public String getProjectId() {
+    return projectId;
+  }
+
   /**
    * Returns the consistency setting for the local Datastore emulator.
    */
+  @Deprecated
   public double consistency() {
     return consistency;
   }
 
+  /**
+   * Returns the consistency setting for the local Datastore emulator.
+   */
+  public double getConsistency() {
+    return consistency;
+  }
+
   /**
    * Creates a local Datastore helper with the specified settings for project ID and consistency.
    *
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/RemoteDatastoreHelper.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/RemoteDatastoreHelper.java
index dd55e1481577..8e4febcf4580 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/RemoteDatastoreHelper.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/RemoteDatastoreHelper.java
@@ -28,7 +28,7 @@
 
 /**
  * Utility to create a remote datastore configuration for testing. Datastore options can be obtained
- * via the {@link #options()} method. Returned options use a randomly generated namespace
+ * via the {@link #getOptions()} method. Returned options use a randomly generated namespace
  * ({@link DatastoreOptions#namespace()}) that can be used to run the tests. Once the tests are run,
  * all entities in the namespace can be deleted using {@link #deleteNamespace()}. Returned options
  * also have custom {@link DatastoreOptions#retryParams()}: {@link RetryParams#retryMaxAttempts()}
@@ -55,15 +55,24 @@ private RemoteDatastoreHelper(DatastoreOptions options) {
    * Returns a {@link DatastoreOptions} object to be used for testing. The options are associated
    * to a randomly generated namespace.
    */
+  @Deprecated
   public DatastoreOptions options() {
     return options;
   }
 
+  /**
+   * Returns a {@link DatastoreOptions} object to be used for testing. The options are associated
+   * to a randomly generated namespace.
+   */
+  public DatastoreOptions getOptions() {
+    return options;
+  }
+
   /**
    * Deletes all entities in the namespace associated with this {@link RemoteDatastoreHelper}.
    */
   public void deleteNamespace() {
-    StructuredQuery query = Query.keyQueryBuilder().namespace(namespace).build();
+    StructuredQuery query = Query.newKeyQueryBuilder().setNamespace(namespace).build();
     QueryResults keys = datastore.run(query);
     while (keys.hasNext()) {
       datastore.delete(keys.next());
diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/package-info.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/package-info.java
index ec4ae11e6a02..3000b96f3f4e 100644
--- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/package-info.java
+++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/testing/package-info.java
@@ -22,7 +22,7 @@
  * 
 {@code
  * LocalDatastoreHelper helper = LocalDatastoreHelper.create();
  * helper.start();
- * Datastore localDatastore = helper.options().service();
+ * Datastore localDatastore = helper.getOptions().service();
  * } 
* *

After the test: diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseDatastoreBatchWriterTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseDatastoreBatchWriterTest.java index a1ae3f28dd5b..402085c4d5df 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseDatastoreBatchWriterTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseDatastoreBatchWriterTest.java @@ -33,17 +33,17 @@ public class BaseDatastoreBatchWriterTest { - private static final Key KEY1 = Key.builder("dataset1", "kind1", "name1").build(); - private static final Key KEY2 = Key.builder(KEY1, 1).build(); - private static final Key KEY3 = Key.builder(KEY1, 2).build(); - private static final IncompleteKey INCOMPLETE_KEY = IncompleteKey.builder(KEY1).build(); - private static final Entity ENTITY1 = Entity.builder(KEY1).build(); - private static final Entity ENTITY2 = Entity.builder(KEY2).set("bak", true).build(); - private static final Entity ENTITY3 = Entity.builder(KEY3).set("bak", true).build(); + private static final Key KEY1 = Key.newBuilder("dataset1", "kind1", "name1").build(); + private static final Key KEY2 = Key.newBuilder(KEY1, 1).build(); + private static final Key KEY3 = Key.newBuilder(KEY1, 2).build(); + private static final IncompleteKey INCOMPLETE_KEY = IncompleteKey.newBuilder(KEY1).build(); + private static final Entity ENTITY1 = Entity.newBuilder(KEY1).build(); + private static final Entity ENTITY2 = Entity.newBuilder(KEY2).set("bak", true).build(); + private static final Entity ENTITY3 = Entity.newBuilder(KEY3).set("bak", true).build(); private static final FullEntity INCOMPLETE_ENTITY_1 = - Entity.builder(INCOMPLETE_KEY).build(); + Entity.newBuilder(INCOMPLETE_KEY).build(); private static final FullEntity INCOMPLETE_ENTITY_2 = - Entity.builder(INCOMPLETE_KEY).set("name", "dan").build(); + Entity.newBuilder(INCOMPLETE_KEY).set("name", "dan").build(); private DatastoreBatchWriter batchWriter; @@ -61,10 +61,16 @@ protected DatastoreBatchWriter() { } @Override + @Deprecated protected Datastore datastore() { return datastore; } + @Override + protected Datastore getDatastore() { + return datastore; + } + void finish() { verify(datastore); } @@ -83,20 +89,20 @@ public void tearDown() { @Test public void testAdd() throws Exception { Entity entity2 = - Entity.builder(ENTITY2).key(Key.builder(KEY1).name("name2").build()).build(); + Entity.newBuilder(ENTITY2).setKey(Key.newBuilder(KEY1).setName("name2").build()).build(); List pbs = new LinkedList<>(); pbs.add(com.google.datastore.v1.Mutation.newBuilder().setInsert(ENTITY1.toPb()).build()); pbs.add(com.google.datastore.v1.Mutation.newBuilder() - .setInsert(Entity.builder(KEY2, INCOMPLETE_ENTITY_1).build().toPb()).build()); + .setInsert(Entity.newBuilder(KEY2, INCOMPLETE_ENTITY_1).build().toPb()).build()); pbs.add(com.google.datastore.v1.Mutation.newBuilder() - .setInsert(Entity.builder(KEY3, INCOMPLETE_ENTITY_2).build().toPb()).build()); + .setInsert(Entity.newBuilder(KEY3, INCOMPLETE_ENTITY_2).build().toPb()).build()); pbs.add(com.google.datastore.v1.Mutation.newBuilder().setInsert(entity2.toPb()).build()); List entities = batchWriter .add(ENTITY1, INCOMPLETE_ENTITY_1, INCOMPLETE_ENTITY_2, entity2); assertEquals(pbs, batchWriter.toMutationPbList()); assertEquals(ENTITY1, entities.get(0)); - assertEquals(Entity.builder(KEY2, INCOMPLETE_ENTITY_1).build(), entities.get(1)); - assertEquals(Entity.builder(KEY3, INCOMPLETE_ENTITY_2).build(), entities.get(2)); + assertEquals(Entity.newBuilder(KEY2, INCOMPLETE_ENTITY_1).build(), entities.get(1)); + assertEquals(Entity.newBuilder(KEY3, INCOMPLETE_ENTITY_2).build(), entities.get(2)); assertEquals(entity2, entities.get(3)); } @@ -165,7 +171,7 @@ public void testUpdate() throws Exception { @Test public void testUpdateAfterUpdate() throws Exception { - Entity entity = Entity.builder(ENTITY1).set("foo", "bar").build(); + Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build(); List pbs = new LinkedList<>(); pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpdate(entity.toPb()).build()); batchWriter.update(ENTITY1); @@ -175,7 +181,7 @@ public void testUpdateAfterUpdate() throws Exception { @Test public void testUpdateAfterAdd() throws Exception { - Entity entity = Entity.builder(ENTITY1).set("foo", "bar").build(); + Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build(); List pbs = new LinkedList<>(); pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build()); batchWriter.add(ENTITY1); @@ -185,7 +191,7 @@ public void testUpdateAfterAdd() throws Exception { @Test public void testUpdateAfterPut() throws Exception { - Entity entity = Entity.builder(ENTITY1).set("foo", "bar").build(); + Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build(); List pbs = new LinkedList<>(); pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build()); batchWriter.put(ENTITY1); @@ -224,16 +230,16 @@ public void testPutIncompleteKey() throws Exception { List pbs = new LinkedList<>(); pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(ENTITY1.toPb()).build()); pbs.add(com.google.datastore.v1.Mutation.newBuilder() - .setUpsert(Entity.builder(KEY2, INCOMPLETE_ENTITY_1).build().toPb()) + .setUpsert(Entity.newBuilder(KEY2, INCOMPLETE_ENTITY_1).build().toPb()) .build()); pbs.add(com.google.datastore.v1.Mutation.newBuilder() - .setUpsert(Entity.builder(KEY3, INCOMPLETE_ENTITY_2).build().toPb()) + .setUpsert(Entity.newBuilder(KEY3, INCOMPLETE_ENTITY_2).build().toPb()) .build()); Entity putEntity = batchWriter.put(ENTITY1); List putEntities = batchWriter.put(INCOMPLETE_ENTITY_1, INCOMPLETE_ENTITY_2); assertEquals(ENTITY1, putEntity); - assertEquals(Entity.builder(KEY2, INCOMPLETE_ENTITY_1).build(), putEntities.get(0)); - assertEquals(Entity.builder(KEY3, INCOMPLETE_ENTITY_2).build(), putEntities.get(1)); + assertEquals(Entity.newBuilder(KEY2, INCOMPLETE_ENTITY_1).build(), putEntities.get(0)); + assertEquals(Entity.newBuilder(KEY3, INCOMPLETE_ENTITY_2).build(), putEntities.get(1)); assertEquals(pbs, batchWriter.toMutationPbList()); } @@ -254,7 +260,7 @@ public void testPutWithDeferredAllocation() throws Exception { @Test public void testPutAfterPut() throws Exception { - Entity entity = Entity.builder(ENTITY1).set("foo", "bar").build(); + Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build(); List pbs = new LinkedList<>(); pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build()); Entity putEntity1 = batchWriter.put(ENTITY1); @@ -266,7 +272,7 @@ public void testPutAfterPut() throws Exception { @Test public void testPutAfterAdd() throws Exception { - Entity entity = Entity.builder(ENTITY1).set("foo", "bar").build(); + Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build(); List pbs = new LinkedList<>(); pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build()); batchWriter.add(ENTITY1); @@ -276,7 +282,7 @@ public void testPutAfterAdd() throws Exception { @Test public void testPutAfterUpdate() throws Exception { - Entity entity = Entity.builder(ENTITY1).set("foo", "bar").build(); + Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build(); List pbs = new LinkedList<>(); pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build()); batchWriter.update(ENTITY1); @@ -287,7 +293,7 @@ public void testPutAfterUpdate() throws Exception { @Test public void testPutAfterDelete() throws Exception { - Entity entity = Entity.builder(ENTITY1).set("foo", "bar").build(); + Entity entity = Entity.newBuilder(ENTITY1).set("foo", "bar").build(); List pbs = new LinkedList<>(); pbs.add(com.google.datastore.v1.Mutation.newBuilder().setUpsert(entity.toPb()).build()); batchWriter.delete(KEY1); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseEntityTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseEntityTest.java index 08884a997bc0..598b6c2dde66 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseEntityTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseEntityTest.java @@ -36,11 +36,11 @@ public class BaseEntityTest { private static final Blob BLOB = Blob.copyFrom(new byte[]{1, 2}); private static final DateTime DATE_TIME = DateTime.now(); private static final LatLng LAT_LNG = new LatLng(37.422035, -122.084124); - private static final Key KEY = Key.builder("ds1", "k1", "n1").build(); - private static final Entity ENTITY = Entity.builder(KEY).set("name", "foo").build(); - private static final IncompleteKey INCOMPLETE_KEY = IncompleteKey.builder("ds1", "k1").build(); + private static final Key KEY = Key.newBuilder("ds1", "k1", "n1").build(); + private static final Entity ENTITY = Entity.newBuilder(KEY).set("name", "foo").build(); + private static final IncompleteKey INCOMPLETE_KEY = IncompleteKey.newBuilder("ds1", "k1").build(); private static final FullEntity PARTIAL_ENTITY = - Entity.builder(INCOMPLETE_KEY).build(); + Entity.newBuilder(INCOMPLETE_KEY).build(); private Builder builder; @@ -67,8 +67,8 @@ public void setUp() { builder.set("booleanList", true, false, true); builder.set("dateTimeList", DateTime.now(), DateTime.now(), DateTime.now()); builder.set("doubleList", 12.3, 4.56, .789); - builder.set("keyList", KEY, Key.builder("ds2", "k2", "n2").build(), - Key.builder("ds3", "k3", "n3").build()); + builder.set("keyList", KEY, Key.newBuilder("ds2", "k2", "n2").build(), + Key.newBuilder("ds3", "k3", "n3").build()); builder.set("entityList", ENTITY, PARTIAL_ENTITY); builder.set("stringList", "s1", "s2", "s3"); builder.set("longList", 1, 23, 456); @@ -165,7 +165,7 @@ public void testGetLatLng() throws Exception { public void testGetKey() throws Exception { BaseEntity entity = builder.build(); assertEquals(KEY, entity.getKey("key")); - Key key = Key.builder(KEY).name("BLA").build(); + Key key = Key.newBuilder(KEY).setName("BLA").build(); entity = builder.set("key", key).build(); assertEquals(key, entity.getKey("key")); } @@ -220,6 +220,19 @@ public void testGetBlob() throws Exception { @Test public void testNames() throws Exception { + Set names = + ImmutableSet.builder() + .add("string", "stringValue", "boolean", "double", "long", "list1", "list2", "list3") + .add("entity", "partialEntity", "null", "dateTime", "blob", "key", "blobList") + .add("booleanList", "dateTimeList", "doubleList", "keyList", "entityList", "stringList") + .add("longList", "latLng", "latLngList") + .build(); + BaseEntity entity = builder.build(); + assertEquals(names, entity.getNames()); + } + + @Test + public void testNamesDeprecated() throws Exception { Set names = ImmutableSet.builder() .add("string", "stringValue", "boolean", "double", "long", "list1", "list2", "list3") @@ -230,4 +243,18 @@ public void testNames() throws Exception { BaseEntity entity = builder.build(); assertEquals(names, entity.names()); } + + @Test + public void testKey() throws Exception { + builder.setKey(KEY); + BaseEntity entity = builder.build(); + assertEquals(KEY, entity.getKey()); + } + + @Test + public void testKeyDeprecated() throws Exception { + builder.key(KEY); + BaseEntity entity = builder.build(); + assertEquals(KEY, entity.key()); + } } diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseKeyTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseKeyTest.java index 9d46c2eebb94..aa5302d15d62 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseKeyTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BaseKeyTest.java @@ -47,15 +47,30 @@ protected BaseKey build() { return new BaseKey(projectId, namespace, path.build()) { @Override + @Deprecated protected BaseKey parent() { return null; } + + @Override + protected BaseKey getParent() { + return null; + } }; } } @Test - public void testDataset() throws Exception { + public void testProjectId() throws Exception { + Builder builder = new Builder("ds1", "k"); + BaseKey key = builder.build(); + assertEquals("ds1", key.getProjectId()); + key = builder.setProjectId("ds2").build(); + assertEquals("ds2", key.getProjectId()); + } + + @Test + public void testProjectIdDeprecated() throws Exception { Builder builder = new Builder("ds1", "k"); BaseKey key = builder.build(); assertEquals("ds1", key.projectId()); @@ -70,12 +85,28 @@ public void testBadDatasetInConstructor() throws Exception { @Test(expected = IllegalArgumentException.class) public void testBadDatasetInSetter() throws Exception { + Builder builder = new Builder("d", "k"); + builder.setProjectId(" "); + } + + @Test(expected = IllegalArgumentException.class) + public void testBadDatasetInSetterDeprecated() throws Exception { Builder builder = new Builder("d", "k"); builder.projectId(" "); } @Test public void testNamespace() throws Exception { + Builder builder = new Builder("ds", "k"); + BaseKey key = builder.build(); + assertTrue(key.getNamespace() != null); + assertTrue(key.getNamespace().isEmpty()); + key = builder.setNamespace("ns").build(); + assertEquals("ns", key.getNamespace()); + } + + @Test + public void testNamespaceDeprecated() throws Exception { Builder builder = new Builder("ds", "k"); BaseKey key = builder.build(); assertTrue(key.namespace() != null); @@ -86,6 +117,15 @@ public void testNamespace() throws Exception { @Test public void testKind() throws Exception { + Builder builder = new Builder("ds", "k1"); + BaseKey key = builder.build(); + assertEquals("k1", key.getKind()); + key = builder.setKind("k2").build(); + assertEquals("k2", key.getKind()); + } + + @Test + public void testKindDeprecated() throws Exception { Builder builder = new Builder("ds", "k1"); BaseKey key = builder.build(); assertEquals("k1", key.kind()); @@ -106,12 +146,32 @@ public void testBadKindInConstructor() throws Exception { @Test(expected = IllegalArgumentException.class) public void testBadKindInSetter() throws Exception { + Builder builder = new Builder("ds", "k1"); + builder.setKind(""); + } + + @Test(expected = IllegalArgumentException.class) + public void testBadKindInSetterDeprecated() throws Exception { Builder builder = new Builder("ds", "k1"); builder.kind(""); } @Test public void testAncestors() throws Exception { + Builder builder = new Builder("ds", "k"); + BaseKey key = builder.build(); + assertTrue(key.getAncestors().isEmpty()); + List path = new ArrayList<>(); + path.add(PathElement.of("p1", "v1")); + key = builder.addAncestor(path.get(0)).build(); + assertEquals(path, key.getAncestors()); + path.add(PathElement.of("p2", "v2")); + key = builder.addAncestor(path.get(1)).build(); + assertEquals(path, key.getAncestors()); + } + + @Test + public void testAncestorsDeprecated() throws Exception { Builder builder = new Builder("ds", "k"); BaseKey key = builder.build(); assertTrue(key.ancestors().isEmpty()); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BlobTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BlobTest.java index 009c1a31ee1e..2746880f7735 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BlobTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BlobTest.java @@ -55,6 +55,12 @@ public void testEquals() throws Exception { @Test public void testLength() throws Exception { + assertEquals(bytes1.length, blob1.getLength()); + assertEquals(bytes2.length, blob2.getLength()); + } + + @Test + public void testLengthDeprecated() throws Exception { assertEquals(bytes1.length, blob1.length()); assertEquals(bytes2.length, blob2.length()); } diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BlobValueTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BlobValueTest.java index 3c6586939a54..2232cfb55a54 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BlobValueTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BlobValueTest.java @@ -32,7 +32,6 @@ public void testToBuilder() throws Exception { assertEquals(value, value.toBuilder().build()); } - @SuppressWarnings("deprecation") @Test public void testOf() throws Exception { BlobValue value = BlobValue.of(CONTENT); @@ -43,6 +42,15 @@ public void testOf() throws Exception { @SuppressWarnings("deprecation") @Test public void testBuilder() throws Exception { + BlobValue.Builder builder = BlobValue.newBuilder(CONTENT); + BlobValue value = builder.setMeaning(1).setExcludeFromIndexes(true).build(); + assertEquals(CONTENT, value.get()); + assertEquals(1, value.getMeaning()); + assertTrue(value.excludeFromIndexes()); + } + + @Test + public void testBuilderDeprecated() throws Exception { BlobValue.Builder builder = BlobValue.builder(CONTENT); BlobValue value = builder.meaning(1).excludeFromIndexes(true).build(); assertEquals(CONTENT, value.get()); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BooleanValueTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BooleanValueTest.java index 2750c70e992b..983be5db7a62 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BooleanValueTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/BooleanValueTest.java @@ -30,7 +30,6 @@ public void testToBuilder() throws Exception { assertEquals(value, value.toBuilder().build()); } - @SuppressWarnings("deprecation") @Test public void testOf() throws Exception { BooleanValue value = BooleanValue.of(false); @@ -41,6 +40,15 @@ public void testOf() throws Exception { @SuppressWarnings("deprecation") @Test public void testBuilder() throws Exception { + BooleanValue.Builder builder = BooleanValue.newBuilder(true); + BooleanValue value = builder.setMeaning(1).setExcludeFromIndexes(true).build(); + assertTrue(value.get()); + assertEquals(1, value.getMeaning()); + assertTrue(value.excludeFromIndexes()); + } + + @Test + public void testBuilderDeprecated() throws Exception { BooleanValue.Builder builder = BooleanValue.builder(true); BooleanValue value = builder.meaning(1).excludeFromIndexes(true).build(); assertTrue(value.get()); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreHelperTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreHelperTest.java index 2538a75847bd..95a61d47484f 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreHelperTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreHelperTest.java @@ -46,19 +46,19 @@ public void testNewKeyFactory() { expect(options.namespace()).andReturn("ns1").once(); replay(options); KeyFactory keyFactory = DatastoreHelper.newKeyFactory(options); - Key key = keyFactory.kind("k").newKey("bla"); - assertEquals("ds1", key.projectId()); - assertEquals("ns1", key.namespace()); - assertEquals("k", key.kind()); - assertEquals("bla", key.name()); + Key key = keyFactory.setKind("k").newKey("bla"); + assertEquals("ds1", key.getProjectId()); + assertEquals("ns1", key.getNamespace()); + assertEquals("k", key.getKind()); + assertEquals("bla", key.getName()); verify(options); } @Test public void testAllocateId() throws Exception { Datastore datastore = createStrictMock(Datastore.class); - IncompleteKey pKey1 = IncompleteKey.builder("ds", "k").build(); - Key key1 = Key.builder(pKey1, 1).build(); + IncompleteKey pKey1 = IncompleteKey.newBuilder("ds", "k").build(); + Key key1 = Key.newBuilder(pKey1, 1).build(); expect(datastore.allocateId(new IncompleteKey[] {pKey1})) .andReturn(Collections.singletonList(key1)); replay(datastore); @@ -69,10 +69,10 @@ public void testAllocateId() throws Exception { @Test public void testGetWithDatastore() throws Exception { Datastore datastore = createStrictMock(Datastore.class); - IncompleteKey pKey1 = IncompleteKey.builder("ds", "k").build(); - Key key1 = Key.builder(pKey1, 1).build(); - Entity entity1 = Entity.builder(key1).build(); - Key key2 = Key.builder(pKey1, 2).build(); + IncompleteKey pKey1 = IncompleteKey.newBuilder("ds", "k").build(); + Key key1 = Key.newBuilder(pKey1, 1).build(); + Entity entity1 = Entity.newBuilder(key1).build(); + Key key2 = Key.newBuilder(pKey1, 2).build(); ReadOption eventualConsistency = ReadOption.eventualConsistency(); expect(datastore.get(Collections.singletonList(key1))) .andReturn(Collections.singletonList(entity1).iterator()); @@ -90,10 +90,10 @@ public void testGetWithDatastore() throws Exception { @Test public void testGetWithTransaction() throws Exception { Transaction transaction = createStrictMock(Transaction.class); - IncompleteKey pKey1 = IncompleteKey.builder("ds", "k").build(); - Key key1 = Key.builder(pKey1, 1).build(); - Entity entity1 = Entity.builder(key1).build(); - Key key2 = Key.builder(pKey1, 2).build(); + IncompleteKey pKey1 = IncompleteKey.newBuilder("ds", "k").build(); + Key key1 = Key.newBuilder(pKey1, 1).build(); + Entity entity1 = Entity.newBuilder(key1).build(); + Key key2 = Key.newBuilder(pKey1, 2).build(); expect(transaction.get(new Key[] {key1})) .andReturn(Collections.singletonList(entity1).iterator()); expect(transaction.get(new Key[] {key2})).andReturn(Collections.emptyIterator()); @@ -106,9 +106,9 @@ public void testGetWithTransaction() throws Exception { @Test public void testAdd() throws Exception { Datastore datastore = createStrictMock(Datastore.class); - IncompleteKey pKey = IncompleteKey.builder("ds", "k").build(); - Key key = Key.builder(pKey, 1).build(); - Entity entity = Entity.builder(key).build(); + IncompleteKey pKey = IncompleteKey.newBuilder("ds", "k").build(); + Key key = Key.newBuilder(pKey, 1).build(); + Entity entity = Entity.newBuilder(key).build(); expect(datastore.add(new Entity[] {entity})).andReturn(Collections.singletonList(entity)); replay(datastore); assertEquals(entity, DatastoreHelper.add(datastore, entity)); @@ -118,11 +118,11 @@ public void testAdd() throws Exception { @Test public void testFetchWithDatastore() throws Exception { Datastore datastore = createStrictMock(Datastore.class); - IncompleteKey pKey1 = IncompleteKey.builder("ds", "k").build(); - Key key1 = Key.builder(pKey1, 1).build(); - Key key2 = Key.builder(pKey1, "a").build(); - Entity entity1 = Entity.builder(key1).build(); - Entity entity2 = Entity.builder(key2).build(); + IncompleteKey pKey1 = IncompleteKey.newBuilder("ds", "k").build(); + Key key1 = Key.newBuilder(pKey1, 1).build(); + Key key2 = Key.newBuilder(pKey1, "a").build(); + Entity entity1 = Entity.newBuilder(key1).build(); + Entity entity2 = Entity.newBuilder(key2).build(); ReadOption eventualConsistency = ReadOption.eventualConsistency(); expect(datastore.get(ImmutableList.of(key1, key2))) .andReturn(Iterators.forArray(entity1, entity2)) @@ -145,11 +145,11 @@ public void testFetchWithDatastore() throws Exception { @Test public void testFetchWithTransaction() throws Exception { Transaction transaction = createStrictMock(Transaction.class); - IncompleteKey pKey1 = IncompleteKey.builder("ds", "k").build(); - Key key1 = Key.builder(pKey1, 1).build(); - Key key2 = Key.builder(pKey1, "a").build(); - Entity entity1 = Entity.builder(key1).build(); - Entity entity2 = Entity.builder(key2).build(); + IncompleteKey pKey1 = IncompleteKey.newBuilder("ds", "k").build(); + Key key1 = Key.newBuilder(pKey1, 1).build(); + Key key2 = Key.newBuilder(pKey1, "a").build(); + Entity entity1 = Entity.newBuilder(key1).build(); + Entity entity2 = Entity.newBuilder(key2).build(); expect(transaction.get(new Key[] {key1, key2})) .andReturn(Iterators.forArray(entity1, entity2)) .once(); @@ -166,15 +166,15 @@ public void testRunInTransaction() throws Exception { final Datastore datastore = createStrictMock(Datastore.class); final Transaction transaction = createStrictMock(Transaction.class); expect(datastore.newTransaction()).andReturn(transaction).once(); - expect(transaction.active()).andReturn(true).once(); + expect(transaction.isActive()).andReturn(true).once(); expect(transaction.commit()).andReturn(null).once(); - expect(transaction.active()).andReturn(false).once(); + expect(transaction.isActive()).andReturn(false).once(); replay(datastore, transaction); String value = DatastoreHelper.runInTransaction(datastore, new TransactionCallable() { @Override public String run(DatastoreReaderWriter readerWriter) { - assertTrue(transaction.active()); + assertTrue(transaction.isActive()); assertSame(transaction, readerWriter); return "done"; } @@ -188,16 +188,16 @@ public void testRunInTransactionWithException() throws Exception { final Datastore datastore = createStrictMock(Datastore.class); final Transaction transaction = createStrictMock(Transaction.class); expect(datastore.newTransaction()).andReturn(transaction).once(); - expect(transaction.active()).andReturn(true).once(); + expect(transaction.isActive()).andReturn(true).once(); transaction.rollback(); EasyMock.expectLastCall().once(); - expect(transaction.active()).andReturn(false).once(); + expect(transaction.isActive()).andReturn(false).once(); replay(datastore, transaction); try { DatastoreHelper.runInTransaction(datastore, new TransactionCallable() { @Override public Void run(DatastoreReaderWriter readerWriter) throws Exception { - assertTrue(transaction.active()); + assertTrue(transaction.isActive()); assertSame(transaction, readerWriter); throw new Exception("Bla"); } diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTest.java index 8e8b52fce5ed..7b99f36abc4c 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DatastoreTest.java @@ -68,7 +68,7 @@ public class DatastoreTest { private static LocalDatastoreHelper helper = LocalDatastoreHelper.create(1.0); - private static final DatastoreOptions options = helper.options(); + private static final DatastoreOptions options = helper.getOptions(); private static final Datastore datastore = options.service(); private static final String PROJECT_ID = options.projectId(); private static final String KIND1 = "kind1"; @@ -76,19 +76,19 @@ public class DatastoreTest { private static final String KIND3 = "kind3"; private static final NullValue NULL_VALUE = NullValue.of(); private static final StringValue STR_VALUE = StringValue.of("str"); - private static final BooleanValue BOOL_VALUE = BooleanValue.builder(false) - .excludeFromIndexes(true).build(); + private static final BooleanValue BOOL_VALUE = BooleanValue.newBuilder(false) + .setExcludeFromIndexes(true).build(); private static final IncompleteKey INCOMPLETE_KEY1 = - IncompleteKey.builder(PROJECT_ID, KIND1).build(); + IncompleteKey.newBuilder(PROJECT_ID, KIND1).build(); private static final IncompleteKey INCOMPLETE_KEY2 = - IncompleteKey.builder(PROJECT_ID, KIND2).build(); - private static final Key KEY1 = Key.builder(INCOMPLETE_KEY1, "name").build(); - private static final Key KEY2 = Key.builder(KEY1, KIND2, 1).build(); - private static final Key KEY3 = Key.builder(KEY2).name("bla").build(); - private static final Key KEY4 = Key.builder(KEY2).name("newName1").build(); - private static final Key KEY5 = Key.builder(KEY2).name("newName2").build(); + IncompleteKey.newBuilder(PROJECT_ID, KIND2).build(); + private static final Key KEY1 = Key.newBuilder(INCOMPLETE_KEY1, "name").build(); + private static final Key KEY2 = Key.newBuilder(KEY1, KIND2, 1).build(); + private static final Key KEY3 = Key.newBuilder(KEY2).setName("bla").build(); + private static final Key KEY4 = Key.newBuilder(KEY2).setName("newName1").build(); + private static final Key KEY5 = Key.newBuilder(KEY2).setName("newName2").build(); private static final KeyValue KEY_VALUE = KeyValue.of(KEY1); - private static final ListValue LIST_VALUE1 = ListValue.builder() + private static final ListValue LIST_VALUE1 = ListValue.newBuilder() .addValue(NULL_VALUE) .addValue(STR_VALUE, BOOL_VALUE) .build(); @@ -98,15 +98,16 @@ public class DatastoreTest { private static final LatLngValue LAT_LNG_VALUE = new LatLngValue(new LatLng(37.422035, -122.084124)); private static final FullEntity PARTIAL_ENTITY1 = - FullEntity.builder(INCOMPLETE_KEY2).set("str", STR_VALUE).set("bool", BOOL_VALUE) + FullEntity.newBuilder(INCOMPLETE_KEY2).set("str", STR_VALUE).set("bool", BOOL_VALUE) .set("list", LIST_VALUE1).build(); private static final FullEntity PARTIAL_ENTITY2 = - FullEntity.builder(PARTIAL_ENTITY1).remove("str").set("bool", true) + FullEntity.newBuilder(PARTIAL_ENTITY1).remove("str").set("bool", true) .set("list", LIST_VALUE1.get()).build(); private static final FullEntity PARTIAL_ENTITY3 = - FullEntity.builder(PARTIAL_ENTITY1).key(IncompleteKey.builder(PROJECT_ID, KIND3).build()) + FullEntity.newBuilder(PARTIAL_ENTITY1) + .setKey(IncompleteKey.newBuilder(PROJECT_ID, KIND3).build()) .build(); - private static final Entity ENTITY1 = Entity.builder(KEY1) + private static final Entity ENTITY1 = Entity.newBuilder(KEY1) .set("str", STR_VALUE) .set("date", DATE_TIME_VALUE) .set("latLng", LAT_LNG_VALUE) @@ -115,9 +116,9 @@ public class DatastoreTest { .set("list", LIST_VALUE2) .set("emptyList", EMPTY_LIST_VALUE) .build(); - private static final Entity ENTITY2 = Entity.builder(ENTITY1).key(KEY2).remove("str") + private static final Entity ENTITY2 = Entity.newBuilder(ENTITY1).setKey(KEY2).remove("str") .set("name", "Dan").setNull("null").set("age", 20).build(); - private static final Entity ENTITY3 = Entity.builder(ENTITY1).key(KEY3).remove("str") + private static final Entity ENTITY3 = Entity.newBuilder(ENTITY1).setKey(KEY3).remove("str") .set("null", NULL_VALUE).set("partial1", PARTIAL_ENTITY2).set("partial2", ENTITY2).build(); private DatastoreOptions rpcMockOptions; @@ -142,7 +143,7 @@ public void setUp() { .serviceRpcFactory(rpcFactoryMock) .build(); EasyMock.expect(rpcFactoryMock.create(rpcMockOptions)).andReturn(rpcMock); - StructuredQuery query = Query.keyQueryBuilder().build(); + StructuredQuery query = Query.newKeyQueryBuilder().build(); QueryResults result = datastore.run(query); datastore.delete(Iterators.toArray(result, Key.class)); datastore.add(ENTITY1, ENTITY2); @@ -162,7 +163,7 @@ public void testGetOptions() { public void testNewTransactionCommit() { Transaction transaction = datastore.newTransaction(); transaction.add(ENTITY3); - Entity entity2 = Entity.builder(ENTITY2) + Entity entity2 = Entity.newBuilder(ENTITY2) .clear() .setNull("bla") .build(); @@ -204,7 +205,7 @@ public void testTransactionWithRead() { transaction = datastore.newTransaction(); assertEquals(ENTITY3, transaction.get(KEY3)); // update entity3 during the transaction - datastore.put(Entity.builder(ENTITY3).clear().build()); + datastore.put(Entity.newBuilder(ENTITY3).clear().build()); transaction.update(ENTITY2); try { transaction.commit(); @@ -216,9 +217,9 @@ public void testTransactionWithRead() { @Test public void testTransactionWithQuery() { - Query query = Query.entityQueryBuilder() - .kind(KIND2) - .filter(PropertyFilter.hasAncestor(KEY2)) + Query query = Query.newEntityQueryBuilder() + .setKind(KIND2) + .setFilter(PropertyFilter.hasAncestor(KEY2)) .build(); Transaction transaction = datastore.newTransaction(); QueryResults results = transaction.run(query); @@ -231,9 +232,9 @@ public void testTransactionWithQuery() { transaction = datastore.newTransaction(); results = transaction.run(query); assertEquals(ENTITY2, results.next()); - transaction.delete(ENTITY3.key()); + transaction.delete(ENTITY3.getKey()); // update entity2 during the transaction - datastore.put(Entity.builder(ENTITY2).clear().build()); + datastore.put(Entity.newBuilder(ENTITY2).clear().build()); try { transaction.commit(); fail("Expecting a failure"); @@ -246,8 +247,8 @@ public void testTransactionWithQuery() { public void testNewTransactionRollback() { Transaction transaction = datastore.newTransaction(); transaction.add(ENTITY3); - Entity entity2 = Entity.builder(ENTITY2).clear().setNull("bla") - .set("list3", StringValue.of("bla"), StringValue.builder("bla").build()).build(); + Entity entity2 = Entity.newBuilder(ENTITY2).clear().setNull("bla") + .set("list3", StringValue.of("bla"), StringValue.newBuilder("bla").build()).build(); transaction.update(entity2); transaction.delete(KEY1); transaction.rollback(); @@ -292,7 +293,7 @@ private void verifyNotUsable(DatastoreWriter writer) { } try { - writer.delete(ENTITY3.key()); + writer.delete(ENTITY3.getKey()); fail("Expecting a failure"); } catch (DatastoreException ex) { // expected to fail @@ -302,28 +303,29 @@ private void verifyNotUsable(DatastoreWriter writer) { @Test public void testNewBatch() { Batch batch = datastore.newBatch(); - Entity entity1 = Entity.builder(ENTITY1).clear().build(); - Entity entity2 = Entity.builder(ENTITY2).clear().setNull("bla").build(); - Entity entity4 = Entity.builder(KEY4).set("value", StringValue.of("value")).build(); - Entity entity5 = Entity.builder(KEY5).set("value", "value").build(); + Entity entity1 = Entity.newBuilder(ENTITY1).clear().build(); + Entity entity2 = Entity.newBuilder(ENTITY2).clear().setNull("bla").build(); + Entity entity4 = Entity.newBuilder(KEY4).set("value", StringValue.of("value")).build(); + Entity entity5 = Entity.newBuilder(KEY5).set("value", "value").build(); List entities = batch.add(entity4, PARTIAL_ENTITY2, entity5); Entity entity6 = entities.get(1); assertSame(entity4, entities.get(0)); - assertEquals(PARTIAL_ENTITY2.properties(), entity6.properties()); - assertEquals(PARTIAL_ENTITY2.key().projectId(), entity6.key().projectId()); - assertEquals(PARTIAL_ENTITY2.key().namespace(), entity6.key().namespace()); - assertEquals(PARTIAL_ENTITY2.key().ancestors(), entity6.key().ancestors()); - assertEquals(PARTIAL_ENTITY2.key().kind(), entity6.key().kind()); - assertEquals(PARTIAL_ENTITY2.key(), IncompleteKey.builder(entity6.key()).build()); - assertNotEquals(PARTIAL_ENTITY2.key().path(), entity6.key().path()); - assertNotEquals(PARTIAL_ENTITY2.key(), entity6.key()); + assertEquals(PARTIAL_ENTITY2.getProperties(), entity6.getProperties()); + assertEquals(PARTIAL_ENTITY2.getKey().getProjectId(), entity6.getKey().getProjectId()); + assertEquals(PARTIAL_ENTITY2.getKey().getNamespace(), entity6.getKey().getNamespace()); + assertEquals(PARTIAL_ENTITY2.getKey().getAncestors(), entity6.getKey().getAncestors()); + assertEquals(PARTIAL_ENTITY2.getKey().getKind(), entity6.getKey().getKind()); + assertEquals(PARTIAL_ENTITY2.getKey(), IncompleteKey.newBuilder(entity6.getKey()).build()); + assertNotEquals(PARTIAL_ENTITY2.getKey().getPath(), entity6.getKey().getPath()); + assertNotEquals(PARTIAL_ENTITY2.getKey(), entity6.getKey()); assertSame(entity5, entities.get(2)); batch.addWithDeferredIdAllocation(PARTIAL_ENTITY3); batch.put(ENTITY3, entity1, entity2); Batch.Response response = batch.submit(); - entities = datastore.fetch(KEY1, KEY2, KEY3, entity4.key(), entity5.key(), entity6.key()); + entities = + datastore.fetch(KEY1, KEY2, KEY3, entity4.getKey(), entity5.getKey(), entity6.getKey()); assertEquals(entity1, entities.get(0)); assertEquals(entity2, entities.get(1)); assertEquals(ENTITY3, entities.get(2)); @@ -331,10 +333,10 @@ public void testNewBatch() { assertEquals(entity5, entities.get(4)); assertEquals(entity6, entities.get(5)); assertEquals(6, entities.size()); - List generatedKeys = response.generatedKeys(); + List generatedKeys = response.getGeneratedKeys(); assertEquals(1, generatedKeys.size()); - assertEquals(PARTIAL_ENTITY3.properties(), datastore.get(generatedKeys.get(0)).properties()); - assertEquals(PARTIAL_ENTITY3.key(), IncompleteKey.builder(generatedKeys.get(0)).build()); + assertEquals(PARTIAL_ENTITY3.getProperties(), datastore.get(generatedKeys.get(0)).getProperties()); + assertEquals(PARTIAL_ENTITY3.getKey(), IncompleteKey.newBuilder(generatedKeys.get(0)).build()); try { batch.submit(); @@ -345,10 +347,10 @@ public void testNewBatch() { verifyNotUsable(batch); batch = datastore.newBatch(); - batch.delete(entity4.key(), entity5.key()); + batch.delete(entity4.getKey(), entity5.getKey()); batch.update(ENTITY1, ENTITY2, ENTITY3); batch.submit(); - entities = datastore.fetch(KEY1, KEY2, KEY3, entity4.key(), entity5.key()); + entities = datastore.fetch(KEY1, KEY2, KEY3, entity4.getKey(), entity5.getKey()); assertEquals(ENTITY1, entities.get(0)); assertEquals(ENTITY2, entities.get(1)); assertEquals(ENTITY3, entities.get(2)); @@ -360,14 +362,14 @@ public void testNewBatch() { @Test public void testRunGqlQueryNoCasting() { Query query1 = - Query.gqlQueryBuilder(ResultType.ENTITY, "select * from " + KIND1).build(); + Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from " + KIND1).build(); QueryResults results1 = datastore.run(query1); assertTrue(results1.hasNext()); assertEquals(ENTITY1, results1.next()); assertFalse(results1.hasNext()); datastore.put(ENTITY3); - Query query2 = Query.gqlQueryBuilder( + Query query2 = Query.newGqlQueryBuilder( ResultType.ENTITY, "select * from " + KIND2 + " order by __key__").build(); QueryResults results2 = datastore.run(query2); assertTrue(results2.hasNext()); @@ -376,27 +378,27 @@ public void testRunGqlQueryNoCasting() { assertEquals(ENTITY3, results2.next()); assertFalse(results2.hasNext()); - query1 = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from bla").build(); + query1 = Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from bla").build(); results1 = datastore.run(query1); assertFalse(results1.hasNext()); Query keyOnlyQuery = - Query.gqlQueryBuilder(ResultType.KEY, "select __key__ from " + KIND1).build(); + Query.newGqlQueryBuilder(ResultType.KEY, "select __key__ from " + KIND1).build(); QueryResults keyOnlyResults = datastore.run(keyOnlyQuery); assertTrue(keyOnlyResults.hasNext()); assertEquals(KEY1, keyOnlyResults.next()); assertFalse(keyOnlyResults.hasNext()); - GqlQuery keyProjectionQuery = Query.gqlQueryBuilder( + GqlQuery keyProjectionQuery = Query.newGqlQueryBuilder( ResultType.PROJECTION_ENTITY, "select __key__ from " + KIND1).build(); QueryResults keyProjectionResult = datastore.run(keyProjectionQuery); assertTrue(keyProjectionResult.hasNext()); ProjectionEntity projectionEntity = keyProjectionResult.next(); - assertEquals(KEY1, projectionEntity.key()); - assertTrue(projectionEntity.properties().isEmpty()); + assertEquals(KEY1, projectionEntity.getKey()); + assertTrue(projectionEntity.getProperties().isEmpty()); assertFalse(keyProjectionResult.hasNext()); - GqlQuery projectionQuery = Query.gqlQueryBuilder( + GqlQuery projectionQuery = Query.newGqlQueryBuilder( ResultType.PROJECTION_ENTITY, "select str, date from " + KIND1).build(); QueryResults projectionResult = datastore.run(projectionQuery); @@ -404,9 +406,9 @@ public void testRunGqlQueryNoCasting() { projectionEntity = projectionResult.next(); assertEquals("str", projectionEntity.getString("str")); assertEquals(DATE_TIME_VALUE.get(), projectionEntity.getDateTime("date")); - assertEquals(DATE_TIME_VALUE.get().timestampMicroseconds(), + assertEquals(DATE_TIME_VALUE.get().getTimestampMicroseconds(), projectionEntity.getLong("date")); - assertEquals(2, projectionEntity.names().size()); + assertEquals(2, projectionEntity.getNames().size()); assertFalse(projectionResult.hasNext()); } @@ -414,15 +416,15 @@ public void testRunGqlQueryNoCasting() { public void testRunGqlQueryWithCasting() { @SuppressWarnings("unchecked") Query query1 = - (Query) Query.gqlQueryBuilder("select * from " + KIND1).build(); + (Query) Query.newGqlQueryBuilder("select * from " + KIND1).build(); QueryResults results1 = datastore.run(query1); assertTrue(results1.hasNext()); assertEquals(ENTITY1, results1.next()); assertFalse(results1.hasNext()); - Query query2 = Query.gqlQueryBuilder("select * from " + KIND1).build(); + Query query2 = Query.newGqlQueryBuilder("select * from " + KIND1).build(); QueryResults results2 = datastore.run(query2); - assertSame(Entity.class, results2.resultClass()); + assertSame(Entity.class, results2.getResultClass()); @SuppressWarnings("unchecked") QueryResults results3 = (QueryResults) results2; assertTrue(results3.hasNext()); @@ -440,7 +442,7 @@ public void testGqlQueryPagination() throws DatastoreException { EasyMock.replay(rpcFactoryMock, rpcMock); Datastore mockDatastore = rpcMockOptions.service(); QueryResults results = - mockDatastore.run(Query.gqlQueryBuilder(ResultType.KEY, "select __key__ from *").build()); + mockDatastore.run(Query.newGqlQueryBuilder(ResultType.KEY, "select __key__ from *").build()); int count = 0; while (results.hasNext()) { count += 1; @@ -453,43 +455,43 @@ public void testGqlQueryPagination() throws DatastoreException { @Test public void testRunStructuredQuery() { Query query = - Query.entityQueryBuilder().kind(KIND1).orderBy(OrderBy.asc("__key__")).build(); + Query.newEntityQueryBuilder().setKind(KIND1).setOrderBy(OrderBy.asc("__key__")).build(); QueryResults results1 = datastore.run(query); assertTrue(results1.hasNext()); assertEquals(ENTITY1, results1.next()); assertFalse(results1.hasNext()); - Query keyOnlyQuery = Query.keyQueryBuilder().kind(KIND1).build(); + Query keyOnlyQuery = Query.newKeyQueryBuilder().setKind(KIND1).build(); QueryResults results2 = datastore.run(keyOnlyQuery); assertTrue(results2.hasNext()); - assertEquals(ENTITY1.key(), results2.next()); + assertEquals(ENTITY1.getKey(), results2.next()); assertFalse(results2.hasNext()); StructuredQuery keyOnlyProjectionQuery = - Query.projectionEntityQueryBuilder() - .kind(KIND1).projection("__key__").build(); + Query.newProjectionEntityQueryBuilder() + .setKind(KIND1).setProjection("__key__").build(); QueryResults results3 = datastore.run(keyOnlyProjectionQuery); assertTrue(results3.hasNext()); ProjectionEntity projectionEntity = results3.next(); - assertEquals(ENTITY1.key(), projectionEntity.key()); - assertTrue(projectionEntity.names().isEmpty()); + assertEquals(ENTITY1.getKey(), projectionEntity.getKey()); + assertTrue(projectionEntity.getNames().isEmpty()); assertFalse(results2.hasNext()); - StructuredQuery projectionQuery = Query.projectionEntityQueryBuilder() - .kind(KIND2) - .projection("age") - .filter(PropertyFilter.gt("age", 18)) - .distinctOn("age") - .orderBy(OrderBy.asc("age")) - .limit(10) + StructuredQuery projectionQuery = Query.newProjectionEntityQueryBuilder() + .setKind(KIND2) + .setProjection("age") + .setFilter(PropertyFilter.gt("age", 18)) + .setDistinctOn("age") + .setOrderBy(OrderBy.asc("age")) + .setLimit(10) .build(); QueryResults results4 = datastore.run(projectionQuery); assertTrue(results4.hasNext()); ProjectionEntity entity = results4.next(); - assertEquals(ENTITY2.key(), entity.key()); + assertEquals(ENTITY2.getKey(), entity.getKey()); assertEquals(20, entity.getLong("age")); - assertEquals(1, entity.properties().size()); + assertEquals(1, entity.getProperties().size()); assertFalse(results4.hasNext()); } @@ -502,7 +504,7 @@ public void testStructuredQueryPagination() throws DatastoreException { } EasyMock.replay(rpcFactoryMock, rpcMock); Datastore datastore = rpcMockOptions.service(); - QueryResults results = datastore.run(Query.keyQueryBuilder().build()); + QueryResults results = datastore.run(Query.newKeyQueryBuilder().build()); int count = 0; while (results.hasNext()) { count += 1; @@ -513,11 +515,11 @@ public void testStructuredQueryPagination() throws DatastoreException { } private List buildResponsesForQueryPagination() { - Entity entity4 = Entity.builder(KEY4).set("value", StringValue.of("value")).build(); - Entity entity5 = Entity.builder(KEY5).set("value", "value").build(); + Entity entity4 = Entity.newBuilder(KEY4).set("value", StringValue.of("value")).build(); + Entity entity5 = Entity.newBuilder(KEY5).set("value", "value").build(); datastore.add(ENTITY3, entity4, entity5); List responses = new ArrayList<>(); - Query query = Query.keyQueryBuilder().build(); + Query query = Query.newKeyQueryBuilder().build(); RunQueryRequest.Builder requestPb = RunQueryRequest.newBuilder(); query.populatePb(requestPb); QueryResultBatch queryResultBatchPb = RunQueryResponse.newBuilder() @@ -566,7 +568,7 @@ public void testQueryPaginationWithLimit() throws DatastoreException { int limit = 2; int totalCount = 0; Iterator cursorIter = endCursors.iterator(); - StructuredQuery query = Query.entityQueryBuilder().limit(limit).build(); + StructuredQuery query = Query.newEntityQueryBuilder().setLimit(limit).build(); while (true) { QueryResults results = datastore.run(query); int resultCount = 0; @@ -577,23 +579,23 @@ public void testQueryPaginationWithLimit() throws DatastoreException { } assertTrue(cursorIter.hasNext()); Cursor expectedEndCursor = Cursor.copyFrom(cursorIter.next().toByteArray()); - assertEquals(expectedEndCursor, results.cursorAfter()); + assertEquals(expectedEndCursor, results.getCursorAfter()); if (resultCount < limit) { break; } - query = query.toBuilder().startCursor(results.cursorAfter()).build(); + query = query.toBuilder().setStartCursor(results.getCursorAfter()).build(); } assertEquals(5, totalCount); EasyMock.verify(rpcFactoryMock, rpcMock); } private List buildResponsesForQueryPaginationWithLimit() { - Entity entity4 = Entity.builder(KEY4).set("value", StringValue.of("value")).build(); - Entity entity5 = Entity.builder(KEY5).set("value", "value").build(); + Entity entity4 = Entity.newBuilder(KEY4).set("value", StringValue.of("value")).build(); + Entity entity5 = Entity.newBuilder(KEY5).set("value", "value").build(); datastore.add(ENTITY3, entity4, entity5); DatastoreRpc datastoreRpc = datastore.options().rpc(); List responses = new ArrayList<>(); - Query query = Query.entityQueryBuilder().build(); + Query query = Query.newEntityQueryBuilder().build(); RunQueryRequest.Builder requestPb = RunQueryRequest.newBuilder(); query.populatePb(requestPb); QueryResultBatch queryResultBatchPb = RunQueryResponse.newBuilder() @@ -652,7 +654,7 @@ public void testEventualConsistencyQuery() { EasyMock.replay(rpcFactoryMock, rpcMock); Datastore datastore = rpcMockOptions.service(); datastore.run( - Query.gqlQueryBuilder("FROM * SELECT *").build(), ReadOption.eventualConsistency()); + Query.newGqlQueryBuilder("FROM * SELECT *").build(), ReadOption.eventualConsistency()); EasyMock.verify(rpcFactoryMock, rpcMock); } @@ -669,43 +671,43 @@ public void testToUrlSafe() { @Test public void testAllocateId() { - KeyFactory keyFactory = datastore.newKeyFactory().kind(KIND1); + KeyFactory keyFactory = datastore.newKeyFactory().setKind(KIND1); IncompleteKey pk1 = keyFactory.newKey(); Key key1 = datastore.allocateId(pk1); - assertEquals(key1.projectId(), pk1.projectId()); - assertEquals(key1.namespace(), pk1.namespace()); - assertEquals(key1.ancestors(), pk1.ancestors()); - assertEquals(key1.kind(), pk1.kind()); + assertEquals(key1.getProjectId(), pk1.getProjectId()); + assertEquals(key1.getNamespace(), pk1.getNamespace()); + assertEquals(key1.getAncestors(), pk1.getAncestors()); + assertEquals(key1.getKind(), pk1.getKind()); assertTrue(key1.hasId()); assertFalse(key1.hasName()); - assertEquals(Key.builder(pk1, key1.id()).build(), key1); + assertEquals(Key.newBuilder(pk1, key1.getId()).build(), key1); Key key2 = datastore.allocateId(pk1); assertNotEquals(key1, key2); - assertEquals(Key.builder(pk1, key2.id()).build(), key2); + assertEquals(Key.newBuilder(pk1, key2.getId()).build(), key2); Key key3 = datastore.allocateId(key1); assertNotEquals(key1, key3); - assertEquals(Key.builder(pk1, key3.id()).build(), key3); + assertEquals(Key.newBuilder(pk1, key3.getId()).build(), key3); } @Test public void testAllocateIdArray() { - KeyFactory keyFactory = datastore.newKeyFactory().kind(KIND1); + KeyFactory keyFactory = datastore.newKeyFactory().setKind(KIND1); IncompleteKey incompleteKey1 = keyFactory.newKey(); IncompleteKey incompleteKey2 = - keyFactory.kind(KIND2).ancestors(PathElement.of(KIND1, 10)).newKey(); + keyFactory.setKind(KIND2).addAncestor(PathElement.of(KIND1, 10)).newKey(); Key key3 = keyFactory.newKey("name"); Key key4 = keyFactory.newKey(1); List result = datastore.allocateId(incompleteKey1, incompleteKey2, key3, key4, incompleteKey1, key3); assertEquals(6, result.size()); - assertEquals(Key.builder(incompleteKey1, result.get(0).id()).build(), result.get(0)); - assertEquals(Key.builder(incompleteKey1, result.get(4).id()).build(), result.get(4)); - assertEquals(Key.builder(incompleteKey2, result.get(1).id()).build(), result.get(1)); - assertEquals(Key.builder(key3).id(result.get(2).id()).build(), result.get(2)); - assertEquals(Key.builder(key3).id(result.get(5).id()).build(), result.get(5)); - assertEquals(Key.builder(key4).id(result.get(3).id()).build(), result.get(3)); + assertEquals(Key.newBuilder(incompleteKey1, result.get(0).getId()).build(), result.get(0)); + assertEquals(Key.newBuilder(incompleteKey1, result.get(4).getId()).build(), result.get(4)); + assertEquals(Key.newBuilder(incompleteKey2, result.get(1).getId()).build(), result.get(1)); + assertEquals(Key.newBuilder(key3).setId(result.get(2).getId()).build(), result.get(2)); + assertEquals(Key.newBuilder(key3).setId(result.get(5).getId()).build(), result.get(5)); + assertEquals(Key.newBuilder(key4).setId(result.get(3).getId()).build(), result.get(3)); } @Test @@ -729,7 +731,7 @@ public void testGet() { assertEquals(PARTIAL_ENTITY1, value6); ListValue value7 = entity.getValue("emptyList"); assertEquals(EMPTY_LIST_VALUE, value7); - assertEquals(7, entity.names().size()); + assertEquals(7, entity.getNames().size()); assertFalse(entity.contains("bla")); } @@ -759,7 +761,7 @@ public void testLookupEventualConsistency() { public void testGetArrayNoDeferredResults() { datastore.put(ENTITY3); Iterator result = - datastore.fetch(KEY1, Key.builder(KEY1).name("bla").build(), KEY2, KEY3).iterator(); + datastore.fetch(KEY1, Key.newBuilder(KEY1).setName("bla").build(), KEY2, KEY3).iterator(); assertEquals(ENTITY1, result.next()); assertNull(result.next()); assertEquals(ENTITY2, result.next()); @@ -772,10 +774,10 @@ public void testGetArrayNoDeferredResults() { FullEntity partial2 = entity3.getEntity("partial2"); assertEquals(PARTIAL_ENTITY2, partial1); assertEquals(ENTITY2, partial2); - assertEquals(ValueType.BOOLEAN, entity3.getValue("bool").type()); + assertEquals(ValueType.BOOLEAN, entity3.getValue("bool").getType()); assertEquals(LAT_LNG_VALUE, entity3.getValue("latLng")); assertEquals(EMPTY_LIST_VALUE, entity3.getValue("emptyList")); - assertEquals(8, entity3.names().size()); + assertEquals(8, entity3.getNames().size()); assertFalse(entity3.contains("bla")); try { entity3.getString("str"); @@ -797,7 +799,7 @@ public void testGetArrayDeferredResults() throws DatastoreException { Iterator iter = createDatastoreForDeferredLookup().get(KEY1, KEY2, KEY3, KEY4, KEY5); Set keysOfFoundEntities = new HashSet<>(); while (iter.hasNext()) { - keysOfFoundEntities.add(iter.next().key()); + keysOfFoundEntities.add(iter.next().getKey()); } assertEquals(requestedKeys, keysOfFoundEntities); } @@ -806,11 +808,11 @@ public void testGetArrayDeferredResults() throws DatastoreException { public void testFetchArrayDeferredResults() throws DatastoreException { List foundEntities = createDatastoreForDeferredLookup().fetch(KEY1, KEY2, KEY3, KEY4, KEY5); - assertEquals(foundEntities.get(0).key(), KEY1); - assertEquals(foundEntities.get(1).key(), KEY2); - assertEquals(foundEntities.get(2).key(), KEY3); - assertEquals(foundEntities.get(3).key(), KEY4); - assertEquals(foundEntities.get(4).key(), KEY5); + assertEquals(foundEntities.get(0).getKey(), KEY1); + assertEquals(foundEntities.get(1).getKey(), KEY2); + assertEquals(foundEntities.get(2).getKey(), KEY3); + assertEquals(foundEntities.get(3).getKey(), KEY4); + assertEquals(foundEntities.get(4).getKey(), KEY5); assertEquals(foundEntities.size(), 5); } @@ -830,8 +832,8 @@ private Datastore createDatastoreForDeferredLookup() throws DatastoreException { .addKeys(keysPb.get(4)) .build()); lookupRequests.add(LookupRequest.newBuilder().addKeys(keysPb.get(4)).build()); - Entity entity4 = Entity.builder(KEY4).set("value", StringValue.of("value")).build(); - Entity entity5 = Entity.builder(KEY5).set("value", "value").build(); + Entity entity4 = Entity.newBuilder(KEY4).set("value", StringValue.of("value")).build(); + Entity entity5 = Entity.newBuilder(KEY5).set("value", "value").build(); List lookupResponses = new ArrayList<>(); lookupResponses.add( LookupResponse.newBuilder() @@ -860,7 +862,7 @@ private Datastore createDatastoreForDeferredLookup() throws DatastoreException { @Test public void testAddEntity() { - List keys = datastore.fetch(ENTITY1.key(), ENTITY3.key()); + List keys = datastore.fetch(ENTITY1.getKey(), ENTITY3.getKey()); assertEquals(ENTITY1, keys.get(0)); assertNull(keys.get(1)); assertEquals(2, keys.size()); @@ -873,19 +875,19 @@ public void testAddEntity() { } List entities = datastore.add(ENTITY3, PARTIAL_ENTITY1, PARTIAL_ENTITY2); - assertEquals(ENTITY3, datastore.get(ENTITY3.key())); + assertEquals(ENTITY3, datastore.get(ENTITY3.getKey())); assertEquals(ENTITY3, entities.get(0)); - assertEquals(PARTIAL_ENTITY1.properties(), entities.get(1).properties()); - assertEquals(PARTIAL_ENTITY1.key().ancestors(), entities.get(1).key().ancestors()); - assertNotNull(datastore.get(entities.get(1).key())); - assertEquals(PARTIAL_ENTITY2.properties(), entities.get(2).properties()); - assertEquals(PARTIAL_ENTITY2.key().ancestors(), entities.get(2).key().ancestors()); - assertNotNull(datastore.get(entities.get(2).key())); + assertEquals(PARTIAL_ENTITY1.getProperties(), entities.get(1).getProperties()); + assertEquals(PARTIAL_ENTITY1.getKey().getAncestors(), entities.get(1).getKey().getAncestors()); + assertNotNull(datastore.get(entities.get(1).getKey())); + assertEquals(PARTIAL_ENTITY2.getProperties(), entities.get(2).getProperties()); + assertEquals(PARTIAL_ENTITY2.getKey().getAncestors(), entities.get(2).getKey().getAncestors()); + assertNotNull(datastore.get(entities.get(2).getKey())); } @Test public void testUpdate() { - List keys = datastore.fetch(ENTITY1.key(), ENTITY3.key()); + List keys = datastore.fetch(ENTITY1.getKey(), ENTITY3.getKey()); assertEquals(ENTITY1, keys.get(0)); assertNull(keys.get(1)); assertEquals(2, keys.size()); @@ -897,44 +899,44 @@ public void testUpdate() { // expected; } datastore.add(ENTITY3); - assertEquals(ENTITY3, datastore.get(ENTITY3.key())); - Entity entity3 = Entity.builder(ENTITY3).clear().set("bla", new NullValue()).build(); + assertEquals(ENTITY3, datastore.get(ENTITY3.getKey())); + Entity entity3 = Entity.newBuilder(ENTITY3).clear().set("bla", new NullValue()).build(); assertNotEquals(ENTITY3, entity3); datastore.update(entity3); - assertEquals(entity3, datastore.get(ENTITY3.key())); + assertEquals(entity3, datastore.get(ENTITY3.getKey())); } @Test public void testPut() { - Entity updatedEntity = Entity.builder(ENTITY1).set("new_property", 42L).build(); + Entity updatedEntity = Entity.newBuilder(ENTITY1).set("new_property", 42L).build(); assertEquals(updatedEntity, datastore.put(updatedEntity)); - assertEquals(updatedEntity, datastore.get(updatedEntity.key())); + assertEquals(updatedEntity, datastore.get(updatedEntity.getKey())); - Entity entity2 = Entity.builder(ENTITY2).clear().set("bla", new NullValue()).build(); + Entity entity2 = Entity.newBuilder(ENTITY2).clear().set("bla", new NullValue()).build(); assertNotEquals(ENTITY2, entity2); List entities = datastore.put(ENTITY1, entity2, ENTITY3, PARTIAL_ENTITY1); assertEquals(ENTITY1, entities.get(0)); assertEquals(entity2, entities.get(1)); assertEquals(ENTITY3, entities.get(2)); - assertEquals(PARTIAL_ENTITY1.properties(), entities.get(3).properties()); - assertEquals(PARTIAL_ENTITY1.key().ancestors(), entities.get(3).key().ancestors()); - assertEquals(ENTITY1, datastore.get(ENTITY1.key())); - assertEquals(entity2, datastore.get(entity2.key())); - assertEquals(ENTITY3, datastore.get(ENTITY3.key())); - Entity entity = datastore.get(entities.get(3).key()); + assertEquals(PARTIAL_ENTITY1.getProperties(), entities.get(3).getProperties()); + assertEquals(PARTIAL_ENTITY1.getKey().getAncestors(), entities.get(3).getKey().getAncestors()); + assertEquals(ENTITY1, datastore.get(ENTITY1.getKey())); + assertEquals(entity2, datastore.get(entity2.getKey())); + assertEquals(ENTITY3, datastore.get(ENTITY3.getKey())); + Entity entity = datastore.get(entities.get(3).getKey()); assertEquals(entities.get(3), entity); } @Test public void testDelete() { Iterator keys = - datastore.fetch(ENTITY1.key(), ENTITY2.key(), ENTITY3.key()).iterator(); + datastore.fetch(ENTITY1.getKey(), ENTITY2.getKey(), ENTITY3.getKey()).iterator(); assertEquals(ENTITY1, keys.next()); assertEquals(ENTITY2, keys.next()); assertNull(keys.next()); assertFalse(keys.hasNext()); - datastore.delete(ENTITY1.key(), ENTITY2.key(), ENTITY3.key()); - keys = datastore.fetch(ENTITY1.key(), ENTITY2.key(), ENTITY3.key()).iterator(); + datastore.delete(ENTITY1.getKey(), ENTITY2.getKey(), ENTITY3.getKey()); + keys = datastore.fetch(ENTITY1.getKey(), ENTITY2.getKey(), ENTITY3.getKey()).iterator(); assertNull(keys.next()); assertNull(keys.next()); assertNull(keys.next()); @@ -943,12 +945,12 @@ public void testDelete() { @Test public void testKeyFactory() { - KeyFactory keyFactory = datastore.newKeyFactory().kind(KIND1); + KeyFactory keyFactory = datastore.newKeyFactory().setKind(KIND1); assertEquals(INCOMPLETE_KEY1, keyFactory.newKey()); - assertEquals(IncompleteKey.builder(INCOMPLETE_KEY1).kind(KIND2).build(), - datastore.newKeyFactory().kind(KIND2).newKey()); + assertEquals(IncompleteKey.newBuilder(INCOMPLETE_KEY1).setKind(KIND2).build(), + datastore.newKeyFactory().setKind(KIND2).newKey()); assertEquals(KEY1, keyFactory.newKey("name")); - assertEquals(Key.builder(KEY1).id(2).build(), keyFactory.newKey(2)); + assertEquals(Key.newBuilder(KEY1).setId(2).build(), keyFactory.newKey(2)); } @Test diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DateTimeTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DateTimeTest.java index 34c2f7b7e29f..3131ea54747b 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DateTimeTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DateTimeTest.java @@ -28,6 +28,13 @@ public class DateTimeTest { @Test public void testTimestampMicroseconds() throws Exception { + Calendar cal = Calendar.getInstance(); + DateTime date = DateTime.copyFrom(cal); + assertEquals(cal.getTimeInMillis() * 1000, date.getTimestampMicroseconds()); + } + + @Test + public void testTimestampMicrosecondsDepreated() throws Exception { Calendar cal = Calendar.getInstance(); DateTime date = DateTime.copyFrom(cal); assertEquals(cal.getTimeInMillis() * 1000, date.timestampMicroseconds()); @@ -35,6 +42,13 @@ public void testTimestampMicroseconds() throws Exception { @Test public void testTimestampMillis() throws Exception { + Calendar cal = Calendar.getInstance(); + DateTime date = DateTime.copyFrom(cal); + assertEquals(cal.getTimeInMillis(), date.getTimestampMillis()); + } + + @Test + public void testTimestampMillisDepreated() throws Exception { Calendar cal = Calendar.getInstance(); DateTime date = DateTime.copyFrom(cal); assertEquals(cal.getTimeInMillis(), date.timestampMillis()); @@ -59,8 +73,8 @@ public void testNow() throws Exception { Calendar cal1 = Calendar.getInstance(); DateTime now = DateTime.now(); Calendar cal2 = Calendar.getInstance(); - assertTrue(now.timestampMillis() >= cal1.getTimeInMillis()); - assertTrue(now.timestampMillis() <= cal2.getTimeInMillis()); + assertTrue(now.getTimestampMillis() >= cal1.getTimeInMillis()); + assertTrue(now.getTimestampMillis() <= cal2.getTimeInMillis()); } @Test @@ -74,4 +88,3 @@ public void testCopyFrom() throws Exception { assertNotEquals(date1, date3); } } - diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DateTimeValueTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DateTimeValueTest.java index 8262e97241fa..501f7c46cba8 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DateTimeValueTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DateTimeValueTest.java @@ -32,7 +32,6 @@ public void testToBuilder() throws Exception { assertEquals(value, value.toBuilder().build()); } - @SuppressWarnings("deprecation") @Test public void testOf() throws Exception { DateTimeValue value = DateTimeValue.of(CONTENT); @@ -43,6 +42,15 @@ public void testOf() throws Exception { @SuppressWarnings("deprecation") @Test public void testBuilder() throws Exception { + DateTimeValue.Builder builder = DateTimeValue.newBuilder(CONTENT); + DateTimeValue value = builder.setMeaning(1).setExcludeFromIndexes(true).build(); + assertEquals(CONTENT, value.get()); + assertEquals(1, value.getMeaning()); + assertTrue(value.excludeFromIndexes()); + } + + @Test + public void testBuilderDeprecated() throws Exception { DateTimeValue.Builder builder = DateTimeValue.builder(CONTENT); DateTimeValue value = builder.meaning(1).excludeFromIndexes(true).build(); assertEquals(CONTENT, value.get()); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DoubleValueTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DoubleValueTest.java index ecc80fd14454..d3e7f8b76e56 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DoubleValueTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/DoubleValueTest.java @@ -43,6 +43,15 @@ public void testOf() throws Exception { @SuppressWarnings("deprecation") @Test public void testBuilder() throws Exception { + DoubleValue.Builder builder = DoubleValue.newBuilder(CONTENT); + DoubleValue value = builder.setMeaning(1).setExcludeFromIndexes(true).build(); + assertEquals(CONTENT, value.get()); + assertEquals(1, value.getMeaning()); + assertTrue(value.excludeFromIndexes()); + } + + @Test + public void testBuilderDeprecated() throws Exception { DoubleValue.Builder builder = DoubleValue.builder(CONTENT); DoubleValue value = builder.meaning(1).excludeFromIndexes(true).build(); assertEquals(CONTENT, value.get()); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/EntityTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/EntityTest.java index c3aad6f285ff..470c58243567 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/EntityTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/EntityTest.java @@ -24,35 +24,61 @@ public class EntityTest { - private static final Key KEY1 = Key.builder("ds1", "k1", "n1").build(); - private static final Key KEY2 = Key.builder("ds1", "k2", 1).build(); - private static final IncompleteKey INCOMPLETE_KEY = IncompleteKey.builder("ds1", "k2").build(); - private static final Entity ENTITY = Entity.builder(KEY1).set("foo", "bar").build(); + private static final Key KEY1 = Key.newBuilder("ds1", "k1", "n1").build(); + private static final Key KEY2 = Key.newBuilder("ds1", "k2", 1).build(); + private static final IncompleteKey INCOMPLETE_KEY = IncompleteKey.newBuilder("ds1", "k2").build(); + private static final Entity ENTITY = Entity.newBuilder(KEY1).set("foo", "bar").build(); + private static final Entity DEPRECATED_ENTITY = Entity.builder(KEY1).set("foo", "bar").build(); private static final FullEntity INCOMPLETE_ENTITY = - Entity.builder(INCOMPLETE_KEY).set("a", "b").build(); + Entity.newBuilder(INCOMPLETE_KEY).set("a", "b").build(); @Test public void testEntity() throws Exception { assertTrue(ENTITY.hasKey()); - assertEquals(KEY1, ENTITY.key()); + assertEquals(KEY1, ENTITY.getKey()); assertEquals("bar", ENTITY.getString("foo")); } + @Test + public void testEntityDeprecated() throws Exception { + assertTrue(ENTITY.hasKey()); + assertEquals(KEY1, DEPRECATED_ENTITY.key()); + assertEquals("bar", DEPRECATED_ENTITY.getString("foo")); + } + @Test public void testCopyFrom() throws Exception { + Entity.Builder builder = Entity.newBuilder(ENTITY); + assertEquals(ENTITY, builder.build()); + Entity entity = builder.setKey(KEY2).build(); + assertNotEquals(ENTITY, entity); + assertEquals(KEY2, entity.getKey()); + assertEquals(ENTITY.getProperties(), entity.getProperties()); + } + + @Test + public void testCopyFromDeprecated() throws Exception { Entity.Builder builder = Entity.builder(ENTITY); assertEquals(ENTITY, builder.build()); Entity entity = builder.key(KEY2).build(); assertNotEquals(ENTITY, entity); assertEquals(KEY2, entity.key()); - assertEquals(ENTITY.properties(), entity.properties()); + assertEquals(ENTITY.getProperties(), entity.getProperties()); } @Test public void testCopyFromIncompleteEntity() throws Exception { + Entity.Builder builder = Entity.newBuilder(KEY2, INCOMPLETE_ENTITY); + Entity entity = builder.build(); + assertNotEquals(INCOMPLETE_ENTITY, entity); + assertEquals(INCOMPLETE_ENTITY.getProperties(), entity.getProperties()); + } + + @Test + public void testCopyFromIncompleteEntityDeprecated() throws Exception { Entity.Builder builder = Entity.builder(KEY2, INCOMPLETE_ENTITY); Entity entity = builder.build(); assertNotEquals(INCOMPLETE_ENTITY, entity); - assertEquals(INCOMPLETE_ENTITY.properties(), entity.properties()); + assertEquals(INCOMPLETE_ENTITY.getProperties(), entity.getProperties()); } } diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/EntityValueTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/EntityValueTest.java index 07fb3bb0d5cf..ca50ddefeb5e 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/EntityValueTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/EntityValueTest.java @@ -24,8 +24,8 @@ public class EntityValueTest { - private static final Key KEY = Key.builder("ds", "kind", 1).build(); - private static final Entity CONTENT = Entity.builder(KEY).set("FOO", "BAR").build(); + private static final Key KEY = Key.newBuilder("ds", "kind", 1).build(); + private static final Entity CONTENT = Entity.newBuilder(KEY).set("FOO", "BAR").build(); @Test public void testToBuilder() throws Exception { @@ -44,6 +44,15 @@ public void testOf() throws Exception { @SuppressWarnings("deprecation") @Test public void testBuilder() throws Exception { + EntityValue.Builder builder = EntityValue.newBuilder(CONTENT); + EntityValue value = builder.setMeaning(1).setExcludeFromIndexes(true).build(); + assertEquals(CONTENT, value.get()); + assertEquals(1, value.getMeaning()); + assertTrue(value.excludeFromIndexes()); + } + + @Test + public void testBuilderDeprecated() throws Exception { EntityValue.Builder builder = EntityValue.builder(CONTENT); EntityValue value = builder.meaning(1).excludeFromIndexes(true).build(); assertEquals(CONTENT, value.get()); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/FullEntityTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/FullEntityTest.java index c1a47212e422..c48ea5aad7fc 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/FullEntityTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/FullEntityTest.java @@ -25,29 +25,41 @@ public class FullEntityTest { - private static final Key KEY1 = Key.builder("ds1", "k1", "n1").build(); - private static final Key KEY2 = Key.builder("ds1", "k2", 1).build(); - private static final IncompleteKey INCOMPLETE_KEY = IncompleteKey.builder("ds1", "k2").build(); - private static final Entity ENTITY = Entity.builder(KEY1).set("foo", "bar").build(); + private static final Key KEY1 = Key.newBuilder("ds1", "k1", "n1").build(); + private static final Key KEY2 = Key.newBuilder("ds1", "k2", 1).build(); + private static final IncompleteKey INCOMPLETE_KEY = IncompleteKey.newBuilder("ds1", "k2").build(); + private static final Entity ENTITY = Entity.newBuilder(KEY1).set("foo", "bar").build(); private static final FullEntity COMPLETE_ENTITY1 = ENTITY; private static final FullEntity COMPLETE_ENTITY2 = - FullEntity.builder(KEY2).set("foo", "bar").build(); + FullEntity.newBuilder(KEY2).set("foo", "bar").build(); private static final FullEntity INCOMPLETE_ENTITY = - Entity.builder(INCOMPLETE_KEY).set("a", "b").build(); + Entity.newBuilder(INCOMPLETE_KEY).set("a", "b").build(); @Test public void testFullEntity() throws Exception { assertTrue(COMPLETE_ENTITY1.hasKey()); - assertEquals(KEY1, COMPLETE_ENTITY1.key()); + assertEquals(KEY1, COMPLETE_ENTITY1.getKey()); assertEquals("bar", COMPLETE_ENTITY1.getString("foo")); assertTrue(COMPLETE_ENTITY2.hasKey()); - assertEquals(KEY2, COMPLETE_ENTITY2.key()); + assertEquals(KEY2, COMPLETE_ENTITY2.getKey()); assertEquals("bar", COMPLETE_ENTITY2.getString("foo")); } @Test public void testNoKey() throws Exception { + FullEntity entity = FullEntity.newBuilder().set("foo", "bar").build(); + assertFalse(entity.hasKey()); + assertNull(entity.getKey()); + assertEquals("bar", entity.getString("foo")); + + entity = FullEntity.newBuilder((IncompleteKey) null).build(); + assertFalse(entity.hasKey()); + assertNull(entity.getKey()); + } + + @Test + public void testNoKeyDeprecated() throws Exception { FullEntity entity = FullEntity.builder().set("foo", "bar").build(); assertFalse(entity.hasKey()); assertNull(entity.key()); @@ -60,6 +72,18 @@ public void testNoKey() throws Exception { @Test public void testCopyFrom() throws Exception { + FullEntity.Builder builder1 = FullEntity.newBuilder(ENTITY); + assertEquals(ENTITY, builder1.build()); + + builder1 = FullEntity.newBuilder(COMPLETE_ENTITY1); + assertEquals(COMPLETE_ENTITY1, builder1.build()); + + FullEntity.Builder builder2 = FullEntity.newBuilder(INCOMPLETE_ENTITY); + assertEquals(INCOMPLETE_ENTITY, builder2.build()); + } + + @Test + public void testCopyFromDeprected() throws Exception { FullEntity.Builder builder1 = FullEntity.builder(ENTITY); assertEquals(ENTITY, builder1.build()); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/IncompleteKeyTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/IncompleteKeyTest.java index f4562901d5c6..bb5531106603 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/IncompleteKeyTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/IncompleteKeyTest.java @@ -26,38 +26,67 @@ public class IncompleteKeyTest { private static IncompleteKey pk1, pk2; + private static IncompleteKey deprecatedPk1, deprecatedPk2; private static Key parent1; @Before public void setUp() { - pk1 = IncompleteKey.builder("ds", "kind1").build(); - parent1 = Key.builder("ds", "kind2", 10).namespace("ns").build(); - pk2 = IncompleteKey.builder(parent1, "kind3").build(); + pk1 = IncompleteKey.newBuilder("ds", "kind1").build(); + parent1 = Key.newBuilder("ds", "kind2", 10).setNamespace("ns").build(); + pk2 = IncompleteKey.newBuilder(parent1, "kind3").build(); + deprecatedPk1 = IncompleteKey.builder("ds", "kind1").build(); + deprecatedPk2 = IncompleteKey.builder(parent1, "kind3").build(); } @Test public void testBuilders() throws Exception { - assertEquals("ds", pk1.projectId()); - assertEquals("kind1", pk1.kind()); - assertTrue(pk1.ancestors().isEmpty()); - - assertEquals("ds", pk2.projectId()); - assertEquals("kind3", pk2.kind()); - assertEquals(parent1.path(), pk2.ancestors()); - - assertEquals(pk2, IncompleteKey.builder(pk2).build()); - IncompleteKey pk3 = IncompleteKey.builder(pk2).kind("kind4").build(); - assertEquals("ds", pk3.projectId()); - assertEquals("kind4", pk3.kind()); - assertEquals(parent1.path(), pk3.ancestors()); + assertEquals("ds", pk1.getProjectId()); + assertEquals("kind1", pk1.getKind()); + assertTrue(pk1.getAncestors().isEmpty()); + + assertEquals("ds", pk2.getProjectId()); + assertEquals("kind3", pk2.getKind()); + assertEquals(parent1.getPath(), pk2.getAncestors()); + + assertEquals(pk2, IncompleteKey.newBuilder(pk2).build()); + IncompleteKey pk3 = IncompleteKey.newBuilder(pk2).setKind("kind4").build(); + assertEquals("ds", pk3.getProjectId()); + assertEquals("kind4", pk3.getKind()); + assertEquals(parent1.getPath(), pk3.getAncestors()); + } + + @Test + public void testBuildersDeprecated() throws Exception { + assertEquals("ds", deprecatedPk1.projectId()); + assertEquals("kind1", deprecatedPk1.kind()); + assertTrue(deprecatedPk1.ancestors().isEmpty()); + + assertEquals("ds", deprecatedPk2.projectId()); + assertEquals("kind3", deprecatedPk2.kind()); + assertEquals(parent1.path(), deprecatedPk2.ancestors()); + + assertEquals(deprecatedPk2, IncompleteKey.builder(deprecatedPk2).build()); + IncompleteKey deprecatedPk3 = IncompleteKey.builder(deprecatedPk2).kind("kind4").build(); + assertEquals("ds", deprecatedPk3.projectId()); + assertEquals("kind4", deprecatedPk3.kind()); + assertEquals(parent1.path(), deprecatedPk3.ancestors()); } @Test public void testParent() { - assertNull(pk1.parent()); - assertEquals(parent1, pk2.parent()); - Key parent2 = Key.builder("ds", "kind3", "name").namespace("ns").build(); - IncompleteKey pk3 = IncompleteKey.builder(parent2, "kind3").build(); - assertEquals(parent2, pk3.parent()); + assertNull(pk1.getParent()); + assertEquals(parent1, pk2.getParent()); + Key parent2 = Key.newBuilder("ds", "kind3", "name").setNamespace("ns").build(); + IncompleteKey pk3 = IncompleteKey.newBuilder(parent2, "kind3").build(); + assertEquals(parent2, pk3.getParent()); + } + + @Test + public void testParentDeprecated() { + assertNull(deprecatedPk1.parent()); + assertEquals(parent1, deprecatedPk2.parent()); + Key parent2 = Key.newBuilder("ds", "kind3", "name").setName("ns").build(); + IncompleteKey deprecatedPk3 = IncompleteKey.builder(parent2, "kind3").build(); + assertEquals(parent2, deprecatedPk3.parent()); } } diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/KeyFactoryTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/KeyFactoryTest.java index 93f08de11be8..45aec369d9b3 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/KeyFactoryTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/KeyFactoryTest.java @@ -29,43 +29,87 @@ public class KeyFactoryTest { private static final String PROJECT_ID = "projectid"; private KeyFactory keyFactory; + private KeyFactory deprecatedKeyFactory; @Before public void setUp() { - keyFactory = new KeyFactory(PROJECT_ID).kind("k"); + keyFactory = new KeyFactory(PROJECT_ID).setKind("k"); + deprecatedKeyFactory = new KeyFactory(PROJECT_ID).kind("k"); } @Test public void testReset() { - IncompleteKey key = - keyFactory.projectId("ds1").namespace("ns1").ancestors(PathElement.of("p", 1)).build(); + IncompleteKey key = keyFactory + .setProjectId("ds1") + .setNamespace("ns1") + .addAncestor(PathElement.of("p", 1)) + .build(); + assertEquals("k", key.getKind()); + assertEquals("ds1", key.getProjectId()); + assertEquals("ns1", key.getNamespace()); + assertEquals(1, key.getAncestors().size()); + + keyFactory.reset(); + try { + keyFactory.newKey(1); + } catch (NullPointerException ex) { + assertEquals("kind must not be null", ex.getMessage()); + } + keyFactory.setKind("k1"); + key = keyFactory.newKey(); + assertEquals("k1", key.getKind()); + assertEquals(PROJECT_ID, key.getProjectId()); + assertTrue(key.getNamespace().isEmpty()); + assertTrue(key.getAncestors().isEmpty()); + + keyFactory = new KeyFactory(PROJECT_ID, "ns1").setKind("k"); + key = keyFactory.newKey(); + assertEquals(PROJECT_ID, key.getProjectId()); + assertEquals("ns1", key.getNamespace()); + key = keyFactory.setProjectId("bla1").setNamespace("bla2").build(); + assertEquals("bla1", key.getProjectId()); + assertEquals("bla2", key.getNamespace()); + keyFactory.reset().setKind("kind"); + key = keyFactory.newKey(); + assertEquals(PROJECT_ID, key.getProjectId()); + assertEquals("ns1", key.getNamespace()); + assertEquals("kind", key.getKind()); + } + + @Test + public void testResetDeprecated() { + IncompleteKey key = deprecatedKeyFactory + .projectId("ds1") + .namespace("ns1") + .ancestors(PathElement.of("p", 1)) + .build(); assertEquals("k", key.kind()); assertEquals("ds1", key.projectId()); assertEquals("ns1", key.namespace()); assertEquals(1, key.ancestors().size()); - keyFactory.reset(); + deprecatedKeyFactory.reset(); try { - keyFactory.newKey(1); + deprecatedKeyFactory.newKey(1); } catch (NullPointerException ex) { assertEquals("kind must not be null", ex.getMessage()); } - keyFactory.kind("k1"); - key = keyFactory.newKey(); + deprecatedKeyFactory.kind("k1"); + key = deprecatedKeyFactory.newKey(); assertEquals("k1", key.kind()); assertEquals(PROJECT_ID, key.projectId()); assertTrue(key.namespace().isEmpty()); assertTrue(key.ancestors().isEmpty()); - keyFactory = new KeyFactory(PROJECT_ID, "ns1").kind("k"); - key = keyFactory.newKey(); + deprecatedKeyFactory = new KeyFactory(PROJECT_ID, "ns1").kind("k"); + key = deprecatedKeyFactory.newKey(); assertEquals(PROJECT_ID, key.projectId()); assertEquals("ns1", key.namespace()); - key = keyFactory.projectId("bla1").namespace("bla2").build(); + key = deprecatedKeyFactory.projectId("bla1").namespace("bla2").build(); assertEquals("bla1", key.projectId()); assertEquals("bla2", key.namespace()); - keyFactory.reset().kind("kind"); - key = keyFactory.newKey(); + deprecatedKeyFactory.reset().kind("kind"); + key = deprecatedKeyFactory.newKey(); assertEquals(PROJECT_ID, key.projectId()); assertEquals("ns1", key.namespace()); assertEquals("kind", key.kind()); @@ -79,7 +123,19 @@ public void testNewKey() throws Exception { verifyKey(key, "n", ""); PathElement p1 = PathElement.of("k1", "n"); PathElement p2 = PathElement.of("k2", 10); - key = keyFactory.namespace("ns").ancestors(p1, p2).newKey("k3"); + key = keyFactory.setNamespace("ns").addAncestors(p1, p2).newKey("k3"); + verifyKey(key, "k3", "ns", p1, p2); + } + + @Test + public void testNewKeyDeprecated() throws Exception { + Key key = keyFactory.newKey(1); + verifyKey(key, 1L, ""); + key = deprecatedKeyFactory.newKey("n"); + verifyKey(key, "n", ""); + PathElement p1 = PathElement.of("k1", "n"); + PathElement p2 = PathElement.of("k2", 10); + key = deprecatedKeyFactory.namespace("ns").ancestors(p1, p2).newKey("k3"); verifyKey(key, "k3", "ns", p1, p2); } @@ -89,7 +145,17 @@ public void testNewIncompleteKey() throws Exception { verifyIncompleteKey(key, ""); PathElement p1 = PathElement.of("k1", "n"); PathElement p2 = PathElement.of("k2", 10); - key = keyFactory.namespace("ns").ancestors(p1, p2).newKey(); + key = keyFactory.setNamespace("ns").addAncestors(p1, p2).newKey(); + verifyIncompleteKey(key, "ns", p1, p2); + } + + @Test + public void testNewIncompleteKeyDeprecated() throws Exception { + IncompleteKey key = deprecatedKeyFactory.newKey(); + verifyIncompleteKey(key, ""); + PathElement p1 = PathElement.of("k1", "n"); + PathElement p2 = PathElement.of("k2", 10); + key = deprecatedKeyFactory.namespace("ns").ancestors(p1, p2).newKey(); verifyIncompleteKey(key, "ns", p1, p2); } @@ -99,21 +165,21 @@ public void testNewIncompleteWithNoKind() { } private void verifyKey(Key key, String name, String namespace, PathElement... ancestors) { - assertEquals(name, key.name()); + assertEquals(name, key.getName()); verifyIncompleteKey(key, namespace, ancestors); } private void verifyKey(Key key, Long id, String namespace, PathElement... ancestors) { - assertEquals(id, key.id()); + assertEquals(id, key.getId()); verifyIncompleteKey(key, namespace, ancestors); } private void verifyIncompleteKey(IncompleteKey key, String namespace, PathElement... ancestors) { - assertEquals("k", key.kind()); - assertEquals(PROJECT_ID, key.projectId()); - assertEquals(namespace, key.namespace()); - assertEquals(ancestors.length, key.ancestors().size()); - Iterator iter = key.ancestors().iterator(); + assertEquals("k", key.getKind()); + assertEquals(PROJECT_ID, key.getProjectId()); + assertEquals(namespace, key.getNamespace()); + assertEquals(ancestors.length, key.getAncestors().size()); + Iterator iter = key.getAncestors().iterator(); for (PathElement ancestor : ancestors) { assertEquals(ancestor, iter.next()); } diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/KeyTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/KeyTest.java index 398ea22d01e4..aaa50130da0c 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/KeyTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/KeyTest.java @@ -26,6 +26,15 @@ public class KeyTest { @Test public void testHasId() throws Exception { + Key.Builder builder = Key.newBuilder("d", "k", 10); + Key key = builder.build(); + assertTrue(key.hasId()); + key = builder.setName("bla").build(); + assertFalse(key.hasId()); + } + + @Test + public void testHasIdDeprecated() throws Exception { Key.Builder builder = Key.builder("d", "k", 10); Key key = builder.build(); assertTrue(key.hasId()); @@ -35,6 +44,15 @@ public void testHasId() throws Exception { @Test public void testId() throws Exception { + Key.Builder builder = Key.newBuilder("d", "k", 10); + Key key = builder.build(); + assertEquals(Long.valueOf(10), key.getId()); + key = builder.setId(100).build(); + assertEquals(Long.valueOf(100), key.getId()); + } + + @Test + public void testIdDeprecated() throws Exception { Key.Builder builder = Key.builder("d", "k", 10); Key key = builder.build(); assertEquals(Long.valueOf(10), key.id()); @@ -44,6 +62,15 @@ public void testId() throws Exception { @Test public void testHasName() throws Exception { + Key.Builder builder = Key.newBuilder("d", "k", "n"); + Key key = builder.build(); + assertTrue(key.hasName()); + key = builder.setId(1).build(); + assertFalse(key.hasName()); + } + + @Test + public void testHasNameDeprecated() throws Exception { Key.Builder builder = Key.builder("d", "k", "n"); Key key = builder.build(); assertTrue(key.hasName()); @@ -53,6 +80,15 @@ public void testHasName() throws Exception { @Test public void testName() throws Exception { + Key.Builder builder = Key.newBuilder("d", "k", "n"); + Key key = builder.build(); + assertEquals("n", key.getName()); + key = builder.setName("o").build(); + assertEquals("o", key.getName()); + } + + @Test + public void testNameDeprecated() throws Exception { Key.Builder builder = Key.builder("d", "k", "n"); Key key = builder.build(); assertEquals("n", key.name()); @@ -62,6 +98,15 @@ public void testName() throws Exception { @Test public void testNameOrId() throws Exception { + Key.Builder builder = Key.newBuilder("d", "k", "n"); + Key key = builder.build(); + assertEquals("n", key.getNameOrId()); + key = builder.setId(1).build(); + assertEquals(Long.valueOf(1), key.getNameOrId()); + } + + @Test + public void testNameOrIdDeprecated() throws Exception { Key.Builder builder = Key.builder("d", "k", "n"); Key key = builder.build(); assertEquals("n", key.nameOrId()); @@ -71,7 +116,7 @@ public void testNameOrId() throws Exception { @Test public void testToAndFromUrlSafe() throws Exception { - Key key = Key.builder("d", "k", "n").build(); + Key key = Key.newBuilder("d", "k", "n").build(); String urlSafe = key.toUrlSafe(); Key copy = Key.fromUrlSafe(urlSafe); assertEquals(key, copy); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/KeyValueTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/KeyValueTest.java index 0d2670b48c88..3f7d5d4a5af9 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/KeyValueTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/KeyValueTest.java @@ -24,7 +24,7 @@ public class KeyValueTest { - private static final Key CONTENT = Key.builder("ds", "kind", 1).build(); + private static final Key CONTENT = Key.newBuilder("ds", "kind", 1).build(); @Test public void testToBuilder() throws Exception { @@ -43,7 +43,16 @@ public void testOf() throws Exception { @SuppressWarnings("deprecation") @Test public void testBuilder() throws Exception { - KeyValue.Builder builder = KeyValue.builder(CONTENT); + KeyValue.Builder builder = KeyValue.newBuilder(CONTENT); + KeyValue value = builder.setMeaning(1).setExcludeFromIndexes(true).build(); + assertEquals(CONTENT, value.get()); + assertEquals(1, value.getMeaning()); + assertTrue(value.excludeFromIndexes()); + } + + @Test + public void testBuilderDeprecated() throws Exception { + KeyValue.Builder builder = KeyValue.newBuilder(CONTENT); KeyValue value = builder.meaning(1).excludeFromIndexes(true).build(); assertEquals(CONTENT, value.get()); assertEquals(1, value.meaning()); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/LatLngTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/LatLngTest.java index 401d8cc0c4c8..f693808263c3 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/LatLngTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/LatLngTest.java @@ -36,6 +36,18 @@ public class LatLngTest { private static final String INVALID_LNG_MESSAGE = "latitude must be in the range [-180, 180] degrees"; + @Test + public void testLatLng() { + assertEquals(37.422035, gp1.getLatitude(), 0); + assertEquals(-122.084124, gp1.getLongitude(), 0); + } + + @Test + public void testLatLngDeprecated() { + assertEquals(37.422035, gp1.latitude(), 0); + assertEquals(-122.084124, gp1.longitude(), 0); + } + @Test public void testEquals() { assertEquals(gp1, gp1); @@ -74,4 +86,3 @@ public void testLowerLngRange() { new LatLng(0, -181); } } - diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/LatLngValueTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/LatLngValueTest.java index 583f89ef6cfe..ae3c36b50ad4 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/LatLngValueTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/LatLngValueTest.java @@ -43,6 +43,15 @@ public void testOf() throws Exception { @SuppressWarnings("deprecation") @Test public void testBuilder() throws Exception { + LatLngValue.Builder builder = LatLngValue.newBuilder(CONTENT); + LatLngValue value = builder.setMeaning(1).setExcludeFromIndexes(true).build(); + assertEquals(CONTENT, value.get()); + assertEquals(1, value.getMeaning()); + assertTrue(value.excludeFromIndexes()); + } + + @Test + public void testBuilderDeprecated() throws Exception { LatLngValue.Builder builder = LatLngValue.builder(CONTENT); LatLngValue value = builder.meaning(1).excludeFromIndexes(true).build(); assertEquals(CONTENT, value.get()); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/ListValueTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/ListValueTest.java index 567f2778dc38..d4d3a0ed8015 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/ListValueTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/ListValueTest.java @@ -43,10 +43,10 @@ public class ListValueTest { private static final DateTime DATETIME2 = new DateTime(2); private static final LatLng LATLNG1 = LatLng.of(DOUBLE1, DOUBLE2); private static final LatLng LATLNG2 = LatLng.of(DOUBLE2, DOUBLE1); - private static final Key KEY1 = Key.builder("project", "kind", "name1").build(); - private static final Key KEY2 = Key.builder("project", "kind", "name2").build(); - private static final FullEntity ENTITY1 = FullEntity.builder(KEY1).build(); - private static final FullEntity ENTITY2 = FullEntity.builder(KEY2).build(); + private static final Key KEY1 = Key.newBuilder("project", "kind", "name1").build(); + private static final Key KEY2 = Key.newBuilder("project", "kind", "name2").build(); + private static final FullEntity ENTITY1 = FullEntity.newBuilder(KEY1).build(); + private static final FullEntity ENTITY2 = FullEntity.newBuilder(KEY2).build(); private static final Blob BLOB1 = Blob.copyFrom(new byte[]{0xD, 0xE, 0xA, 0xD}); private static final Blob BLOB2 = Blob.copyFrom(new byte[]{0xB, 0x0, 0x0, 0x0}); @@ -107,13 +107,13 @@ public void testOf() throws Exception { @SuppressWarnings("deprecation") @Test public void testBuilder() throws Exception { - ListValue.Builder builder = ListValue.builder().set(CONTENT); - ListValue value = builder.meaning(1).excludeFromIndexes(true).build(); + ListValue.Builder builder = ListValue.newBuilder().set(CONTENT); + ListValue value = builder.setMeaning(1).setExcludeFromIndexes(true).build(); assertEquals(CONTENT, value.get()); - assertEquals(1, value.meaning()); + assertEquals(1, value.getMeaning()); assertTrue(value.excludeFromIndexes()); - builder = ListValue.builder(); + builder = ListValue.newBuilder(); for (Value v : CONTENT) { builder.addValue(v); } @@ -199,4 +199,19 @@ public void testBuilder() throws Exception { builder = builder.addValue(BLOB1, BLOB2); assertEquals(ImmutableList.of(BlobValue.of(BLOB1), BlobValue.of(BLOB2)), builder.build().get()); } + + @Test + public void testBuilderDeprecated() throws Exception { + ListValue.Builder builder = ListValue.builder().set(CONTENT); + ListValue value = builder.meaning(1).excludeFromIndexes(true).build(); + assertEquals(CONTENT, value.get()); + assertEquals(1, value.meaning()); + assertTrue(value.excludeFromIndexes()); + + builder = ListValue.builder(); + for (Value v : CONTENT) { + builder.addValue(v); + } + assertEquals(CONTENT, builder.build().get()); + } } diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/LongValueTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/LongValueTest.java index 135f5fb8ac6a..5765cf5f4182 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/LongValueTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/LongValueTest.java @@ -43,6 +43,15 @@ public void testOf() throws Exception { @SuppressWarnings("deprecation") @Test public void testBuilder() throws Exception { + LongValue.Builder builder = LongValue.newBuilder(CONTENT); + LongValue value = builder.setMeaning(1).setExcludeFromIndexes(true).build(); + assertEquals(CONTENT, value.get()); + assertEquals(1, value.getMeaning()); + assertTrue(value.excludeFromIndexes()); + } + + @Test + public void testBuilderDeprecated() throws Exception { LongValue.Builder builder = LongValue.builder(CONTENT); LongValue value = builder.meaning(1).excludeFromIndexes(true).build(); assertEquals(CONTENT, value.get()); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/NullValueTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/NullValueTest.java index ffed6e69c4f5..e49c8e429735 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/NullValueTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/NullValueTest.java @@ -41,6 +41,15 @@ public void testOf() throws Exception { @SuppressWarnings("deprecation") @Test public void testBuilder() throws Exception { + NullValue.Builder builder = NullValue.newBuilder(); + NullValue value = builder.setMeaning(1).setExcludeFromIndexes(true).build(); + assertNull(value.get()); + assertEquals(1, value.getMeaning()); + assertTrue(value.excludeFromIndexes()); + } + + @Test + public void testBuilderDeprecated() throws Exception { NullValue.Builder builder = NullValue.builder(); NullValue value = builder.meaning(1).excludeFromIndexes(true).build(); assertNull(value.get()); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/PathElementTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/PathElementTest.java index 269dddb51d71..3d69c10d8048 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/PathElementTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/PathElementTest.java @@ -31,6 +31,13 @@ public class PathElementTest { @Test public void testKind() throws Exception { + assertEquals("k1", PE_1.getKind()); + assertEquals("k2", PE_2.getKind()); + assertEquals("k3", PE_3.getKind()); + } + + @Test + public void testKindDeprected() throws Exception { assertEquals("k1", PE_1.kind()); assertEquals("k2", PE_2.kind()); assertEquals("k3", PE_3.kind()); @@ -45,6 +52,13 @@ public void testHasId() throws Exception { @Test public void testId() throws Exception { + assertNull(PE_1.getId()); + assertNull(PE_2.getId()); + assertEquals(Long.valueOf(1), PE_3.getId()); + } + + @Test + public void testIdDeprecated() throws Exception { assertNull(PE_1.id()); assertNull(PE_2.id()); assertEquals(Long.valueOf(1), PE_3.id()); @@ -59,6 +73,13 @@ public void testHasName() throws Exception { @Test public void testName() throws Exception { + assertNull(PE_1.getName()); + assertEquals("n", PE_2.getName()); + assertNull(PE_3.getName()); + } + + @Test + public void testNameDeprecated() throws Exception { assertNull(PE_1.name()); assertEquals("n", PE_2.name()); assertNull(PE_3.name()); @@ -66,6 +87,13 @@ public void testName() throws Exception { @Test public void testNameOrId() throws Exception { + assertNull(PE_1.getNameOrId()); + assertEquals("n", PE_2.getNameOrId()); + assertEquals(Long.valueOf(1), PE_3.getNameOrId()); + } + + @Test + public void testNameOrIdDeprecated() throws Exception { assertNull(PE_1.nameOrId()); assertEquals("n", PE_2.nameOrId()); assertEquals(Long.valueOf(1), PE_3.nameOrId()); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/ProjectionEntityTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/ProjectionEntityTest.java index 2b53e6efc04c..d666921298e7 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/ProjectionEntityTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/ProjectionEntityTest.java @@ -26,15 +26,15 @@ public class ProjectionEntityTest { - private static final Key KEY = Key.builder("ds1", "k1", "n1").build(); + private static final Key KEY = Key.newBuilder("ds1", "k1", "n1").build(); private static final StringValue STRING_INDEX_VALUE = - StringValue.builder("foo").meaning(18).build(); + StringValue.newBuilder("foo").setMeaning(18).build(); private static final BlobValue BLOB_VALUE = BlobValue.of(Blob.copyFrom(new byte[]{1})); private static final DateTimeValue DATE_TIME_VALUE = DateTimeValue.of(DateTime.now()); private static final LongValue LONG_INDEX_VALUE = - LongValue.builder(DATE_TIME_VALUE.get().timestampMicroseconds()).meaning(18).build(); + LongValue.newBuilder(DATE_TIME_VALUE.get().getTimestampMicroseconds()).setMeaning(18).build(); private static final ProjectionEntity ENTITY1 = - new ProjectionEntity.Builder().key(KEY).set("a", "b").build(); + new ProjectionEntity.Builder().setKey(KEY).set("a", "b").build(); private static final ProjectionEntity ENTITY2 = new ProjectionEntity.Builder() .set("a", STRING_INDEX_VALUE) .set("b", BLOB_VALUE) @@ -50,8 +50,8 @@ public void testHasKey() throws Exception { @Test public void testKey() throws Exception { - assertEquals(KEY, ENTITY1.key()); - assertNull(ENTITY2.key()); + assertEquals(KEY, ENTITY1.getKey()); + assertNull(ENTITY2.getKey()); } @Test diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/RawValueTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/RawValueTest.java index 4c82b6d888e0..5b4f57ba21c6 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/RawValueTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/RawValueTest.java @@ -42,10 +42,10 @@ public void testOf() throws Exception { @SuppressWarnings("deprecation") @Test public void testBuilder() throws Exception { - RawValue.Builder builder = RawValue.builder(CONTENT); - RawValue value = builder.meaning(1).excludeFromIndexes(true).build(); + RawValue.Builder builder = RawValue.newBuilder(CONTENT); + RawValue value = builder.setMeaning(1).setExcludeFromIndexes(true).build(); assertEquals(CONTENT, value.get()); - assertEquals(1, value.meaning()); + assertEquals(1, value.getMeaning()); assertTrue(value.excludeFromIndexes()); } } diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/SerializationTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/SerializationTest.java index 07f94255c985..505043a4ffbb 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/SerializationTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/SerializationTest.java @@ -28,50 +28,51 @@ public class SerializationTest extends BaseSerializationTest { private static final IncompleteKey INCOMPLETE_KEY1 = - IncompleteKey.builder("ds", "k").ancestors(PathElement.of("p", 1)).build(); - private static final Key KEY1 = Key.builder("ds", "k", "n").build(); + IncompleteKey.newBuilder("ds", "k").addAncestor(PathElement.of("p", 1)).build(); + private static final Key KEY1 = Key.newBuilder("ds", "k", "n").build(); private static final IncompleteKey INCOMPLETE_KEY2 = - IncompleteKey.builder(KEY1, "v").ancestors(PathElement.of("p", 1)).build(); - private static final Key KEY2 = Key.builder(KEY1, "v", 2).build(); + IncompleteKey.newBuilder(KEY1, "v").addAncestor(PathElement.of("p", 1)).build(); + private static final Key KEY2 = Key.newBuilder(KEY1, "v", 2).build(); private static final DateTime DATE_TIME1 = DateTime.now(); private static final LatLng LAT_LNG = new LatLng(37.422035, -122.084124); private static final Blob BLOB1 = Blob.copyFrom(UTF_8.encode("hello world")); private static final Cursor CURSOR1 = Cursor.copyFrom(new byte[] {1, 2}); private static final Cursor CURSOR2 = Cursor.copyFrom(new byte[] {10}); private static final Query GQL1 = - Query.gqlQueryBuilder("select * from kind1 where name = @name and age > @1") + Query.newGqlQueryBuilder("select * from kind1 where name = @name and age > @1") .setBinding("name", "name1") .addBinding(20) - .namespace("ns1") + .setNamespace("ns1") .build(); private static final Query GQL2 = - Query.gqlQueryBuilder( + Query.newGqlQueryBuilder( Query.ResultType.ENTITY, "select * from kind1 where name = @name and age > @1") .setBinding("name", "name1") .addBinding(20) - .namespace("ns1") + .setNamespace("ns1") .build(); private static final Query QUERY1 = - Query.entityQueryBuilder().kind("kind1").build(); - private static final Query QUERY2 = Query.keyQueryBuilder() - .kind("k") - .filter(PropertyFilter.eq("p1", "hello")) + Query.newEntityQueryBuilder().setKind("kind1").build(); + private static final Query QUERY2 = Query.newKeyQueryBuilder() + .setKind("k") + .setFilter(PropertyFilter.eq("p1", "hello")) .build(); private static final Query QUERY3 = - Query.projectionEntityQueryBuilder() - .kind("k") - .namespace("ns1") - .projection("p") - .limit(100) - .offset(5) - .startCursor(CURSOR1) - .endCursor(CURSOR2) - .filter(CompositeFilter.and(PropertyFilter.gt("p1", 10), PropertyFilter.eq("a", "v"))) + Query.newProjectionEntityQueryBuilder() + .setKind("k") + .setNamespace("ns1") + .addProjection("p") + .setLimit(100) + .setOffset(5) + .setStartCursor(CURSOR1) + .setEndCursor(CURSOR2) + .setFilter(CompositeFilter.and(PropertyFilter.gt("p1", 10), PropertyFilter.eq("a", "v"))) .addDistinctOn("p") .addOrderBy(OrderBy.asc("p")) .build(); private static final KeyValue KEY_VALUE = KeyValue.of(KEY1); - private static final NullValue NULL_VALUE = NullValue.builder().excludeFromIndexes(true).build(); + private static final NullValue NULL_VALUE = + NullValue.newBuilder().setExcludeFromIndexes(true).build(); private static final StringValue STRING_VALUE = StringValue.of("hello"); private static final LongValue LONG_VALUE = LongValue.of(123); private static final DoubleValue DOUBLE_VALUE = DoubleValue.of(12.34); @@ -81,23 +82,24 @@ public class SerializationTest extends BaseSerializationTest { private static final RawValue RAW_VALUE = RawValue.of(com.google.datastore.v1.Value.newBuilder().setMeaning(18).build()); private static final LatLngValue LAT_LNG_VALUE = LatLngValue.of(LAT_LNG); - private static final Entity ENTITY1 = Entity.builder(KEY1).build(); + private static final Entity ENTITY1 = Entity.newBuilder(KEY1).build(); private static final Entity ENTITY2 = - Entity.builder(KEY2).set("null", NullValue.of()).build(); - private static final Entity ENTITY3 = Entity.builder(KEY2) - .set("p1", StringValue.builder("hi1").meaning(10).build()) - .set("p2", StringValue.builder("hi2").meaning(11).excludeFromIndexes(true).build()) - .set("p3", LongValue.builder(100).excludeFromIndexes(true).meaning(100).build()) + Entity.newBuilder(KEY2).set("null", NullValue.of()).build(); + private static final Entity ENTITY3 = Entity.newBuilder(KEY2) + .set("p1", StringValue.newBuilder("hi1").setMeaning(10).build()) + .set("p2", StringValue.newBuilder("hi2").setMeaning(11).setExcludeFromIndexes(true).build()) + .set("p3", LongValue.newBuilder(100).setExcludeFromIndexes(true).setMeaning(100).build()) .set("blob", BLOB1) .build(); - private static final FullEntity EMBEDDED_ENTITY = Entity.builder(INCOMPLETE_KEY1) - .set("p1", STRING_VALUE) - .set("p2", LongValue.builder(100).excludeFromIndexes(true).meaning(100).build()) - .build(); + private static final FullEntity EMBEDDED_ENTITY = + Entity.newBuilder(INCOMPLETE_KEY1) + .set("p1", STRING_VALUE) + .set("p2", LongValue.newBuilder(100).setExcludeFromIndexes(true).setMeaning(100).build()) + .build(); private static final EntityValue EMBEDDED_ENTITY_VALUE1 = EntityValue.of(ENTITY1); private static final EntityValue EMBEDDED_ENTITY_VALUE2 = EntityValue.of(ENTITY2); private static final EntityValue EMBEDDED_ENTITY_VALUE3 = EntityValue.of(EMBEDDED_ENTITY); - private static final ListValue LIST_VALUE = ListValue.builder() + private static final ListValue LIST_VALUE = ListValue.newBuilder() .addValue(NULL_VALUE) .addValue(STRING_VALUE) .addValue(new NullValue()) diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/StringValueTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/StringValueTest.java index 8dab36015515..ee26ea0103b7 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/StringValueTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/StringValueTest.java @@ -42,6 +42,15 @@ public void testOf() throws Exception { @SuppressWarnings("deprecation") @Test public void testBuilder() throws Exception { + StringValue.Builder builder = StringValue.newBuilder(CONTENT); + StringValue value = builder.setMeaning(1).setExcludeFromIndexes(true).build(); + assertEquals(CONTENT, value.get()); + assertEquals(1, value.getMeaning()); + assertTrue(value.excludeFromIndexes()); + } + + @Test + public void testBuilderDeprecated() throws Exception { StringValue.Builder builder = StringValue.builder(CONTENT); StringValue value = builder.meaning(1).excludeFromIndexes(true).build(); assertEquals(CONTENT, value.get()); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/StructuredQueryTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/StructuredQueryTest.java index cc2ec78e06a1..a19423b0709b 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/StructuredQueryTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/StructuredQueryTest.java @@ -50,7 +50,40 @@ public class StructuredQueryTest { private static final String DISTINCT_ON1 = "p6"; private static final String DISTINCT_ON2 = "p7"; private static final List DISTINCT_ON = ImmutableList.of(DISTINCT_ON1, DISTINCT_ON2); - private static final EntityQuery ENTITY_QUERY = Query.entityQueryBuilder() + private static final EntityQuery ENTITY_QUERY = Query.newEntityQueryBuilder() + .setNamespace(NAMESPACE) + .setKind(KIND) + .setStartCursor(START_CURSOR) + .setEndCursor(END_CURSOR) + .setOffset(OFFSET) + .setLimit(LIMIT) + .setFilter(FILTER) + .setOrderBy(ORDER_BY_1, ORDER_BY_2) + .build(); + private static final KeyQuery KEY_QUERY = Query.newKeyQueryBuilder() + .setNamespace(NAMESPACE) + .setKind(KIND) + .setStartCursor(START_CURSOR) + .setEndCursor(END_CURSOR) + .setOffset(OFFSET) + .setLimit(LIMIT) + .setFilter(FILTER) + .setOrderBy(ORDER_BY_1, ORDER_BY_2) + .build(); + private static final ProjectionEntityQuery PROJECTION_QUERY = + Query.newProjectionEntityQueryBuilder() + .setNamespace(NAMESPACE) + .setKind(KIND) + .setStartCursor(START_CURSOR) + .setEndCursor(END_CURSOR) + .setOffset(OFFSET) + .setLimit(LIMIT) + .setFilter(FILTER) + .setOrderBy(ORDER_BY_1, ORDER_BY_2) + .setProjection(PROJECTION1, PROJECTION2) + .setDistinctOn(DISTINCT_ON1, DISTINCT_ON2) + .build(); + private static final EntityQuery DEPRECATED_ENTITY_QUERY = Query.entityQueryBuilder() .namespace(NAMESPACE) .kind(KIND) .startCursor(START_CURSOR) @@ -60,7 +93,7 @@ public class StructuredQueryTest { .filter(FILTER) .orderBy(ORDER_BY_1, ORDER_BY_2) .build(); - private static final KeyQuery KEY_QUERY = Query.keyQueryBuilder() + private static final KeyQuery DEPRECATED_KEY_QUERY = Query.keyQueryBuilder() .namespace(NAMESPACE) .kind(KIND) .startCursor(START_CURSOR) @@ -70,7 +103,7 @@ public class StructuredQueryTest { .filter(FILTER) .orderBy(ORDER_BY_1, ORDER_BY_2) .build(); - private static final ProjectionEntityQuery PROJECTION_QUERY = + private static final ProjectionEntityQuery DEPRECATED_PROJECTION_QUERY = Query.projectionEntityQueryBuilder() .namespace(NAMESPACE) .kind(KIND) @@ -87,25 +120,58 @@ public class StructuredQueryTest { @Test public void testEntityQueryBuilder() { compareBaseBuilderFields(ENTITY_QUERY); - assertTrue(ENTITY_QUERY.projection().isEmpty()); - assertTrue(ENTITY_QUERY.distinctOn().isEmpty()); + assertTrue(ENTITY_QUERY.getProjection().isEmpty()); + assertTrue(ENTITY_QUERY.getDistinctOn().isEmpty()); + } + + @Test + public void testEntityQueryBuilderDeprecated() { + compareBaseBuilderFieldsDeprecated(ENTITY_QUERY); + assertTrue(DEPRECATED_ENTITY_QUERY.projection().isEmpty()); + assertTrue(DEPRECATED_ENTITY_QUERY.distinctOn().isEmpty()); } @Test public void testKeyQueryBuilder() { compareBaseBuilderFields(KEY_QUERY); - assertEquals(ImmutableList.of(StructuredQuery.KEY_PROPERTY_NAME), KEY_QUERY.projection()); - assertTrue(KEY_QUERY.distinctOn().isEmpty()); + assertEquals(ImmutableList.of(StructuredQuery.KEY_PROPERTY_NAME), KEY_QUERY.getProjection()); + assertTrue(KEY_QUERY.getDistinctOn().isEmpty()); + } + + @Test + public void testKeyQueryBuilderDeprecated() { + compareBaseBuilderFieldsDeprecated(DEPRECATED_KEY_QUERY); + assertEquals(ImmutableList.of(StructuredQuery.KEY_PROPERTY_NAME), + DEPRECATED_KEY_QUERY.projection()); + assertTrue(DEPRECATED_KEY_QUERY.distinctOn().isEmpty()); } @Test public void testProjectionEntityQueryBuilder() { compareBaseBuilderFields(PROJECTION_QUERY); - assertEquals(PROJECTION, PROJECTION_QUERY.projection()); - assertEquals(DISTINCT_ON, PROJECTION_QUERY.distinctOn()); + assertEquals(PROJECTION, PROJECTION_QUERY.getProjection()); + assertEquals(DISTINCT_ON, PROJECTION_QUERY.getDistinctOn()); + } + + @Test + public void testProjectionEntityQueryBuilderDeprecated() { + compareBaseBuilderFieldsDeprecated(DEPRECATED_PROJECTION_QUERY); + assertEquals(PROJECTION, DEPRECATED_PROJECTION_QUERY.projection()); + assertEquals(DISTINCT_ON, DEPRECATED_PROJECTION_QUERY.distinctOn()); } private void compareBaseBuilderFields(StructuredQuery query) { + assertEquals(NAMESPACE, query.namespace()); + assertEquals(KIND, query.getKind()); + assertEquals(START_CURSOR, query.getStartCursor()); + assertEquals(END_CURSOR, query.getEndCursor()); + assertEquals(OFFSET, query.getOffset()); + assertEquals(LIMIT, query.getLimit()); + assertEquals(FILTER, query.getFilter()); + assertEquals(ORDER_BY, query.getOrderBy()); + } + + private void compareBaseBuilderFieldsDeprecated(StructuredQuery query) { assertEquals(NAMESPACE, query.namespace()); assertEquals(KIND, query.kind()); assertEquals(START_CURSOR, query.startCursor()); @@ -127,15 +193,15 @@ public void mergeFrom() { } private void compareMergedQuery(StructuredQuery expected, StructuredQuery actual) { - assertEquals(expected.kind(), actual.kind()); - assertEquals(expected.startCursor(), actual.startCursor()); - assertEquals(expected.endCursor(), actual.endCursor()); - assertEquals(expected.offset(), actual.offset()); - assertEquals(expected.limit(), actual.limit()); - assertEquals(expected.filter(), actual.filter()); - assertEquals(expected.orderBy(), actual.orderBy()); - assertEquals(expected.projection(), actual.projection()); - assertEquals(expected.distinctOn(), actual.distinctOn()); + assertEquals(expected.getKind(), actual.getKind()); + assertEquals(expected.getStartCursor(), actual.getStartCursor()); + assertEquals(expected.getEndCursor(), actual.getEndCursor()); + assertEquals(expected.getOffset(), actual.getOffset()); + assertEquals(expected.getLimit(), actual.getLimit()); + assertEquals(expected.getFilter(), actual.getFilter()); + assertEquals(expected.getOrderBy(), actual.getOrderBy()); + assertEquals(expected.getProjection(), actual.getProjection()); + assertEquals(expected.getDistinctOn(), actual.getDistinctOn()); } @Test @@ -162,8 +228,8 @@ public void testToBuilder() { @Test public void testKeyOnly() { - assertTrue(KEY_QUERY.keyOnly()); - assertFalse(ENTITY_QUERY.keyOnly()); - assertFalse(PROJECTION_QUERY.keyOnly()); + assertTrue(KEY_QUERY.isKeyOnly()); + assertFalse(ENTITY_QUERY.isKeyOnly()); + assertFalse(PROJECTION_QUERY.isKeyOnly()); } } diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/ValueTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/ValueTest.java index bb039d1a1ac9..e36d69657b6d 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/ValueTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/ValueTest.java @@ -34,10 +34,10 @@ public class ValueTest { - private static final Key KEY = Key.builder("ds", "kind", 1).build(); + private static final Key KEY = Key.newBuilder("ds", "kind", 1).build(); private static final Blob BLOB = Blob.copyFrom(new byte[]{}); private static final DateTime DATE_TIME = DateTime.now(); - private static final Entity ENTITY = Entity.builder(KEY).set("FOO", "BAR").build(); + private static final Entity ENTITY = Entity.newBuilder(KEY).set("FOO", "BAR").build(); private static final NullValue NULL_VALUE = NullValue.of(); private static final StringValue STRING_VALUE = StringValue.of("hello"); private static final RawValue RAW_VALUE = RawValue.of(STRING_VALUE.toPb()); @@ -115,6 +115,13 @@ public void setUp() throws Exception { @Test public void testType() throws Exception { + for (Map.Entry> entry : typeToValue.entrySet()) { + assertEquals(entry.getKey(), entry.getValue().getType()); + } + } + + @Test + public void testTypeDeprecated() throws Exception { for (Map.Entry> entry : typeToValue.entrySet()) { assertEquals(entry.getKey(), entry.getValue().type()); } @@ -122,6 +129,17 @@ public void testType() throws Exception { @Test public void testExcludeFromIndexes() throws Exception { + for (Map.Entry> entry : typeToValue.entrySet()) { + assertFalse(entry.getValue().excludeFromIndexes()); + } + TestBuilder builder = new TestBuilder(); + assertFalse(builder.build().excludeFromIndexes()); + assertTrue(builder.setExcludeFromIndexes(true).build().excludeFromIndexes()); + assertFalse(builder.setExcludeFromIndexes(false).build().excludeFromIndexes()); + } + + @Test + public void testExcludeFromIndexesDeprecated() throws Exception { for (Map.Entry> entry : typeToValue.entrySet()) { assertFalse(entry.getValue().excludeFromIndexes()); } @@ -134,6 +152,12 @@ public void testExcludeFromIndexes() throws Exception { @SuppressWarnings("deprecation") @Test public void testMeaning() throws Exception { + TestBuilder builder = new TestBuilder(); + assertEquals(10, builder.setMeaning(10).build().getMeaning()); + } + + @Test + public void testMeaningDeprecated() throws Exception { TestBuilder builder = new TestBuilder(); assertEquals(10, builder.meaning(10).build().meaning()); } @@ -157,12 +181,12 @@ public void testToBuilder() throws Exception { Set content = Collections.singleton("bla"); @SuppressWarnings("rawtypes") ValueBuilder builder = new TestBuilder(); - builder.meaning(1).set(content).excludeFromIndexes(true); + builder.setMeaning(1).set(content).setExcludeFromIndexes(true); Value value = builder.build(); builder = value.toBuilder(); - assertEquals(1, value.meaning()); + assertEquals(1, value.getMeaning()); assertTrue(value.excludeFromIndexes()); - assertEquals(ValueType.LIST, value.type()); + assertEquals(ValueType.LIST, value.getType()); assertEquals(content, value.get()); assertEquals(value, builder.build()); } diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTest.java index 35664071f862..c0a3901a9acd 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/it/ITDatastoreTest.java @@ -73,7 +73,7 @@ public class ITDatastoreTest { private static final RemoteDatastoreHelper HELPER = RemoteDatastoreHelper.create(); - private static final DatastoreOptions OPTIONS = HELPER.options(); + private static final DatastoreOptions OPTIONS = HELPER.getOptions(); private static final Datastore DATASTORE = OPTIONS.service(); private static final String PROJECT_ID = OPTIONS.projectId(); private static final String NAMESPACE = OPTIONS.namespace(); @@ -82,19 +82,28 @@ public class ITDatastoreTest { private static final String KIND3 = "kind3"; private static final NullValue NULL_VALUE = NullValue.of(); private static final StringValue STR_VALUE = StringValue.of("str"); - private static final BooleanValue BOOL_VALUE = BooleanValue.builder(false) - .excludeFromIndexes(true).build(); + private static final BooleanValue BOOL_VALUE = BooleanValue.newBuilder(false) + .setExcludeFromIndexes(true).build(); private static final IncompleteKey INCOMPLETE_KEY1 = - IncompleteKey.builder(PROJECT_ID, KIND1).namespace(NAMESPACE).build(); + IncompleteKey.newBuilder(PROJECT_ID, KIND1).setNamespace(NAMESPACE).build(); private static final IncompleteKey INCOMPLETE_KEY2 = - IncompleteKey.builder(PROJECT_ID, KIND2).namespace(NAMESPACE).build(); - private static final Key KEY1 = Key.builder(INCOMPLETE_KEY1, "name").build(); - private static final Key KEY2 = Key.builder(KEY1, KIND2, 1).build(); - private static final Key KEY3 = Key.builder(KEY2).name("bla").namespace(NAMESPACE).build(); - private static final Key KEY4 = Key.builder(KEY2).name("newName1").namespace(NAMESPACE).build(); - private static final Key KEY5 = Key.builder(KEY2).name("newName2").namespace(NAMESPACE).build(); + IncompleteKey.newBuilder(PROJECT_ID, KIND2).setNamespace(NAMESPACE).build(); + private static final Key KEY1 = Key.newBuilder(INCOMPLETE_KEY1, "name").build(); + private static final Key KEY2 = Key.newBuilder(KEY1, KIND2, 1).build(); + private static final Key KEY3 = Key.newBuilder(KEY2) + .setName("bla") + .setNamespace(NAMESPACE) + .build(); + private static final Key KEY4 = Key.newBuilder(KEY2) + .setName("newName1") + .setNamespace(NAMESPACE) + .build(); + private static final Key KEY5 = Key.newBuilder(KEY2) + .setName("newName2") + .setNamespace(NAMESPACE) + .build(); private static final KeyValue KEY_VALUE = KeyValue.of(KEY1); - private static final ListValue LIST_VALUE1 = ListValue.builder() + private static final ListValue LIST_VALUE1 = ListValue.newBuilder() .addValue(NULL_VALUE) .addValue(STR_VALUE, BOOL_VALUE) .build(); @@ -104,15 +113,17 @@ public class ITDatastoreTest { private static final LatLngValue LAT_LNG_VALUE = new LatLngValue(LatLng.of(37.422035, -122.084124)); private static final FullEntity PARTIAL_ENTITY1 = - FullEntity.builder(INCOMPLETE_KEY2).set("str", STR_VALUE).set("bool", BOOL_VALUE) + FullEntity.newBuilder(INCOMPLETE_KEY2).set("str", STR_VALUE).set("bool", BOOL_VALUE) .set("list", LIST_VALUE1).build(); private static final FullEntity PARTIAL_ENTITY2 = - FullEntity.builder(PARTIAL_ENTITY1).remove("str").set("bool", true) + FullEntity.newBuilder(PARTIAL_ENTITY1).remove("str").set("bool", true) .set("list", LIST_VALUE1.get()).build(); private static final FullEntity PARTIAL_ENTITY3 = - FullEntity.builder(PARTIAL_ENTITY1).key(IncompleteKey.builder(PROJECT_ID, KIND3).build()) + FullEntity.newBuilder(PARTIAL_ENTITY1) + + .setKey(IncompleteKey.newBuilder(PROJECT_ID, KIND3).build()) .build(); - private static final Entity ENTITY1 = Entity.builder(KEY1) + private static final Entity ENTITY1 = Entity.newBuilder(KEY1) .set("str", STR_VALUE) .set("date", DATE_TIME_VALUE) .set("latLng", LAT_LNG_VALUE) @@ -121,9 +132,9 @@ public class ITDatastoreTest { .set("list", LIST_VALUE2) .set("emptyList", EMPTY_LIST_VALUE) .build(); - private static final Entity ENTITY2 = Entity.builder(ENTITY1).key(KEY2).remove("str") + private static final Entity ENTITY2 = Entity.newBuilder(ENTITY1).setKey(KEY2).remove("str") .set("name", "Dan").setNull("null").set("age", 20).build(); - private static final Entity ENTITY3 = Entity.builder(ENTITY1).key(KEY3).remove("str") + private static final Entity ENTITY3 = Entity.newBuilder(ENTITY1).setKey(KEY3).remove("str") .set("null", NULL_VALUE).set("partial1", PARTIAL_ENTITY2).set("partial2", ENTITY2).build(); @Rule @@ -148,14 +159,14 @@ public void tearDown() { public void testNewTransactionCommit() { Transaction transaction = DATASTORE.newTransaction(); transaction.add(ENTITY3); - Entity entity2 = Entity.builder(ENTITY2) + Entity entity2 = Entity.newBuilder(ENTITY2) .clear() .setNull("bla") .build(); transaction.update(entity2); transaction.delete(KEY1); transaction.commit(); - assertFalse(transaction.active()); + assertFalse(transaction.isActive()); List list = DATASTORE.fetch(KEY1, KEY2, KEY3); assertNull(list.get(0)); @@ -189,8 +200,8 @@ public void testTransactionWithRead() { transaction = DATASTORE.newTransaction(); assertEquals(ENTITY3, transaction.get(KEY3)); // update entity3 during the transaction - DATASTORE.put(Entity.builder(ENTITY2).clear().set("from", "datastore").build()); - transaction.update(Entity.builder(ENTITY2).clear().set("from", "transaction").build()); + DATASTORE.put(Entity.newBuilder(ENTITY2).clear().set("from", "datastore").build()); + transaction.update(Entity.newBuilder(ENTITY2).clear().set("from", "transaction").build()); try { transaction.commit(); fail("Expecting a failure"); @@ -201,10 +212,10 @@ public void testTransactionWithRead() { @Test public void testTransactionWithQuery() throws InterruptedException { - Query query = Query.entityQueryBuilder() - .kind(KIND2) - .filter(PropertyFilter.hasAncestor(KEY2)) - .namespace(NAMESPACE) + Query query = Query.newEntityQueryBuilder() + .setKind(KIND2) + .setFilter(PropertyFilter.hasAncestor(KEY2)) + .setNamespace(NAMESPACE) .build(); Transaction transaction = DATASTORE.newTransaction(); QueryResults results = transaction.run(query); @@ -230,9 +241,9 @@ public void testTransactionWithQuery() throws InterruptedException { assertTrue(results.hasNext()); assertEquals(ENTITY2, results.next()); assertFalse(results.hasNext()); - transaction.delete(ENTITY3.key()); + transaction.delete(ENTITY3.getKey()); // update entity2 during the transaction - DATASTORE.put(Entity.builder(ENTITY2).clear().build()); + DATASTORE.put(Entity.newBuilder(ENTITY2).clear().build()); try { transaction.commit(); fail("Expecting a failure"); @@ -245,8 +256,8 @@ public void testTransactionWithQuery() throws InterruptedException { public void testNewTransactionRollback() { Transaction transaction = DATASTORE.newTransaction(); transaction.add(ENTITY3); - Entity entity2 = Entity.builder(ENTITY2).clear().setNull("bla") - .set("list3", StringValue.of("bla"), StringValue.builder("bla").build()).build(); + Entity entity2 = Entity.newBuilder(ENTITY2).clear().setNull("bla") + .set("list3", StringValue.of("bla"), StringValue.newBuilder("bla").build()).build(); transaction.update(entity2); transaction.delete(KEY1); transaction.rollback(); @@ -269,28 +280,28 @@ public void testNewTransactionRollback() { @Test public void testNewBatch() { Batch batch = DATASTORE.newBatch(); - Entity entity1 = Entity.builder(ENTITY1).clear().build(); - Entity entity2 = Entity.builder(ENTITY2).clear().setNull("bla").build(); - Entity entity4 = Entity.builder(KEY4).set("value", StringValue.of("value")).build(); - Entity entity5 = Entity.builder(KEY5).set("value", "value").build(); + Entity entity1 = Entity.newBuilder(ENTITY1).clear().build(); + Entity entity2 = Entity.newBuilder(ENTITY2).clear().setNull("bla").build(); + Entity entity4 = Entity.newBuilder(KEY4).set("value", StringValue.of("value")).build(); + Entity entity5 = Entity.newBuilder(KEY5).set("value", "value").build(); List entities = batch.add(entity4, PARTIAL_ENTITY2, entity5); Entity entity6 = entities.get(1); assertSame(entity4, entities.get(0)); - assertEquals(PARTIAL_ENTITY2.names(), entity6.names()); - assertEquals(PARTIAL_ENTITY2.key().projectId(), entity6.key().projectId()); - assertEquals(PARTIAL_ENTITY2.key().namespace(), entity6.key().namespace()); - assertEquals(PARTIAL_ENTITY2.key().ancestors(), entity6.key().ancestors()); - assertEquals(PARTIAL_ENTITY2.key().kind(), entity6.key().kind()); - assertEquals(PARTIAL_ENTITY2.key(), IncompleteKey.builder(entity6.key()).build()); - assertEquals(PARTIAL_ENTITY2.key().ancestors(), entity6.key().ancestors()); - assertNotEquals(PARTIAL_ENTITY2.key(), entity6.key()); + assertEquals(PARTIAL_ENTITY2.getNames(), entity6.getNames()); + assertEquals(PARTIAL_ENTITY2.getKey().getProjectId(), entity6.getKey().getProjectId()); + assertEquals(PARTIAL_ENTITY2.getKey().getNamespace(), entity6.getKey().getNamespace()); + assertEquals(PARTIAL_ENTITY2.getKey().getAncestors(), entity6.getKey().getAncestors()); + assertEquals(PARTIAL_ENTITY2.getKey().getKind(), entity6.getKey().getKind()); + assertEquals(PARTIAL_ENTITY2.getKey(), IncompleteKey.newBuilder(entity6.getKey()).build()); + assertEquals(PARTIAL_ENTITY2.getKey().getAncestors(), entity6.getKey().getAncestors()); + assertNotEquals(PARTIAL_ENTITY2.getKey(), entity6.getKey()); assertSame(entity5, entities.get(2)); batch.addWithDeferredIdAllocation(PARTIAL_ENTITY3); batch.put(ENTITY3, entity1, entity2); Batch.Response response = batch.submit(); - entities = DATASTORE.fetch(KEY1, KEY2, KEY3, entity4.key(), entity5.key(), entity6.key()); + entities = DATASTORE.fetch(KEY1, KEY2, KEY3, entity4.getKey(), entity5.getKey(), entity6.getKey()); assertEquals(entity1, entities.get(0)); assertEquals(entity2, entities.get(1)); assertEquals(ENTITY3, entities.get(2)); @@ -298,10 +309,10 @@ public void testNewBatch() { assertEquals(entity5, entities.get(4)); assertEquals(entity6, entities.get(5)); assertEquals(6, entities.size()); - List generatedKeys = response.generatedKeys(); + List generatedKeys = response.getGeneratedKeys(); assertEquals(1, generatedKeys.size()); - assertEquals(PARTIAL_ENTITY3.names(), DATASTORE.get(generatedKeys.get(0)).names()); - assertEquals(PARTIAL_ENTITY3.key(), IncompleteKey.builder(generatedKeys.get(0)).build()); + assertEquals(PARTIAL_ENTITY3.getNames(), DATASTORE.get(generatedKeys.get(0)).getNames()); + assertEquals(PARTIAL_ENTITY3.getKey(), IncompleteKey.newBuilder(generatedKeys.get(0)).build()); try { batch.submit(); @@ -311,10 +322,10 @@ public void testNewBatch() { } batch = DATASTORE.newBatch(); - batch.delete(entity4.key(), entity5.key(), entity6.key()); + batch.delete(entity4.getKey(), entity5.getKey(), entity6.getKey()); batch.update(ENTITY1, ENTITY2, ENTITY3); batch.submit(); - entities = DATASTORE.fetch(KEY1, KEY2, KEY3, entity4.key(), entity5.key(), entity6.key()); + entities = DATASTORE.fetch(KEY1, KEY2, KEY3, entity4.getKey(), entity5.getKey(), entity6.getKey()); assertEquals(ENTITY1, entities.get(0)); assertEquals(ENTITY2, entities.get(1)); assertEquals(ENTITY3, entities.get(2)); @@ -326,8 +337,8 @@ public void testNewBatch() { @Test public void testRunGqlQueryNoCasting() throws InterruptedException { - Query query1 = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from " + KIND1) - .namespace(NAMESPACE) + Query query1 = Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from " + KIND1) + .setNamespace(NAMESPACE) .build(); QueryResults results1 = DATASTORE.run(query1); while (Iterators.size(results1) < 1) { @@ -341,8 +352,8 @@ public void testRunGqlQueryNoCasting() throws InterruptedException { DATASTORE.put(ENTITY3); Query query2 = - Query.gqlQueryBuilder(ResultType.ENTITY, "select * from " + KIND2 + " order by __key__") - .namespace(NAMESPACE) + Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from " + KIND2 + " order by __key__") + .setNamespace(NAMESPACE) .build(); QueryResults results2 = DATASTORE.run(query2); while (Iterators.size(results2) < 2) { @@ -356,14 +367,14 @@ public void testRunGqlQueryNoCasting() throws InterruptedException { assertEquals(ENTITY3, results2.next()); assertFalse(results2.hasNext()); - query1 = Query.gqlQueryBuilder(ResultType.ENTITY, "select * from bla") - .namespace(NAMESPACE) + query1 = Query.newGqlQueryBuilder(ResultType.ENTITY, "select * from bla") + .setNamespace(NAMESPACE) .build(); results1 = DATASTORE.run(query1); assertFalse(results1.hasNext()); - Query keyOnlyQuery = Query.gqlQueryBuilder(ResultType.KEY, "select __key__ from " + KIND1) - .namespace(NAMESPACE) + Query keyOnlyQuery = Query.newGqlQueryBuilder(ResultType.KEY, "select __key__ from " + KIND1) + .setNamespace(NAMESPACE) .build(); QueryResults keyOnlyResults = DATASTORE.run(keyOnlyQuery); while (Iterators.size(keyOnlyResults) < 1) { @@ -376,8 +387,8 @@ public void testRunGqlQueryNoCasting() throws InterruptedException { assertFalse(keyOnlyResults.hasNext()); GqlQuery keyProjectionQuery = - Query.gqlQueryBuilder(ResultType.PROJECTION_ENTITY, "select __key__ from " + KIND1) - .namespace(NAMESPACE) + Query.newGqlQueryBuilder(ResultType.PROJECTION_ENTITY, "select __key__ from " + KIND1) + .setNamespace(NAMESPACE) .build(); QueryResults keyProjectionResult = DATASTORE.run(keyProjectionQuery); while (Iterators.size(keyProjectionResult) < 1) { @@ -387,16 +398,16 @@ public void testRunGqlQueryNoCasting() throws InterruptedException { keyProjectionResult = DATASTORE.run(keyProjectionQuery); assertTrue(keyProjectionResult.hasNext()); ProjectionEntity projectionEntity = keyProjectionResult.next(); - assertEquals(KEY1, projectionEntity.key()); - assertTrue(projectionEntity.names().isEmpty()); + assertEquals(KEY1, projectionEntity.getKey()); + assertTrue(projectionEntity.getNames().isEmpty()); assertFalse(keyProjectionResult.hasNext()); } @Test public void testRunGqlQueryWithCasting() throws InterruptedException { @SuppressWarnings("unchecked") - Query query1 = (Query) Query.gqlQueryBuilder("select * from " + KIND1) - .namespace(NAMESPACE) + Query query1 = (Query) Query.newGqlQueryBuilder("select * from " + KIND1) + .setNamespace(NAMESPACE) .build(); QueryResults results1 = DATASTORE.run(query1); while (Iterators.size(results1) < 1) { @@ -408,8 +419,8 @@ public void testRunGqlQueryWithCasting() throws InterruptedException { assertEquals(ENTITY1, results1.next()); assertFalse(results1.hasNext()); - Query query2 = Query.gqlQueryBuilder("select * from " + KIND1) - .namespace(NAMESPACE) + Query query2 = Query.newGqlQueryBuilder("select * from " + KIND1) + .setNamespace(NAMESPACE) .build(); QueryResults results2 = DATASTORE.run(query2); while (Iterators.size(results2) < 1) { @@ -417,7 +428,7 @@ public void testRunGqlQueryWithCasting() throws InterruptedException { results2 = DATASTORE.run(query2); } results2 = DATASTORE.run(query1); - assertSame(Entity.class, results2.resultClass()); + assertSame(Entity.class, results2.getResultClass()); @SuppressWarnings("unchecked") QueryResults results3 = (QueryResults) results2; assertTrue(results3.hasNext()); @@ -428,7 +439,7 @@ public void testRunGqlQueryWithCasting() throws InterruptedException { @Test public void testRunStructuredQuery() throws InterruptedException { Query query = - Query.entityQueryBuilder().kind(KIND1).orderBy(OrderBy.asc("__key__")).build(); + Query.newEntityQueryBuilder().setKind(KIND1).setOrderBy(OrderBy.asc("__key__")).build(); QueryResults results1 = DATASTORE.run(query); while (Iterators.size(results1) < 1) { Thread.sleep(500); @@ -439,7 +450,7 @@ public void testRunStructuredQuery() throws InterruptedException { assertEquals(ENTITY1, results1.next()); assertFalse(results1.hasNext()); - Query keyOnlyQuery = Query.keyQueryBuilder().kind(KIND1).build(); + Query keyOnlyQuery = Query.newKeyQueryBuilder().setKind(KIND1).build(); QueryResults results2 = DATASTORE.run(keyOnlyQuery); while (Iterators.size(results2) < 1) { Thread.sleep(500); @@ -447,12 +458,12 @@ public void testRunStructuredQuery() throws InterruptedException { } results2 = DATASTORE.run(keyOnlyQuery); assertTrue(results2.hasNext()); - assertEquals(ENTITY1.key(), results2.next()); + assertEquals(ENTITY1.getKey(), results2.next()); assertFalse(results2.hasNext()); StructuredQuery keyOnlyProjectionQuery = - Query.projectionEntityQueryBuilder() - .kind(KIND1).projection("__key__").build(); + Query.newProjectionEntityQueryBuilder() + .setKind(KIND1).setProjection("__key__").build(); QueryResults results3 = DATASTORE.run(keyOnlyProjectionQuery); while (Iterators.size(results3) < 1) { Thread.sleep(500); @@ -461,17 +472,17 @@ public void testRunStructuredQuery() throws InterruptedException { results3 = DATASTORE.run(keyOnlyProjectionQuery); assertTrue(results3.hasNext()); ProjectionEntity projectionEntity = results3.next(); - assertEquals(ENTITY1.key(), projectionEntity.key()); - assertTrue(projectionEntity.names().isEmpty()); + assertEquals(ENTITY1.getKey(), projectionEntity.getKey()); + assertTrue(projectionEntity.getNames().isEmpty()); assertFalse(results2.hasNext()); - StructuredQuery projectionQuery = Query.projectionEntityQueryBuilder() - .kind(KIND2) - .projection("age") - .filter(PropertyFilter.gt("age", 18)) - .distinctOn("age") - .orderBy(OrderBy.asc("age")) - .limit(10) + StructuredQuery projectionQuery = Query.newProjectionEntityQueryBuilder() + .setKind(KIND2) + .setProjection("age") + .setFilter(PropertyFilter.gt("age", 18)) + .setDistinctOn("age") + .setOrderBy(OrderBy.asc("age")) + .setLimit(10) .build(); QueryResults results4 = DATASTORE.run(projectionQuery); @@ -482,51 +493,51 @@ public void testRunStructuredQuery() throws InterruptedException { results4 = DATASTORE.run(projectionQuery); assertTrue(results4.hasNext()); ProjectionEntity entity = results4.next(); - assertEquals(ENTITY2.key(), entity.key()); + assertEquals(ENTITY2.getKey(), entity.getKey()); assertEquals(20, entity.getLong("age")); - assertEquals(1, entity.names().size()); + assertEquals(1, entity.getNames().size()); assertFalse(results4.hasNext()); } @Test public void testAllocateId() { - KeyFactory keyFactory = DATASTORE.newKeyFactory().kind(KIND1); + KeyFactory keyFactory = DATASTORE.newKeyFactory().setKind(KIND1); IncompleteKey pk1 = keyFactory.newKey(); Key key1 = DATASTORE.allocateId(pk1); - assertEquals(key1.projectId(), pk1.projectId()); - assertEquals(key1.namespace(), pk1.namespace()); - assertEquals(key1.ancestors(), pk1.ancestors()); - assertEquals(key1.kind(), pk1.kind()); + assertEquals(key1.getProjectId(), pk1.getProjectId()); + assertEquals(key1.getNamespace(), pk1.getNamespace()); + assertEquals(key1.getAncestors(), pk1.getAncestors()); + assertEquals(key1.getKind(), pk1.getKind()); assertTrue(key1.hasId()); assertFalse(key1.hasName()); - assertEquals(Key.builder(pk1, key1.id()).build(), key1); + assertEquals(Key.newBuilder(pk1, key1.getId()).build(), key1); Key key2 = DATASTORE.allocateId(pk1); assertNotEquals(key1, key2); - assertEquals(Key.builder(pk1, key2.id()).build(), key2); + assertEquals(Key.newBuilder(pk1, key2.getId()).build(), key2); Key key3 = DATASTORE.allocateId(key1); assertNotEquals(key1, key3); - assertEquals(Key.builder(pk1, key3.id()).build(), key3); + assertEquals(Key.newBuilder(pk1, key3.getId()).build(), key3); } @Test public void testAllocateIdArray() { - KeyFactory keyFactory = DATASTORE.newKeyFactory().kind(KIND1); + KeyFactory keyFactory = DATASTORE.newKeyFactory().setKind(KIND1); IncompleteKey incompleteKey1 = keyFactory.newKey(); IncompleteKey incompleteKey2 = - keyFactory.kind(KIND2).ancestors(PathElement.of(KIND1, 10)).newKey(); + keyFactory.setKind(KIND2).addAncestors(PathElement.of(KIND1, 10)).newKey(); Key key3 = keyFactory.newKey("name"); Key key4 = keyFactory.newKey(1); List result = DATASTORE.allocateId(incompleteKey1, incompleteKey2, key3, key4, incompleteKey1, key3); assertEquals(6, result.size()); - assertEquals(Key.builder(incompleteKey1, result.get(0).id()).build(), result.get(0)); - assertEquals(Key.builder(incompleteKey1, result.get(4).id()).build(), result.get(4)); - assertEquals(Key.builder(incompleteKey2, result.get(1).id()).build(), result.get(1)); - assertEquals(Key.builder(key3).id(result.get(2).id()).build(), result.get(2)); - assertEquals(Key.builder(key3).id(result.get(5).id()).build(), result.get(5)); - assertEquals(Key.builder(key4).id(result.get(3).id()).build(), result.get(3)); + assertEquals(Key.newBuilder(incompleteKey1, result.get(0).getId()).build(), result.get(0)); + assertEquals(Key.newBuilder(incompleteKey1, result.get(4).getId()).build(), result.get(4)); + assertEquals(Key.newBuilder(incompleteKey2, result.get(1).getId()).build(), result.get(1)); + assertEquals(Key.newBuilder(key3).setId(result.get(2).getId()).build(), result.get(2)); + assertEquals(Key.newBuilder(key3).setId(result.get(5).getId()).build(), result.get(5)); + assertEquals(Key.newBuilder(key4).setId(result.get(3).getId()).build(), result.get(3)); } @Test @@ -550,7 +561,7 @@ public void testGet() { assertEquals(PARTIAL_ENTITY1, value6); ListValue value7 = entity.getValue("emptyList"); assertEquals(EMPTY_LIST_VALUE, value7); - assertEquals(7, entity.names().size()); + assertEquals(7, entity.getNames().size()); assertFalse(entity.contains("bla")); } @@ -558,7 +569,7 @@ public void testGet() { public void testGetArrayNoDeferredResults() { DATASTORE.put(ENTITY3); Iterator result = - DATASTORE.fetch(KEY1, Key.builder(KEY1).name("bla").build(), KEY2, KEY3).iterator(); + DATASTORE.fetch(KEY1, Key.newBuilder(KEY1).setName("bla").build(), KEY2, KEY3).iterator(); assertEquals(ENTITY1, result.next()); assertNull(result.next()); assertEquals(ENTITY2, result.next()); @@ -571,10 +582,10 @@ public void testGetArrayNoDeferredResults() { FullEntity partial2 = entity3.getEntity("partial2"); assertEquals(PARTIAL_ENTITY2, partial1); assertEquals(ENTITY2, partial2); - assertEquals(ValueType.BOOLEAN, entity3.getValue("bool").type()); + assertEquals(ValueType.BOOLEAN, entity3.getValue("bool").getType()); assertEquals(LAT_LNG_VALUE, entity3.getValue("latLng")); assertEquals(EMPTY_LIST_VALUE, entity3.getValue("emptyList")); - assertEquals(8, entity3.names().size()); + assertEquals(8, entity3.getNames().size()); assertFalse(entity3.contains("bla")); try { entity3.getString("str"); @@ -587,7 +598,7 @@ public void testGetArrayNoDeferredResults() { @Test public void testAddEntity() { - List keys = DATASTORE.fetch(ENTITY1.key(), ENTITY3.key()); + List keys = DATASTORE.fetch(ENTITY1.getKey(), ENTITY3.getKey()); assertEquals(ENTITY1, keys.get(0)); assertNull(keys.get(1)); assertEquals(2, keys.size()); @@ -600,22 +611,22 @@ public void testAddEntity() { } List entities = DATASTORE.add(ENTITY3, PARTIAL_ENTITY1, PARTIAL_ENTITY2); - assertEquals(ENTITY3, DATASTORE.get(ENTITY3.key())); + assertEquals(ENTITY3, DATASTORE.get(ENTITY3.getKey())); assertEquals(ENTITY3, entities.get(0)); - assertEquals(PARTIAL_ENTITY1.names(), entities.get(1).names()); - assertEquals(PARTIAL_ENTITY1.key().ancestors(), entities.get(1).key().ancestors()); - assertNotNull(DATASTORE.get(entities.get(1).key())); - assertEquals(PARTIAL_ENTITY2.names(), entities.get(2).names()); - assertEquals(PARTIAL_ENTITY2.key().ancestors(), entities.get(2).key().ancestors()); - assertNotNull(DATASTORE.get(entities.get(2).key())); + assertEquals(PARTIAL_ENTITY1.getNames(), entities.get(1).getNames()); + assertEquals(PARTIAL_ENTITY1.getKey().getAncestors(), entities.get(1).getKey().getAncestors()); + assertNotNull(DATASTORE.get(entities.get(1).getKey())); + assertEquals(PARTIAL_ENTITY2.getNames(), entities.get(2).getNames()); + assertEquals(PARTIAL_ENTITY2.getKey().getAncestors(), entities.get(2).getKey().getAncestors()); + assertNotNull(DATASTORE.get(entities.get(2).getKey())); for (Entity entity : entities) { - DATASTORE.delete(entity.key()); + DATASTORE.delete(entity.getKey()); } } @Test public void testUpdate() { - List keys = DATASTORE.fetch(ENTITY1.key(), ENTITY3.key()); + List keys = DATASTORE.fetch(ENTITY1.getKey(), ENTITY3.getKey()); assertEquals(ENTITY1, keys.get(0)); assertNull(keys.get(1)); assertEquals(2, keys.size()); @@ -627,47 +638,47 @@ public void testUpdate() { // expected; } DATASTORE.add(ENTITY3); - assertEquals(ENTITY3, DATASTORE.get(ENTITY3.key())); - Entity entity3 = Entity.builder(ENTITY3).clear().set("bla", new NullValue()).build(); + assertEquals(ENTITY3, DATASTORE.get(ENTITY3.getKey())); + Entity entity3 = Entity.newBuilder(ENTITY3).clear().set("bla", new NullValue()).build(); assertNotEquals(ENTITY3, entity3); DATASTORE.update(entity3); - assertEquals(entity3, DATASTORE.get(ENTITY3.key())); + assertEquals(entity3, DATASTORE.get(ENTITY3.getKey())); } @Test public void testPut() { - Entity updatedEntity = Entity.builder(ENTITY1).set("new_property", 42L).build(); + Entity updatedEntity = Entity.newBuilder(ENTITY1).set("new_property", 42L).build(); assertEquals(updatedEntity, DATASTORE.put(updatedEntity)); - assertEquals(updatedEntity, DATASTORE.get(updatedEntity.key())); + assertEquals(updatedEntity, DATASTORE.get(updatedEntity.getKey())); - Entity entity2 = Entity.builder(ENTITY2).clear().set("bla", new NullValue()).build(); + Entity entity2 = Entity.newBuilder(ENTITY2).clear().set("bla", new NullValue()).build(); assertNotEquals(ENTITY2, entity2); List entities = DATASTORE.put(ENTITY1, entity2, ENTITY3, PARTIAL_ENTITY1); assertEquals(ENTITY1, entities.get(0)); assertEquals(entity2, entities.get(1)); assertEquals(ENTITY3, entities.get(2)); - assertEquals(PARTIAL_ENTITY1.names(), entities.get(3).names()); - assertEquals(PARTIAL_ENTITY1.key().ancestors(), entities.get(3).key().ancestors()); - assertEquals(ENTITY1, DATASTORE.get(ENTITY1.key())); - assertEquals(entity2, DATASTORE.get(entity2.key())); - assertEquals(ENTITY3, DATASTORE.get(ENTITY3.key())); - Entity entity = DATASTORE.get(entities.get(3).key()); + assertEquals(PARTIAL_ENTITY1.getNames(), entities.get(3).getNames()); + assertEquals(PARTIAL_ENTITY1.getKey().getAncestors(), entities.get(3).getKey().getAncestors()); + assertEquals(ENTITY1, DATASTORE.get(ENTITY1.getKey())); + assertEquals(entity2, DATASTORE.get(entity2.getKey())); + assertEquals(ENTITY3, DATASTORE.get(ENTITY3.getKey())); + Entity entity = DATASTORE.get(entities.get(3).getKey()); assertEquals(entities.get(3), entity); for (Entity entityToDelete : entities) { - DATASTORE.delete(entityToDelete.key()); + DATASTORE.delete(entityToDelete.getKey()); } } @Test public void testDelete() { Iterator keys = - DATASTORE.fetch(ENTITY1.key(), ENTITY2.key(), ENTITY3.key()).iterator(); + DATASTORE.fetch(ENTITY1.getKey(), ENTITY2.getKey(), ENTITY3.getKey()).iterator(); assertEquals(ENTITY1, keys.next()); assertEquals(ENTITY2, keys.next()); assertNull(keys.next()); assertFalse(keys.hasNext()); - DATASTORE.delete(ENTITY1.key(), ENTITY2.key(), ENTITY3.key()); - keys = DATASTORE.fetch(ENTITY1.key(), ENTITY2.key(), ENTITY3.key()).iterator(); + DATASTORE.delete(ENTITY1.getKey(), ENTITY2.getKey(), ENTITY3.getKey()); + keys = DATASTORE.fetch(ENTITY1.getKey(), ENTITY2.getKey(), ENTITY3.getKey()).iterator(); assertNull(keys.next()); assertNull(keys.next()); assertNull(keys.next()); diff --git a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/testing/LocalDatastoreHelperTest.java b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/testing/LocalDatastoreHelperTest.java index cab189ae8cb9..4aa0a7261f62 100644 --- a/google-cloud-datastore/src/test/java/com/google/cloud/datastore/testing/LocalDatastoreHelperTest.java +++ b/google-cloud-datastore/src/test/java/com/google/cloud/datastore/testing/LocalDatastoreHelperTest.java @@ -49,6 +49,16 @@ public class LocalDatastoreHelperTest { @Test public void testCreate() { + LocalDatastoreHelper helper = LocalDatastoreHelper.create(0.75); + assertTrue(Math.abs(0.75 - helper.getConsistency()) < TOLERANCE); + assertTrue(helper.getProjectId().startsWith(PROJECT_ID_PREFIX)); + helper = LocalDatastoreHelper.create(); + assertTrue(Math.abs(0.9 - helper.getConsistency()) < TOLERANCE); + assertTrue(helper.getProjectId().startsWith(PROJECT_ID_PREFIX)); + } + + @Test + public void testCreateDeprecated() { LocalDatastoreHelper helper = LocalDatastoreHelper.create(0.75); assertTrue(Math.abs(0.75 - helper.consistency()) < TOLERANCE); assertTrue(helper.projectId().startsWith(PROJECT_ID_PREFIX)); @@ -60,11 +70,11 @@ public void testCreate() { @Test public void testOptions() { LocalDatastoreHelper helper = LocalDatastoreHelper.create(); - DatastoreOptions options = helper.options(); + DatastoreOptions options = helper.getOptions(); assertTrue(options.projectId().startsWith(PROJECT_ID_PREFIX)); assertTrue(options.host().startsWith("localhost:")); assertSame(AuthCredentials.noAuth(), options.authCredentials()); - options = helper.options(NAMESPACE); + options = helper.getOptions(NAMESPACE); assertTrue(options.projectId().startsWith(PROJECT_ID_PREFIX)); assertTrue(options.host().startsWith("localhost:")); assertSame(AuthCredentials.noAuth(), options.authCredentials()); @@ -75,9 +85,9 @@ public void testOptions() { public void testStartStopReset() throws IOException, InterruptedException { LocalDatastoreHelper helper = LocalDatastoreHelper.create(); helper.start(); - Datastore datastore = helper.options().service(); - Key key = datastore.newKeyFactory().kind("kind").newKey("name"); - datastore.put(Entity.builder(key).build()); + Datastore datastore = helper.getOptions().service(); + Key key = datastore.newKeyFactory().setKind("kind").newKey("name"); + datastore.put(Entity.newBuilder(key).build()); assertNotNull(datastore.get(key)); helper.reset(); assertNull(datastore.get(key));