最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

executor包執(zhí)行器功能

 更新時間:2022年02月18日 09:37:26   作者:灰太狼_cxh  
這篇文章主要介紹了executor包執(zhí)行器功能,executor包中的各個子包提供的功能,最終這些功能都由Executor接口及其實現(xiàn)類共同對外提供服務。下文介紹該執(zhí)行功能,具有一定的參考價值,需要的朋友可以考一下

Executor接口基于以下方法可以完成增,刪,改查以及事務處理等操作。事實上,mybatis中的所有數(shù)據(jù)庫操作是通過調(diào)用這些方法實現(xiàn)的。

public interface Executor {
?
? ResultHandler NO_RESULT_HANDLER = null;
?
? // 數(shù)據(jù)更新操作,其中數(shù)據(jù)的增加、刪除、更新均可由該方法實現(xiàn)
? int update(MappedStatement ms, Object parameter) throws SQLException;
? // 數(shù)據(jù)查詢操作,返回結(jié)果為列表形式
? <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey cacheKey, BoundSql boundSql) throws SQLException;
? // 數(shù)據(jù)查詢操作,返回結(jié)果為列表形式
? /**
? ?* 執(zhí)行查詢操作
? ?* @param ms 映射語句對象
? ?* @param parameter 參數(shù)對象
? ?* @param rowBounds 翻頁限制
? ?* @param resultHandler 結(jié)果處理器
? ?* @param <E> 輸出結(jié)果類型
? ?* @return 查詢結(jié)果
? ?* @throws SQLException
? ?*/
? <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler) throws SQLException;
? // 數(shù)據(jù)查詢操作,返回結(jié)果為游標形式
? <E> Cursor<E> queryCursor(MappedStatement ms, Object parameter, RowBounds rowBounds) throws SQLException;
? // 清理緩存
? List<BatchResult> flushStatements() throws SQLException;
? // 提交事務
? void commit(boolean required) throws SQLException;
? // 回滾事務
? void rollback(boolean required) throws SQLException;
? // 創(chuàng)建當前查詢的緩存鍵值
? CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql);
? // 本地緩存是否有指定值
? boolean isCached(MappedStatement ms, CacheKey key);
? // 清理本地緩存
? void clearLocalCache();
? // 懶加載
? void deferLoad(MappedStatement ms, MetaObject resultObject, String property, CacheKey key, Class<?> targetType);
? // 獲取事務
? Transaction getTransaction();
? // 關(guān)閉執(zhí)行器
? void close(boolean forceRollback);
? // 判斷執(zhí)行器是否關(guān)閉
? boolean isClosed();
? // 設(shè)置執(zhí)行器包裝
? void setExecutorWrapper(Executor executor);
?
}

BaseExecutor是一個抽象類,并用到了模板模式,實現(xiàn)了其子類的一些共有的基礎(chǔ)功能,而將與子類直接相關(guān)的操作交給子類處理。

