
Ultimate access to all questions.
Which improvement would you recommend for the following Cloud Datastore code that adds a credit to an account balance?
public Entity creditAccount(long accountId, long creditAmount) {
Entity account = datastore.get(keyFactory.newKey(accountId));
account = Entity.builder(account)
.set("balance", account.getLong("balance") + creditAmount)
.build();
datastore.put(account);
return account;
}
public Entity creditAccount(long accountId, long creditAmount) {
Entity account = datastore.get(keyFactory.newKey(accountId));
account = Entity.builder(account)
.set("balance", account.getLong("balance") + creditAmount)
.build();
datastore.put(account);
return account;
}
A
Get the entity with an ancestor query.
B
Get and put the entity in a transaction.
C
Use a strongly consistent transactional database.
D
Don't return the account entity from the function.