object EmployeeDAO { val employees = TableQuery[Employees] def db: Database = Database.forDataSource(DB.getDataSource()) def filterQuery(id: Long): Query[Employees, Employee, Seq] = employees.filter(_.id === id) def findById(id: Long): Future[Employee] = try db.run(filterQuery(id).result.head) finally db.close
In my 2.1 code, the DAO methods have an implicit session parameter. I assume I could pass a Database instance in similar fashion.
Surely the code linked below is wrong? Creating a Database on each method call? Calling close even if the future has not completed?
--
---
You received this message because you are subscribed to the Google Groups "Slick / ScalaQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaquery+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/5549C74A.6040307%40typesafe.com.
For more options, visit https://groups.google.com/d/optout.
db.run(query)
the connections never seem to be releases properly and I end up with SQLTimeout exceptions when i try and do enough things that require the db.
I've tried a few other things I've seen floating around the web:
try db.run(query)
finally db.close()
gives me (as expected):
java.sql.SQLException: Interrupted during connection acquisition
at com.zaxxer.hikari.pool.BaseHikariPool.getConnection(BaseHikariPool.java:220) ~[HikariCP-2.3.7.jar:na]
at com.zaxxer.hikari.pool.BaseHikariPool.getConnection(BaseHikariPool.java:182) ~[HikariCP-2.3.7.jar:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:93) ~[HikariCP-2.3.7.jar:na]
at slick.jdbc.HikariCPJdbcDataSource.createConnection(JdbcDataSource.scala:131) ~[slick_2.11-3.0.0.jar:na]
at slick.jdbc.JdbcBackend$BaseSession.conn$lzycompute(JdbcBackend.scala:394) ~[slick_2.11-3.0.0.jar:na]
Caused by: java.lang.InterruptedException: null
at java.util.concurrent.locks.AbstractQueuedLongSynchronizer.tryAcquireSharedNanos(AbstractQueuedLongSynchronizer.java:1104) ~[na:1.8.0_31]
at com.zaxxer.hikari.util.ConcurrentBag.borrow(ConcurrentBag.java:134) ~[HikariCP-2.3.7.jar:na]
at com.zaxxer.hikari.pool.BaseHikariPool.getConnection(BaseHikariPool.java:201) ~[HikariCP-2.3.7.jar:na]
at com.zaxxer.hikari.pool.BaseHikariPool.getConnection(BaseHikariPool.java:182) ~[HikariCP-2.3.7.jar:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:93) ~[HikariCP-2.3.7.jar:na]
db.run(query) andThen { case _ => db.close() }
gives me
java.util.concurrent.RejectedExecutionException: Task slick.backend.DatabaseComponent$DatabaseDef$$anon$2@63ff7e8c rejected from java.util.concurrent.ThreadPoolExecutor@379febc7[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 1]
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2047) ~[na:1.8.0_31]
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:823) ~[na:1.8.0_31]
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1369) ~[na:1.8.0_31]
at scala.concurrent.impl.ExecutionContextImpl$$anon$1.execute(ExecutionContextImpl.scala:136) ~[scala-library-2.11.6.jar:na]
at slick.backend.DatabaseComponent$DatabaseDef$class.runSynchronousDatabaseAction(DatabaseComponent.scala:224) ~[slick_2.11-3.0.0.jar:na]
What is the correct way to deal with db connections in slick 3.0.0?
--
---
You received this message because you are subscribed to the Google Groups "Slick / ScalaQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalaquery+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalaquery/0ca33086-1b3c-4980-90cb-4c70fe8021ec%40googlegroups.com.