Permalink
Browse files

pooling and tcpdumps

  • Loading branch information...
1 parent 3bbb361 commit fe7a7103cbb1ad0519b891b21aa1f15dfb169b00 @fernandezpablo85 committed Apr 7, 2013
View
@@ -11,5 +11,6 @@ libraryDependencies ++= List(
"org.slf4j" % "slf4j-api" % "1.6.4",
"ch.qos.logback" % "logback-classic" % "1.0.1",
"ch.qos.logback" % "logback-core" % "1.0.1",
- "postgresql" % "postgresql" % "9.1-901.jdbc4"
+ "postgresql" % "postgresql" % "9.1-901.jdbc4",
+ "c3p0" % "c3p0" % "0.9.1.2"
)
View
Binary file not shown.
View
Binary file not shown.
@@ -6,7 +6,11 @@
</encoder>
</appender>
- <logger name="scala.slick.session" level="DEBUG">
+ <logger name="scala.slick.session" level="ERROR">
+ <appender-ref ref="STDOUT" />
+ </logger>
+
+ <logger name="com.mchange.v2.c3p0" level="OFF">
<appender-ref ref="STDOUT" />
</logger>
@@ -0,0 +1,21 @@
+package org.example
+
+import scala.slick.driver.PostgresDriver.simple._
+import com.mchange.v2.c3p0.ComboPooledDataSource
+
+trait DatabaseAccess {
+ val Url = "jdbc:postgresql://localhost:5432/demo"
+ val Driver = "org.postgresql.Driver"
+
+ val database = Database.forURL(Url, driver = Driver)
+
+ val databasePool = {
+ val ds = new ComboPooledDataSource
+ ds.setDriverClass(Driver)
+ ds.setJdbcUrl(Url)
+ ds.setMinPoolSize(20)
+ ds.setAcquireIncrement(5)
+ ds.setMaxPoolSize(100)
+ Database.forDataSource(ds)
+ }
+}
@@ -3,9 +3,7 @@ package org.example
import scala.slick.driver.PostgresDriver.simple._
import Database.threadLocalSession
-object UserDao {
-
- val database = Database.forURL("jdbc:postgresql://localhost:5432/demo", driver = "org.postgresql.Driver")
+object UserDao extends DatabaseAccess {
case class User(id: Option[Int], name: String, last: String)
@@ -23,14 +21,12 @@ object UserDao {
)
}
- def insert(name: String, lastName: String) = {
- database withSession {
- Users.insertProjection.insert(User(None, name, lastName))
- }
+ def insert(name: String, lastName: String) = databasePool withSession {
+ Users.insertProjection.insert(User(None, name, lastName))
}
- def findByLastName(last: String) = database withSession {
+ def findByLastName(last: String) = databasePool withSession {
val query = for (u <- Users if u.lastName is last) yield (u)
query.list
}
-}
+}

0 comments on commit fe7a710

Please sign in to comment.