Index: lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningAction.java =================================================================== RCS file: /usr/local/cvsroot/lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningAction.java,v diff -u -r1.27 -r1.28 --- lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningAction.java 11 Dec 2013 17:56:41 -0000 1.27 +++ lams_tool_scratchie/src/java/org/lamsfoundation/lams/tool/scratchie/web/action/LearningAction.java 11 Dec 2013 19:46:43 -0000 1.28 @@ -47,6 +47,7 @@ import org.apache.struts.action.ActionRedirect; import org.apache.tomcat.util.json.JSONException; import org.apache.tomcat.util.json.JSONObject; +import org.hibernate.exception.LockAcquisitionException; import org.lamsfoundation.lams.learning.web.bean.ActivityPositionDTO; import org.lamsfoundation.lams.learning.web.util.LearningWebUtil; import org.lamsfoundation.lams.notebook.model.NotebookEntry; @@ -439,14 +440,33 @@ String nextActivityUrl = null; try { - nextActivityUrl = service.finishToolSession(toolSessionId, user.getUserID().longValue()); + nextActivityUrl = finishToolSession(toolSessionId, user.getUserID().longValue()); request.setAttribute(ScratchieConstants.ATTR_NEXT_ACTIVITY_URL, nextActivityUrl); } catch (ScratchieApplicationException e) { LearningAction.log.error("Failed get next activity url:" + e.getMessage()); } return mapping.findForward(ScratchieConstants.SUCCESS); } + + public String finishToolSession(Long toolSessionId, Long userId) throws ScratchieApplicationException { + final int MAX_TRANSACTION_RETRIES = 5; + String nextActivityUrl = null; + for (int i = 0; i < MAX_TRANSACTION_RETRIES; i++) { + try { + nextActivityUrl = service.finishToolSession(toolSessionId, userId);; + break; + } catch (LockAcquisitionException e) { + if (i == MAX_TRANSACTION_RETRIES - 1) { + throw new ScratchieApplicationException(e); + } + } catch (Exception e) { + throw new ScratchieApplicationException(e); + } + log.warn("Transaction retry: " + (i + 1)); + } + return nextActivityUrl; + } /** * Display empty reflection form.