当前位置:网站首页>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.
边栏推荐
- Usage of group by
- Use ffmpeg command line to push UDP and RTP streams (H264 and TS), and ffplay receives
- 图数据库|Nebula Graph v3.1.0 性能报告
- How to use percona tool to add fields to MySQL table after interruption
- Analysis of the difference between array and linked list
- Flink real-time data warehouse (7): Flink realizes the full pull module to extract data in MySQL
- Bone conduction non ear Bluetooth headset brand, bone conduction Bluetooth headset brand recommendation
- mysql 计算经纬度范围内的数据
- 中科大脑知识图谱平台建设及业务实践
- Solve * * warning * *: your ApplicationContext is unlikely to start due to a @componentscan of the defau
猜你喜欢
dried food! Understand the structural vulnerability of graph convolution networks
Another graduation season
The sea of stars hidden behind the nebula graph
Crawl the information of national colleges and universities in 1 minute and make it into a large screen for visualization!
基于 Nebula Graph 构建百亿关系知识图谱实践
去除router-link中的下划线
Construction and business practice of Zhongke brain knowledge map platform
解决** WARNING ** : Your ApplicationContext is unlikely to start due to a @ComponentScan of the defau
Everyone Xinfu builds: a one-stop intelligent business credit service platform
Yyds dry goods inventory student attendance system based on QT design
随机推荐
Usage of group by
Multi data source configuration code
Construction and business practice of Zhongke brain knowledge map platform
Locate: cannot execute stat() `/var/lib/mlocate/mlocate Db ': there is no such file or directory
隐藏在 Nebula Graph 背后的星辰大海
如何實現十億級離線 CSV 導入 Nebula Graph
/Bin/ld: cannot find -lcrypto
/Bin/ld: cannot find -llz4
(practice C language every day) the sum of the nearest three numbers
Target detection - make your own deep learning target detection data set with labelimg
/Bin/ld: cannot find -lxslt
Mobile web development learning notes - Layout
HMS core machine learning service helps zaful users to shop conveniently
Bone conduction non ear Bluetooth headset brand, bone conduction Bluetooth headset brand recommendation
Another graduation season
/Bin/ld: cannot find -lxml2
GraphX 图计算实践之模式匹配抽取特定子图
[fluent] dart data type string type (string definition | string splicing | string API call)
Wise target detection 23 - pytoch builds SSD target detection platform
Fastjson list to jsonarray and jsonarray to list "suggested collections"