java - Xodus 是否需要 txn.commit() ?

标签 java xodus

这是我的代码:

@覆盖 公共(public)无效updateUser(字符串实例,字符串商店名称,最终字符串用户Id, 最终字符串新用户名,最终字符串新密码){ if (商店名称 == null || 商店名称 == null) { 返回; } 最终 PersistentEntityStoreEntityStore = PersistentEntityStores.newInstance(xodusRoot + 实例); EntityStore.executeInTransaction(new StoreTransactionalExecutable() { @覆盖 公共(public)无效执行(@NotNull最终StoreTransaction txn){ EntityId 角色EntityId = txn.toEntityId(userId); 最终实体实体 = txn.getEntity(roleEntityId); if(newUsername!= null) { entity.setProperty("用户名", newUsername); } if(新密码!= null) { entity.setProperty("密码", newPassword); } //txn.commit(); } }); 实体商店.close(); } 我想知道对于这段代码,是否需要 txn.commit(); 以便执行事务,回滚怎么样?

ps。

如果所有事务都成功完成,但我希望此代码返回 boolean 值,但除了返回 boolean 值的 txn.commit 之外找不到其他方法,是这样吗?那么一定是需要的吗?

最佳答案

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

关于java - Xodus 是否需要 txn.commit() ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51844967/

相关文章:

java - 如何查看完成方法调用所花费的时间?

java - CompressBackupUtil 不备份 blob

java - Xodus - 从备份恢复环境/目录

java - java中的非局部变量

java - 如何处理 Java PreparedStatement 中的特殊字符?

java - 实例化新类时,代理后面的Java applet会暂时卡住

java - AlphaComposite.Clear 的错误,它认为其背景是黑色

java - 最近 Xodus 版本中的服务提供商接口(interface)

java - 如何在 Xodus 中获取给定实体类型的属性类型?

java - Xodus VFS 无法保存字节