From b7a5c2fa7c8efbe6c16e239f5f4faa3f919d5d58 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Thu, 13 Oct 2016 14:53:35 +0200 Subject: [PATCH] Update Datastore examples, snippets and READMEs to use renamed getters/setters/builders --- README.md | 8 +- TESTING.md | 2 +- google-cloud-datastore/README.md | 8 +- .../com/google/cloud/datastore/Datastore.java | 52 +++++----- .../com/google/cloud/datastore/Query.java | 18 ++-- .../google/cloud/datastore/Transaction.java | 32 +++--- .../examples/datastore/DatastoreExample.java | 52 +++++----- .../snippets/AddEntitiesAndRunQuery.java | 14 +-- .../datastore/snippets/CreateEntity.java | 4 +- .../datastore/snippets/DatastoreSnippets.java | 52 +++++----- .../datastore/snippets/QuerySnippets.java | 97 +++++++++++++++++-- .../snippets/TransactionSnippets.java | 68 +++++++++---- .../datastore/snippets/UpdateEntity.java | 4 +- .../snippets/ITDatastoreSnippets.java | 10 +- .../datastore/snippets/ITQuerySnippets.java | 59 +++++++++-- .../snippets/ITTransactionSnippets.java | 46 +++++---- 16 files changed, 344 insertions(+), 182 deletions(-) diff --git a/README.md b/README.md index c2eea2a7da6a..28b7b9a91848 100644 --- a/README.md +++ b/README.md @@ -282,9 +282,9 @@ import com.google.cloud.datastore.Key; import com.google.cloud.datastore.KeyFactory; 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()) @@ -303,12 +303,12 @@ import com.google.cloud.datastore.Key; import com.google.cloud.datastore.KeyFactory; 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/TESTING.md b/TESTING.md index 830f2b72ca78..a2439fdb04f1 100644 --- a/TESTING.md +++ b/TESTING.md @@ -84,7 +84,7 @@ You can test against a temporary local Datastore by following these steps: 2. Create and use a `Datastore` object with the options given by the `LocalDatastoreHelper` instance. For example: ```java - Datastore localDatastore = helper.options().service(); + Datastore localDatastore = helper.getOptions().service(); ``` 3. Run your tests. diff --git a/google-cloud-datastore/README.md b/google-cloud-datastore/README.md index b974fb7adff4..f4bd23333540 100644 --- a/google-cloud-datastore/README.md +++ b/google-cloud-datastore/README.md @@ -92,7 +92,7 @@ Then add the following code to put an entity in Datastore. ```java KeyFactory keyFactory = datastore.newKeyFactory().kind("Person"); Key key = keyFactory.newKey("john.doe@gmail.com"); -Entity entity = Entity.builder(key) +Entity entity = Entity.newBuilder(key) .set("name", "John Doe") .set("age", 51) .set("favorite_food", "pizza") @@ -126,9 +126,9 @@ import com.google.cloud.datastore.StructuredQuery.PropertyFilter; Then add the following code to your program: ```java -Query query = Query.entityQueryBuilder() - .kind("Person") - .filter(PropertyFilter.eq("favorite_food", "pizza")) +Query query = Query.newEntityQueryBuilder() + .setKind("Person") + .setFilter(PropertyFilter.eq("favorite_food", "pizza")) .build(); QueryResults results = datastore.run(query); while (results.hasNext()) { diff --git a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Datastore.java b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Datastore.java index 2d590bdaa730..afb0058c7fae 100644 --- a/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Datastore.java +++ b/google-cloud-datastore/src/main/java/com/google/cloud/datastore/Datastore.java @@ -76,11 +76,11 @@ interface TransactionCallable { *
 {@code
    * String keyName1 = "my_key_name_1";
    * String keyName2 = "my_key_name_2";
-   * Key key1 = datastore.newKeyFactory().kind("MyKind").newKey(keyName1);
-   * Key key2 = datastore.newKeyFactory().kind("MyKind").newKey(keyName2);
+   * Key key1 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName1);
+   * Key key2 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName2);
    * Batch batch = datastore.newBatch();
-   * Entity entity1 = Entity.builder(key1).set("name", "John").build();
-   * Entity entity2 = Entity.builder(key2).set("title", "title").build();
+   * Entity entity1 = Entity.newBuilder(key1).set("name", "John").build();
+   * Entity entity2 = Entity.newBuilder(key2).set("title", "title").build();
    * batch.add(entity1);
    * batch.add(entity2);
    * batch.submit();
@@ -96,7 +96,7 @@ interface TransactionCallable {
    *
    * 

Example of allocating an id. *

 {@code
-   * KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+   * KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
    * IncompleteKey incompleteKey = keyFactory.newKey();
    * 
    * // let cloud datastore automatically assign an id
@@ -112,7 +112,7 @@ interface TransactionCallable {
    *
    * 

Example of allocating multiple ids in a single batch. *

 {@code
-   * KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+   * KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
    * IncompleteKey incompleteKey1 = keyFactory.newKey();
    * IncompleteKey incompleteKey2 = keyFactory.newKey();
    * 
@@ -132,13 +132,13 @@ interface TransactionCallable {
    * 
 {@code
    * String keyName1 = "my_key_name_1";
    * String keyName2 = "my_key_name_2";
-   * Key key1 = datastore.newKeyFactory().kind("MyKind").newKey(keyName1);
-   * Entity.Builder entityBuilder1 = Entity.builder(key1);
+   * Key key1 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName1);
+   * Entity.Builder entityBuilder1 = Entity.newBuilder(key1);
    * entityBuilder1.set("propertyName", "updatedValue1");
    * Entity entity1 = entityBuilder1.build();
    * 
-   * Key key2 = datastore.newKeyFactory().kind("MyKind").newKey(keyName2);
-   * Entity.Builder entityBuilder2 = Entity.builder(key2);
+   * Key key2 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName2);
+   * Entity.Builder entityBuilder2 = Entity.newBuilder(key2);
    * entityBuilder2.set("propertyName", "updatedValue2");
    * Entity entity2 = entityBuilder2.build();
    * 
@@ -156,8 +156,8 @@ interface TransactionCallable {
    * 

Example of putting a single entity. *

 {@code
    * String keyName = "my_key_name";
-   * Key key = datastore.newKeyFactory().kind("MyKind").newKey(keyName);
-   * Entity.Builder entityBuilder = Entity.builder(key);
+   * Key key = datastore.newKeyFactory().setKind("MyKind").newKey(keyName);
+   * Entity.Builder entityBuilder = Entity.newBuilder(key);
    * entityBuilder.set("propertyName", "value");
    * Entity entity = entityBuilder.build();
    * datastore.put(entity);
@@ -175,13 +175,13 @@ interface TransactionCallable {
    * 
 {@code
    * String keyName1 = "my_key_name1";
    * String keyName2 = "my_key_name2";
-   * Key key1 = datastore.newKeyFactory().kind("MyKind").newKey(keyName1);
-   * Entity.Builder entityBuilder1 = Entity.builder(key1);
+   * Key key1 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName1);
+   * Entity.Builder entityBuilder1 = Entity.newBuilder(key1);
    * entityBuilder1.set("propertyName", "value1");
    * Entity entity1 = entityBuilder1.build();
    * 
-   * Key key2 = datastore.newKeyFactory().kind("MyKind").newKey(keyName2);
-   * Entity.Builder entityBuilder2 = Entity.builder(key2);
+   * Key key2 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName2);
+   * Entity.Builder entityBuilder2 = Entity.newBuilder(key2);
    * entityBuilder2.set("propertyName", "value2");
    * Entity entity2 = entityBuilder2.build();
    * 
@@ -200,8 +200,8 @@ interface TransactionCallable {
    * 
 {@code
    * String keyName1 = "my_key_name1";
    * String keyName2 = "my_key_name2";
-   * Key key1 = datastore.newKeyFactory().kind("MyKind").newKey(keyName1);
-   * Key key2 = datastore.newKeyFactory().kind("MyKind").newKey(keyName2);
+   * Key key1 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName1);
+   * Key key2 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName2);
    * datastore.delete(key1, key2);
    * }
* @@ -228,7 +228,7 @@ interface TransactionCallable { *

Example of getting an entity. *

 {@code
    * String keyName = "my_key_name";
-   * Key key = datastore.newKeyFactory().kind("MyKind").newKey(keyName);
+   * Key key = datastore.newKeyFactory().setKind("MyKind").newKey(keyName);
    * Entity entity = datastore.get(key);
    * // Do something with the entity
    * }
@@ -248,7 +248,7 @@ interface TransactionCallable { *
 {@code
    * String firstKeyName = "my_first_key_name";
    * String secondKeyName = "my_second_key_name";
-   * KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+   * KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
    * Key firstKey = keyFactory.newKey(firstKeyName);
    * Key secondKey = keyFactory.newKey(secondKeyName);
    * Iterator entitiesIterator = datastore.get(Lists.newArrayList(firstKey, secondKey));
@@ -274,7 +274,7 @@ interface TransactionCallable {
    * 
 {@code
    * String firstKeyName = "my_first_key_name";
    * String secondKeyName = "my_second_key_name";
-   * KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+   * KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
    * Key firstKey = keyFactory.newKey(firstKeyName);
    * Key secondKey = keyFactory.newKey(secondKeyName);
    * List entities = datastore.fetch(Lists.newArrayList(firstKey, secondKey));
@@ -293,8 +293,8 @@ interface TransactionCallable {
    * 

Example of running a query to find all entities of one kind. *

 {@code
    * String kind = "my_kind";
-   * StructuredQuery query = Query.entityQueryBuilder()
-   *     .kind(kind)
+   * StructuredQuery query = Query.newEntityQueryBuilder()
+   *     .setKind(kind)
    *     .build();
    * QueryResults results = datastore.run(query);
    * List entities = Lists.newArrayList();
@@ -310,9 +310,9 @@ interface TransactionCallable {
    * String kind = "my_kind";
    * String property = "my_property";
    * String value = "my_value";
-   * StructuredQuery query = Query.entityQueryBuilder()
-   *     .kind(kind)
-   *     .filter(PropertyFilter.eq(property, value))
+   * StructuredQuery query = Query.newEntityQueryBuilder()
+   *     .setKind(kind)
+   *     .setFilter(PropertyFilter.eq(property, value))
    *     .build();
    * QueryResults results = datastore.run(query);
    * List entities = Lists.newArrayList();
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 cb80178c6839..0e140b18f672 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
@@ -205,7 +205,7 @@ public static GqlQuery.Builder gqlQueryBuilder(String gql) {
    * 
 {@code
    * String kind = "my_kind";
    * String gqlQuery = "select * from " + kind;
-   * Query query = Query.gqlQueryBuilder(gqlQuery).build();
+   * Query query = Query.newGqlQueryBuilder(gqlQuery).build();
    * QueryResults results = datastore.run(query);
    * // Use results
    * }
@@ -242,7 +242,7 @@ public static GqlQuery.Builder gqlQueryBuilder(ResultType resultType, *
 {@code
    * String kind = "my_kind";
    * String gqlQuery = "select * from " + kind;
-   * Query query = Query.gqlQueryBuilder(Query.ResultType.ENTITY, gqlQuery).build();
+   * Query query = Query.newGqlQueryBuilder(Query.ResultType.ENTITY, gqlQuery).build();
    * QueryResults results = datastore.run(query);
    * // Use results
    * }
@@ -259,7 +259,7 @@ public static GqlQuery.Builder newGqlQueryBuilder(ResultType resultTyp *

Example of creating and running an entity query. *

 {@code
    * String kind = "my_kind";
-   * Query query = Query.entityQueryBuilder().kind(kind).build();
+   * Query query = Query.entityQueryBuilder().setKind(kind).build();
    * QueryResults results = datastore.run(query);
    * // Use results
    * }
@@ -276,7 +276,7 @@ public static EntityQuery.Builder entityQueryBuilder() { *

Example of creating and running an entity query. *

 {@code
    * String kind = "my_kind";
-   * Query query = Query.entityQueryBuilder().kind(kind).build();
+   * Query query = Query.newEntityQueryBuilder().setKind(kind).build();
    * QueryResults results = datastore.run(query);
    * // Use results
    * }
@@ -292,7 +292,7 @@ public static EntityQuery.Builder newEntityQueryBuilder() { *

Example of creating and running a key query. *

 {@code
    * String kind = "my_kind";
-   * Query query = Query.keyQueryBuilder().kind(kind).build();
+   * Query query = Query.keyQueryBuilder().setKind(kind).build();
    * QueryResults results = datastore.run(query);
    * // Use results
    * }
@@ -309,7 +309,7 @@ public static KeyQuery.Builder keyQueryBuilder() { *

Example of creating and running a key query. *

 {@code
    * String kind = "my_kind";
-   * Query query = Query.keyQueryBuilder().kind(kind).build();
+   * Query query = Query.newKeyQueryBuilder().setKind(kind).build();
    * QueryResults results = datastore.run(query);
    * // Use results
    * }
@@ -327,7 +327,7 @@ public static KeyQuery.Builder newKeyQueryBuilder() { * String kind = "my_kind"; * String property = "my_property"; * Query query = Query.projectionEntityQueryBuilder() - * .kind(kind) + * .setKind(kind) * .addProjection(property) * .build(); * QueryResults results = datastore.run(query); @@ -347,8 +347,8 @@ public static ProjectionEntityQuery.Builder projectionEntityQueryBuilder() { *
 {@code
    * String kind = "my_kind";
    * String property = "my_property";
-   * Query query = Query.projectionEntityQueryBuilder()
-   *     .kind(kind)
+   * Query query = Query.newProjectionEntityQueryBuilder()
+   *     .setKind(kind)
    *     .addProjection(property)
    *     .build();
    * QueryResults results = datastore.run(query);
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 b2e378d4ab54..02cd7cf63ed8 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
@@ -79,7 +79,7 @@ interface Response {
    * 

Example of getting an entity for a given key. *

 {@code
    * String keyName = "my_key_name";
-   * Key key = datastore.newKeyFactory().kind("MyKind").newKey(keyName);
+   * Key key = datastore.newKeyFactory().setKind("MyKind").newKey(keyName);
    * Entity entity = transaction.get(key);
    * transaction.commit();
    * // Do something with the entity
@@ -100,7 +100,7 @@ interface Response {
    * 
 {@code
    * String firstKeyName = "my_first_key_name";
    * String secondKeyName = "my_second_key_name";
-   * KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+   * KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
    * Key firstKey = keyFactory.newKey(firstKeyName);
    * Key secondKey = keyFactory.newKey(secondKeyName);
    * Iterator entitiesIterator = transaction.get(firstKey, secondKey);
@@ -128,7 +128,7 @@ interface Response {
    * 
 {@code
    * String firstKeyName = "my_first_key_name";
    * String secondKeyName = "my_second_key_name";
-   * KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+   * KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
    * Key firstKey = keyFactory.newKey(firstKeyName);
    * Key secondKey = keyFactory.newKey(secondKeyName);
    * List entities = transaction.fetch(firstKey, secondKey);
@@ -153,12 +153,12 @@ interface Response {
    * 

Example of running a query to find all entities with an ancestor. *

 {@code
    * String parentKeyName = "my_parent_key_name";
-   * KeyFactory keyFactory = datastore.newKeyFactory().kind("ParentKind");
+   * KeyFactory keyFactory = datastore.newKeyFactory().setKind("ParentKind");
    * Key parentKey = keyFactory.newKey(parentKeyName);
    * // Build a query
-   * Query query = Query.entityQueryBuilder()
-   *     .kind("MyKind")
-   *     .filter(PropertyFilter.hasAncestor(parentKey))
+   * Query query = Query.newEntityQueryBuilder()
+   *     .setKind("MyKind")
+   *     .setFilter(PropertyFilter.hasAncestor(parentKey))
    *     .build();
    * QueryResults results = transaction.run(query);
    * List entities = Lists.newArrayList();
@@ -181,9 +181,9 @@ interface Response {
    * 

Example of committing a transaction. *

 {@code
    * // create an entity
-   * KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+   * KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
    * Key key = datastore.allocateId(keyFactory.newKey());
-   * Entity entity = Entity.builder(key).set("description", "commit()").build();
+   * Entity entity = Entity.newBuilder(key).set("description", "commit()").build();
    * 
    * // add the entity and commit
    * try {
@@ -204,9 +204,9 @@ interface Response {
    * 

Example of rolling back a transaction. *

 {@code
    * // create an entity
-   * KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+   * KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
    * Key key = datastore.allocateId(keyFactory.newKey());
-   * Entity entity = Entity.builder(key).set("description", "rollback()").build();
+   * Entity entity = Entity.newBuilder(key).set("description", "rollback()").build();
    * 
    * // add the entity and rollback
    * transaction.put(entity);
@@ -224,9 +224,9 @@ interface Response {
    * 

Example of verifying if a transaction is active. *

 {@code
    * // create an entity
-   * KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+   * KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
    * Key key = datastore.allocateId(keyFactory.newKey());
-   * Entity entity = Entity.builder(key).set("description", "active()").build();
+   * Entity entity = Entity.newBuilder(key).set("description", "active()").build();
    * // calling transaction.active() now would return true
    * try {
    *   // add the entity and commit
@@ -253,9 +253,9 @@ interface Response {
    * 

Example of verifying if a transaction is active. *

 {@code
    * // create an entity
-   * KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+   * KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
    * Key key = datastore.allocateId(keyFactory.newKey());
-   * Entity entity = Entity.builder(key).set("description", "active()").build();
+   * Entity entity = Entity.newBuilder(key).set("description", "active()").build();
    * // calling transaction.active() now would return true
    * try {
    *   // add the entity and commit
@@ -264,7 +264,7 @@ interface Response {
    * } finally {
    *   // if committing succeeded
    *   // then transaction.active() will be false
-   *   if (transaction.active()) {
+   *   if (transaction.isActive()) {
    *     // otherwise it's true and we need to rollback
    *     transaction.rollback();
    *   }
diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/DatastoreExample.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/DatastoreExample.java
index 524958fbd042..515d1ceac5d4 100644
--- a/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/DatastoreExample.java
+++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/DatastoreExample.java
@@ -80,10 +80,10 @@ public void run(Transaction tx, Key userKey, Void arg) {
         System.out.println("Nothing to delete, user does not exist.");
         return;
       }
-      Query query = Query.keyQueryBuilder()
-          .namespace(NAMESPACE)
-          .kind(COMMENT_KIND)
-          .filter(PropertyFilter.hasAncestor(userKey))
+      Query query = Query.newKeyQueryBuilder()
+          .setNamespace(NAMESPACE)
+          .setKind(COMMENT_KIND)
+          .setFilter(PropertyFilter.hasAncestor(userKey))
           .build();
       QueryResults comments = tx.run(query);
       int count = 0;
@@ -92,7 +92,7 @@ public void run(Transaction tx, Key userKey, Void arg) {
         count++;
       }
       tx.delete(userKey);
-      System.out.printf("Deleting user '%s' and %d comment[s].%n", userKey.name(), count);
+      System.out.printf("Deleting user '%s' and %d comment[s].%n", userKey.getName(), count);
     }
 
     @Override
@@ -110,7 +110,7 @@ private static class DisplayAction extends DatastoreAction {
     public void run(Transaction tx, Key userKey, Void arg) {
       Entity user = tx.get(userKey);
       if (user == null) {
-        System.out.printf("User '%s' does not exist.%n", userKey.name());
+        System.out.printf("User '%s' does not exist.%n", userKey.getName());
         return;
       }
       if (user.contains("contact")) {
@@ -118,17 +118,17 @@ public void run(Transaction tx, Key userKey, Void arg) {
         String email = contact.getString("email");
         String phone = contact.getString("phone");
         System.out.printf("User '%s' email is '%s', phone is '%s'.%n",
-            userKey.name(), email, phone);
+            userKey.getName(), email, phone);
       }
-      System.out.printf("User '%s' has %d comment[s].%n", userKey.name(), user.getLong("count"));
+      System.out.printf("User '%s' has %d comment[s].%n", userKey.getName(), user.getLong("count"));
       int limit = 200;
       Map sortedComments = new TreeMap<>();
       StructuredQuery query =
-          Query.entityQueryBuilder()
-              .namespace(NAMESPACE)
-              .kind(COMMENT_KIND)
-              .filter(PropertyFilter.hasAncestor(userKey))
-              .limit(limit)
+          Query.newEntityQueryBuilder()
+              .setNamespace(NAMESPACE)
+              .setKind(COMMENT_KIND)
+              .setFilter(PropertyFilter.hasAncestor(userKey))
+              .setLimit(limit)
               .build();
       while (true) {
         QueryResults results = tx.run(query);
@@ -141,7 +141,7 @@ public void run(Transaction tx, Key userKey, Void arg) {
         if (resultCount < limit) {
           break;
         }
-        query = query.toBuilder().startCursor(results.cursorAfter()).build();
+        query = query.toBuilder().setStartCursor(results.getCursorAfter()).build();
       }
       // We could have added "ORDER BY timestamp" to the query to avoid sorting, but that would
       // require adding an ancestor index for timestamp.
@@ -166,19 +166,19 @@ public void run(Transaction tx, Key userKey, String content) {
       Entity user = tx.get(userKey);
       if (user == null) {
         System.out.println("Adding a new user.");
-        user = Entity.builder(userKey).set("count", 1).build();
+        user = Entity.newBuilder(userKey).set("count", 1).build();
         tx.add(user);
       } else {
-        user = Entity.builder(user).set("count", user.getLong("count") + 1L).build();
+        user = Entity.newBuilder(user).set("count", user.getLong("count") + 1L).build();
         tx.update(user);
       }
-      IncompleteKey commentKey = IncompleteKey.builder(userKey, COMMENT_KIND).build();
-      FullEntity comment = FullEntity.builder(commentKey)
+      IncompleteKey commentKey = IncompleteKey.newBuilder(userKey, COMMENT_KIND).build();
+      FullEntity comment = FullEntity.newBuilder(commentKey)
           .set("content", content)
           .set("timestamp", DateTime.now())
           .build();
       tx.addWithDeferredIdAllocation(comment);
-      System.out.printf("Adding a comment to user '%s'.%n", userKey.name());
+      System.out.printf("Adding a comment to user '%s'.%n", userKey.getName());
     }
 
     @Override
@@ -231,15 +231,15 @@ public void run(Transaction tx, Key userKey, Contact contact) {
       Entity user = tx.get(userKey);
       if (user == null) {
         System.out.println("Adding a new user.");
-        user = Entity.builder(userKey).set("count", 0L).build();
+        user = Entity.newBuilder(userKey).set("count", 0L).build();
         tx.add(user);
       }
-      FullEntity contactEntity = FullEntity.builder()
+      FullEntity contactEntity = FullEntity.newBuilder()
           .set("email", contact.email())
           .set("phone", contact.phone())
           .build();
-      tx.update(Entity.builder(user).set("contact", contactEntity).build());
-      System.out.printf("Setting contact for user '%s'.%n", userKey.name());
+      tx.update(Entity.newBuilder(user).set("contact", contactEntity).build());
+      System.out.printf("Setting contact for user '%s'.%n", userKey.getName());
     }
 
     @Override
@@ -293,9 +293,9 @@ public static void main(String... args) throws Exception {
     //       .build();
     DatastoreOptions options =
         DatastoreOptions.builder().projectId(projectId).namespace(NAMESPACE).build();
-    String name = args.length > 1 ? args[1] : System.getProperty("user.name");
+    String name = args.length > 1 ? args[1] : System.getProperty("user.getName");
     Datastore datastore = options.service();
-    KeyFactory keyFactory = datastore.newKeyFactory().kind(USER_KIND);
+    KeyFactory keyFactory = datastore.newKeyFactory().setKind(USER_KIND);
     Key key = keyFactory.newKey(name);
     String actionName = args.length > 2 ? args[2].toLowerCase() : DEFAULT_ACTION;
     DatastoreAction action = ACTIONS.get(actionName);
@@ -322,7 +322,7 @@ public static void main(String... args) throws Exception {
       action.run(tx, key, request);
       tx.commit();
     } finally {
-      if (tx.active()) {
+      if (tx.isActive()) {
         tx.rollback();
       }
     }
diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/AddEntitiesAndRunQuery.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/AddEntitiesAndRunQuery.java
index 29b8453ccf28..122d93dbb637 100644
--- a/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/AddEntitiesAndRunQuery.java
+++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/AddEntitiesAndRunQuery.java
@@ -43,9 +43,9 @@ public static void main(String... args) {
     Datastore datastore = DatastoreOptions.defaultInstance().service();
 
     // Add an entity to Datastore
-    KeyFactory keyFactory = datastore.newKeyFactory().kind("Person");
+    KeyFactory keyFactory = datastore.newKeyFactory().setKind("Person");
     Key key = keyFactory.newKey("john.doe@gmail.com");
-    Entity entity = Entity.builder(key)
+    Entity entity = Entity.newBuilder(key)
         .set("name", "John Doe")
         .set("age", 51)
         .set("favorite_food", "pizza")
@@ -57,13 +57,13 @@ public static void main(String... args) {
 
     // Add a couple more entities to make the query results more interesting
     Key janeKey = keyFactory.newKey("jane.doe@gmail.com");
-    Entity janeEntity = Entity.builder(janeKey)
+    Entity janeEntity = Entity.newBuilder(janeKey)
         .set("name", "Jane Doe")
         .set("age", 44)
         .set("favorite_food", "pizza")
         .build();
     Key joeKey = keyFactory.newKey("joe.shmoe@gmail.com");
-    Entity joeEntity = Entity.builder(joeKey)
+    Entity joeEntity = Entity.newBuilder(joeKey)
         .set("name", "Joe Shmoe")
         .set("age", 27)
         .set("favorite_food", "sushi")
@@ -71,9 +71,9 @@ public static void main(String... args) {
     datastore.put(janeEntity, joeEntity);
 
     // Run a query
-    Query query = Query.entityQueryBuilder()
-        .kind("Person")
-        .filter(PropertyFilter.eq("favorite_food", "pizza"))
+    Query query = Query.newEntityQueryBuilder()
+        .setKind("Person")
+        .setFilter(PropertyFilter.eq("favorite_food", "pizza"))
         .build();
     QueryResults results = datastore.run(query);
     while (results.hasNext()) {
diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/CreateEntity.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/CreateEntity.java
index 0ed4c5081450..9da67416f34b 100644
--- a/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/CreateEntity.java
+++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/CreateEntity.java
@@ -36,9 +36,9 @@ public class CreateEntity {
 
   public static void main(String... args) {
     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())
diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/DatastoreSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/DatastoreSnippets.java
index 7eee484af92a..0233830f6606 100644
--- a/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/DatastoreSnippets.java
+++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/DatastoreSnippets.java
@@ -76,11 +76,11 @@ public String run(DatastoreReaderWriter readerWriter) {
   // [VARIABLE "my_key_name_2"]
   public Batch newBatch(String keyName1, String keyName2) {
     // [START newBatch]
-    Key key1 = datastore.newKeyFactory().kind("MyKind").newKey(keyName1);
-    Key key2 = datastore.newKeyFactory().kind("MyKind").newKey(keyName2);
+    Key key1 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName1);
+    Key key2 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName2);
     Batch batch = datastore.newBatch();
-    Entity entity1 = Entity.builder(key1).set("name", "John").build();
-    Entity entity2 = Entity.builder(key2).set("title", "title").build();
+    Entity entity1 = Entity.newBuilder(key1).set("name", "John").build();
+    Entity entity2 = Entity.newBuilder(key2).set("title", "title").build();
     batch.add(entity1);
     batch.add(entity2);
     batch.submit();
@@ -94,7 +94,7 @@ public Batch newBatch(String keyName1, String keyName2) {
   // [TARGET allocateId(IncompleteKey)]
   public Key allocateIdSingle() {
     // [START allocateIdSingle]
-    KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+    KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
     IncompleteKey incompleteKey = keyFactory.newKey();
 
     // let cloud datastore automatically assign an id
@@ -109,7 +109,7 @@ public Key allocateIdSingle() {
   // [TARGET allocateId(IncompleteKey...)]
   public List batchAllocateId() {
     // [START batchAllocateId]
-    KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+    KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
     IncompleteKey incompleteKey1 = keyFactory.newKey();
     IncompleteKey incompleteKey2 = keyFactory.newKey();
 
@@ -127,13 +127,13 @@ public List batchAllocateId() {
   // [VARIABLE "my_key_name_2"]
   public void batchUpdateEntities(String keyName1, String keyName2) {
     // [START batchUpdateEntities]
-    Key key1 = datastore.newKeyFactory().kind("MyKind").newKey(keyName1);
-    Entity.Builder entityBuilder1 = Entity.builder(key1);
+    Key key1 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName1);
+    Entity.Builder entityBuilder1 = Entity.newBuilder(key1);
     entityBuilder1.set("propertyName", "updatedValue1");
     Entity entity1 = entityBuilder1.build();
 
-    Key key2 = datastore.newKeyFactory().kind("MyKind").newKey(keyName2);
-    Entity.Builder entityBuilder2 = Entity.builder(key2);
+    Key key2 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName2);
+    Entity.Builder entityBuilder2 = Entity.newBuilder(key2);
     entityBuilder2.set("propertyName", "updatedValue2");
     Entity entity2 = entityBuilder2.build();
 
@@ -148,8 +148,8 @@ public void batchUpdateEntities(String keyName1, String keyName2) {
   // [VARIABLE "my_key_name"]
   public void putSingleEntity(String keyName) {
     // [START putSingleEntity]
-    Key key = datastore.newKeyFactory().kind("MyKind").newKey(keyName);
-    Entity.Builder entityBuilder = Entity.builder(key);
+    Key key = datastore.newKeyFactory().setKind("MyKind").newKey(keyName);
+    Entity.Builder entityBuilder = Entity.newBuilder(key);
     entityBuilder.set("propertyName", "value");
     Entity entity = entityBuilder.build();
     datastore.put(entity);
@@ -164,13 +164,13 @@ public void putSingleEntity(String keyName) {
   // [VARIABLE "my_key_name2"]
   public void batchPutEntities(String keyName1, String keyName2) {
     // [START batchPutEntities]
-    Key key1 = datastore.newKeyFactory().kind("MyKind").newKey(keyName1);
-    Entity.Builder entityBuilder1 = Entity.builder(key1);
+    Key key1 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName1);
+    Entity.Builder entityBuilder1 = Entity.newBuilder(key1);
     entityBuilder1.set("propertyName", "value1");
     Entity entity1 = entityBuilder1.build();
 
-    Key key2 = datastore.newKeyFactory().kind("MyKind").newKey(keyName2);
-    Entity.Builder entityBuilder2 = Entity.builder(key2);
+    Key key2 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName2);
+    Entity.Builder entityBuilder2 = Entity.newBuilder(key2);
     entityBuilder2.set("propertyName", "value2");
     Entity entity2 = entityBuilder2.build();
 
@@ -186,8 +186,8 @@ public void batchPutEntities(String keyName1, String keyName2) {
   // [VARIABLE "my_key_name2"]
   public void batchDeleteEntities(String keyName1, String keyName2) {
     // [START batchDeleteEntities]
-    Key key1 = datastore.newKeyFactory().kind("MyKind").newKey(keyName1);
-    Key key2 = datastore.newKeyFactory().kind("MyKind").newKey(keyName2);
+    Key key1 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName1);
+    Key key2 = datastore.newKeyFactory().setKind("MyKind").newKey(keyName2);
     datastore.delete(key1, key2);
     // [END batchDeleteEntities]
   }
@@ -210,7 +210,7 @@ public KeyFactory createKeyFactory() {
   // [VARIABLE "my_key_name"]
   public Entity getEntityWithKey(String keyName) {
     // [START getEntityWithKey]
-    Key key = datastore.newKeyFactory().kind("MyKind").newKey(keyName);
+    Key key = datastore.newKeyFactory().setKind("MyKind").newKey(keyName);
     Entity entity = datastore.get(key);
     // Do something with the entity
     // [END getEntityWithKey]
@@ -226,7 +226,7 @@ public Entity getEntityWithKey(String keyName) {
   public List getEntitiesWithKeys(String firstKeyName, String secondKeyName) {
     // TODO change so that it's not necessary to hold the entities in a list for integration testing
     // [START getEntitiesWithKeys]
-    KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+    KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
     Key firstKey = keyFactory.newKey(firstKeyName);
     Key secondKey = keyFactory.newKey(secondKeyName);
     Iterator entitiesIterator = datastore.get(Lists.newArrayList(firstKey, secondKey));
@@ -248,7 +248,7 @@ public List getEntitiesWithKeys(String firstKeyName, String secondKeyNam
   // [VARIABLE "my_second_key_name"]
   public List fetchEntitiesWithKeys(String firstKeyName, String secondKeyName) {
     // [START fetchEntitiesWithKeys]
-    KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+    KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
     Key firstKey = keyFactory.newKey(firstKeyName);
     Key secondKey = keyFactory.newKey(secondKeyName);
     List entities = datastore.fetch(Lists.newArrayList(firstKey, secondKey));
@@ -267,8 +267,8 @@ public List fetchEntitiesWithKeys(String firstKeyName, String secondKeyN
   public List runQuery(String kind) {
     // TODO change so that it's not necessary to hold the entities in a list for integration testing
     // [START runQuery]
-    StructuredQuery query = Query.entityQueryBuilder()
-        .kind(kind)
+    StructuredQuery query = Query.newEntityQueryBuilder()
+        .setKind(kind)
         .build();
     QueryResults results = datastore.run(query);
     List entities = Lists.newArrayList();
@@ -291,9 +291,9 @@ public List runQuery(String kind) {
   public List runQueryOnProperty(String kind, String property, String value) {
     // TODO change so that it's not necessary to hold the entities in a list for integration testing
     // [START runQueryOnProperty]
-    StructuredQuery query = Query.entityQueryBuilder()
-        .kind(kind)
-        .filter(PropertyFilter.eq(property, value))
+    StructuredQuery query = Query.newEntityQueryBuilder()
+        .setKind(kind)
+        .setFilter(PropertyFilter.eq(property, value))
         .build();
     QueryResults results = datastore.run(query);
     List entities = Lists.newArrayList();
diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/QuerySnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/QuerySnippets.java
index b35437cbac9f..878a21629934 100644
--- a/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/QuerySnippets.java
+++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/QuerySnippets.java
@@ -43,71 +43,148 @@ public QuerySnippets(Datastore datastore) {
   /**
    * Example of creating and running a GQL query.
    */
-  // [TARGET gqlQueryBuilder(String)]
+  // [TARGET newGqlQueryBuilder(String)]
   // [VARIABLE "my_kind"]
   public QueryResults newQuery(String kind) {
     // [START newQuery]
     String gqlQuery = "select * from " + kind;
-    Query query = Query.gqlQueryBuilder(gqlQuery).build();
+    Query query = Query.newGqlQueryBuilder(gqlQuery).build();
     QueryResults results = datastore.run(query);
     // Use results
     // [END newQuery]
     return results;
   }
 
+  /**
+   * Example of creating and running a GQL query.
+   */
+  // [TARGET gqlQueryBuilder(String)]
+  // [VARIABLE "my_kind"]
+  public QueryResults newQueryDeprecated(String kind) {
+    // [START newQueryDeprecated]
+    String gqlQuery = "select * from " + kind;
+    Query query = Query.gqlQueryBuilder(gqlQuery).build();
+    QueryResults results = datastore.run(query);
+    // Use results
+    // [END newQueryDeprecated]
+    return results;
+  }
+
   /**
    * Example of creating and running a typed GQL query.
    */
-  // [TARGET gqlQueryBuilder(ResultType, String)]
+  // [TARGET newGqlQueryBuilder(ResultType, String)]
   // [VARIABLE "my_kind"]
   public QueryResults newTypedQuery(String kind) {
     // [START newTypedQuery]
     String gqlQuery = "select * from " + kind;
-    Query query = Query.gqlQueryBuilder(Query.ResultType.ENTITY, gqlQuery).build();
+    Query query = Query.newGqlQueryBuilder(Query.ResultType.ENTITY, gqlQuery).build();
     QueryResults results = datastore.run(query);
     // Use results
     // [END newTypedQuery]
     return results;
   }
 
+  /**
+   * Example of creating and running a typed GQL query.
+   */
+  // [TARGET gqlQueryBuilder(ResultType, String)]
+  // [VARIABLE "my_kind"]
+  public QueryResults newTypedQueryDeprecated(String kind) {
+    // [START newTypedQueryDeprecated]
+    String gqlQuery = "select * from " + kind;
+    Query query = Query.gqlQueryBuilder(Query.ResultType.ENTITY, gqlQuery).build();
+    QueryResults results = datastore.run(query);
+    // Use results
+    // [END newTypedQueryDeprecated]
+    return results;
+  }
+
   /**
    * Example of creating and running an entity query.
    */
-  // [TARGET entityQueryBuilder()]
+  // [TARGET newEntityQueryBuilder()]
   // [VARIABLE "my_kind"]
   public QueryResults newEntityQuery(String kind) {
     // [START newEntityQuery]
-    Query query = Query.entityQueryBuilder().kind(kind).build();
+    Query query = Query.newEntityQueryBuilder().setKind(kind).build();
     QueryResults results = datastore.run(query);
     // Use results
     // [END newEntityQuery]
     return results;
   }
 
+  /**
+   * Example of creating and running an entity query.
+   */
+  // [TARGET entityQueryBuilder()]
+  // [VARIABLE "my_kind"]
+  public QueryResults newEntityQueryDeprecated(String kind) {
+    // [START newEntityQueryDeprecated]
+    Query query = Query.entityQueryBuilder().setKind(kind).build();
+    QueryResults results = datastore.run(query);
+    // Use results
+    // [END newEntityQueryDeprecated]
+    return results;
+  }
+
   /**
    * Example of creating and running a key query.
    */
-  // [TARGET keyQueryBuilder()]
+  // [TARGET newKeyQueryBuilder()]
   // [VARIABLE "my_kind"]
   public QueryResults newKeyQuery(String kind) {
     // [START newKeyQuery]
-    Query query = Query.keyQueryBuilder().kind(kind).build();
+    Query query = Query.newKeyQueryBuilder().setKind(kind).build();
     QueryResults results = datastore.run(query);
     // Use results
     // [END newKeyQuery]
     return results;
   }
 
+  /**
+   * Example of creating and running a key query.
+   */
+  // [TARGET keyQueryBuilder()]
+  // [VARIABLE "my_kind"]
+  public QueryResults newKeyQueryDeprecated(String kind) {
+    // [START newKeyQueryDeprecated]
+    Query query = Query.keyQueryBuilder().setKind(kind).build();
+    QueryResults results = datastore.run(query);
+    // Use results
+    // [END newKeyQueryDeprecated]
+    return results;
+  }
+
   /**
    * Example of creating and running a projection entity query.
    */
-  // [TARGET projectionEntityQueryBuilder()]
+  // [TARGET newProjectionEntityQueryBuilder()]
   // [VARIABLE "my_kind"]
   // [VARIABLE "my_property"]
   public QueryResults newProjectionEntityQuery(String kind, String property) {
     // [START newProjectionEntityQuery]
+    Query query = Query.newProjectionEntityQueryBuilder()
+        .setKind(kind)
+        .addProjection(property)
+        .build();
+    QueryResults results = datastore.run(query);
+    // Use results
+    // [END newProjectionEntityQuery]
+    return results;
+  }
+
+  /**
+   * Example of creating and running a projection entity query.
+   */
+  // [TARGET projectionEntityQueryBuilder()]
+  // [VARIABLE "my_kind"]
+  // [VARIABLE "my_property"]
+  public QueryResults newProjectionEntityQueryDeprecated(String kind,
+      String property) {
+    // [START newProjectionEntityQuery]
     Query query = Query.projectionEntityQueryBuilder()
-        .kind(kind)
+        .setKind(kind)
         .addProjection(property)
         .build();
     QueryResults results = datastore.run(query);
diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/TransactionSnippets.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/TransactionSnippets.java
index eb6b5d4afdd4..07b5577759b2 100644
--- a/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/TransactionSnippets.java
+++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/TransactionSnippets.java
@@ -53,9 +53,9 @@ public TransactionSnippets(Transaction transaction) {
   // [TARGET get(Key)]
   // [VARIABLE "my_key_name"]
   public Entity get(String keyName) {
-    Datastore datastore = transaction.datastore();
+    Datastore datastore = transaction.getDatastore();
     // [START get]
-    Key key = datastore.newKeyFactory().kind("MyKind").newKey(keyName);
+    Key key = datastore.newKeyFactory().setKind("MyKind").newKey(keyName);
     Entity entity = transaction.get(key);
     transaction.commit();
     // Do something with the entity
@@ -70,10 +70,10 @@ public Entity get(String keyName) {
   // [VARIABLE "my_first_key_name"]
   // [VARIABLE "my_second_key_name"]
   public List getMultiple(String firstKeyName, String secondKeyName) {
-    Datastore datastore = transaction.datastore();
+    Datastore datastore = transaction.getDatastore();
     // TODO change so that it's not necessary to hold the entities in a list for integration testing
     // [START getMultiple]
-    KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+    KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
     Key firstKey = keyFactory.newKey(firstKeyName);
     Key secondKey = keyFactory.newKey(secondKeyName);
     Iterator entitiesIterator = transaction.get(firstKey, secondKey);
@@ -95,9 +95,9 @@ public List getMultiple(String firstKeyName, String secondKeyName) {
   // [VARIABLE "my_first_key_name"]
   // [VARIABLE "my_second_key_name"]
   public List fetchEntitiesWithKeys(String firstKeyName, String secondKeyName) {
-    Datastore datastore = transaction.datastore();
+    Datastore datastore = transaction.getDatastore();
     // [START fetchEntitiesWithKeys]
-    KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+    KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
     Key firstKey = keyFactory.newKey(firstKeyName);
     Key secondKey = keyFactory.newKey(secondKeyName);
     List entities = transaction.fetch(firstKey, secondKey);
@@ -115,14 +115,14 @@ public List fetchEntitiesWithKeys(String firstKeyName, String secondKeyN
   // [TARGET run(Query)]
   // [VARIABLE "my_parent_key_name"]
   public List run(String parentKeyName) {
-    Datastore datastore = transaction.datastore();
+    Datastore datastore = transaction.getDatastore();
     // [START run]
-    KeyFactory keyFactory = datastore.newKeyFactory().kind("ParentKind");
+    KeyFactory keyFactory = datastore.newKeyFactory().setKind("ParentKind");
     Key parentKey = keyFactory.newKey(parentKeyName);
     // Build a query
-    Query query = Query.entityQueryBuilder()
-        .kind("MyKind")
-        .filter(PropertyFilter.hasAncestor(parentKey))
+    Query query = Query.newEntityQueryBuilder()
+        .setKind("MyKind")
+        .setFilter(PropertyFilter.hasAncestor(parentKey))
         .build();
     QueryResults results = transaction.run(query);
     List entities = Lists.newArrayList();
@@ -141,12 +141,12 @@ public List run(String parentKeyName) {
    */
   // [TARGET commit()]
   public Key commit() {
-    Datastore datastore = transaction.datastore();
+    Datastore datastore = transaction.getDatastore();
     // [START commit]
     // create an entity
-    KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+    KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
     Key key = datastore.allocateId(keyFactory.newKey());
-    Entity entity = Entity.builder(key).set("description", "commit()").build();
+    Entity entity = Entity.newBuilder(key).set("description", "commit()").build();
 
     // add the entity and commit
     try {
@@ -165,12 +165,12 @@ public Key commit() {
    */
   // [TARGET rollback()]
   public Key rollback() {
-    Datastore datastore = transaction.datastore();
+    Datastore datastore = transaction.getDatastore();
     // [START rollback]
     // create an entity
-    KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+    KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
     Key key = datastore.allocateId(keyFactory.newKey());
-    Entity entity = Entity.builder(key).set("description", "rollback()").build();
+    Entity entity = Entity.newBuilder(key).set("description", "rollback()").build();
 
     // add the entity and rollback
     transaction.put(entity);
@@ -185,12 +185,12 @@ public Key rollback() {
    */
   // [TARGET active()]
   public Key active() {
-    Datastore datastore = transaction.datastore();
+    Datastore datastore = transaction.getDatastore();
     // [START active]
     // create an entity
-    KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
+    KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
     Key key = datastore.allocateId(keyFactory.newKey());
-    Entity entity = Entity.builder(key).set("description", "active()").build();
+    Entity entity = Entity.newBuilder(key).set("description", "active()").build();
     // calling transaction.active() now would return true
     try {
       // add the entity and commit
@@ -207,4 +207,32 @@ public Key active() {
     // [END active]
     return key;
   }
+
+  /**
+   * Example of verifying if a transaction is active.
+   */
+  // [TARGET isActive()]
+  public Key isActive() {
+    Datastore datastore = transaction.getDatastore();
+    // [START isActive]
+    // create an entity
+    KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
+    Key key = datastore.allocateId(keyFactory.newKey());
+    Entity entity = Entity.newBuilder(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.isActive()) {
+        // otherwise it's true and we need to rollback
+        transaction.rollback();
+      }
+    }
+    // [END isActive]
+    return key;
+  }
 }
diff --git a/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/UpdateEntity.java b/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/UpdateEntity.java
index 79cb6e8b9a5e..ce423b2535c4 100644
--- a/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/UpdateEntity.java
+++ b/google-cloud-examples/src/main/java/com/google/cloud/examples/datastore/snippets/UpdateEntity.java
@@ -36,12 +36,12 @@ public class UpdateEntity {
 
   public static void main(String... args) {
     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-examples/src/test/java/com/google/cloud/examples/datastore/snippets/ITDatastoreSnippets.java b/google-cloud-examples/src/test/java/com/google/cloud/examples/datastore/snippets/ITDatastoreSnippets.java
index 9aef5a2f2d8d..c071f89547e7 100644
--- a/google-cloud-examples/src/test/java/com/google/cloud/examples/datastore/snippets/ITDatastoreSnippets.java
+++ b/google-cloud-examples/src/test/java/com/google/cloud/examples/datastore/snippets/ITDatastoreSnippets.java
@@ -69,22 +69,22 @@ private String registerKey(String keyName) {
   }
 
   private String registerKey(String keyName, String kind) {
-    Key key = datastore.newKeyFactory().kind(kind).newKey(keyName);
+    Key key = datastore.newKeyFactory().setKind(kind).newKey(keyName);
     registeredKeys.add(key);
-    return key.name();
+    return key.getName();
   }
 
   private Map createEntityMap(List entities) {
     Map entityMap = new HashMap<>();
     for (Entity entity : entities) {
-      entityMap.put(entity.key().name(), entity);
+      entityMap.put(entity.getKey().getName(), entity);
     }
     return entityMap;
   }
 
   private void addEntity(String keyName, String keyClass, String property, String value) {
-    Key key = datastore.newKeyFactory().kind(keyClass).newKey(keyName);
-    Entity.Builder entityBuilder = Entity.builder(key);
+    Key key = datastore.newKeyFactory().setKind(keyClass).newKey(keyName);
+    Entity.Builder entityBuilder = Entity.newBuilder(key);
     entityBuilder.set(property, value);
     Entity entity = entityBuilder.build();
     datastore.put(entity);
diff --git a/google-cloud-examples/src/test/java/com/google/cloud/examples/datastore/snippets/ITQuerySnippets.java b/google-cloud-examples/src/test/java/com/google/cloud/examples/datastore/snippets/ITQuerySnippets.java
index d735c12c1f75..bb1ee6782e18 100644
--- a/google-cloud-examples/src/test/java/com/google/cloud/examples/datastore/snippets/ITQuerySnippets.java
+++ b/google-cloud-examples/src/test/java/com/google/cloud/examples/datastore/snippets/ITQuerySnippets.java
@@ -55,16 +55,16 @@ public String apply(ProjectionEntity entity) {
   @BeforeClass
   public static void beforeClass() {
     datastore = DatastoreOptions.defaultInstance().service();
-    Key key1 = Key.builder(datastore.options().projectId(), KIND, "key1").build();
-    Key key2 = Key.builder(datastore.options().projectId(), KIND, "key2").build();
-    entity1 = Entity.builder(key1).set("description", "entity1").build();
-    entity2 = Entity.builder(key2).set("description", "entity2").build();
+    Key key1 = Key.newBuilder(datastore.options().projectId(), KIND, "key1").build();
+    Key key2 = Key.newBuilder(datastore.options().projectId(), KIND, "key2").build();
+    entity1 = Entity.newBuilder(key1).set("description", "entity1").build();
+    entity2 = Entity.newBuilder(key2).set("description", "entity2").build();
     datastore.put(entity1, entity2);
   }
 
   @AfterClass
   public static void afterClass() {
-    datastore.delete(entity1.key(), entity2.key());
+    datastore.delete(entity1.getKey(), entity2.getKey());
   }
 
   @Test
@@ -78,6 +78,17 @@ public void testNewQuery() throws InterruptedException {
     }
   }
 
+  @Test
+  public void testNewQueryDeprecated() throws InterruptedException {
+    QuerySnippets transactionSnippets = new QuerySnippets(datastore);
+    QueryResults results = transactionSnippets.newQueryDeprecated(KIND);
+    Set resultSet = Sets.newHashSet(results);
+    while (!resultSet.contains(entity1) || !resultSet.contains(entity2)) {
+      Thread.sleep(500);
+      resultSet = Sets.newHashSet(results);
+    }
+  }
+
   @Test
   public void testNewTypedQuery() throws InterruptedException {
     QuerySnippets transactionSnippets = new QuerySnippets(datastore);
@@ -89,6 +100,17 @@ public void testNewTypedQuery() throws InterruptedException {
     }
   }
 
+  @Test
+  public void testNewTypedQueryDeprecated() throws InterruptedException {
+    QuerySnippets transactionSnippets = new QuerySnippets(datastore);
+    QueryResults results = transactionSnippets.newTypedQueryDeprecated(KIND);
+    Set resultSet = Sets.newHashSet(results);
+    while (!resultSet.contains(entity1) || !resultSet.contains(entity2)) {
+      Thread.sleep(500);
+      resultSet = Sets.newHashSet(results);
+    }
+  }
+
   @Test
   public void testNewEntityQuery() throws InterruptedException {
     QuerySnippets transactionSnippets = new QuerySnippets(datastore);
@@ -105,7 +127,18 @@ public void testNewKeyQuery() throws InterruptedException {
     QuerySnippets transactionSnippets = new QuerySnippets(datastore);
     QueryResults results = transactionSnippets.newKeyQuery(KIND);
     Set resultSet = Sets.newHashSet(results);
-    while (!resultSet.contains(entity1.key()) || !resultSet.contains(entity2.key())) {
+    while (!resultSet.contains(entity1.getKey()) || !resultSet.contains(entity2.getKey())) {
+      Thread.sleep(500);
+      resultSet = Sets.newHashSet(results);
+    }
+  }
+
+  @Test
+  public void testNewKeyQueryDeprecated() throws InterruptedException {
+    QuerySnippets transactionSnippets = new QuerySnippets(datastore);
+    QueryResults results = transactionSnippets.newKeyQueryDeprecated(KIND);
+    Set resultSet = Sets.newHashSet(results);
+    while (!resultSet.contains(entity1.getKey()) || !resultSet.contains(entity2.getKey())) {
       Thread.sleep(500);
       resultSet = Sets.newHashSet(results);
     }
@@ -124,4 +157,18 @@ public void testNewProjectionEntityQuery() throws InterruptedException {
       resultSet = Sets.newHashSet(Iterators.transform(results, ENTITY_TO_DESCRIPTION_FUNCTION));
     }
   }
+
+  @Test
+  public void testNewProjectionEntityQueryDeprecated() throws InterruptedException {
+    QuerySnippets transactionSnippets = new QuerySnippets(datastore);
+    QueryResults results =
+        transactionSnippets.newProjectionEntityQueryDeprecated(KIND, "description");
+    Set resultSet =
+        Sets.newHashSet(Iterators.transform(results, ENTITY_TO_DESCRIPTION_FUNCTION));
+    while (!resultSet.contains(entity1.getString("description"))
+        || !resultSet.contains(entity2.getString("description"))) {
+      Thread.sleep(500);
+      resultSet = Sets.newHashSet(Iterators.transform(results, ENTITY_TO_DESCRIPTION_FUNCTION));
+    }
+  }
 }
diff --git a/google-cloud-examples/src/test/java/com/google/cloud/examples/datastore/snippets/ITTransactionSnippets.java b/google-cloud-examples/src/test/java/com/google/cloud/examples/datastore/snippets/ITTransactionSnippets.java
index 07492ffa2d27..418c50e84dd0 100644
--- a/google-cloud-examples/src/test/java/com/google/cloud/examples/datastore/snippets/ITTransactionSnippets.java
+++ b/google-cloud-examples/src/test/java/com/google/cloud/examples/datastore/snippets/ITTransactionSnippets.java
@@ -45,7 +45,7 @@ public class ITTransactionSnippets {
 
   private String registerKey(Key key) {
     registeredKeys.add(key);
-    return key.name();
+    return key.getName();
   }
 
   private String registerKey(String keyName) {
@@ -53,9 +53,9 @@ private String registerKey(String keyName) {
   }
 
   private String registerKey(String keyName, String kind) {
-    Key key = datastore.newKeyFactory().kind(kind).newKey(keyName);
+    Key key = datastore.newKeyFactory().setKind(kind).newKey(keyName);
     registeredKeys.add(key);
-    return key.name();
+    return key.getName();
   }
 
   @BeforeClass
@@ -70,8 +70,8 @@ public void afterTest() {
 
   @Test
   public void testGet() {
-    Key key1 = datastore.newKeyFactory().kind("MyKind").newKey("fetch_key_1");
-    Entity entity1 = Entity.builder(key1).set("description", "fetch1").build();
+    Key key1 = datastore.newKeyFactory().setKind("MyKind").newKey("fetch_key_1");
+    Entity entity1 = Entity.newBuilder(key1).set("description", "fetch1").build();
     datastore.put(entity1);
     registerKey("fetch_key_1");
 
@@ -82,10 +82,10 @@ public void testGet() {
 
   @Test
   public void testGetMultiple() {
-    Key key1 = datastore.newKeyFactory().kind("MyKind").newKey("fetch_key_1");
-    Key key2 = datastore.newKeyFactory().kind("MyKind").newKey("fetch_key_2");
-    Entity entity1 = Entity.builder(key1).set("description", "fetch1").build();
-    Entity entity2 = Entity.builder(key2).set("description", "fetch2").build();
+    Key key1 = datastore.newKeyFactory().setKind("MyKind").newKey("fetch_key_1");
+    Key key2 = datastore.newKeyFactory().setKind("MyKind").newKey("fetch_key_2");
+    Entity entity1 = Entity.newBuilder(key1).set("description", "fetch1").build();
+    Entity entity2 = Entity.newBuilder(key2).set("description", "fetch2").build();
     datastore.put(entity1, entity2);
     registerKey("fetch_key_1");
     registerKey("fetch_key_2");
@@ -101,10 +101,10 @@ public void testGetMultiple() {
 
   @Test
   public void testFetchEntitiesWithKeys() {
-    Key key1 = datastore.newKeyFactory().kind("MyKind").newKey("fetch_key_1");
-    Key key2 = datastore.newKeyFactory().kind("MyKind").newKey("fetch_key_2");
-    Entity entity1 = Entity.builder(key1).set("description", "fetch1").build();
-    Entity entity2 = Entity.builder(key2).set("description", "fetch2").build();
+    Key key1 = datastore.newKeyFactory().setKind("MyKind").newKey("fetch_key_1");
+    Key key2 = datastore.newKeyFactory().setKind("MyKind").newKey("fetch_key_2");
+    Entity entity1 = Entity.newBuilder(key1).set("description", "fetch1").build();
+    Entity entity2 = Entity.newBuilder(key2).set("description", "fetch2").build();
     datastore.put(entity1, entity2);
     registerKey("fetch_key_1");
     registerKey("fetch_key_2");
@@ -120,17 +120,17 @@ public void testFetchEntitiesWithKeys() {
 
   @Test
   public void testRun() {
-    Key key1 = datastore.newKeyFactory().kind("ParentKind").newKey("run_key_1");
-    Entity entity1 = Entity.builder(key1).set("description", "run1").build();
+    Key key1 = datastore.newKeyFactory().setKind("ParentKind").newKey("run_key_1");
+    Entity entity1 = Entity.newBuilder(key1).set("description", "run1").build();
     datastore.put(entity1);
     Key key2 = datastore
         .newKeyFactory()
-        .kind("MyKind")
-        .ancestors(PathElement.of("ParentKind", "run_key_1"))
+        .setKind("MyKind")
+        .addAncestor(PathElement.of("ParentKind", "run_key_1"))
         .newKey("run_key_2");
     registerKey(key1);
     registerKey(key2);
-    Entity entity2 = Entity.builder(key2).set("description", "run2").build();
+    Entity entity2 = Entity.newBuilder(key2).set("description", "run2").build();
     datastore.put(entity2);
 
     Transaction transaction = datastore.newTransaction();
@@ -168,4 +168,14 @@ public void testActive() {
     assertNotNull(result);
     datastore.delete(key);
   }
+
+  @Test
+  public void testIsActive() {
+    Transaction transaction = datastore.newTransaction();
+    TransactionSnippets transactionSnippets = new TransactionSnippets(transaction);
+    Key key = transactionSnippets.isActive();
+    Entity result = datastore.get(key);
+    assertNotNull(result);
+    datastore.delete(key);
+  }
 }