下面是我的代码:
`@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,是这样的吗?所以它必须是必需的?
发布于 2018-08-15 00:04:50
如果使用像executeInTranction()或computeInTransaction()这样的方法,那么就不应该调用txn.commit()。只需使用executeInTranction()方法来确保事务已提交-如果您的程序到达executeInTranction之后的下一条语句,则事务已提交。
https://stackoverflow.com/questions/51844967
复制相似问题