conn 配置

来源:互联网 发布:java poijar包 编辑:程序博客网 时间:2024/06/08 16:59

一.

1.Using Typesafe Config

mydb = {  dataSourceClass = "org.postgresql.ds.PGSimpleDataSource"  properties = {    databaseName = "mydb"    user = "myuser"    password = "secret"  }  numThreads = 10}

2.Using a JDBC URL

val db = Database.forURL("jdbc:h2:mem:test1;DB_CLOSE_DELAY=-1", driver="org.h2.Driver")


3.Using a DataSource

val db = Database.forDataSource(dataSource: javax.sql.DataSource)


4.Using a JNDI Name

val db = Database.forName(jndiName: String)


二.Database thread pool

val db = Database.forURL("jdbc:h2:mem:test1;DB_CLOSE_DELAY=-1", driver="org.h2.Driver",  executor = AsyncExecutor("test1", numThreads=10, queueSize=1000))

Tag:

Every Database contains an AsyncExecutor that manages the thread pool for asynchronous execution of Database I/O Actions. Its size is the main parameter to tune for the best performance of the Databaseobject. It should be set to the value that you would use for the size of the connection pool in a traditional, blocking application (see About Pool Sizing in the HikariCP documentation for further information). When using Database.forConfig, the thread pool is configured directly in the external configuration file together with the connection parameters. If you use any other factory method to get a Database, you can either use a default configuration or specify a custom AsyncExecutor:


DatabaseConfig

tsql {  driver = "slick.driver.H2Driver$"  db {    connectionPool = disabled    driver = "org.h2.Driver"    url = "jdbc:h2:mem:tsql1;INIT=runscript from 'src/main/resources/create-schema.sql'"  }}

Tag:

On top of the configuration syntax for Database, there is another layer in the form of DatabaseConfigwhich allows you to configure a Slick driver plus a matching Database together. This makes it easy to abstract over different kinds of database systems by simply changing a configuration file.



0 0
原创粉丝点击