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 @@ 1.0-SNAPSHOT - 2.7.5 - 1.1-M6 + 2.7.7 + 1.1-M7 UTF-8 @@ -22,10 +22,11 @@ - mysql - mysql-connector-java - 5.1.10 + com.h2database + h2 + 1.2.121 + 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 => {SHtml.submit("ClickMe", () => { + (new Service).say("Hello") + })} + } } } 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 @@ + /* Alternative content @@ -30,6 +31,12 @@ src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player"/> + */ + + + In Scope test + +