首页 > 数据库技术 > 详细

mysql asyn 实战

时间:2015-03-13 22:18:39      阅读:320      评论:0      收藏:0      [点我收藏+]

创建configuration时,发现URLParser找不到,于是只能使用配置文件来,当然使用配置文件比使用URL初始化还要直观些

  def configurationWithPassword = new Configuration(
    host = "localhost",
    port = 3306,
    username = "root",
    password = Some("123"),
    database = Some("test")
  )

 

Configuration文件本身是case class,它的code是

case class Configuration(username: String,
                         host: String = "localhost",
                         port: Int = 5432,
                         password: Option[String] = None,
                         database: Option[String] = None,
                         charset: Charset = Configuration.DefaultCharset,
                         maximumMessageSize: Int = 16777216,
                         allocator: AbstractByteBufAllocator = PooledByteBufAllocator.DEFAULT,
                         connectTimeout: Duration = 5.seconds,
                         testTimeout: Duration = 5.seconds
                          )

 

这让我想到了slick,slick我连配置文件都搞不出来。总觉得slick的设计有些反人类。

 

对于单连接

  def sinConnection: MySQLConnection = {
    val configuration: Configuration = configurationWithPassword
    new MySQLConnection(configuration)
  }

 

对于线程池连接

  def poolConnection: ConnectionPool[MySQLConnection] = {
    val configuration: Configuration = configurationPool
    val factory = new MySQLConnectionFactory(configuration)
    val pool    = new ConnectionPool[MySQLConnection](factory, PoolConfiguration.Default)
    pool
  }

 

ResultSet并不是java.sql.resultSet而是作者自己创建的新类型

trait ResultSet extends IndexSeq[RowData]

而rowData则表示一行数据,也是一个顺序表

trait RowData extends IndexedSeq[Any]

这样,ResultSet就像是个二维表了

 

mysql asyn 实战

原文:http://www.cnblogs.com/xinsheng/p/4336066.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!