简体   繁体   中英

Can I use @Transactional from Guice with Google App Engine's Datastore?

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);
    }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM