SIMPLE/REUSE/BATCH 三种执行器的区别?
生活随笔
收集整理的這篇文章主要介紹了
SIMPLE/REUSE/BATCH 三种执行器的区别?
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
SimpleExecutor 使用后直接關閉Statement:closeStatement(stmt);
// SimpleExecutor.java public int doUpdate(MappedStatement ms, Object parameter) throws SQLException {Statement stmt = null;//中間省略……} finally {closeStatement(stmt);} }ReuseExecutor 放在緩存中,可復用:PrepareStatement——getStatement()
// ReuseExecutor.Java public int doUpdate(MappedStatement ms, Object parameter) throws SQLException {//中間省略……Statement stmt = prepareStatement(handler, ms.getStatementLog());//中間省略…… } private Statement prepareStatement(StatementHandler handler, Log statementLog) throws SQLException {Statement stmt;//中間省略……if (hasStatementFor(sql)) {stmt = getStatement(sql);//中間省略……} private Statement getStatement(String s) {return statementMap.get(s); }BatchExecutor 支持復用且可以批量執行update(),通過ps.addBatch()實現handler.batch(stmt);
// BatchExecutor.Java public int doUpdate(MappedStatement ms, Object parameterObject) throws SQLException {//中間省略……final Statement stmt;//中間省略……stmt = statementList.get(last);//中間省略……statementList.add(stmt);batchResultList.add(new BatchResult(ms, sql, parameterObject)); }handler.batch(stmt); }?
總結
以上是生活随笔為你收集整理的SIMPLE/REUSE/BATCH 三种执行器的区别?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java 类型和数据库类型怎么实现相互映
- 下一篇: MyBatis 一级缓存与二级缓存的区别