Skip to content

Commit

Permalink
fix(sample): change update entity sample to use transaction (#1633)
Browse files Browse the repository at this point in the history
  • Loading branch information
cindy-peng committed Oct 28, 2024
1 parent 4461f5b commit 17b411f
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions com/google/datastore/snippets/ConceptsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,17 @@ public void testLookup() {
public void testUpdate() {
datastore.put(testEntity);
// [START datastore_update]
Entity task = Entity.newBuilder(datastore.get(taskKey)).set("priority", 5).build();
datastore.update(task);
Entity task;
Transaction txn = datastore.newTransaction();
try {
task = Entity.newBuilder(txn.get(taskKey)).set("priority", 5).build();
txn.put(task);
txn.commit();
} finally {
if (txn.isActive()) {
txn.rollback();
}
}
// [END datastore_update]
assertEquals(task, datastore.get(taskKey));
}
Expand Down

0 comments on commit 17b411f

Please sign in to comment.