final Trivial triv = new Trivial(123L, "foo", 5);
try (Closeable root = TestObjectifyService.begin()) {
ofy().transact(new VoidWork() {
@Override
public void vrun() {
ofy().defer().save().entity(triv);
// Can load out of session
assertThat(ofy().load().entity(triv).now(), is(triv));
// But not datastore
try {
ds().get(null, Key.create(triv).getRaw());
assert false : "Entity should not have been saved yet";
} catch (EntityNotFoundException e) {
// correct
}
}
});
{
Trivial loaded = ofy().load().entity(triv).now();
assertThat(loaded, equalTo(triv));
}
ofy().transact(new VoidWork() {
@Override
public void vrun() {
ofy().defer().delete().entity(triv);
// Deleted in session