javax.sql.DataSource Scala Examples
The following examples show how to use javax.sql.DataSource.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: WithMysqlContext.scala From quill with Apache License 2.0 | 5 votes |
package io.getquill.codegen.util import java.io.Closeable import io.getquill.{ MySQLDialect => TheDialect, MysqlJdbcContext => TheContext, Literal, SnakeCase } import io.getquill.codegen.integration.CodegenTestCases._ import io.getquill.codegen.util.ConfigPrefix.{ TestMysqlDB => TheDB } import javax.sql.DataSource trait WithMysqlContext extends WithContextAux { import io.getquill.codegen.generated.mysql._ implicit def mysqlSimpleContextForTest1: Aux[TheDB, `1-simple-snake`, TheContext[SnakeCase]] = new WithContextBase[TheDB, `1-simple-snake`](TheDB, `1-simple-snake`) { override type QuillContext = TheContext[SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new QuillContext(SnakeCase, ds) } implicit def mysqlSimpleContextForTest2: Aux[TheDB, `2-simple-literal`, TheContext[SnakeCase]] = new WithContextBase[TheDB, `2-simple-literal`](TheDB, `2-simple-literal`) { override type QuillContext = TheContext[SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new QuillContext(SnakeCase, ds) } implicit def mysqlContextForTest1: Aux[TheDB, `1-comp-sanity`, TheContext[SnakeCase]] = new WithContextBase[TheDB, `1-comp-sanity`](TheDB, `1-comp-sanity`) { override type QuillContext = TheContext[SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new QuillContext(SnakeCase, ds) } implicit def mysqlContextForTest2: Aux[TheDB, `2-comp-stereo-single`, TheContext[SnakeCase] with `2-comp-stereo-single-lib`.public.PublicExtensions[TheDialect, SnakeCase]] = new WithContextBase[TheDB, `2-comp-stereo-single`](TheDB, `2-comp-stereo-single`) { override type QuillContext = TheContext[SnakeCase] with `2-comp-stereo-single-lib`.public.PublicExtensions[TheDialect, SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[SnakeCase](SnakeCase, ds) with `2-comp-stereo-single-lib`.public.PublicExtensions[TheDialect, SnakeCase] } implicit def mysqlContextForTest3: Aux[TheDB, `3-comp-stereo-oneschema`, TheContext[Literal] with `3-comp-stereo-oneschema-lib`.public.PublicExtensions[TheDialect, Literal]] = new WithContextBase[TheDB, `3-comp-stereo-oneschema`](TheDB, `3-comp-stereo-oneschema`) { override type QuillContext = TheContext[Literal] with `3-comp-stereo-oneschema-lib`.public.PublicExtensions[TheDialect, Literal] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[Literal](Literal, ds) with `3-comp-stereo-oneschema-lib`.public.PublicExtensions[TheDialect, Literal] } implicit def mysqlContextForTest4: Aux[TheDB, `4-comp-stereo-twoschema`, TheContext[Literal] with `4-comp-stereo-twoschema-lib`.public.PublicExtensions[TheDialect, Literal] with `4-comp-stereo-twoschema-lib`.common.CommonExtensions[TheDialect, Literal]] = new WithContextBase[TheDB, `4-comp-stereo-twoschema`](TheDB, `4-comp-stereo-twoschema`) { override type QuillContext = TheContext[Literal] with `4-comp-stereo-twoschema-lib`.public.PublicExtensions[TheDialect, Literal] with `4-comp-stereo-twoschema-lib`.common.CommonExtensions[TheDialect, Literal] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[Literal](Literal, ds) with `4-comp-stereo-twoschema-lib`.public.PublicExtensions[TheDialect, Literal] with `4-comp-stereo-twoschema-lib`.common.CommonExtensions[TheDialect, Literal] } implicit def mysqlContextForTest5: Aux[TheDB, `5-comp-non-stereo-allschema`, TheContext[Literal] with `5-comp-non-stereo-allschema-lib`.public.PublicExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.alpha.AlphaExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.bravo.BravoExtensions[TheDialect, Literal]] = new WithContextBase[TheDB, `5-comp-non-stereo-allschema`](TheDB, `5-comp-non-stereo-allschema`) { override type QuillContext = TheContext[Literal] with `5-comp-non-stereo-allschema-lib`.public.PublicExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.alpha.AlphaExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.bravo.BravoExtensions[TheDialect, Literal] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[Literal](Literal, ds) with `5-comp-non-stereo-allschema-lib`.public.PublicExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.alpha.AlphaExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.bravo.BravoExtensions[TheDialect, Literal] } }
Example 2
Source File: PostgresqlClient.scala From izanami with Apache License 2.0 | 5 votes |
package store.postgresql import akka.actor.ActorSystem import cats.effect.Blocker import doobie.util.transactor.Transactor import doobie.util.transactor.Transactor.Aux import env.PostgresqlConfig import javax.sql.DataSource import libs.logs.{IzanamiLogger, ZLogger} import play.api.db.{Database, Databases} import zio.{Task, UIO, ZManaged} import zio.interop.catz._ import scala.concurrent.ExecutionContext case class PostgresqlClient(database: Database, transactor: Transactor[Task]) object PostgresqlClient { def postgresqlClient(system: ActorSystem, cf: Option[PostgresqlConfig]): ZManaged[ZLogger, Throwable, Option[PostgresqlClient]] = cf.map { config => ZManaged .make( ZLogger.info(s"Creating database instance") *> Task { Databases( config.driver, config.url, config = Map( "username" -> config.username, "password" -> config.password, "pool" -> "hikaricp" ) ) } )(database => UIO(database.shutdown())) .mapM { database => ZLogger.info(s"Creating transactor instance") *> Task { val ce: ExecutionContext = system.dispatchers.lookup("izanami.jdbc-connection-dispatcher") val te: ExecutionContext = system.dispatchers.lookup("izanami.jdbc-transaction-dispatcher") val transact: Aux[Task, DataSource] = Transactor .fromDataSource[Task](database.dataSource, ce, Blocker.liftExecutionContext(te)) Some(PostgresqlClient(database, transact)) } } } .getOrElse(ZManaged.effectTotal(None)) }
Example 3
Source File: FlywayModule.scala From scala-server-toolkit with MIT License | 5 votes |
package com.avast.sst.flyway import cats.effect.Sync import javax.sql.DataSource import org.flywaydb.core.Flyway import scala.jdk.CollectionConverters._ object FlywayModule { def make[F[_]: Sync](dataSource: DataSource, config: FlywayConfig): F[Flyway] = { Sync[F].delay { val builder = Flyway.configure .dataSource(dataSource) .baselineOnMigrate(config.baselineOnMigrate) .cleanDisabled(config.cleanDisabled) .cleanOnValidationError(config.cleanOnValidationError) .connectRetries(config.connectRetries) .encoding(config.encoding) .group(config.group) .ignoreFutureMigrations(config.ignoreFutureMigrations) .ignoreIgnoredMigrations(config.ignoreIgnoredMigrations) .ignoreMissingMigrations(config.ignoreMissingMigrations) .ignorePendingMigrations(config.ignorePendingMigrations) .mixed(config.mixed) .outOfOrder(config.outOfOrder) .validateOnMigrate(config.validateOnMigrate) .placeholderReplacement(config.placeholderReplacement) .placeholders(config.placeholders.asJava) config.baselineVersion.foreach(builder.baselineVersion) config.targetVersion.foreach(builder.target) config.baselineDescription.foreach(builder.baselineDescription) config.installedBy.foreach(builder.installedBy) if (config.locations.nonEmpty) builder.locations(config.locations: _*) builder.load() } } }
Example 4
Source File: JdbcSource.scala From fusion-data with Apache License 2.0 | 5 votes |
package mass.connector.sql import java.sql.ResultSet import akka.NotUsed import akka.stream.scaladsl.Source import fusion.jdbc.ConnectionPreparedStatementCreator import fusion.jdbc.util.JdbcUtils import javax.sql.DataSource object JdbcSource { def apply(sql: String, args: Iterable[Any], fetchRowSize: Int)( implicit dataSource: DataSource): Source[ResultSet, NotUsed] = Source.fromGraph(new JdbcSourceStage(dataSource, conn => { val stmt = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY) JdbcUtils.setStatementParameters(stmt, args) }, fetchRowSize)) def apply(creator: ConnectionPreparedStatementCreator, fetchRowSize: Int)( implicit dataSource: DataSource): Source[ResultSet, NotUsed] = Source.fromGraph(new JdbcSourceStage(dataSource, creator, fetchRowSize)) }
Example 5
Source File: JdbcSourceStage.scala From fusion-data with Apache License 2.0 | 5 votes |
package mass.connector.sql import java.sql.{ Connection, PreparedStatement, ResultSet } import akka.stream.stage.{ GraphStage, GraphStageLogic, OutHandler } import akka.stream.{ Attributes, Outlet, SourceShape } import javax.sql.DataSource import fusion.jdbc.ConnectionPreparedStatementCreator import fusion.jdbc.util.JdbcUtils import scala.util.control.NonFatal class JdbcSourceStage(dataSource: DataSource, creator: ConnectionPreparedStatementCreator, fetchRowSize: Int) extends GraphStage[SourceShape[ResultSet]] { private val out: Outlet[ResultSet] = Outlet("JdbcSource.out") override def shape: SourceShape[ResultSet] = SourceShape(out) override def createLogic(inheritedAttributes: Attributes): GraphStageLogic = new GraphStageLogic(shape) with OutHandler { var maybeConn = Option.empty[(Connection, Boolean, PreparedStatement, ResultSet)] setHandler(out, this) override def onPull(): Unit = maybeConn match { case Some((_, _, _, rs)) if rs.next() => push(out, rs) case Some(_) => completeStage() case None => () // doing nothing, waiting for in preStart() to be completed } override def preStart(): Unit = try { val conn = dataSource.getConnection val autoCommit = conn.getAutoCommit conn.setAutoCommit(false) val stmt = creator(conn) val rs = stmt.executeQuery() // rs.setFetchDirection(ResultSet.TYPE_FORWARD_ONLY) rs.setFetchSize(fetchRowSize) maybeConn = Option((conn, autoCommit, stmt, rs)) } catch { case NonFatal(e) => failStage(e) } override def postStop(): Unit = for { (conn, autoCommit, stmt, rs) <- maybeConn } { JdbcUtils.closeResultSet(rs) JdbcUtils.closeStatement(stmt) conn.setAutoCommit(autoCommit) JdbcUtils.closeConnection(conn) } } }
Example 6
Source File: OracleMonixJdbcContext.scala From quill with Apache License 2.0 | 5 votes |
package io.getquill import java.io.Closeable import com.typesafe.config.Config import io.getquill.context.jdbc.OracleJdbcContextBase import io.getquill.context.monix.{ MonixJdbcContext, Runner } import io.getquill.util.LoadConfig import javax.sql.DataSource class OracleMonixJdbcContext[N <: NamingStrategy]( val naming: N, val dataSource: DataSource with Closeable, runner: Runner ) extends MonixJdbcContext[OracleDialect, N](dataSource, runner) with OracleJdbcContextBase[N] { def this(naming: N, config: JdbcContextConfig, runner: Runner) = this(naming, config.dataSource, runner) def this(naming: N, config: Config, runner: Runner) = this(naming, JdbcContextConfig(config), runner) def this(naming: N, configPrefix: String, runner: Runner) = this(naming, LoadConfig(configPrefix), runner) def this(naming: N, configPrefix: String) = this(naming, LoadConfig(configPrefix), Runner.default) }
Example 7
Source File: PostgresMonixJdbcContext.scala From quill with Apache License 2.0 | 5 votes |
package io.getquill import java.io.Closeable import com.typesafe.config.Config import io.getquill.context.jdbc.PostgresJdbcContextBase import io.getquill.context.monix.{ MonixJdbcContext, Runner } import io.getquill.util.LoadConfig import javax.sql.DataSource class PostgresMonixJdbcContext[N <: NamingStrategy]( val naming: N, val dataSource: DataSource with Closeable, runner: Runner ) extends MonixJdbcContext[PostgresDialect, N](dataSource, runner) with PostgresJdbcContextBase[N] { def this(naming: N, config: JdbcContextConfig, runner: Runner) = this(naming, config.dataSource, runner) def this(naming: N, config: Config, runner: Runner) = this(naming, JdbcContextConfig(config), runner) def this(naming: N, configPrefix: String, runner: Runner) = this(naming, LoadConfig(configPrefix), runner) def this(naming: N, configPrefix: String) = this(naming, LoadConfig(configPrefix), Runner.default) }
Example 8
Source File: SqlServerMonixJdbcContext.scala From quill with Apache License 2.0 | 5 votes |
package io.getquill import java.io.Closeable import com.typesafe.config.Config import io.getquill.context.jdbc.SqlServerJdbcContextBase import io.getquill.context.monix.{ MonixJdbcContext, Runner } import io.getquill.util.LoadConfig import javax.sql.DataSource class SqlServerMonixJdbcContext[N <: NamingStrategy]( val naming: N, val dataSource: DataSource with Closeable, runner: Runner ) extends MonixJdbcContext[SQLServerDialect, N](dataSource, runner) with SqlServerJdbcContextBase[N] { def this(naming: N, config: JdbcContextConfig, runner: Runner) = this(naming, config.dataSource, runner) def this(naming: N, config: Config, runner: Runner) = this(naming, JdbcContextConfig(config), runner) def this(naming: N, configPrefix: String, runner: Runner) = this(naming, LoadConfig(configPrefix), runner) def this(naming: N, configPrefix: String) = this(naming, LoadConfig(configPrefix), Runner.default) }
Example 9
Source File: SqliteMonixJdbcContext.scala From quill with Apache License 2.0 | 5 votes |
package io.getquill import java.io.Closeable import com.typesafe.config.Config import io.getquill.context.jdbc.SqliteJdbcContextBase import io.getquill.context.monix.{ MonixJdbcContext, Runner } import io.getquill.util.LoadConfig import javax.sql.DataSource class SqliteMonixJdbcContext[N <: NamingStrategy]( val naming: N, val dataSource: DataSource with Closeable, runner: Runner ) extends MonixJdbcContext[SqliteDialect, N](dataSource, runner) with SqliteJdbcContextBase[N] { def this(naming: N, config: JdbcContextConfig, runner: Runner) = this(naming, config.dataSource, runner) def this(naming: N, config: Config, runner: Runner) = this(naming, JdbcContextConfig(config), runner) def this(naming: N, configPrefix: String, runner: Runner) = this(naming, LoadConfig(configPrefix), runner) def this(naming: N, configPrefix: String) = this(naming, LoadConfig(configPrefix), Runner.default) }
Example 10
Source File: H2MonixJdbcContext.scala From quill with Apache License 2.0 | 5 votes |
package io.getquill import java.io.Closeable import com.typesafe.config.Config import io.getquill.context.jdbc.H2JdbcContextBase import io.getquill.context.monix.{ MonixJdbcContext, Runner } import io.getquill.util.LoadConfig import javax.sql.DataSource class H2MonixJdbcContext[N <: NamingStrategy]( val naming: N, val dataSource: DataSource with Closeable, runner: Runner ) extends MonixJdbcContext[H2Dialect, N](dataSource, runner) with H2JdbcContextBase[N] { def this(naming: N, config: JdbcContextConfig, runner: Runner) = this(naming, config.dataSource, runner) def this(naming: N, config: Config, runner: Runner) = this(naming, JdbcContextConfig(config), runner) def this(naming: N, configPrefix: String, runner: Runner) = this(naming, LoadConfig(configPrefix), runner) def this(naming: N, configPrefix: String) = this(naming, LoadConfig(configPrefix), Runner.default) }
Example 11
Source File: MysqlMonixJdbcContext.scala From quill with Apache License 2.0 | 5 votes |
package io.getquill import java.io.Closeable import com.typesafe.config.Config import io.getquill.context.jdbc.MysqlJdbcContextBase import io.getquill.context.monix.{ MonixJdbcContext, Runner } import io.getquill.util.LoadConfig import javax.sql.DataSource class MysqlMonixJdbcContext[N <: NamingStrategy]( val naming: N, val dataSource: DataSource with Closeable, runner: Runner ) extends MonixJdbcContext[MySQLDialect, N](dataSource, runner) with MysqlJdbcContextBase[N] { def this(naming: N, config: JdbcContextConfig, runner: Runner) = this(naming, config.dataSource, runner) def this(naming: N, config: Config, runner: Runner) = this(naming, JdbcContextConfig(config), runner) def this(naming: N, configPrefix: String, runner: Runner) = this(naming, LoadConfig(configPrefix), runner) def this(naming: N, configPrefix: String) = this(naming, LoadConfig(configPrefix), Runner.default) }
Example 12
Source File: SchemaMaker.scala From quill with Apache License 2.0 | 5 votes |
package io.getquill.codegen.util import java.io.Closeable import io.getquill._ import io.getquill.codegen.integration.DbHelper import javax.sql.DataSource import org.scalatest.freespec.AnyFreeSpec import scala.language.implicitConversions abstract class CodegenSpec extends AnyFreeSpec with SchemaMaker { type Prefix <: ConfigPrefix val prefix: Prefix implicit def regToOption[T](t: T) = Some(t) } object SchemaMaker extends SchemaMaker case class SchemaMakerCoordinates(dbPrefix: ConfigPrefix, naming: NamingStrategy, schemaConfig: SchemaConfig) trait SchemaMaker { private[getquill] def withDatasource[T](schemaConfig: SchemaConfig, dbPrefix: ConfigPrefix)(testCode: DataSource with Closeable => T): T = { val ds = dbPrefix.makeDatasource val helper = new DbHelper(schemaConfig, dbPrefix, ds) DbHelper.dropTables(ds) helper.setup() testCode(ds) } def withContext[T](coords: SchemaMakerCoordinates)(testCode: => T): T = { import coords._ withDatasource(schemaConfig, dbPrefix)(ds => { testCode }) } }
Example 13
Source File: ConfigPrefix.scala From quill with Apache License 2.0 | 5 votes |
package io.getquill.codegen.util import java.io.Closeable import com.typesafe.config.ConfigFactory import io.getquill.JdbcContextConfig import javax.sql.DataSource import OptionOps._ import scala.util.Try sealed trait ConfigPrefix { def value: String def packagePath: String private[getquill] def loadConfig = ConfigFactory .load(getClass.getClassLoader, "application-codegen.conf") .getConfig(value) private[getquill] def makeDatasource: DataSource with Closeable = JdbcContextConfig(loadConfig).dataSource } object ConfigPrefix { sealed trait TestH2DB extends ConfigPrefix { val value = "testH2DB"; val packagePath = "h2" } sealed trait TestMysqlDB extends ConfigPrefix { val value = "testMysqlDB"; val packagePath = "mysql" } sealed trait TestOracleDB extends ConfigPrefix { val value = "testOracleDB"; val packagePath = "oracle" } sealed trait TestPostgresDB extends ConfigPrefix { val value = "testPostgresDB"; val packagePath = "postgres" } sealed trait TestSqliteDB extends ConfigPrefix { val value = "testSqliteDB"; val packagePath = "sqlite" } sealed trait TestSqlServerDB extends ConfigPrefix { val value = "testSqlServerDB"; val packagePath = "sqlserver" } case object TestH2DB extends TestH2DB case object TestMysqlDB extends TestMysqlDB case object TestOracleDB extends TestOracleDB case object TestPostgresDB extends TestPostgresDB case object TestSqliteDB extends TestSqliteDB case object TestSqlServerDB extends TestSqlServerDB def all = List( TestH2DB, TestMysqlDB, TestOracleDB, TestPostgresDB, TestSqliteDB, TestSqlServerDB ) def fromValue(str: String): Try[ConfigPrefix] = ConfigPrefix.all.find(_.value == str).toTry(new IllegalArgumentException(s"Could not find the value: '${str}'")) }
Example 14
Source File: SimpleJdbcCodegen.scala From quill with Apache License 2.0 | 5 votes |
package io.getquill.codegen.jdbc import com.typesafe.config.Config import io.getquill.JdbcContextConfig import io.getquill.codegen.jdbc.gen.JdbcGeneratorBase import io.getquill.codegen.jdbc.model.JdbcTypes.JdbcConnectionMaker import io.getquill.codegen.model.{ LiteralNames, NameParser } import io.getquill.util.LoadConfig import javax.sql.DataSource class SimpleJdbcCodegen( override val connectionMakers: Seq[JdbcConnectionMaker], override val packagePrefix: String = "" ) extends JdbcGeneratorBase(connectionMakers, packagePrefix) { def this(connectionMaker: JdbcConnectionMaker, packagePrefix: String) = this(Seq(connectionMaker), packagePrefix) def this(dataSource: DataSource, packagePrefix: String) = this(Seq(() => { dataSource.getConnection }), packagePrefix) def this(config: JdbcContextConfig, packagePrefix: String) = this(config.dataSource, packagePrefix) def this(config: Config, packagePrefix: String) = this(JdbcContextConfig(config), packagePrefix) def this(configPrefix: String, packagePrefix: String) = this(LoadConfig(configPrefix), packagePrefix) override def nameParser: NameParser = LiteralNames }
Example 15
Source File: WithOracleContext.scala From quill with Apache License 2.0 | 5 votes |
package io.getquill.codegen.util import java.io.Closeable import io.getquill.codegen.integration.CodegenTestCases._ import io.getquill.codegen.util.ConfigPrefix.{ TestOracleDB => TheDB } import io.getquill.{ Literal, SnakeCase, OracleDialect => TheDialect, OracleJdbcContext => TheContext } import javax.sql.DataSource // Need separate object for Oracle contexts since WithOracleContext itself is excluded in builds // that are not compiling with Oracle object WithOracleContextStandalone extends WithContextAux with WithOracleContext trait WithOracleContext extends WithContextAux { import io.getquill.codegen.generated.oracle._ implicit def oracleSimpleContextForTest1: Aux[TheDB, `1-simple-snake`, TheContext[SnakeCase]] = new WithContextBase[TheDB, `1-simple-snake`](TheDB, `1-simple-snake`) { override type QuillContext = TheContext[SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new QuillContext(SnakeCase, ds) } implicit def oracleSimpleContextForTest2: Aux[TheDB, `2-simple-literal`, TheContext[SnakeCase]] = new WithContextBase[TheDB, `2-simple-literal`](TheDB, `2-simple-literal`) { override type QuillContext = TheContext[SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new QuillContext(SnakeCase, ds) } implicit def oracleContextForTest1: Aux[TheDB, `1-comp-sanity`, TheContext[SnakeCase]] = new WithContextBase[TheDB, `1-comp-sanity`](TheDB, `1-comp-sanity`) { override type QuillContext = TheContext[SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new QuillContext(SnakeCase, ds) } implicit def oracleContextForTest2: Aux[TheDB, `2-comp-stereo-single`, TheContext[SnakeCase] with `2-comp-stereo-single-lib`.public.PublicExtensions[TheDialect, SnakeCase]] = new WithContextBase[TheDB, `2-comp-stereo-single`](TheDB, `2-comp-stereo-single`) { override type QuillContext = TheContext[SnakeCase] with `2-comp-stereo-single-lib`.public.PublicExtensions[TheDialect, SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[SnakeCase](SnakeCase, ds) with `2-comp-stereo-single-lib`.public.PublicExtensions[TheDialect, SnakeCase] } implicit def oracleContextForTest3: Aux[TheDB, `3-comp-stereo-oneschema`, TheContext[Literal] with `3-comp-stereo-oneschema-lib`.public.PublicExtensions[TheDialect, Literal]] = new WithContextBase[TheDB, `3-comp-stereo-oneschema`](TheDB, `3-comp-stereo-oneschema`) { override type QuillContext = TheContext[Literal] with `3-comp-stereo-oneschema-lib`.public.PublicExtensions[TheDialect, Literal] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[Literal](Literal, ds) with `3-comp-stereo-oneschema-lib`.public.PublicExtensions[TheDialect, Literal] } implicit def oracleContextForTest4: Aux[TheDB, `4-comp-stereo-twoschema`, TheContext[Literal] with `4-comp-stereo-twoschema-lib`.public.PublicExtensions[TheDialect, Literal] with `4-comp-stereo-twoschema-lib`.common.CommonExtensions[TheDialect, Literal]] = new WithContextBase[TheDB, `4-comp-stereo-twoschema`](TheDB, `4-comp-stereo-twoschema`) { override type QuillContext = TheContext[Literal] with `4-comp-stereo-twoschema-lib`.public.PublicExtensions[TheDialect, Literal] with `4-comp-stereo-twoschema-lib`.common.CommonExtensions[TheDialect, Literal] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[Literal](Literal, ds) with `4-comp-stereo-twoschema-lib`.public.PublicExtensions[TheDialect, Literal] with `4-comp-stereo-twoschema-lib`.common.CommonExtensions[TheDialect, Literal] } implicit def oracleContextForTest5: Aux[TheDB, `5-comp-non-stereo-allschema`, TheContext[Literal] with `5-comp-non-stereo-allschema-lib`.public.PublicExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.alpha.AlphaExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.bravo.BravoExtensions[TheDialect, Literal]] = new WithContextBase[TheDB, `5-comp-non-stereo-allschema`](TheDB, `5-comp-non-stereo-allschema`) { override type QuillContext = TheContext[Literal] with `5-comp-non-stereo-allschema-lib`.public.PublicExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.alpha.AlphaExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.bravo.BravoExtensions[TheDialect, Literal] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[Literal](Literal, ds) with `5-comp-non-stereo-allschema-lib`.public.PublicExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.alpha.AlphaExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.bravo.BravoExtensions[TheDialect, Literal] } }
Example 16
Source File: JdbcJournal.scala From akka-tools with MIT License | 5 votes |
package no.nextgentel.oss.akkatools.persistence.jdbcjournal import javax.sql.DataSource import com.typesafe.config.Config import no.nextgentel.oss.akkatools.cluster.ClusterNodeRepo object JdbcJournalConfig { val defaultConfigName = "default" private var name2Config = Map[String, JdbcJournalConfig]() def setConfig(config:JdbcJournalConfig): Unit = { setConfig(defaultConfigName, config) } def setConfig(configName:String, config:JdbcJournalConfig): Unit = { name2Config = name2Config + (configName -> config) } def getConfig(configName:String):JdbcJournalConfig = { name2Config.getOrElse(configName, throw new Exception(s"Configuration with name '$configName' has not ben set.")) } def createJdbcJournalRuntimeData(): JdbcJournalRuntimeData = { createJdbcJournalRuntimeData(defaultConfigName) } def createJdbcJournalRuntimeData(configName:String): JdbcJournalRuntimeData = { val config = getConfig(configName) val repo = config.createStorageRepo() JdbcJournalRuntimeData(repo, repo, config.persistenceIdParser, config.maxRowsPrRead) } // Java helper def create(dataSource: DataSource, schemaName: String, fatalErrorHandler: JdbcJournalErrorHandler) = JdbcJournalConfig(dataSource, Option(fatalErrorHandler), StorageRepoConfig(Option(schemaName))) } case class JdbcJournalConfig ( dataSource: DataSource, fatalErrorHandler: Option[JdbcJournalErrorHandler] = None, // The fatalErrorHandler is called when something bad has happened - like getting unique PK key errors - Which is probably a symptom of split brain storageRepoConfig: StorageRepoConfig = StorageRepoConfig(schemaName = None), persistenceIdParser:PersistenceIdParser = new PersistenceIdParserImpl('/'), maxRowsPrRead: Int = 1000, databaseImpl:String = "oracle" ) { def createStorageRepo():StorageRepoWithClusterNodeRepo = { databaseImpl.toLowerCase() match { case "oracle" => new StorageRepoImpl(dataSource, storageRepoConfig, fatalErrorHandler) case "mysql" => new StorageRepoMySQLImpl(dataSource, storageRepoConfig, fatalErrorHandler) case "postgres" => new StorageRepoPostgresImpl(dataSource, storageRepoConfig, fatalErrorHandler) case x => throw new Exception(s"Do not understand databaseImpl=$databaseImpl") } } } // ------------------------------------------------------------------ case class JdbcJournalRuntimeData( repo:StorageRepo, clusterNodeRepo:ClusterNodeRepo, persistenceIdParser:PersistenceIdParser, maxRowsPrRead:Int) trait JdbcJournalRuntimeDataExtractor { val config: Config val configName = config.getString("configName") val runtimeData:JdbcJournalRuntimeData = JdbcJournalConfig.createJdbcJournalRuntimeData(configName) }
Example 17
Source File: WithSqliteContext.scala From quill with Apache License 2.0 | 5 votes |
package io.getquill.codegen.util import java.io.Closeable import io.getquill.codegen.integration.CodegenTestCases._ import io.getquill.codegen.util.ConfigPrefix.{ TestSqliteDB => TheDB } import io.getquill.{ SnakeCase, SqliteDialect => TheDialect, SqliteJdbcContext => TheContext } import javax.sql.DataSource trait WithSqliteContext extends WithContextAux { import io.getquill.codegen.generated.sqlite._ implicit def sqliteSimpleContextForTest1: Aux[TheDB, `1-simple-snake`, TheContext[SnakeCase]] = new WithContextBase[TheDB, `1-simple-snake`](TheDB, `1-simple-snake`) { override type QuillContext = TheContext[SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new QuillContext(SnakeCase, ds) } implicit def sqliteSimpleContextForTest2: Aux[TheDB, `2-simple-literal`, TheContext[SnakeCase]] = new WithContextBase[TheDB, `2-simple-literal`](TheDB, `2-simple-literal`) { override type QuillContext = TheContext[SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new QuillContext(SnakeCase, ds) } implicit def sqliteContextForTest1: Aux[TheDB, `1-comp-sanity`, TheContext[SnakeCase]] = new WithContextBase[TheDB, `1-comp-sanity`](TheDB, `1-comp-sanity`) { override type QuillContext = TheContext[SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new QuillContext(SnakeCase, ds) } implicit def sqliteContextForTest2: Aux[TheDB, `2-comp-stereo-single`, TheContext[SnakeCase] with `2-comp-stereo-single-lib`.public.PublicExtensions[TheDialect, SnakeCase]] = new WithContextBase[TheDB, `2-comp-stereo-single`](TheDB, `2-comp-stereo-single`) { override type QuillContext = TheContext[SnakeCase] with `2-comp-stereo-single-lib`.public.PublicExtensions[TheDialect, SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[SnakeCase](SnakeCase, ds) with `2-comp-stereo-single-lib`.public.PublicExtensions[TheDialect, SnakeCase] } }
Example 18
Source File: WithContext.scala From quill with Apache License 2.0 | 5 votes |
package io.getquill.codegen.util import java.io.Closeable import io.getquill.codegen.integration.CodegenTestCases import io.getquill.context.jdbc.JdbcContext import javax.sql.DataSource trait WithContext[Prefix <: ConfigPrefix, CTest <: CodegenTestCases] extends SchemaMaker { type QuillContext <: JdbcContext[_, _] def ctest: CTest def dbPrefix: Prefix protected def makeContext(ds: DataSource with Closeable): QuillContext def run(testCode: QuillContext => Any): Unit = { withContext(ctest.schemaMakerCoordinates(dbPrefix))(testCode) () } } abstract class WithContextBase[Prefix <: ConfigPrefix, CTest <: CodegenTestCases](val dbPrefix: Prefix, val ctest: CTest) extends WithContext[Prefix, CTest] // Cannot include WithOracleContext here since it is not being compiled in all builds object WithContext extends WithContextAux with WithH2Context with WithMysqlContext with WithPostgresContext with WithSqliteContext with WithSqlServerContext trait WithContextAux { type Aux[Prefix <: ConfigPrefix, CTest <: CodegenTestCases, Ret] = WithContext[Prefix, CTest] { type QuillContext = Ret } def apply[Prefix <: ConfigPrefix, CTest <: CodegenTestCases](implicit cft: WithContext[Prefix, CTest]): Aux[Prefix, CTest, cft.QuillContext] = cft }
Example 19
Source File: WithH2Context.scala From quill with Apache License 2.0 | 5 votes |
package io.getquill.codegen.util import java.io.Closeable import io.getquill.{ H2Dialect => TheDialect, H2JdbcContext => TheContext, Literal, SnakeCase } import io.getquill.codegen.integration.CodegenTestCases._ import io.getquill.codegen.util.ConfigPrefix.{ TestH2DB => TheDB } import javax.sql.DataSource trait WithH2Context extends WithContextAux { import io.getquill.codegen.generated.h2._ implicit def h2SimpleContextForTest1: Aux[TheDB, `1-simple-snake`, TheContext[SnakeCase]] = new WithContextBase[TheDB, `1-simple-snake`](TheDB, `1-simple-snake`) { override type QuillContext = TheContext[SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new QuillContext(SnakeCase, ds) } implicit def h2SimpleContextForTest2: Aux[TheDB, `2-simple-literal`, TheContext[SnakeCase]] = new WithContextBase[TheDB, `2-simple-literal`](TheDB, `2-simple-literal`) { override type QuillContext = TheContext[SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new QuillContext(SnakeCase, ds) } implicit def h2ContextForTest1: Aux[TheDB, `1-comp-sanity`, TheContext[SnakeCase]] = new WithContextBase[TheDB, `1-comp-sanity`](TheDB, `1-comp-sanity`) { override type QuillContext = TheContext[SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new QuillContext(SnakeCase, ds) } implicit def h2ContextForTest2: Aux[TheDB, `2-comp-stereo-single`, TheContext[SnakeCase] with `2-comp-stereo-single-lib`.public.PublicExtensions[TheDialect, SnakeCase]] = new WithContextBase[TheDB, `2-comp-stereo-single`](TheDB, `2-comp-stereo-single`) { override type QuillContext = TheContext[SnakeCase] with `2-comp-stereo-single-lib`.public.PublicExtensions[TheDialect, SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[SnakeCase](SnakeCase, ds) with `2-comp-stereo-single-lib`.public.PublicExtensions[TheDialect, SnakeCase] } implicit def h2ContextForTest3: Aux[TheDB, `3-comp-stereo-oneschema`, TheContext[Literal] with `3-comp-stereo-oneschema-lib`.public.PublicExtensions[TheDialect, Literal]] = new WithContextBase[TheDB, `3-comp-stereo-oneschema`](TheDB, `3-comp-stereo-oneschema`) { override type QuillContext = TheContext[Literal] with `3-comp-stereo-oneschema-lib`.public.PublicExtensions[TheDialect, Literal] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[Literal](Literal, ds) with `3-comp-stereo-oneschema-lib`.public.PublicExtensions[TheDialect, Literal] } implicit def h2ContextForTest4: Aux[TheDB, `4-comp-stereo-twoschema`, TheContext[Literal] with `4-comp-stereo-twoschema-lib`.public.PublicExtensions[TheDialect, Literal] with `4-comp-stereo-twoschema-lib`.common.CommonExtensions[TheDialect, Literal]] = new WithContextBase[TheDB, `4-comp-stereo-twoschema`](TheDB, `4-comp-stereo-twoschema`) { override type QuillContext = TheContext[Literal] with `4-comp-stereo-twoschema-lib`.public.PublicExtensions[TheDialect, Literal] with `4-comp-stereo-twoschema-lib`.common.CommonExtensions[TheDialect, Literal] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[Literal](Literal, ds) with `4-comp-stereo-twoschema-lib`.public.PublicExtensions[TheDialect, Literal] with `4-comp-stereo-twoschema-lib`.common.CommonExtensions[TheDialect, Literal] } implicit def h2ContextForTest5: Aux[TheDB, `5-comp-non-stereo-allschema`, TheContext[Literal] with `5-comp-non-stereo-allschema-lib`.public.PublicExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.alpha.AlphaExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.bravo.BravoExtensions[TheDialect, Literal]] = new WithContextBase[TheDB, `5-comp-non-stereo-allschema`](TheDB, `5-comp-non-stereo-allschema`) { override type QuillContext = TheContext[Literal] with `5-comp-non-stereo-allschema-lib`.public.PublicExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.alpha.AlphaExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.bravo.BravoExtensions[TheDialect, Literal] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[Literal](Literal, ds) with `5-comp-non-stereo-allschema-lib`.public.PublicExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.alpha.AlphaExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.bravo.BravoExtensions[TheDialect, Literal] } }
Example 20
Source File: WithPostgresContext.scala From quill with Apache License 2.0 | 5 votes |
package io.getquill.codegen.util import java.io.Closeable import io.getquill.codegen.integration.CodegenTestCases._ import io.getquill.codegen.util.ConfigPrefix.{ TestPostgresDB => TheDB } import io.getquill.{ Literal, SnakeCase, PostgresDialect => TheDialect, PostgresJdbcContext => TheContext } import javax.sql.DataSource trait WithPostgresContext extends WithContextAux { import io.getquill.codegen.generated.postgres._ implicit def postgresSimpleContextForTest1: Aux[TheDB, `1-simple-snake`, TheContext[SnakeCase]] = new WithContextBase[TheDB, `1-simple-snake`](TheDB, `1-simple-snake`) { override type QuillContext = TheContext[SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new QuillContext(SnakeCase, ds) } implicit def postgresSimpleContextForTest2: Aux[TheDB, `2-simple-literal`, TheContext[SnakeCase]] = new WithContextBase[TheDB, `2-simple-literal`](TheDB, `2-simple-literal`) { override type QuillContext = TheContext[SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new QuillContext(SnakeCase, ds) } implicit def postgresContextForTest1: Aux[TheDB, `1-comp-sanity`, TheContext[SnakeCase]] = new WithContextBase[TheDB, `1-comp-sanity`](TheDB, `1-comp-sanity`) { override type QuillContext = TheContext[SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new QuillContext(SnakeCase, ds) } implicit def postgresContextForTest2: Aux[TheDB, `2-comp-stereo-single`, TheContext[SnakeCase] with `2-comp-stereo-single-lib`.public.PublicExtensions[TheDialect, SnakeCase]] = new WithContextBase[TheDB, `2-comp-stereo-single`](TheDB, `2-comp-stereo-single`) { override type QuillContext = TheContext[SnakeCase] with `2-comp-stereo-single-lib`.public.PublicExtensions[TheDialect, SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[SnakeCase](SnakeCase, ds) with `2-comp-stereo-single-lib`.public.PublicExtensions[TheDialect, SnakeCase] } implicit def postgresContextForTest3: Aux[TheDB, `3-comp-stereo-oneschema`, TheContext[Literal] with `3-comp-stereo-oneschema-lib`.public.PublicExtensions[TheDialect, Literal]] = new WithContextBase[TheDB, `3-comp-stereo-oneschema`](TheDB, `3-comp-stereo-oneschema`) { override type QuillContext = TheContext[Literal] with `3-comp-stereo-oneschema-lib`.public.PublicExtensions[TheDialect, Literal] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[Literal](Literal, ds) with `3-comp-stereo-oneschema-lib`.public.PublicExtensions[TheDialect, Literal] } implicit def postgresContextForTest4: Aux[TheDB, `4-comp-stereo-twoschema`, TheContext[Literal] with `4-comp-stereo-twoschema-lib`.public.PublicExtensions[TheDialect, Literal] with `4-comp-stereo-twoschema-lib`.common.CommonExtensions[TheDialect, Literal]] = new WithContextBase[TheDB, `4-comp-stereo-twoschema`](TheDB, `4-comp-stereo-twoschema`) { override type QuillContext = TheContext[Literal] with `4-comp-stereo-twoschema-lib`.public.PublicExtensions[TheDialect, Literal] with `4-comp-stereo-twoschema-lib`.common.CommonExtensions[TheDialect, Literal] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[Literal](Literal, ds) with `4-comp-stereo-twoschema-lib`.public.PublicExtensions[TheDialect, Literal] with `4-comp-stereo-twoschema-lib`.common.CommonExtensions[TheDialect, Literal] } implicit def postgresContextForTest5: Aux[TheDB, `5-comp-non-stereo-allschema`, TheContext[Literal] with `5-comp-non-stereo-allschema-lib`.public.PublicExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.alpha.AlphaExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.bravo.BravoExtensions[TheDialect, Literal]] = new WithContextBase[TheDB, `5-comp-non-stereo-allschema`](TheDB, `5-comp-non-stereo-allschema`) { override type QuillContext = TheContext[Literal] with `5-comp-non-stereo-allschema-lib`.public.PublicExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.alpha.AlphaExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.bravo.BravoExtensions[TheDialect, Literal] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[Literal](Literal, ds) with `5-comp-non-stereo-allschema-lib`.public.PublicExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.alpha.AlphaExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.bravo.BravoExtensions[TheDialect, Literal] } }
Example 21
Source File: WithSqlServerContext.scala From quill with Apache License 2.0 | 5 votes |
package io.getquill.codegen.util import java.io.Closeable import io.getquill.codegen.integration.CodegenTestCases._ import io.getquill.codegen.util.ConfigPrefix.{ TestSqlServerDB => TheDB } import io.getquill.{ Literal, SnakeCase, SQLServerDialect => TheDialect, SqlServerJdbcContext => TheContext } import javax.sql.DataSource trait WithSqlServerContext extends WithContextAux { import io.getquill.codegen.generated.sqlserver._ implicit def sqlServerSimpleContextForTest1: Aux[TheDB, `1-simple-snake`, TheContext[SnakeCase]] = new WithContextBase[TheDB, `1-simple-snake`](TheDB, `1-simple-snake`) { override type QuillContext = TheContext[SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new QuillContext(SnakeCase, ds) } implicit def sqlServerSimpleContextForTest2: Aux[TheDB, `2-simple-literal`, TheContext[SnakeCase]] = new WithContextBase[TheDB, `2-simple-literal`](TheDB, `2-simple-literal`) { override type QuillContext = TheContext[SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new QuillContext(SnakeCase, ds) } implicit def sqlServerContextForTest1: Aux[TheDB, `1-comp-sanity`, TheContext[SnakeCase]] = new WithContextBase[TheDB, `1-comp-sanity`](TheDB, `1-comp-sanity`) { override type QuillContext = TheContext[SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new QuillContext(SnakeCase, ds) } implicit def sqlServerContextForTest2: Aux[TheDB, `2-comp-stereo-single`, TheContext[SnakeCase] with `2-comp-stereo-single-lib`.public.PublicExtensions[TheDialect, SnakeCase]] = new WithContextBase[TheDB, `2-comp-stereo-single`](TheDB, `2-comp-stereo-single`) { override type QuillContext = TheContext[SnakeCase] with `2-comp-stereo-single-lib`.public.PublicExtensions[TheDialect, SnakeCase] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[SnakeCase](SnakeCase, ds) with `2-comp-stereo-single-lib`.public.PublicExtensions[TheDialect, SnakeCase] } implicit def sqlServerContextForTest3: Aux[TheDB, `3-comp-stereo-oneschema`, TheContext[Literal] with `3-comp-stereo-oneschema-lib`.public.PublicExtensions[TheDialect, Literal]] = new WithContextBase[TheDB, `3-comp-stereo-oneschema`](TheDB, `3-comp-stereo-oneschema`) { override type QuillContext = TheContext[Literal] with `3-comp-stereo-oneschema-lib`.public.PublicExtensions[TheDialect, Literal] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[Literal](Literal, ds) with `3-comp-stereo-oneschema-lib`.public.PublicExtensions[TheDialect, Literal] } implicit def sqlServerContextForTest4: Aux[TheDB, `4-comp-stereo-twoschema`, TheContext[Literal] with `4-comp-stereo-twoschema-lib`.public.PublicExtensions[TheDialect, Literal] with `4-comp-stereo-twoschema-lib`.common.CommonExtensions[TheDialect, Literal]] = new WithContextBase[TheDB, `4-comp-stereo-twoschema`](TheDB, `4-comp-stereo-twoschema`) { override type QuillContext = TheContext[Literal] with `4-comp-stereo-twoschema-lib`.public.PublicExtensions[TheDialect, Literal] with `4-comp-stereo-twoschema-lib`.common.CommonExtensions[TheDialect, Literal] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[Literal](Literal, ds) with `4-comp-stereo-twoschema-lib`.public.PublicExtensions[TheDialect, Literal] with `4-comp-stereo-twoschema-lib`.common.CommonExtensions[TheDialect, Literal] } implicit def sqlServerContextForTest5: Aux[TheDB, `5-comp-non-stereo-allschema`, TheContext[Literal] with `5-comp-non-stereo-allschema-lib`.public.PublicExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.alpha.AlphaExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.bravo.BravoExtensions[TheDialect, Literal]] = new WithContextBase[TheDB, `5-comp-non-stereo-allschema`](TheDB, `5-comp-non-stereo-allschema`) { override type QuillContext = TheContext[Literal] with `5-comp-non-stereo-allschema-lib`.public.PublicExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.alpha.AlphaExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.bravo.BravoExtensions[TheDialect, Literal] override protected def makeContext(ds: DataSource with Closeable) = new TheContext[Literal](Literal, ds) with `5-comp-non-stereo-allschema-lib`.public.PublicExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.alpha.AlphaExtensions[TheDialect, Literal] with `5-comp-non-stereo-allschema-lib`.bravo.BravoExtensions[TheDialect, Literal] } }
Example 22
Source File: DatabaseServiceComponent.scala From Scala-Design-Patterns-Second-Edition with MIT License | 5 votes |
package com.ivan.nikolov.scheduler.dao import java.sql.Connection import javax.sql.DataSource import com.ivan.nikolov.scheduler.config.app.AppConfigComponent import org.h2.jdbcx.JdbcConnectionPool trait DatabaseService { val dbDriver: String val connectionString: String val username: String val password: String val ds: DataSource def getConnection: Connection = ds.getConnection } trait DatabaseServiceComponent { this: AppConfigComponent => val databaseService: DatabaseService class H2DatabaseService extends DatabaseService { override val dbDriver: String = "org.h2.Driver" override val connectionString: String = appConfigService.dbConnectionString override val username: String = appConfigService.dbUsername override val password: String = appConfigService.dbPassword override val ds: DataSource = JdbcConnectionPool.create(connectionString, username, password) } }
Example 23
Source File: DatabaseServiceComponent.scala From Scala-Design-Patterns-Second-Edition with MIT License | 5 votes |
package com.ivan.nikolov.scheduler.dao import java.sql.Connection import javax.sql.DataSource import com.ivan.nikolov.scheduler.config.app.AppConfigComponent import org.h2.jdbcx.JdbcConnectionPool trait DatabaseService { val dbDriver: String val connectionString: String val username: String val password: String val ds: DataSource def getConnection: Connection = ds.getConnection } trait DatabaseServiceComponent { this: AppConfigComponent => val databaseService: DatabaseService class H2DatabaseService extends DatabaseService { override val dbDriver: String = "org.h2.Driver" override val connectionString: String = appConfigService.dbConnectionString override val username: String = appConfigService.dbUsername override val password: String = appConfigService.dbPassword override val ds: DataSource = JdbcConnectionPool.create(connectionString, username, password) } }
Example 24
Source File: AppLoader.scala From play-quill-jdbc with MIT License | 5 votes |
import java.io.Closeable import javax.sql.DataSource import controllers.UsersController import io.getquill._ import play.api.ApplicationLoader.Context import play.api._ import play.api.db.evolutions.Evolutions import play.api.db.{DBComponents, HikariCPComponents} import play.api.inject.{Injector, NewInstanceInjector, SimpleInjector} import play.api.routing.Router import play.api.routing.sird._ import models.{Users} class AppLoader extends ApplicationLoader { override def load(context: Context): Application = new BuiltInComponentsFromContext(context) with DBComponents with HikariCPComponents { lazy val db = new H2JdbcContext[SnakeCase](dbApi.database("default").dataSource.asInstanceOf[DataSource with Closeable]) lazy val users = new Users(db) lazy val usersController = new UsersController(users) val router = Router.from { case GET(p"/users/${long(id)}") => usersController.get(id) case POST(p"/users") => usersController.create case DELETE(p"/users/${long(id)}") => usersController.delete(id) case PUT(p"/users/${long(id)}") => usersController.update(id) } override lazy val injector: Injector = new SimpleInjector(NewInstanceInjector) + users + router + cookieSigner + csrfTokenSigner + httpConfiguration + tempFileCreator + global Evolutions.applyEvolutions(dbApi.database("default")) }.application }
Example 25
Source File: DataSourceConnectionPoolFactoryTest.scala From maha with Apache License 2.0 | 5 votes |
// Copyright 2017, Yahoo Holdings Inc. // Licensed under the terms of the Apache License 2.0. Please see LICENSE file in project root for terms. package com.yahoo.maha.service.factory import java.util.UUID import javax.sql.DataSource import com.yahoo.maha.jdbc.JdbcConnection import com.yahoo.maha.service.{DefaultMahaServiceConfigContext, MahaServiceConfigContext} import com.zaxxer.hikari.HikariDataSource import org.json4s.JValue import org.json4s.jackson.JsonMethods._ import org.scalatest.{FunSuite, Matchers} class DataSourceConnectionPoolFactoryTest extends BaseFactoryTest{ implicit val context: MahaServiceConfigContext = DefaultMahaServiceConfigContext() test("Test Creation of HikariDataSource") { val uuid = UUID.randomUUID().toString.replace("-","") val jsonString = s""" |{ |"driverClassName" : "org.h2.Driver", |"jdbcUrl" : "jdbc:h2:mem:$uuid;MODE=Oracle;DB_CLOSE_DELAY=-1", |"username" : "sa", |"passwordProviderFactoryClassName" : "com.yahoo.maha.service.factory.PassThroughPasswordProviderFactory", |"passwordProviderConfig" : [{"key" : "value"}], |"passwordKey" : "h2.test.database.password", |"poolName" : "test-pool", |"maximumPoolSize" : 10, |"minimumIdle" : 1, |"autoCommit": true, |"connectionTestQuery" : "SELECT 1 FROM DUAL", |"validationTimeout" : 1000000, |"idleTimeout" : 1000000, |"maxLifetime" : 10000000, |"dataSourceProperties": [{"key": "propertyKey" , "value": "propertyValue"}] |} """.stripMargin val factoryResult = getFactory[DataSourceFactory]("com.yahoo.maha.service.factory.HikariDataSourceFactory", closer) assert(factoryResult.isSuccess) val factory = factoryResult.toOption.get val json = parse(jsonString) val generatorResult = factory.fromJson(json) assert(generatorResult.isSuccess, generatorResult) assert(generatorResult.toList.head.isInstanceOf[DataSource]) generatorResult.foreach { ds=> val connection = new JdbcConnection(ds) assert(ds.asInstanceOf[HikariDataSource].getIdleTimeout == 1000000) assert(ds.asInstanceOf[HikariDataSource].getPoolName == "test-pool") val ddlResult = connection.executeUpdate("create table test(key varchar(20), value varchar(20));") assert(ddlResult.isSuccess) } assert(KvPair.fieldJSONW.write(KvPair("1", "2")).isInstanceOf[JValue]) } }
Example 26
Source File: DatabaseInitializer.scala From reliable-http-client with Apache License 2.0 | 5 votes |
package rhttpc.transport.amqpjdbc.slick.helpers import java.io.PrintWriter import java.sql.Connection import java.util.logging.Logger import javax.sql.DataSource import com.typesafe.config.Config import org.flywaydb.core.Flyway import slick.jdbc.JdbcBackend import scala.concurrent.ExecutionContext class DatabaseInitializer(db: JdbcBackend.Database) { def initDatabase()(implicit executionContext: ExecutionContext) = { migrateIfNeeded(db) db } private def migrateIfNeeded(db: JdbcBackend.Database) = { Flyway.configure .dataSource(new DatabaseDataSource(db)) .baselineOnMigrate(true) .load .migrate } } object DatabaseInitializer { def apply(config: Config) = { val db = JdbcBackend.Database.forConfig("db", config) new DatabaseInitializer(db) } } class DatabaseDataSource(db: JdbcBackend.Database) extends DataSource { private val conn = db.createSession().conn override def getConnection: Connection = conn override def getConnection(username: String, password: String): Connection = conn override def unwrap[T](iface: Class[T]): T = conn.unwrap(iface) override def isWrapperFor(iface: Class[_]): Boolean = conn.isWrapperFor(iface) override def setLogWriter(out: PrintWriter): Unit = ??? override def getLoginTimeout: Int = ??? override def setLoginTimeout(seconds: Int): Unit = ??? override def getParentLogger: Logger = ??? override def getLogWriter: PrintWriter = ??? }
Example 27
Source File: SlickJdbcMigration.scala From reliable-http-client with Apache License 2.0 | 5 votes |
package rhttpc.transport.amqpjdbc.slick import java.io.PrintWriter import java.lang.reflect.{InvocationHandler, Method, Proxy} import java.sql.Connection import java.util.logging.Logger import javax.sql.DataSource import org.flywaydb.core.api.migration.{BaseJavaMigration, Context} import slick.jdbc.JdbcProfile import scala.concurrent.Await import scala.concurrent.duration._ trait SlickJdbcMigration extends BaseJavaMigration { protected val profile: JdbcProfile import profile.api._ def migrateActions: DBIOAction[Any, NoStream, _ <: Effect] override final def migrate(context: Context): Unit = { val database = Database.forDataSource(new AlwaysUsingSameConnectionDataSource(context.getConnection), None) Await.result(database.run(migrateActions), 10 minute) } } class AlwaysUsingSameConnectionDataSource(conn: Connection) extends DataSource { private val notClosingConnection = Proxy.newProxyInstance( ClassLoader.getSystemClassLoader, Array[Class[_]](classOf[Connection]), SuppressCloseHandler ).asInstanceOf[Connection] object SuppressCloseHandler extends InvocationHandler { override def invoke(proxy: AnyRef, method: Method, args: Array[AnyRef]): AnyRef = { if (method.getName != "close") { method.invoke(conn, args : _*) } else { null } } } override def getConnection: Connection = notClosingConnection override def getConnection(username: String, password: String): Connection = notClosingConnection override def unwrap[T](iface: Class[T]): T = conn.unwrap(iface) override def isWrapperFor(iface: Class[_]): Boolean = conn.isWrapperFor(iface) override def setLogWriter(out: PrintWriter): Unit = ??? override def getLoginTimeout: Int = ??? override def setLoginTimeout(seconds: Int): Unit = ??? override def getParentLogger: Logger = ??? override def getLogWriter: PrintWriter = ??? }
Example 28
Source File: PersonServlet.scala From jboss-wildfly-test with Apache License 2.0 | 5 votes |
package servlet import javax.annotation.Resource import javax.servlet.annotation._ import javax.servlet.http._ import javax.sql.DataSource import repository.{ JdbcConnection, PersonRepository } @WebServlet(value = Array("/PersonServlet")) class PersonServlet extends HttpServlet { @Resource(lookup = "java:jboss/datasources/PostgresDS") var ds: DataSource = null implicit def conn: JdbcConnection = new JdbcConnection { var dataSource = ds } override def doGet(request: HttpServletRequest, response: HttpServletResponse) { response.setContentType("text/html") response.setCharacterEncoding("UTF-8") val out = response.getWriter out.println("<h3>PersonServlet</h3>") PersonRepository.persons().map { xs ⇒ if (xs.isEmpty) { out.println("No persons in the database") } else { xs.foreach(person ⇒ out.println(person + "<br/>")) } }.recover { case t: Throwable ⇒ t.printStackTrace() out.println("Something bad has happened: " + t.getMessage) } val firstNameOption = Option(request.getParameter("firstName")) val lastNameOption = Option(request.getParameter("lastName")) (firstNameOption, lastNameOption) match { case (Some(firstName), Some(lastName)) ⇒ PersonRepository.savePerson(firstName, lastName) .map { _ ⇒ out.println(s"Person saved") } .recover { case t: Throwable ⇒ t.printStackTrace() out.println("Something bad has happened: " + t.getMessage) } case _ ⇒ out.println( """ |<p> |Enter a user to save: <br/> |<form action='PersonServlet' method='post'> |First name: <input type='text' length='20' name='firstName'/><br/> |Last name: <input type='text' length='20' name='lastName'/><br/> |<input type='submit'/> |</form> |</p> """.stripMargin) out.close() } } override def doPost(req: HttpServletRequest, resp: HttpServletResponse): Unit = doGet(req, resp) }
Example 29
Source File: DataSourceUtil.scala From akka-tools with MIT License | 5 votes |
package no.nextgentel.oss.akkatools.utils import java.sql.Connection import javax.sql.DataSource import liquibase.{Contexts, Liquibase} import liquibase.database.DatabaseFactory import liquibase.database.jvm.JdbcConnection import liquibase.resource.ClassLoaderResourceAccessor import org.h2.jdbcx.JdbcDataSource import scala.util.Random object DataSourceUtil { def createDataSource(h2DbName:String, pathToLiquibaseFile:String = "akka-tools-jdbc-journal-liquibase.sql"):DataSource = { this.synchronized { val dataSource = new JdbcDataSource val name = s"$h2DbName-${Random.nextInt(1000)}" println(s"****> h2-name: '$name'") dataSource.setURL(s"jdbc:h2:mem:$name;mode=oracle;DB_CLOSE_DELAY=-1") dataSource.setUser("sa") dataSource.setPassword("sa") // We need to grab a connection and not release it to prevent the db from being // released when no connections are active.. dataSource.getConnection updateDb(dataSource, pathToLiquibaseFile) dataSource } } private def createLiquibase(dbConnection: Connection, diffFilePath: String): Liquibase = { val database = DatabaseFactory.getInstance.findCorrectDatabaseImplementation(new JdbcConnection(dbConnection)) val classLoader = DataSourceUtil.getClass.getClassLoader val resourceAccessor = new ClassLoaderResourceAccessor(classLoader) new Liquibase(diffFilePath, resourceAccessor, database) } private def updateDb(db: DataSource, diffFilePath: String): Unit = { val dbConnection = db.getConnection val liquibase = createLiquibase(dbConnection, diffFilePath) try { liquibase.update(null.asInstanceOf[Contexts]) } catch { case e: Throwable => throw e } finally { liquibase.forceReleaseLocks() dbConnection.rollback() dbConnection.close() } } }
Example 30
Source File: DataSourceUtil.scala From akka-tools with MIT License | 5 votes |
package no.nextgentel.oss.akkatools.persistence.jdbcjournal import java.sql.Connection import java.util.concurrent.atomic.AtomicInteger import javax.sql.DataSource import liquibase.{Contexts, Liquibase} import liquibase.database.DatabaseFactory import liquibase.database.jvm.JdbcConnection import liquibase.resource.ClassLoaderResourceAccessor import org.h2.jdbcx.JdbcDataSource import scala.util.Random object DataSourceUtil { def createDataSource(h2DbName:String, pathToLiquibaseFile:String = "akka-tools-jdbc-journal-liquibase.sql"):DataSource = { this.synchronized { val dataSource = new JdbcDataSource val name = s"$h2DbName-${Random.nextInt(1000)}" println(s"****> h2-name: '$name'") dataSource.setURL(s"jdbc:h2:mem:$name;mode=oracle;DB_CLOSE_DELAY=-1") dataSource.setUser("sa") dataSource.setPassword("sa") // We need to grab a connection and not release it to prevent the db from being // released when no connections are active.. dataSource.getConnection updateDb(dataSource, pathToLiquibaseFile) dataSource } } private def createLiquibase(dbConnection: Connection, diffFilePath: String): Liquibase = { val database = DatabaseFactory.getInstance.findCorrectDatabaseImplementation(new JdbcConnection(dbConnection)) val classLoader = DataSourceUtil.getClass.getClassLoader val resourceAccessor = new ClassLoaderResourceAccessor(classLoader) new Liquibase(diffFilePath, resourceAccessor, database) } private def updateDb(db: DataSource, diffFilePath: String): Unit = { val dbConnection = db.getConnection val liquibase = createLiquibase(dbConnection, diffFilePath) try { liquibase.update(null.asInstanceOf[Contexts]) } catch { case e: Throwable => throw e } finally { liquibase.forceReleaseLocks() dbConnection.rollback() dbConnection.close() } } }