当前位置:网站首页>Yyds dry inventory executor package (parameter processing function)
Yyds dry inventory executor package (parameter processing function)
2022-07-02 16:14:00 【Grey Wolf_ cxh】
executor package ( Parameter processing function )
sql The parameter assignment in the statement is made by executor In bag parameter Sub package completed .
parameter There is only one sub bag parameterHandler Interface , It defines the 2 A way :
public interface ParameterHandler {
Object getParameterObject();
void setParameters(PreparedStatement ps)
throws SQLException;
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
ParameterHandler Interface has a default implementation class DefaultParameterHandler, It's in scripting In the sub package of the package .
mybatis The statement type that supports parameter setting in is PreparedStatement Interfaces and their sub interfaces CallableStatement, therefore setParameters The input parameter for is PreparedStatement type .
setParameters The implementation logic of the method is to take out the value of each parameter in turn , Then call according to the parameter type PreparedStatement The assignment method in .
public class DefaultParameterHandler implements ParameterHandler {
// Type processor registry
private final TypeHandlerRegistry typeHandlerRegistry;
// MappedStatement object ( It contains complete node information of addition, deletion, modification and query )
private final MappedStatement mappedStatement;
// Parameter object
private final Object parameterObject;
// BoundSql object ( contain SQL sentence 、 Parameters 、 Argument information )
private final BoundSql boundSql;
// Configuration information
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;
}
/**
* Set parameters for the statement
* @param ps sentence
*/
@Override
public void setParameters(PreparedStatement ps) {
ErrorContext.instance().activity("setting parameters").object(mappedStatement.getParameterMap().getId());
// Take out the parameter list
List<ParameterMapping> parameterMappings = boundSql.getParameterMappings();
if (parameterMappings != null) {
for (int i = 0; i < parameterMappings.size(); i++) {
ParameterMapping parameterMapping = parameterMappings.get(i);
// ParameterMode.OUT yes CallableStatement The output parameters of , Already registered separately . So ignore
if (parameterMapping.getMode() != ParameterMode.OUT) {
Object value;
// Take out the attribute name
String propertyName = parameterMapping.getProperty();
if (boundSql.hasAdditionalParameter(propertyName)) {
// Read attribute values from additional parameters
value = boundSql.getAdditionalParameter(propertyName);
} else if (parameterObject == null) {
value = null;
} else if (typeHandlerRegistry.hasTypeHandler(parameterObject.getClass())) {
// Parameter objects are basic types , Then the parameter object is the parameter value
value = parameterObject;
} else {
// Parameter objects are complex types , Get the attribute value of the parameter object
MetaObject metaObject = configuration.newMetaObject(parameterObject);
value = metaObject.getValue(propertyName);
}
// The processor that determines this parameter
TypeHandler typeHandler = parameterMapping.getTypeHandler();
JdbcType jdbcType = parameterMapping.getJdbcType();
if (value == null && jdbcType == null) {
jdbcType = configuration.getJdbcTypeForNull();
}
try {
// This method finally depends on the parameter type , call java.sql.PreparedStatement Parameter assignment method in class , Yes SQL Parameter assignment in a statement
typeHandler.setParameter(ps, i + 1, value, jdbcType);
} catch (TypeException | SQLException e) {
throw new TypeException("Could not set parameters for mapping: " + parameterMapping + ". Cause: " + e, e);
}
}
}
}
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
边栏推荐
- [Xiaobai chat cloud] suggestions on container transformation of small and medium-sized enterprises
- 去除router-link中的下划线
- 数据湖(十一):Iceberg表数据组织与查询
- 处理gzip: stdin: not in gzip formattar: Child returned status 1tar: Error is not recoverable: exitin
- 注册成为harmonyos开发者并安装DevEco Studio 3.0 Beta2 for HarmonyOS
- /Bin/ld: cannot find -lcrypto
- Traversal before, during and after binary tree
- How to import a billion level offline CSV into Nepal graph
- In memory of becoming the first dayu200 tripartite demo contributor
- SQL modification statement
猜你喜欢
Pandora IOT development board learning (RT thread) - Experiment 2 RGB LED experiment (learning notes)
Teach you how to build virtual machines locally and deploy microservices
Huawei ECS installs mysqlb for mysqld service failed because the control process exited with error code. See “sys
Solve * * warning * *: your ApplicationContext is unlikely to start due to a @componentscan of the defau
理想之光不灭
Maui learning road (III) -- in depth discussion of winui3
JS learning notes - operators
Traversal before, during and after binary tree
Introduction to Dynamic Planning II (5.647.62)
微信v3native支付设置的结束时间处理办法
随机推荐
Wise target detection 23 - pytoch builds SSD target detection platform
Boot 事务使用
[Xiaobai chat cloud] suggestions on container transformation of small and medium-sized enterprises
仙人掌之歌——投石问路(2)
Boot 中bean配置覆盖
Leetcode --- longest public prefix
Storage, reading and writing of blood relationship data of Nepal Graph & Data Warehouse
Idea public method extraction shortcut key
智联招聘的基于 Nebula Graph 的推荐实践分享
Use ffmpeg command line to push UDP and RTP streams (H264 and TS), and ffplay receives
AWS云主机扩容
Floyed "suggestions collection"
图数据库|Nebula Graph v3.1.0 性能报告
Remove the underline in router link
中科大脑知识图谱平台建设及业务实践
idea 公共方法抽取快捷键
Maui learning road (III) -- in depth discussion of winui3
day4
Pyinstaller's method of packaging pictures attached to exe
Locate: cannot execute stat() `/var/lib/mlocate/mlocate Db ': there is no such file or directory