Skip to content
This repository
Browse code

Addresses #1235 by being explicit that an exception was thrown in an …

…out of band TransientRequestVar
  • Loading branch information...
commit 380ccf014ed6dda1095ad2d1bade1c23dcd9d3cf 1 parent 3de543d
David Pollak authored March 05, 2012
14  persistence/db/src/main/scala/net/liftweb/db/DB.scala
@@ -21,6 +21,8 @@ import common._
21 21
 import util._
22 22
 import Helpers._
23 23
 
  24
+import net.liftweb.http.S
  25
+
24 26
 import javax.sql.{DataSource}
25 27
 import java.sql.ResultSetMetaData
26 28
 import java.sql.{Statement, ResultSet, Types, PreparedStatement, Connection, DriverManager}
@@ -240,13 +242,13 @@ trait DB extends Loggable {
240 242
               try {
241 243
                 try {
242 244
                   val ret = f
243  
-                  success = true
  245
+                  success = !S.exceptionThrown_?
244 246
                   ret
245 247
                 } catch {
246 248
                   // this is the case when we want to commit the transaction
247 249
                   // but continue to throw the exception
248 250
                   case e: LiftFlowOfControlException => {
249  
-                    success = true
  251
+                    success = !S.exceptionThrown_?
250 252
                     throw e
251 253
                   }
252 254
                 }
@@ -263,13 +265,13 @@ trait DB extends Loggable {
263 265
             try {
264 266
               try {
265 267
                 val ret = f
266  
-                success = true
  268
+                success = !S.exceptionThrown_?
267 269
                 ret
268 270
               } catch {
269 271
                 // this is the case when we want to commit the transaction
270 272
                 // but continue to throw the exception
271 273
                 case e: LiftFlowOfControlException => {
272  
-                  success = true
  274
+                  success = !S.exceptionThrown_?
273 275
                   throw e
274 276
                 }
275 277
               }
@@ -676,13 +678,13 @@ trait DB extends Loggable {
676 678
       var rollback = true
677 679
       try {
678 680
         val ret = f(conn)
679  
-        rollback = false
  681
+        rollback = S.exceptionThrown_?
680 682
         ret
681 683
       } catch {
682 684
         // this is the case when we want to commit the transaction
683 685
         // but continue to throw the exception
684 686
         case e: LiftFlowOfControlException => {
685  
-          rollback = false
  687
+          rollback = S.exceptionThrown_?
686 688
           throw e
687 689
         }
688 690
       } finally {
2  project/Build.scala
@@ -109,7 +109,7 @@ object BuildDef extends Build {
109 109
 
110 110
   lazy val db =
111 111
     persistenceProject("db")
112  
-        .dependsOn(util)
  112
+        .dependsOn(util, webkit)
113 113
         .settings(libraryDependencies += mockito_all)
114 114
 
115 115
   lazy val proto =
2  web/webkit/src/main/scala/net/liftweb/http/LiftRules.scala
@@ -1299,7 +1299,7 @@ class LiftRules() extends Factory with FormVendor with LazyLoggable {
1299 1299
    * a default implementation is already appended.
1300 1300
    *
1301 1301
    */
1302  
-  @volatile var exceptionHandler = RulesSeq[ExceptionHandlerPF].append {
  1302
+  val exceptionHandler = RulesSeq[ExceptionHandlerPF].append {
1303 1303
     case (Props.RunModes.Development, r, e) =>
1304 1304
       logger.error("Exception being returned to browser when processing " + r.uri.toString + ": " + showException(e))
1305 1305
       XhtmlResponse((<html> <body>Exception occured while processing {r.uri}<pre>{showException(e)}</pre> </body> </html>), S.htmlProperties.docType, List("Content-Type" -> "text/html; charset=utf-8"), Nil, 500, S.ieMode)
19  web/webkit/src/main/scala/net/liftweb/http/LiftServlet.scala
@@ -294,6 +294,7 @@ class LiftServlet extends Loggable {
294 294
       case foc: LiftFlowOfControlException => throw foc
295 295
       case e: Exception if !e.getClass.getName.endsWith("RetryRequest") => {
296 296
         val bundle = (Props.mode, req, e)
  297
+        S.assertExceptionThrown()
297 298
         NamedPF.applyBox(bundle, LiftRules.exceptionHandler.toList)
298 299
       }
299 300
     }
@@ -328,7 +329,6 @@ class LiftServlet extends Loggable {
328 329
           LiftSession.onBeginServicing.foreach(_(liftSession, req))
329 330
           val ret: (Boolean, Box[LiftResponse]) =
330 331
             try {
331  
-              try {
332 332
                 // run the continuation in the new session
333 333
                 // if there is a continuation
334 334
                 continuation match {
@@ -353,21 +353,6 @@ class LiftServlet extends Loggable {
353 353
                       (true, Full(liftSession.checkRedirect(req.createNotFound(f))))
354 354
                   }
355 355
                 }
356  
-              } catch {
357  
-                case ContinueResponseException(cre) => throw cre
358  
-
359  
-                case ite: java.lang.reflect.InvocationTargetException if (ite.getCause.isInstanceOf[ResponseShortcutException]) =>
360  
-                  (true, Full(liftSession.handleRedirect(ite.getCause.asInstanceOf[ResponseShortcutException], req)))
361  
-
362  
-                case rd: net.liftweb.http.ResponseShortcutException => (true, Full(liftSession.handleRedirect(rd, req)))
363  
-
364  
-                case e if (e.getClass.getName.endsWith("RetryRequest")) => throw e
365  
-
366  
-                case e: LiftFlowOfControlException => throw e
367  
-
368  
-                case e => (true, NamedPF.applyBox((Props.mode, req, e), LiftRules.exceptionHandler.toList))
369  
-
370  
-              }
371 356
 
372 357
             } finally {
373 358
               if (S.functionMap.size > 0) {
@@ -489,7 +474,7 @@ class LiftServlet extends Loggable {
489 474
         }
490 475
       } catch {
491 476
         case foc: LiftFlowOfControlException => throw foc
492  
-        case e => NamedPF.applyBox((Props.mode, requestState, e), LiftRules.exceptionHandler.toList);
  477
+        case e => S.assertExceptionThrown() ; NamedPF.applyBox((Props.mode, requestState, e), LiftRules.exceptionHandler.toList);
493 478
       }
494 479
       tryo {
495 480
         LiftSession.onEndServicing.foreach(_(liftSession, requestState, ret))
2  web/webkit/src/main/scala/net/liftweb/http/LiftSession.scala
@@ -1145,7 +1145,7 @@ class LiftSession(private[http] val _contextPath: String, val uniqueId: String,
1145 1145
 
1146 1146
       case e: LiftFlowOfControlException => throw e
1147 1147
 
1148  
-      case e => NamedPF.applyBox((Props.mode, request, e), LiftRules.exceptionHandler.toList);
  1148
+      case e => S.assertExceptionThrown() ; NamedPF.applyBox((Props.mode, request, e), LiftRules.exceptionHandler.toList);
1149 1149
 
1150 1150
     }
1151 1151
 
14  web/webkit/src/main/scala/net/liftweb/http/S.scala
@@ -338,6 +338,8 @@ trait S extends HasParams with Loggable {
338 338
   private val _oneShot = new ThreadGlobal[Boolean]
339 339
   private val _disableTestFuncNames = new ThreadGlobal[Boolean]
340 340
 
  341
+  private object _exceptionThrown extends TransientRequestVar(false)
  342
+
341 343
   private object postFuncs extends TransientRequestVar(new ListBuffer[() => Unit])
342 344
 
343 345
   /**
@@ -386,6 +388,18 @@ trait S extends HasParams with Loggable {
386 388
 
387 389
   def location: Box[sitemap.Loc[_]] = CurrentLocation.is
388 390
 
  391
+
  392
+  /**
  393
+   * An exception was thrown during the processing of this request.
  394
+   * This is tested to see if the transaction should be rolled back
  395
+   */
  396
+  def assertExceptionThrown() {_exceptionThrown.set(true)}
  397
+
  398
+  /**
  399
+   * Was an exception thrown during the processing of the current request?
  400
+   */
  401
+  def exceptionThrown_? : Boolean = _exceptionThrown.get
  402
+
389 403
   /**
390 404
    * @return a List of any Cookies that have been set for this Response. If you want
391 405
    * a specific cookie, use findCookie.

0 notes on commit 380ccf0

Please sign in to comment.
Something went wrong with that request. Please try again.