我一直在尝试多线程的解决方案,但还没有运气。
任何能够快速了解代码中发生的事情的人?我在下面分享了我的更新代码。感谢快速帮助。
@ApiMethod(name="updateContact", path = "updateContact", httpMethod = "GET")
public OpinionModel updateEmployeeTitle(@Named("id") Long id,@Named("selectedOpinionIndex") int opinionIndex) {
PersistenceManager pm = PMF.get().getPersistenceManager();
javax.jdo.Transaction tx = pm.currentTransaction();
pm.currentTransaction().begin(); // <-------
OpinionModel e;
try {
e = pm.getObjectById(OpinionModel.class,id);
if (opinionIndex == 1) {
int foo = Integer.parseInt(e.opinion1ResultCount);
foo++;
e.opinion1ResultCount = Integer.toString(foo);
JDOHelper.makeDirty(e, e.opinion1ResultCount);
}else if (opinionIndex == 2) {
int foo = Integer.parseInt(e.opinion2ResultCount);
foo++;
e.opinion2ResultCount = Integer.toString(foo);
JDOHelper.makeDirty(e, e.opinion2ResultCount);
}
else if (opinionIndex == 3) {
int foo = Integer.parseInt(e.opinion3ResultCount);
foo++;
e.opinion3ResultCount = Integer.toString(foo);
JDOHelper.makeDirty(e, e.opinion3ResultCount);
}
else if (opinionIndex == 4) {
int foo = Integer.parseInt(e.opinion4ResultCount);
foo++;
e.opinion4ResultCount = Integer.toString(foo);
JDOHelper.makeDirty(e, e.opinion4ResultCount);
}
else {
System.out.println("Invalid selection");
}
pm.currentTransaction().commit(); // <-------
pm.makePersistent(e);
} finally {
if (tx.isActive())
{
// Error occurred so rollback the transaction
tx.rollback();
}
pm.close();
}
ApiResponse resp = new ApiResponse();
resp.responsecode = "SUCCESS";
resp.responseMessage = "Contact Updated ";
return e;
}