mybatis的sqlsessionFactory

来源:互联网 发布:中国数据统计年鉴 编辑:程序博客网 时间:2024/05/18 08:05

运行一般是这样,

Created with Raphaël 2.1.0sqlSessionFactorysqlSessionFactorysqlsessionsqlsessionsqlsql返回结果返回结果

所以说,好无意思的一件事。
sqlsession工厂到底是怎么来的, 他是build出来的, 所以,这个其实是设计模式。建工厂,出产品,就这样。

  public SqlSessionFactory build(Configuration config) {    return new DefaultSqlSessionFactory(config);  }

其实是一句话,给工厂 new以下就好了。。。而且, 只有这一个new,只有这一个构造方法。

那么问题来了,我们要配置的东西那么多,肿么可能就一个参数。builder设计模式的关键就是这个, 其实他就是把多个构造器的部分给拆了出去,方便操作。多种配置,最终用了一个单构造器。就好了。

and the factory method pattern whose intention is to enable polymorphism, the intention of the builder pattern is to find a solution to the telescoping constructor anti-pattern[citation needed]. The telescoping constructor anti-pattern occurs when the increase of object constructor parameter combination leads to an exponential list of constructors. Instead of using numerous constructors, the builder pattern uses another object, a builder, that receives each initialization parameter step by step and then returns the resulting constructed object at once.

wiki说的好, 工厂模式,是在做多态, builder,是剥离多构造器。

没白看,学到了。。。
最终构造出来的参数是, configuration 这个的构造过程也是个长征, 还是xmlbuilder做的. 逻辑大致相似.

环境造就人,所以啊, 他还是很负责的.

不管了, 继续看 工厂… 工厂早就sqlsession,有3个重要属性.

如何执行,事务隔离级别,是否自动提交...

这个时候, 这3个参数不一定是明着提交的,有可能是从数据源,或者现有的链接里提取.所以还是重载,orz

大概就是如此咯…

0 0