zoukankan      html  css  js  c++  java
  • mysql asyn 实战

    创建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就像是个二维表了

  • 相关阅读:
    Jenkins系列——使用SonarQube进行代码质量检查
    HTTP1.0工作原理
    Jenkins系列——使用checkstyle进行代码规范检查
    Jenkins系列——定时构建
    Hadoop环境搭建
    eclipse3.4+对的处理插件(附SVN插件安装实例)
    MD5
    RedHat6.5更新软件源
    ubuntu软件推荐
    disconf系列【2】——解决zk部署情况为空的问题
  • 原文地址:https://www.cnblogs.com/xinsheng/p/4336066.html
Copyright © 2011-2022 走看看