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

回答

0

我不习惯吉斯,但像任何其他依赖注入框架我想你将不得不宣布某种形式的事务管理器在你的模块配置? 在这种情况下,哪些不存在,或者至少没有被谷歌广告。 也许你会在社区中找到你需要的东西,看看GitHub ......但是我很怀疑Guice是否支持低级数据存储。 虽然你可能在Guice中有一些JPA支持?

或者您也可以开发自己的事务管理器... 我已经开发了我自己的@DatastoreTransactional注解与Spring,但不幸的是使用在生产运行Spring AOP的失败,请参阅: Using Spring AOP on App Engine causes StackOverflowError

相关问题