diff --git a/quill-jdbc/src/main/scala/io/getquill/H2JdbcContext.scala b/quill-jdbc/src/main/scala/io/getquill/H2JdbcContext.scala index 70fbe15a2..3707d6f0f 100644 --- a/quill-jdbc/src/main/scala/io/getquill/H2JdbcContext.scala +++ b/quill-jdbc/src/main/scala/io/getquill/H2JdbcContext.scala @@ -7,7 +7,7 @@ import com.typesafe.config.Config import io.getquill.context.jdbc.{ JdbcContext, H2JdbcContextBase } import io.getquill.util.LoadConfig -class H2JdbcContext[+N <: NamingStrategy](val naming: N, val dataSource: DataSource with Closeable) +class H2JdbcContext[+N <: NamingStrategy](val naming: N, val dataSource: DataSource) extends JdbcContext[H2Dialect, N] with H2JdbcContextBase[H2Dialect, N] { override val idiom: H2Dialect = H2Dialect diff --git a/quill-jdbc/src/main/scala/io/getquill/MysqlJdbcContext.scala b/quill-jdbc/src/main/scala/io/getquill/MysqlJdbcContext.scala index 944802cef..048e1d62e 100644 --- a/quill-jdbc/src/main/scala/io/getquill/MysqlJdbcContext.scala +++ b/quill-jdbc/src/main/scala/io/getquill/MysqlJdbcContext.scala @@ -7,7 +7,7 @@ import com.typesafe.config.Config import io.getquill.context.jdbc.{ JdbcContext, MysqlJdbcContextBase } import io.getquill.util.LoadConfig -class MysqlJdbcContext[+N <: NamingStrategy](val naming: N, val dataSource: DataSource with Closeable) +class MysqlJdbcContext[+N <: NamingStrategy](val naming: N, val dataSource: DataSource) extends JdbcContext[MySQLDialect, N] with MysqlJdbcContextBase[MySQLDialect, N] { override val idiom: MySQLDialect = MySQLDialect diff --git a/quill-jdbc/src/main/scala/io/getquill/OracleJdbcContext.scala b/quill-jdbc/src/main/scala/io/getquill/OracleJdbcContext.scala index 56091cc3b..3084820cd 100644 --- a/quill-jdbc/src/main/scala/io/getquill/OracleJdbcContext.scala +++ b/quill-jdbc/src/main/scala/io/getquill/OracleJdbcContext.scala @@ -7,7 +7,7 @@ import io.getquill.context.jdbc.{ JdbcContext, OracleJdbcContextBase } import io.getquill.util.LoadConfig import javax.sql.DataSource -class OracleJdbcContext[+N <: NamingStrategy](val naming: N, val dataSource: DataSource with Closeable) +class OracleJdbcContext[+N <: NamingStrategy](val naming: N, val dataSource: DataSource) extends JdbcContext[OracleDialect, N] with OracleJdbcContextBase[OracleDialect, N] { override val idiom: OracleDialect = OracleDialect diff --git a/quill-jdbc/src/main/scala/io/getquill/PostgresJdbcContext.scala b/quill-jdbc/src/main/scala/io/getquill/PostgresJdbcContext.scala index 5e2777c38..8309332e9 100644 --- a/quill-jdbc/src/main/scala/io/getquill/PostgresJdbcContext.scala +++ b/quill-jdbc/src/main/scala/io/getquill/PostgresJdbcContext.scala @@ -7,7 +7,7 @@ import com.typesafe.config.Config import io.getquill.context.jdbc.{ JdbcContext, PostgresJdbcContextBase } import io.getquill.util.LoadConfig -class PostgresJdbcContext[+N <: NamingStrategy](val naming: N, val dataSource: DataSource with Closeable) +class PostgresJdbcContext[+N <: NamingStrategy](val naming: N, val dataSource: DataSource) extends JdbcContext[PostgresDialect, N] with PostgresJdbcContextBase[PostgresDialect, N] { override val idiom: PostgresDialect = PostgresDialect diff --git a/quill-jdbc/src/main/scala/io/getquill/SqlServerJdbcContext.scala b/quill-jdbc/src/main/scala/io/getquill/SqlServerJdbcContext.scala index a42479394..6afb556aa 100644 --- a/quill-jdbc/src/main/scala/io/getquill/SqlServerJdbcContext.scala +++ b/quill-jdbc/src/main/scala/io/getquill/SqlServerJdbcContext.scala @@ -7,7 +7,7 @@ import com.typesafe.config.Config import io.getquill.context.jdbc.{ JdbcContext, SqlServerJdbcContextBase } import io.getquill.util.LoadConfig -class SqlServerJdbcContext[+N <: NamingStrategy](val naming: N, val dataSource: DataSource with Closeable) +class SqlServerJdbcContext[+N <: NamingStrategy](val naming: N, val dataSource: DataSource) extends JdbcContext[SQLServerDialect, N] with SqlServerJdbcContextBase[SQLServerDialect, N] { override val idiom: SQLServerDialect = SQLServerDialect diff --git a/quill-jdbc/src/main/scala/io/getquill/SqliteJdbcContext.scala b/quill-jdbc/src/main/scala/io/getquill/SqliteJdbcContext.scala index bdcb2cd1f..70342cc63 100644 --- a/quill-jdbc/src/main/scala/io/getquill/SqliteJdbcContext.scala +++ b/quill-jdbc/src/main/scala/io/getquill/SqliteJdbcContext.scala @@ -7,7 +7,7 @@ import com.typesafe.config.Config import io.getquill.context.jdbc.{ JdbcContext, SqliteJdbcContextBase } import io.getquill.util.LoadConfig -class SqliteJdbcContext[+N <: NamingStrategy](val naming: N, val dataSource: DataSource with Closeable) +class SqliteJdbcContext[+N <: NamingStrategy](val naming: N, val dataSource: DataSource) extends JdbcContext[SqliteDialect, N] with SqliteJdbcContextBase[SqliteDialect, N] { override val idiom: SqliteDialect = SqliteDialect diff --git a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContext.scala b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContext.scala index d7dfd5ee0..c85a4e8c4 100644 --- a/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContext.scala +++ b/quill-jdbc/src/main/scala/io/getquill/context/jdbc/JdbcContext.scala @@ -12,6 +12,7 @@ import scala.util.control.NonFatal import io.getquill.Quoted import scala.annotation.targetName import io.getquill.context.ContextVerbTranslate +import io.getquill.util.ContextLogger abstract class JdbcContext[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] extends JdbcContextBase[Dialect, Naming] @@ -19,6 +20,8 @@ abstract class JdbcContext[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] with ContextVerbTranslate[Dialect, Naming] { + private val logger = ContextLogger(classOf[JdbcContext[_, _]]) + // Need to override these with same values as JdbcRunContext because SyncIOMonad imports them. The imported values need to be overridden override type Result[T] = T override type RunQueryResult[T] = List[T] @@ -32,7 +35,7 @@ abstract class JdbcContext[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] override protected def context: Runner = () def translateContext: TranslateRunner = () - val dataSource: DataSource with Closeable + val dataSource: DataSource @targetName("runQueryDefault") inline def run[T](inline quoted: Quoted[Query[T]]): List[T] = InternalApi.runQueryDefault(quoted) @@ -68,7 +71,13 @@ abstract class JdbcContext[+Dialect <: SqlIdiom, +Naming <: NamingStrategy] finally conn.close() } - override def close() = dataSource.close() + override def close() = + dataSource match { + case closeable: java.io.Closeable => + closeable.close() + case _ => + logger.underlying.warn(s"Could not close the DataSource `$dataSource`. It is not an instance of java.io.Closeable.") + } def probe(sql: String) = Try {