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

java?executor包參數(shù)處理功能?

 更新時間:2022年02月15日 16:57:50   作者:灰太狼_cxh  
這篇文章主要介紹了java?executor包參數(shù)處理功能,sql語句中的參數(shù)賦值是有由executor包中的parameter子包完成的。parameter子包其實只有一個parameterHandler接口并且它定義了兩個方法,下面我們就來看詳細內容吧,需要的朋友可以參考一下

sql語句中的參數(shù)賦值是有由executor包中的parameter子包完成的。

parameter子包其實只有一個parameterHandler接口,它定義了2個方法:

public interface ParameterHandler {

? Object getParameterObject();

? void setParameters(PreparedStatement ps)
? ? ? throws SQLException;

}

ParameterHandler接口有一個默認的實現(xiàn)類DefaultParameterHandler,它在scripting包的子包中。

mybatis中支持進行參數(shù)設置的語句類型是PreparedStatement接口及其子接口CallableStatement, 所以setParameters的輸入?yún)?shù)是PreparedStatement類型。

setParameters方法的實現(xiàn)邏輯就是依次取出每個參數(shù)的值,然后根據(jù)參數(shù)類型調用PreparedStatement中的賦值方法進行賦值。

public class DefaultParameterHandler implements ParameterHandler {
? // 類型處理器注冊表
? private final TypeHandlerRegistry typeHandlerRegistry;
? // MappedStatement對象(包含完整的增刪改查節(jié)點信息)
? private final MappedStatement mappedStatement;
? // 參數(shù)對象
? private final Object parameterObject;
? // BoundSql對象(包含SQL語句、參數(shù)、實參信息)
? private final BoundSql boundSql;
? // 配置信息
? private final Configuration configuration;

? public DefaultParameterHandler(MappedStatement mappedStatement, Object parameterObject, BoundSql boundSql) {
? ? this.mappedStatement = mappedStatement;
? ? this.configuration = mappedStatement.getConfiguration();
? ? this.typeHandlerRegistry = mappedStatement.getConfiguration().getTypeHandlerRegistry();
? ? this.parameterObject = parameterObject;
? ? this.boundSql = boundSql;
? }

? @Override
? public Object getParameterObject() {
? ? return parameterObject;
? }

? /**
? ?* 為語句設置參數(shù)
? ?* @param ps 語句
? ?*/
? @Override
? public void setParameters(PreparedStatement ps) {
? ? ErrorContext.instance().activity("setting parameters").object(mappedStatement.getParameterMap().getId());
? ? // 取出參數(shù)列表
? ? List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
? ? if (parameterMappings != null) {
? ? ? for (int i = 0; i < parameterMappings.size(); i++) {
? ? ? ? ParameterMapping parameterMapping = parameterMappings.get(i);
? ? ? ? // ParameterMode.OUT是CallableStatement的輸出參數(shù),已經單獨注冊。故忽略
? ? ? ? if (parameterMapping.getMode() != ParameterMode.OUT) {
? ? ? ? ? Object value;
? ? ? ? ? // 取出屬性名稱
? ? ? ? ? String propertyName = parameterMapping.getProperty();
? ? ? ? ? if (boundSql.hasAdditionalParameter(propertyName)) {
? ? ? ? ? ? // 從附加參數(shù)中讀取屬性值
? ? ? ? ? ? value = boundSql.getAdditionalParameter(propertyName);
? ? ? ? ? } else if (parameterObject == null) {
? ? ? ? ? ? value = null;
? ? ? ? ? } else if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {
? ? ? ? ? ? // 參數(shù)對象是基本類型,則參數(shù)對象即為參數(shù)值
? ? ? ? ? ? value = parameterObject;
? ? ? ? ? } else {
? ? ? ? ? ? // 參數(shù)對象是復雜類型,取出參數(shù)對象的該屬性值
? ? ? ? ? ? MetaObject metaObject = configuration.newMetaObject(parameterObject);
? ? ? ? ? ? value = metaObject.getValue(propertyName);
? ? ? ? ? }
? ? ? ? ? // 確定該參數(shù)的處理器
? ? ? ? ? TypeHandler typeHandler = parameterMapping.getTypeHandler();
? ? ? ? ? JdbcType jdbcType = parameterMapping.getJdbcType();
? ? ? ? ? if (value == null && jdbcType == null) {
? ? ? ? ? ? jdbcType = configuration.getJdbcTypeForNull();
? ? ? ? ? }
? ? ? ? ? try {
? ? ? ? ? ? // 此方法最終根據(jù)參數(shù)類型,調用java.sql.PreparedStatement類中的參數(shù)賦值方法,對SQL語句中的參數(shù)賦值
? ? ? ? ? ? typeHandler.setParameter(ps, i + 1, value, jdbcType);
? ? ? ? ? } catch (TypeException | SQLException e) {
? ? ? ? ? ? throw new TypeException("Could not set parameters for mapping: " + parameterMapping + ". Cause: " + e, e);
? ? ? ? ? }
? ? ? ? }
? ? ? }
? ? }
? }

}

到此這篇關于java executor包參數(shù)處理功能 的文章就介紹到這了,更多相關executor包參數(shù)處理功能 內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論

宁德市| 林西县| 沅陵县| 林甸县| 禹城市| 青浦区| 西吉县| 武隆县| 九江市| 三门县| 东乌珠穆沁旗| 碌曲县| 恭城| 罗平县| 寿光市| 平安县| 东乌珠穆沁旗| 石景山区| 出国| 德安县| 德格县| 泽库县| 鸡西市| 齐齐哈尔市| 天祝| 武宁县| 肥东县| 阿城市| 榆社县| 张掖市| 宝山区| 洛南县| 宁晋县| 沙湾县| 阜平县| 三穗县| 蒙城县| 手游| 新邵县| 星子县| 资兴市|