@@ -63,6 +63,15 @@ interface Response {
63
63
* to fail if entity was changed by others after it was seen by this transaction) but any
64
64
* write changes in this transaction will not be reflected by the returned entity.
65
65
*
66
+ * <p>Example of getting an entity for a given key.
67
+ * <pre> {@code
68
+ * String keyName = "my_key_name";
69
+ * Key key = datastore.newKeyFactory().kind("MyKind").newKey(keyName);
70
+ * Entity entity = transaction.get(key);
71
+ * transaction.commit();
72
+ * // Do something with the entity
73
+ * }</pre>
74
+ *
66
75
* @throws DatastoreException upon failure or if no longer active
67
76
*/
68
77
@ Override
@@ -74,6 +83,23 @@ interface Response {
74
83
* to fail if any of the entities was changed by others after they were seen by this transaction)
75
84
* but any write changes in this transaction will not be reflected by the returned entities.
76
85
*
86
+ * <p>Example of getting entities for several keys.
87
+ * <pre> {@code
88
+ * String firstKeyName = "my_first_key_name";
89
+ * String secondKeyName = "my_second_key_name";
90
+ * KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
91
+ * Key firstKey = keyFactory.newKey(firstKeyName);
92
+ * Key secondKey = keyFactory.newKey(secondKeyName);
93
+ * Iterator<Entity> entitiesIterator = transaction.get(firstKey, secondKey);
94
+ * List<Entity> entities = Lists.newArrayList();
95
+ * while (entitiesIterator.hasNext()) {
96
+ * Entity entity = entitiesIterator.next();
97
+ * // do something with the entity
98
+ * entities.add(entity);
99
+ * }
100
+ * transaction.commit();
101
+ * }</pre>
102
+ *
77
103
* @throws DatastoreException upon failure or if no longer active
78
104
*/
79
105
@ Override
@@ -85,6 +111,20 @@ interface Response {
85
111
* to fail if any of the entities was changed by others after they were seen by this transaction)
86
112
* but any write changes in this transaction will not be reflected by the returned entities.
87
113
*
114
+ * <p>Example of fetching a list of entities for several keys.
115
+ * <pre> {@code
116
+ * String firstKeyName = "my_first_key_name";
117
+ * String secondKeyName = "my_second_key_name";
118
+ * KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind");
119
+ * Key firstKey = keyFactory.newKey(firstKeyName);
120
+ * Key secondKey = keyFactory.newKey(secondKeyName);
121
+ * List<Entity> entities = transaction.fetch(firstKey, secondKey);
122
+ * for (Entity entity : entities) {
123
+ * // do something with the entity
124
+ * }
125
+ * transaction.commit();
126
+ * }</pre>
127
+ *
88
128
* @throws DatastoreException upon failure or if no longer active
89
129
*/
90
130
@ Override
@@ -97,6 +137,26 @@ interface Response {
97
137
* query was performed) but any write changes in this transaction will not be reflected by
98
138
* the result.
99
139
*
140
+ * <p>Example of running a query to find all entities with an ancestor.
141
+ * <pre> {@code
142
+ * String parentKeyName = "my_parent_key_name";
143
+ * KeyFactory keyFactory = datastore.newKeyFactory().kind("ParentKind");
144
+ * Key parentKey = keyFactory.newKey(parentKeyName);
145
+ * // Build a query
146
+ * Query<Entity> query = Query.entityQueryBuilder()
147
+ * .kind("MyKind")
148
+ * .filter(PropertyFilter.hasAncestor(parentKey))
149
+ * .build();
150
+ * QueryResults<Entity> results = transaction.run(query);
151
+ * List<Entity> entities = Lists.newArrayList();
152
+ * while (results.hasNext()) {
153
+ * Entity result = results.next();
154
+ * // do something with result
155
+ * entities.add(result);
156
+ * }
157
+ * transaction.commit();
158
+ * }</pre>
159
+ *
100
160
* @throws DatastoreException upon failure or if no longer active
101
161
*/
102
162
@ Override
@@ -108,9 +168,10 @@ interface Response {
108
168
* <p>Example of committing a transaction.
109
169
* <pre> {@code
110
170
* // create an entity
111
- * KeyFactory keyFactory = datastore.newKeyFactory().kind("someKind ");
171
+ * KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind ");
112
172
* Key key = datastore.allocateId(keyFactory.newKey());
113
173
* Entity entity = Entity.builder(key).set("description", "commit()").build();
174
+ *
114
175
* // add the entity and commit
115
176
* try {
116
177
* transaction.put(entity);
@@ -130,7 +191,7 @@ interface Response {
130
191
* <p>Example of rolling back a transaction.
131
192
* <pre> {@code
132
193
* // create an entity
133
- * KeyFactory keyFactory = datastore.newKeyFactory().kind("someKind ");
194
+ * KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind ");
134
195
* Key key = datastore.allocateId(keyFactory.newKey());
135
196
* Entity entity = Entity.builder(key).set("description", "rollback()").build();
136
197
*
@@ -150,7 +211,7 @@ interface Response {
150
211
* <p>Example of verifying if a transaction is active.
151
212
* <pre> {@code
152
213
* // create an entity
153
- * KeyFactory keyFactory = datastore.newKeyFactory().kind("someKind ");
214
+ * KeyFactory keyFactory = datastore.newKeyFactory().kind("MyKind ");
154
215
* Key key = datastore.allocateId(keyFactory.newKey());
155
216
* Entity entity = Entity.builder(key).set("description", "active()").build();
156
217
* // calling transaction.active() now would return true
0 commit comments