当前位置:网站首页>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.
边栏推荐
- 数据湖(十一):Iceberg表数据组织与查询
- /Bin/ld: cannot find -lcrypto
- How to import a billion level offline CSV into Nepal graph
- Target detection - make your own deep learning target detection data set with labelimg
- Route service grid traffic through two-level gateway design
- 仙人掌之歌——投石问路(2)
- TypeScript数组乱序输出
- Use ffmpeg command line to push UDP and RTP streams (H264 and TS), and ffplay receives
- SQLServer查询哪些索引利用率低
- Kubernetes family container housekeeper pod online Q & A?
猜你喜欢
结构体的内存对齐
Does bone conduction earphone have external sound? Advantages of bone conduction earphones
The light of ideal never dies
PyC file decompile
Everyone Xinfu builds: a one-stop intelligent business credit service platform
2020.4.12 byte written test questions B DP D monotone stack
Memory alignment of structure
MySQL calculates the data within the longitude and latitude range
2022最新最详细必成功的在Vscode中设置背景图、同时解决不受支持的问题
总结|机器视觉中三大坐标系及其相互关系
随机推荐
How to import a billion level offline CSV into Nepal graph
mysql min() 求某条件下最小的值出现多个结果
Invalid bound statement (not found)解决方法总结
Bean configuration override in boot
Text intelligent expansion and contraction control of swiftui text component (tutorial includes source code)
Storage, reading and writing of blood relationship data of Nepal Graph & Data Warehouse
Yyds dry goods inventory hands-on teaching you to carry out the packaging and release of mofish Library (fishing Library)
Remove the underline in router link
After the win10 system is upgraded for a period of time, the memory occupation is too high
Pattern matching extraction of specific subgraphs in graphx graph Computing Practice
Write your own CPU Chapter 11 - learning notes
By asp Net core downloads files according to the path exception
Application of visualization technology in Nebula graph
Vscode设置标签页多行显示
/Bin/ld: cannot find -lxslt
图数据库|Nebula Graph v3.1.0 性能报告
由ASP.NET Core根据路径下载文件异常引发的探究
Invalid bound statement (not found) solution summary
理想之光不灭
基于 Nebula Graph 构建百亿关系知识图谱实践