2

Can I do something like this? Would it still be a transaction even though I did not use ds.get(tx, key) and ds.put(tx, key)?

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);
    }
}
Charlotte Tan
  • 2,452
  • 2
  • 20
  • 24

1 Answers1

0

I'm not used to Guice, but like any other dependency injection framework I guess you would have to declare some kind of TransactionManager in your module config ? Which in this case, doesn't exist, or at least was not advertised by Google. Maybe you'll find what you need in the community, check out GitHub... but again I highly doubt that Guice supports it out of the box with the low level datastore. You probably have some JPA support in Guice though ?

Or you can develop your own transaction manager... I have developed my own @DatastoreTransactional annotation with Spring, but unfortunately using Spring AOP on the production runtime fails, see : Using Spring AOP on App Engine causes StackOverflowError

Community
  • 1
  • 1
Michael Técourt
  • 3,457
  • 1
  • 28
  • 45