Fixed HibernnateOptimisticLockingExceptions for startproject and team…

src/main/java/org/telscenter/sail/webapp/presentation/web/controllers/student/TeamSignInController.java
      
      
      
      
@@ -38,6 +38,7 @@
      
      
      
      
 import net.sf.sail.webapp.presentation.web.controllers.ControllerUtil;
      
      
      
      
 import net.sf.sail.webapp.service.UserService;
      
      
      
      
 
      
      
      
      
+import org.springframework.orm.hibernate3.HibernateOptimisticLockingFailureException;
      
      
      
      
 import org.springframework.validation.BindException;
      
      
      
      
 import org.springframework.web.servlet.ModelAndView;
      
      
      
      
 import org.springframework.web.servlet.mvc.SimpleFormController;
      
      
      
      
@@ -230,7 +231,19 @@ protected synchronized ModelAndView onSubmit(HttpServletRequest request,
      
      
      
      
     ModelAndView modelAndView = new ModelAndView();
      
      
      
      
     
      
      
      
      
     /* update run statistics */
      
      
      
      
-    this.runService.updateRunStatistics(run.getId());
      
      
      
      
+    int maxLoop = 30;  // to ensure that the following while loop gets run at most this many times.
      
      
      
      
+    int currentLoopIndex = 0;
      
      
      
      
+    while(currentLoopIndex < maxLoop) {
      
      
      
      
+      try {
      
      
      
      
+        this.runService.updateRunStatistics(run.getId());
      
      
      
      
+      } catch (HibernateOptimisticLockingFailureException holfe) {
      
      
      
      
+        // multiple students tried to update run statistics at the same time, resulting in the exception. try again.
      
      
      
      
+        currentLoopIndex++;
      
      
      
      
+        continue;
      
      
      
      
+      }
      
      
      
      
+      // if it reaches here, it means that HibernateOptimisticLockingFailureException was not thrown, so we can exit the loop.
      
      
      
      
+      break;
      
      
      
      
+    }
      
      
      
      
     
      
      
      
      
     LaunchProjectParameters launchProjectParameters = new LaunchProjectParameters();
      
      
      
      
     launchProjectParameters.setRun(run);

你可能感兴趣的:(Fixed HibernnateOptimisticLockingExceptions for startproject and team…)