首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xodus是否需要txn.commit()?

Xodus是否需要txn.commit()?
EN

Stack Overflow用户
提问于 2018-08-14 23:29:53
回答 1查看 101关注 0票数 0

下面是我的代码:

代码语言:javascript
复制
 `@Override     public void updateUser(String instance, String storeName, final String userId,                            final String newUsername, final String newPassword) {         if (storeName == null || storeName == null) {             return;         }         final PersistentEntityStore entityStore = PersistentEntityStores.newInstance(xodusRoot + instance);         entityStore.executeInTransaction(new StoreTransactionalExecutable() {             @Override             public void execute(@NotNull final StoreTransaction txn) {                 EntityId roleEntityId = txn.toEntityId(userId);                 final Entity entity = txn.getEntity(roleEntityId);                 if(newUsername != null) {                     entity.setProperty("username", newUsername);                 }                 if(newPassword != null) {                     entity.setProperty("password", newPassword);                 }                 //txn.commit();             }         });         entityStore.close();     }`  I want to know if for this code, is `txn.commit();` required so the transaction to be executed, how about for rollback? 

ps。

如果所有事务都成功完成,但除了返回boolean的txn.commit之外找不到方法,我希望这段代码返回boolean,是这样的吗?所以它必须是必需的?

EN

回答 1

Stack Overflow用户

发布于 2018-08-15 00:04:50

如果使用像executeInTranction()computeInTransaction()这样的方法,那么就不应该调用txn.commit()。只需使用executeInTranction()方法来确保事务已提交-如果您的程序到达executeInTranction之后的下一条语句,则事务已提交。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51844967

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档