public abstract class BaseExecutor implements Executor {
?
? private static final Log log = LogFactory.getLog(BaseExecutor.class);
?
? protected Transaction transaction;
? protected Executor wrapper;
?
? protected ConcurrentLinkedQueue<DeferredLoad> deferredLoads;
? // 查詢操作的結(jié)果緩存
? protected PerpetualCache localCache;
? // Callable查詢的輸出參數(shù)緩存
? protected PerpetualCache localOutputParameterCache;
? protected Configuration configuration;
?
? protected int queryStack;
? private boolean closed;
?
?
?
?
? /**
? ?* 更新數(shù)據(jù)庫數(shù)據(jù),INSERT/UPDATE/DELETE三種操作都會調(diào)用該方法
? ?* @param ms 映射語句
? ?* @param parameter 參數(shù)對象
? ?* @return 數(shù)據(jù)庫操作結(jié)果
? ?* @throws SQLException
? ?*/
? @Override
? public int update(MappedStatement ms, Object parameter) throws SQLException {
? ? ErrorContext.instance().resource(ms.getResource())
? ? ? ? ? ? .activity("executing an update").object(ms.getId());
? ? if (closed) {
? ? ? // 執(zhí)行器已經(jīng)關(guān)閉
? ? ? throw new ExecutorException("Executor was closed.");
? ? }
? ? // 清理本地緩存
? ? clearLocalCache();
? ? // 返回調(diào)用子類進行操作
? ? return doUpdate(ms, parameter);
? }
?
??
?
? /**
? ?* 執(zhí)行查詢操作
? ?* @param ms 映射語句對象
? ?* @param parameter 參數(shù)對象
? ?* @param rowBounds 翻頁限制
? ?* @param resultHandler 結(jié)果處理器
? ?* @param <E> 輸出結(jié)果類型
? ?* @return 查詢結(jié)果
? ?* @throws SQLException
? ?*/
? @Override
? public <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler) throws SQLException {
? ? BoundSql boundSql = ms.getBoundSql(parameter);
? ? // 生成緩存的鍵
? ? CacheKey key = createCacheKey(ms, parameter, rowBounds, boundSql);
? ? return query(ms, parameter, rowBounds, resultHandler, key, boundSql);
? }
?
? /**
? ?* 查詢數(shù)據(jù)庫中的數(shù)據(jù)
? ?* @param ms 映射語句
? ?* @param parameter 參數(shù)對象
? ?* @param rowBounds 翻頁限制條件
? ?* @param resultHandler 結(jié)果處理器
? ?* @param key 緩存的鍵
? ?* @param boundSql 查詢語句
? ?* @param <E> 結(jié)果類型
? ?* @return 結(jié)果列表
? ?* @throws SQLException
? ?*/
? @SuppressWarnings("unchecked")
? @Override
? public <E> List<E> query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, CacheKey key, BoundSql boundSql) throws SQLException {
? ? ErrorContext.instance().resource(ms.getResource()).activity("executing a query").object(ms.getId());
? ? if (closed) {
? ? ? // 執(zhí)行器已經(jīng)關(guān)閉
? ? ? throw new ExecutorException("Executor was closed.");
? ? }
? ? if (queryStack == 0 && ms.isFlushCacheRequired()) { // 新的查詢棧且要求清除緩存
? ? ? // 清除一級緩存
? ? ? clearLocalCache();
? ? }
? ? List<E> list;
? ? try {
? ? ? queryStack++;
? ? ? // 嘗試從本地緩存獲取結(jié)果
? ? ? list = resultHandler == null ? (List<E>) localCache.getObject(key) : null;
? ? ? if (list != null) {
? ? ? ? // 本地緩存中有結(jié)果,則對于CALLABLE語句還需要綁定到IN/INOUT參數(shù)上
? ? ? ? handleLocallyCachedOutputParameters(ms, key, parameter, boundSql);
? ? ? } else {
? ? ? ? // 本地緩存沒有結(jié)果,故需要查詢數(shù)據(jù)庫
? ? ? ? list = queryFromDatabase(ms, parameter, rowBounds, resultHandler, key, boundSql);
? ? ? }
? ? } finally {
? ? ? queryStack--;
? ? }
? ? if (queryStack == 0) {
? ? ? // 懶加載操作的處理
? ? ? for (DeferredLoad deferredLoad : deferredLoads) {
? ? ? ? deferredLoad.load();
? ? ? }
? ? ? deferredLoads.clear();
? ? ? // 如果本地緩存的作用域為STATEMENT,則立刻清除本地緩存
? ? ? if (configuration.getLocalCacheScope() == LocalCacheScope.STATEMENT) {
? ? ? ? clearLocalCache();
? ? ? }
? ? }
? ? return list;
? }
?
??
?
? /**
? ?* 生成查詢的緩存的鍵
? ?* @param ms 映射語句對象
? ?* @param parameterObject 參數(shù)對象
? ?* @param rowBounds 翻頁限制
? ?* @param boundSql 解析結(jié)束后的SQL語句
? ?* @return 生成的鍵值
? ?*/
? @Override
? public CacheKey createCacheKey(MappedStatement ms, Object parameterObject, RowBounds rowBounds, BoundSql boundSql) {
? ? if (closed) {
? ? ? throw new ExecutorException("Executor was closed.");
? ? }
? ? // 創(chuàng)建CacheKey,并將所有查詢參數(shù)依次更新寫入
? ? CacheKey cacheKey = new CacheKey();
? ? cacheKey.update(ms.getId());
? ? cacheKey.update(rowBounds.getOffset());
? ? cacheKey.update(rowBounds.getLimit());
? ? cacheKey.update(boundSql.getSql());
? ? List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
? ? TypeHandlerRegistry typeHandlerRegistry = ms.getConfiguration().getTypeHandlerRegistry();
? ? for (ParameterMapping parameterMapping : parameterMappings) {
? ? ? if (parameterMapping.getMode() != ParameterMode.OUT) {
? ? ? ? Object value;
? ? ? ? String propertyName = parameterMapping.getProperty();
? ? ? ? if (boundSql.hasAdditionalParameter(propertyName)) {
? ? ? ? ? value = boundSql.getAdditionalParameter(propertyName);
? ? ? ? } else if (parameterObject == null) {
? ? ? ? ? value = null;
? ? ? ? } else if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {
? ? ? ? ? value = parameterObject;
? ? ? ? } else {
? ? ? ? ? MetaObject metaObject = configuration.newMetaObject(parameterObject);
? ? ? ? ? value = metaObject.getValue(propertyName);
? ? ? ? }
? ? ? ? cacheKey.update(value);
? ? ? }
? ? }
? ? if (configuration.getEnvironment() != null) {
? ? ? cacheKey.update(configuration.getEnvironment().getId());
? ? }
? ? return cacheKey;
? }
}

BaseExecutor有四個實現(xiàn)類:

  • CloseExecutor :僅表明自身已經(jīng)關(guān)閉的執(zhí)行器,沒有其他實際功能
  • SimpleExecutor : 一個最為簡單的執(zhí)行器
  • BatchExecutor :支持批量執(zhí)行功能的執(zhí)行器
  • ReuseExecutor : 支持Statement對象復用的執(zhí)行器。

SimpleExecutor,BatchExecutor,ReuseExecutor 這三個執(zhí)行器的選擇是在mybatis的配置文件中進行的,可選的值由session包中的ExecutorType定義,這三個執(zhí)行器主要基于StatementHandler完成創(chuàng)建Statement對象,綁定參數(shù)等工作。

到此這篇關(guān)于executor包執(zhí)行器功能的文章就介紹到這了,更多相關(guān)executor包內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

阳东县| 华池县| 理塘县| 天门市| 类乌齐县| 蓬溪县| 新营市| 富阳市| 无棣县| 仪陇县| 会宁县| 嫩江县| 新晃| 化德县| 左云县| 宝坻区| 绥德县| 白城市| 轮台县| 江安县| 上饶县| 鱼台县| 垦利县| 济宁市| 门头沟区| 曲沃县| 阿克苏市| 河西区| 北碚区| 茌平县| 台中市| 汶上县| 弥勒县| 上蔡县| 武安市| 江都市| 甘洛县| 伊宁市| 鄂尔多斯市| 三台县| 岚皋县|