Skip to content

Commit

Permalink
Update Datastore examples, snippets and READMEs to use renamed getter…
Browse files Browse the repository at this point in the history
…s/setters/builders
  • Loading branch information
mziccard committed Oct 13, 2016
1 parent c1deb59 commit b7a5c2f
Show file tree
Hide file tree
Showing 16 changed files with 344 additions and 182 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions google-cloud-datastore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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("[email protected]");
Entity entity = Entity.builder(key)
Entity entity = Entity.newBuilder(key)
.set("name", "John Doe")
.set("age", 51)
.set("favorite_food", "pizza")
Expand Down Expand Up @@ -126,9 +126,9 @@ import com.google.cloud.datastore.StructuredQuery.PropertyFilter;
Then add the following code to your program:

```java
Query<Entity> query = Query.entityQueryBuilder()
.kind("Person")
.filter(PropertyFilter.eq("favorite_food", "pizza"))
Query<Entity> query = Query.newEntityQueryBuilder()
.setKind("Person")
.setFilter(PropertyFilter.eq("favorite_food", "pizza"))
.build();
QueryResults<Entity> results = datastore.run(query);
while (results.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ interface TransactionCallable<T> {
* <pre> {@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();
Expand All @@ -96,7 +96,7 @@ interface TransactionCallable<T> {
*
* <p>Example of allocating an id.
* <pre> {@code
* KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
* KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
* IncompleteKey incompleteKey = keyFactory.newKey();
*
* // let cloud datastore automatically assign an id
Expand All @@ -112,7 +112,7 @@ interface TransactionCallable<T> {
*
* <p>Example of allocating multiple ids in a single batch.
* <pre> {@code
* KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
* KeyFactory keyFactory = datastore.newKeyFactory().setKind("MyKind");
* IncompleteKey incompleteKey1 = keyFactory.newKey();
* IncompleteKey incompleteKey2 = keyFactory.newKey();
*
Expand All @@ -132,13 +132,13 @@ interface TransactionCallable<T> {
* <pre> {@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();
*
Expand All @@ -156,8 +156,8 @@ interface TransactionCallable<T> {
* <p>Example of putting a single entity.
* <pre> {@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);
Expand All @@ -175,13 +175,13 @@ interface TransactionCallable<T> {
* <pre> {@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();
*
Expand All @@ -200,8 +200,8 @@ interface TransactionCallable<T> {
* <pre> {@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);
* }</pre>
*
Expand All @@ -228,7 +228,7 @@ interface TransactionCallable<T> {
* <p>Example of getting an entity.
* <pre> {@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
* }</pre>
Expand All @@ -248,7 +248,7 @@ interface TransactionCallable<T> {
* <pre> {@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<Entity> entitiesIterator = datastore.get(Lists.newArrayList(firstKey, secondKey));
Expand All @@ -274,7 +274,7 @@ interface TransactionCallable<T> {
* <pre> {@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<Entity> entities = datastore.fetch(Lists.newArrayList(firstKey, secondKey));
Expand All @@ -293,8 +293,8 @@ interface TransactionCallable<T> {
* <p>Example of running a query to find all entities of one kind.
* <pre> {@code
* String kind = "my_kind";
* StructuredQuery<Entity> query = Query.entityQueryBuilder()
* .kind(kind)
* StructuredQuery<Entity> query = Query.newEntityQueryBuilder()
* .setKind(kind)
* .build();
* QueryResults<Entity> results = datastore.run(query);
* List<Entity> entities = Lists.newArrayList();
Expand All @@ -310,9 +310,9 @@ interface TransactionCallable<T> {
* String kind = "my_kind";
* String property = "my_property";
* String value = "my_value";
* StructuredQuery<Entity> query = Query.entityQueryBuilder()
* .kind(kind)
* .filter(PropertyFilter.eq(property, value))
* StructuredQuery<Entity> query = Query.newEntityQueryBuilder()
* .setKind(kind)
* .setFilter(PropertyFilter.eq(property, value))
* .build();
* QueryResults<Entity> results = datastore.run(query);
* List<Entity> entities = Lists.newArrayList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public static GqlQuery.Builder<?> gqlQueryBuilder(String gql) {
* <pre> {@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
* }</pre>
Expand Down Expand Up @@ -242,7 +242,7 @@ public static <V> GqlQuery.Builder<V> gqlQueryBuilder(ResultType<V> resultType,
* <pre> {@code
* String kind = "my_kind";
* String gqlQuery = "select * from " + kind;
* Query<Entity> query = Query.gqlQueryBuilder(Query.ResultType.ENTITY, gqlQuery).build();
* Query<Entity> query = Query.newGqlQueryBuilder(Query.ResultType.ENTITY, gqlQuery).build();
* QueryResults<Entity> results = datastore.run(query);
* // Use results
* }</pre>
Expand All @@ -259,7 +259,7 @@ public static <V> GqlQuery.Builder<V> newGqlQueryBuilder(ResultType<V> resultTyp
* <p>Example of creating and running an entity query.
* <pre> {@code
* String kind = "my_kind";
* Query<Entity> query = Query.entityQueryBuilder().kind(kind).build();
* Query<Entity> query = Query.entityQueryBuilder().setKind(kind).build();
* QueryResults<Entity> results = datastore.run(query);
* // Use results
* }</pre>
Expand All @@ -276,7 +276,7 @@ public static EntityQuery.Builder entityQueryBuilder() {
* <p>Example of creating and running an entity query.
* <pre> {@code
* String kind = "my_kind";
* Query<Entity> query = Query.entityQueryBuilder().kind(kind).build();
* Query<Entity> query = Query.newEntityQueryBuilder().setKind(kind).build();
* QueryResults<Entity> results = datastore.run(query);
* // Use results
* }</pre>
Expand All @@ -292,7 +292,7 @@ public static EntityQuery.Builder newEntityQueryBuilder() {
* <p>Example of creating and running a key query.
* <pre> {@code
* String kind = "my_kind";
* Query<Key> query = Query.keyQueryBuilder().kind(kind).build();
* Query<Key> query = Query.keyQueryBuilder().setKind(kind).build();
* QueryResults<Key> results = datastore.run(query);
* // Use results
* }</pre>
Expand All @@ -309,7 +309,7 @@ public static KeyQuery.Builder keyQueryBuilder() {
* <p>Example of creating and running a key query.
* <pre> {@code
* String kind = "my_kind";
* Query<Key> query = Query.keyQueryBuilder().kind(kind).build();
* Query<Key> query = Query.newKeyQueryBuilder().setKind(kind).build();
* QueryResults<Key> results = datastore.run(query);
* // Use results
* }</pre>
Expand All @@ -327,7 +327,7 @@ public static KeyQuery.Builder newKeyQueryBuilder() {
* String kind = "my_kind";
* String property = "my_property";
* Query<ProjectionEntity> query = Query.projectionEntityQueryBuilder()
* .kind(kind)
* .setKind(kind)
* .addProjection(property)
* .build();
* QueryResults<ProjectionEntity> results = datastore.run(query);
Expand All @@ -347,8 +347,8 @@ public static ProjectionEntityQuery.Builder projectionEntityQueryBuilder() {
* <pre> {@code
* String kind = "my_kind";
* String property = "my_property";
* Query<ProjectionEntity> query = Query.projectionEntityQueryBuilder()
* .kind(kind)
* Query<ProjectionEntity> query = Query.newProjectionEntityQueryBuilder()
* .setKind(kind)
* .addProjection(property)
* .build();
* QueryResults<ProjectionEntity> results = datastore.run(query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ interface Response {
* <p>Example of getting an entity for a given key.
* <pre> {@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
Expand All @@ -100,7 +100,7 @@ interface Response {
* <pre> {@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<Entity> entitiesIterator = transaction.get(firstKey, secondKey);
Expand Down Expand Up @@ -128,7 +128,7 @@ interface Response {
* <pre> {@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<Entity> entities = transaction.fetch(firstKey, secondKey);
Expand All @@ -153,12 +153,12 @@ interface Response {
* <p>Example of running a query to find all entities with an ancestor.
* <pre> {@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<Entity> query = Query.entityQueryBuilder()
* .kind("MyKind")
* .filter(PropertyFilter.hasAncestor(parentKey))
* Query<Entity> query = Query.newEntityQueryBuilder()
* .setKind("MyKind")
* .setFilter(PropertyFilter.hasAncestor(parentKey))
* .build();
* QueryResults<Entity> results = transaction.run(query);
* List<Entity> entities = Lists.newArrayList();
Expand All @@ -181,9 +181,9 @@ interface Response {
* <p>Example of committing a transaction.
* <pre> {@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 {
Expand All @@ -204,9 +204,9 @@ interface Response {
* <p>Example of rolling back a transaction.
* <pre> {@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);
Expand All @@ -224,9 +224,9 @@ interface Response {
* <p>Example of verifying if a transaction is active.
* <pre> {@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
Expand All @@ -253,9 +253,9 @@ interface Response {
* <p>Example of verifying if a transaction is active.
* <pre> {@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
Expand All @@ -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();
* }
Expand Down
Loading

0 comments on commit b7a5c2f

Please sign in to comment.