Oshyshki,

Your call to Service.say is outside the scope of the Lift HTTP request, so
it's not wrapped with the transaction management stuff.  You could insert:

DB.use(
DefaultConnectionIdentifier) {
  ignore =>
  (0 to 5).foreach(i => User.findAll)
}

Inside your say method and all of the requests would be part of the same
transaction.

But to demonstrate that the DB.buildLoanWrapper stuff works correctly, I
added a standard HTML form to the page.  This form is serviced within the
Lift scope, so the Mapper transaction stuff is done correctly.  Please apply
the enclosed diff to your Git project.

Thanks,

David


On Thu, Nov 12, 2009 at 5:16 PM, oshyshko <[email protected]> wrote:

>
> Hello David,
>
> I have added some DB stuff + added "S.addAround(DB.buildLoanWrapper)"
> But the code produces separate transactions.
>
> For example, this code:
> =========================================
> class Service {
>  def say(message: String) {
>    println(message)
>
>    (0 to 5).foreach( i => User.findAll )
>  }
> }
> =========================================
>
>
> Produces this SQL:
> =========================================
> 091113  2:59:24     6 Query     SET autocommit=0
>                    6 Query     SET autocommit=0
>                    6 Query     commit
>                    6 Query     SET autocommit=0
>                    6 Query     SET autocommit=0
>                    6 Query     commit
>                    6 Query     SET autocommit=0
>                    6 Query     SET autocommit=0
>                    6 Query     SELECT user_t.id FROM user_t
>                    6 Query     commit
>                    6 Query     SET autocommit=0
>                    6 Query     SET autocommit=0
>                    6 Query     SELECT user_t.id FROM user_t
>                    6 Query     commit
>                    6 Query     SET autocommit=0
>                    6 Query     SET autocommit=0
>                    6 Query     SELECT user_t.id FROM user_t
>                    6 Query     commit
>                    6 Query     SET autocommit=0
>                    6 Query     SET autocommit=0
>                    6 Query     SELECT user_t.id FROM user_t
>                    6 Query     commit
>                    6 Query     SET autocommit=0
>                    6 Query     SET autocommit=0
>                    6 Query     SELECT user_t.id FROM user_t
>                    6 Query     commit
>                    6 Query     SET autocommit=0
>                    6 Query     SET autocommit=0
>                    6 Query     SELECT user_t.id FROM user_t
>                    6 Query     commit
> =========================================
>
> Basically it behaves like when LiftFilter url mapping was commented in
> "web.xml".
>
> I have updated http://github.com/oshyshko/lift_vs_blazeds
>
> To reproduce it:
>
> 1. mysql -> create database demo;
>
> 2. Enable MySQL query logging by editing "my.ini" + restart MySQL
> daemon:
> [mysqld]
> log=mysql-log.log
>
> 3. Open separate console to watch what's going on
> $ tail -f mysql-log.log
>
> 4. mvn jetty:run-exploded
>
> 5. Open http://localhost:8080/ + click "Say it"
>
> 6. Observe 7 transactions instead of 1 in the log
>  should =>
> 6. Observe all queries inside 1 transaction in the log
>
> On Nov 13, 2:29 am, David Pollak <[email protected]>
> wrote:
> > the issue is the new debugging help screen in dev mode got in the way of
> the
> > passing not found... so...
> >
>
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..8bb6c96
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,42 @@
+# use glob syntax.
+syntax: glob
+*.ser
+*.class
+*~
+*.bak
+*.off
+*.old
+.DS_Store
+
+# logs
+derby.log
+lift_proto.db*
+
+# eclipse conf file
+.settings
+.classpath
+.project
+.manager
+
+# building
+target
+build
+null
+tmp*
+dist
+test-output
+
+# other scm
+.svn
+.CVS
+.hg*
+
+# switch to regexp syntax.
+#  syntax: regexp
+#  ^\.pc/
+
+
+# IntelliJ
+*.iml
+*.ipr
+*.iws
diff --git a/pom.xml b/pom.xml
index dbf1bdf..2f73ce7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -9,8 +9,8 @@
     <version>1.0-SNAPSHOT</version>
 
     <properties>
-        <scala.version>2.7.5</scala.version>
-        <liftweb.version>1.1-M6</liftweb.version>
+        <scala.version>2.7.7</scala.version>
+        <liftweb.version>1.1-M7</liftweb.version>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     </properties>
 
