繁体   English   中英

我可以将Guice的@Transactional与Google App Engine的数据存储区一起使用吗?

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

我可以做这样的事情吗? 即使我没有使用ds.get(tx, key)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);
    }
}

我不习惯Guice,但是像其他依赖注入框架一样,我猜您将不得不在模块配置中声明某种TransactionManager吗? 在这种情况下,它不存在,或者至少不是由Google广告。 也许您会在社区中找到所需的东西,请查看GitHub ...但是我再次怀疑Guice是否使用低级数据存储开箱即用地支持它。 您可能在Guice中有一些JPA支持?

或者,您也可以开发自己的事务管理器...我已经用Spring开发了自己的@DatastoreTransactional批注,但不幸的是,在生产运行时使用Spring AOP失败,请参见: 在App Engine上使用Spring AOP会导致StackOverflowError

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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