我正在使用TokuMx
来组织交易。它有特定的命令来执行此操作。
我尝试在db.runCommand("beginTransaction")
中运行Mongo shell
。它运作良好。
然而,当我在Jongo
中做同样的事情时:
PlayJongo.jongo().runCommand("beginTransaction");
它给了我[error] play - Cannot invoke the action, eventually got an error: java.lang.IllegalArgumentException: Cannot parse query: beginTransaction
我做错了什么?
修改
public static boolean buyProduct(User buyer, User seller, int accountIndex, float productPrice){
boolean isSuccess = false;
PlayJongo.jongo().runCommand("{beginTransaction : 1}");
try{
// Deposit money to seller
seller.getAccounts().get(0).deposit(productPrice);
UserRepository.update(seller);
// Withdraw money from buyer
buyer.getAccounts().get(accountIndex).withdraw(productPrice);
UserRepository.update(buyer);
throw new Exception();
//isSuccess = true;
}
catch (Exception e){
PlayJongo.jongo().runCommand("{rollbackTransaction : 1 }");
isSuccess = false;
}
return isSuccess;
}
答案 0 :(得分:2)
我不是jongo专家,但我在tokumx工作,我刚刚检查了jongo docs。我想你想要
PlayJongo.jongo().runCommand("{beginTransaction:1}");