中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當前位置: 首頁 > news >正文

那里可以做旅游網(wǎng)站的嗎我們公司在做網(wǎng)站推廣

那里可以做旅游網(wǎng)站的嗎,我們公司在做網(wǎng)站推廣,用asp做的網(wǎng)站有多少,寧波 做網(wǎng)站的前言: 前文我們從源碼層面梳理了 SqlSessionFactory 的創(chuàng)建過程,本篇我們繼續(xù)分析一下 SqlSession 的獲取過程。 初識 MyBatis 【MyBatis 核心概念】 案例代碼: public class MyBatisTest {Testpublic void test() throws IOException {/…

前言:

前文我們從源碼層面梳理了 SqlSessionFactory 的創(chuàng)建過程,本篇我們繼續(xù)分析一下 SqlSession 的獲取過程。

初識 MyBatis 【MyBatis 核心概念】

案例代碼:

public class MyBatisTest {@Testpublic void test() throws IOException {//讀取配置文件InputStream is = Resources.getResourceAsStream("mybatis-config.xml");//創(chuàng)建 SqlSessionFactoryBuilder 對象SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();//通過 SqlSessionBuilder 對象 解析 mybatis-config.xml 文件 構(gòu)建一個SqlSessionFactory SqlSessionFactory sqlSessionFactory = builder.build(is);//通過SqlSessionFactory構(gòu)建一個SqlSessionSqlSession session = sqlSessionFactory.openSession();//通過SqlSession 獲取 Mapper 實例UserMapper userMapper = session.getMapper(UserMapper.class);//獲取數(shù)據(jù)List<User> users = userMapper.findAll();//打印輸出for (User user : users) {System.out.println(user);}//關(guān)閉資源session.close();is.close();}
}

本篇我們將主要對 sqlSessionFactory.openSession() 這句代碼進行分析。

獲取 SqlSession 源碼分析

DefaultSqlSessionFactory#openSession 方法源碼分析

DefaultSqlSessionFactory#openSession 方法只是調(diào)用了 DefaultSqlSessionFactory#openSessionFromDataSource 方法,并傳入了默認的執(zhí)行器類型、隔離級別、是否自動提交參數(shù)。

//org.apache.ibatis.session.defaults.DefaultSqlSessionFactory#openSession()
public SqlSession openSession() {//使用默認的執(zhí)行器類型(默認是SIMPLE) 默認隔離級別 非自動提交 委托給 openSessionFromDataSource 方法return this.openSessionFromDataSource(this.configuration.getDefaultExecutorType(), (TransactionIsolationLevel)null, false);
}

執(zhí)行器類型

  • SIMPLE:簡單執(zhí)行器 SimpleExecutor,每執(zhí)行一條 SQL,都會打開一個 Statement,執(zhí)行完成后會關(guān)閉。
  • REUSE:重用執(zhí)行器 ReuseExecutor,其內(nèi)部會緩存一個 Map<String, Statement> ,每次編譯完成的 Statement 都會進行緩存,不會關(guān)閉,可以重復(fù)使用。
  • BATCH:批量執(zhí)行器,基于 JDBC 的 addBatch、executeBatch 功能,只能作用于 insert、update、delete 語句。
  • CachingExecutor:緩存執(zhí)行器,使用了裝飾器模式,在開啟緩存的時候,會在上面三種執(zhí)行器上包裝一層 CachingExecutor。
package org.apache.ibatis.session;public enum ExecutorType {SIMPLE,REUSE,BATCH;private ExecutorType() {}
}

DefaultSqlSessionFactory#openSessionFromDataSource 方法源碼分析

DefaultSqlSessionFactory#openSessionFromDataSource 方法邏輯很簡單,先獲取創(chuàng)建 SqlSession 的必要參數(shù),然后調(diào)用 DefaultSqlSession 的構(gòu)造方法創(chuàng)建了 SqlSession 。

//org.apache.ibatis.session.defaults.DefaultSqlSessionFactory#openSessionFromDataSource
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) {//事務(wù)Transaction tx = null;//SqlSessionDefaultSqlSession var8;try {//獲取環(huán)境Environment environment = this.configuration.getEnvironment();//獲取事務(wù)工廠TransactionFactory transactionFactory = this.getTransactionFactoryFromEnvironment(environment);//獲取一個事務(wù)tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit);//根據(jù) 事務(wù) 和 執(zhí)行器類型創(chuàng)建一個執(zhí)行器Executor executor = this.configuration.newExecutor(tx, execType);//根據(jù)配置 執(zhí)行器 事務(wù)提交方式創(chuàng)建一個默認的 SqlSessionvar8 = new DefaultSqlSession(this.configuration, executor, autoCommit);} catch (Exception var12) {this.closeTransaction(tx);throw ExceptionFactory.wrapException("Error opening session.  Cause: " + var12, var12);} finally {ErrorContext.instance().reset();}return var8;
}//org.apache.ibatis.session.defaults.DefaultSqlSession#DefaultSqlSession(org.apache.ibatis.session.Configuration, org.apache.ibatis.executor.Executor, boolean)
public DefaultSqlSession(Configuration configuration, Executor executor, boolean autoCommit) {this.configuration = configuration;this.executor = executor;this.dirty = false;this.autoCommit = autoCommit;
}

Configuration#newExecutor 方法源碼分析

Configuration#newExecutor 主要是對執(zhí)行器類型進行判斷,然后生成執(zhí)行器,并通過動態(tài)代理得到代理對象,并將執(zhí)行器加入攔截器鏈。

//org.apache.ibatis.session.Configuration#newExecutor
public Executor newExecutor(Transaction transaction, ExecutorType executorType) {executorType = executorType == null ? this.defaultExecutorType : executorType;executorType = executorType == null ? ExecutorType.SIMPLE : executorType;Object executor;//執(zhí)行器類型判斷if (ExecutorType.BATCH == executorType) {executor = new BatchExecutor(this, transaction);} else if (ExecutorType.REUSE == executorType) {executor = new ReuseExecutor(this, transaction);} else {executor = new SimpleExecutor(this, transaction);}//是否開啟緩存if (this.cacheEnabled) {//開啟緩存 創(chuàng)建緩存執(zhí)行器executor = new CachingExecutor((Executor)executor);}//責(zé)任鏈模式 將執(zhí)行器加入攔截器鏈 使用JDK動態(tài)代理增強所有的攔截器 Executor executor = (Executor)this.interceptorChain.pluginAll(executor);return executor;
}

獲取 SqlSession 的源碼很簡單,希望可以幫助到有需要的小伙伴。

歡迎提出建議及對錯誤的地方指出糾正。

http://www.risenshineclean.com/news/38088.html

相關(guān)文章:

  • 線上線下購物商城系統(tǒng)衡陽seo快速排名
  • 國內(nèi)做的比較好的網(wǎng)站360優(yōu)化大師
  • 網(wǎng)站的透明圖片怎么做網(wǎng)絡(luò)服務(wù)主要包括
  • 網(wǎng)站開發(fā)定義名稱app優(yōu)化推廣
  • 怎么做網(wǎng)站推廣臨沂關(guān)鍵詞排名手機優(yōu)化軟件
  • 做網(wǎng)站用c語言可以嗎某個網(wǎng)站seo分析實例
  • 電腦版和手機版網(wǎng)站怎么做的營銷推廣策劃方案范文
  • 昆明免費網(wǎng)站制作南昌seo技術(shù)外包
  • 鄭州公共住宅建設(shè)投資有限公司網(wǎng)站一站式媒體發(fā)稿平臺
  • 1000學(xué)習(xí)做網(wǎng)站貴嗎搜索關(guān)鍵詞推薦
  • 網(wǎng)站建設(shè)報價明細表seo優(yōu)化運營
  • 廈門建站服務(wù)百度付費推廣的費用
  • 自助建站門戶網(wǎng)站東莞網(wǎng)絡(luò)優(yōu)化公司
  • 買模板建設(shè)網(wǎng)站亞馬遜關(guān)鍵詞工具哪個最準
  • 電商 做圖 網(wǎng)站網(wǎng)站數(shù)據(jù)分析
  • 平東網(wǎng)站建設(shè)江北seo綜合優(yōu)化外包
  • 網(wǎng)頁游戲網(wǎng)站模板外貿(mào)平臺
  • 重慶房地產(chǎn)新聞上海網(wǎng)站seoseodian
  • 衡陽有線寬帶網(wǎng)站怎么做app推廣
  • 南京網(wǎng)站制作設(shè)計公司尋找客戶的12種方法
  • 企業(yè)寬帶可以做網(wǎng)站嗎安卓優(yōu)化大師手機版下載
  • 免費直播網(wǎng)站開發(fā)seo關(guān)鍵詞優(yōu)化排名
  • 站長工具亞洲中文精品軟文推廣一般發(fā)布在哪些平臺
  • 南京網(wǎng)站建設(shè)蘇icp備蘭州正規(guī)seo整站優(yōu)化
  • 上海市住房與城鄉(xiāng)建設(shè)管理委員會網(wǎng)站網(wǎng)絡(luò)營銷咨詢公司
  • 管理員怎么看網(wǎng)站在線留言越秀seo搜索引擎優(yōu)化
  • 金壇網(wǎng)站建設(shè)哪家好百度網(wǎng)絡(luò)營銷
  • wordpress菜單不現(xiàn)實seo百度快速排名
  • 手機網(wǎng)站怎么做微信登陸6sem技術(shù)培訓(xùn)
  • 網(wǎng)站策劃書模板大全怎么做一個網(wǎng)站的步驟