@@ -22,10 +22,11 @@
         </dependency>
 
         <dependency>
-            <groupId>mysql</groupId>
-            <artifactId>mysql-connector-java</artifactId>
-            <version>5.1.10</version>
+            <groupId>com.h2database</groupId>
+            <artifactId>h2</artifactId>
+            <version>1.2.121</version>
         </dependency>
+
         
         <!-- liftweb -->
         <dependency>
diff --git a/src/main/scala/services/Boot.scala b/src/main/scala/services/Boot.scala
index afeab71..01851f0 100644
--- a/src/main/scala/services/Boot.scala
+++ b/src/main/scala/services/Boot.scala
@@ -1,9 +1,13 @@
 package services
 
 import net.liftweb.http._
+
+import net.liftweb.common._
+
 import net.liftweb.mapper._
 import net.liftweb.util._
 import java.sql.{Connection, DriverManager}
+import scala.xml.NodeSeq
 
 class Boot extends Bootable {
   def boot {
@@ -16,25 +20,25 @@ class Boot extends Bootable {
     LiftRules.liftRequest.append {
       case Req("messagebroker" :: _, _, _) => false
     }
+
+        LiftRules.snippets.append {
+            case "InScope" :: _ =>
+                ignore => <form action="/">{SHtml.submit("ClickMe", () => {
+                                (new Service).say("Hello")
+                            })}</form>
+        }
   }
 }
 
 object DBVendor extends ConnectionManager {
-  private var pool: List[Connection] = Nil
-  private var poolSize = 0
-  private val maxPoolSize = 10
-
   private def createOne: Box[Connection] = try {
-    val driverName: String = "com.mysql.jdbc.Driver"
-    val dbUrl: String = "jdbc:mysql://localhost/demo?user=root&password=sa"
+    val driverName: String = "org.h2.Driver"
+    val dbUrl: String = "jdbc:h2:lift_proto.db"
 
     Class.forName(driverName)
 
-    val dm = (Props.get("db.user"), Props.get("db.password")) match {
-      case (Full(user), Full(pwd)) =>
-        DriverManager.getConnection(dbUrl, user, pwd)
-      case _ => DriverManager.getConnection(dbUrl)
-    }
+    val dm = DriverManager.getConnection(dbUrl)
+
 
     Full(dm)
   } catch {
@@ -42,33 +46,14 @@ object DBVendor extends ConnectionManager {
   }
 
   def newConnection(name: ConnectionIdentifier): Box[Connection] =
-    synchronized {
-      pool match {
-        case Nil if poolSize < maxPoolSize =>
-          val ret = createOne
-          poolSize = poolSize + 1
-          ret.foreach(c => pool = c :: pool)
-          ret
-        case Nil => wait(1000L); newConnection(name)
-        case x :: xs => try {
-          x.setAutoCommit(false)
-          Full(x)
-        } catch {
-          case e => try {
-            pool = xs
-            poolSize = poolSize - 1
-            x.close
-            newConnection(name)
-          } catch {
-            case e => newConnection(name)
-          }
-        }
-      }
+    {
+      println("Creating connection")
+      createOne
     }
 
   def releaseConnection(conn: Connection): Unit = synchronized {
-    pool = conn :: pool
-    notify
+    println("Releasing " + conn)
+    conn.close()
   }
 }
 
diff --git a/src/main/scala/services/Service.scala b/src/main/scala/services/Service.scala
index f30ecc9..154654d 100644
--- a/src/main/scala/services/Service.scala
+++ b/src/main/scala/services/Service.scala
@@ -2,8 +2,11 @@ package services
 
 class Service {
   def say(message: String) {
+      println("In service.say")
     println(message)
 
     (0 to 5).foreach( i => User.findAll )
+    println("Done service.say")
+    Thread.sleep(100)
   }
 }
\ No newline at end of file
diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html
index e4417fb..77684b1 100644
--- a/src/main/webapp/index.html
+++ b/src/main/webapp/index.html
@@ -23,6 +23,7 @@
 
 <body>
 <div id="container">
+    /*
     <div id="content">
         <h1>Alternative content</h1>
 
@@ -30,6 +31,12 @@
                 src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif";
                 alt="Get Adobe Flash player"/></a></p>
     </div>
+    */
+    
+    <div>
+        In Scope test
+        <lift:InScope/>
+    </div>
 </div>
 </body>
 </html>
\ No newline at end of file

Reply via email to