2
我可以這樣做嗎?即使我沒有使用ds.get(tx, key)
和ds.put(tx, key)
,它仍然是交易嗎?我可以使用Guice的@Transactional和Google App Engine的數據存儲嗎?
public class MyClass {
private final DatastoreService ds;
@Inject
public MyClass(DatastoreService ds) {
this.ds = ds;
}
@Transactional
public void plusOne() {
Key someKey;
Entity thing = ds.get(someKey);
int newValue = thing.getProperty("prop") + 1;
thing.setProperty("prop", newValue);
ds.put(thing);
}
}