Is txn.commit() required with Xodus?



这是我的代码:

@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(); } 我想知道对于此代码,是否需要txn.commit();执行事务,回滚怎么样?

附言。

我希望这段代码在所有事务成功完成时返回布尔值,但除了返回布尔值txn.commit之外找不到方法,是这样吗?所以一定是必需的吗?

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

最新更新