Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the function of java's executor package?

2025-04-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "what is the function of java's executor package", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what is the function of java's executor package"?

Parameter assignments in the sql statement are done by the parameter subpackage in the executor package.

The parameter subpackage actually has only one parameterHandler interface, which defines two methods:

Public interface ParameterHandler {Object getParameterObject (); void setParameters (PreparedStatement ps) throws SQLException;}

The ParameterHandler interface has a default implementation class, DefaultParameterHandler, which is in the subpackage of the scripting package.

The statement type that supports parameter setting in mybatis is the PreparedStatement interface and its subinterface CallableStatement, so the input parameter of setParameters is the PreparedStatement type.

The implementation logic of the setParameters method is to take out the value of each parameter in turn, and then call the assignment method in PreparedStatement according to the parameter type.

Public class DefaultParameterHandler implements ParameterHandler {/ / Type processor registry private final TypeHandlerRegistry typeHandlerRegistry; / / MappedStatement object (contains complete add, delete, change and check node information) private final MappedStatement mappedStatement; / / parameter object private final Object parameterObject; / / BoundSql object (contains SQL statements, 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 statement * @ param ps statement * / @ Override public void setParameters (PreparedStatement ps) {ErrorContext.instance () .activity ("setting parameters") .object (mappedStatement.getParameterMap () .getId ()) / / take out the parameter list List parameterMappings = boundSql.getParameterMappings (); if (parameterMappings! = null) {for (int I = 0; I < parameterMappings.size (); iTunes +) {ParameterMapping parameterMapping = parameterMappings.get (I); / / ParameterMode.OUT is the output parameter of CallableStatement and has been 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 the attribute value value = boundSql.getAdditionalParameter (propertyName) from the additional parameter } else if (parameterObject = = null) {value = null;} else if (typeHandlerRegistry.hasTypeHandler (parameterObject.getClass () {/ / the parameter object is the basic type, then the parameter object is the parameter value value = parameterObject } else {/ / the parameter object is a complex type. Take out the attribute value of the parameter object MetaObject metaObject = configuration.newMetaObject (parameterObject); value = metaObject.getValue (propertyName);} / / the processor that determines the parameter TypeHandler typeHandler = parameterMapping.getTypeHandler (); JdbcType jdbcType = parameterMapping.getJdbcType () If (value = = null & & jdbcType = = null) {jdbcType = configuration.getJdbcTypeForNull ();} try {/ / this method finally calls the parameter assignment method in the java.sql.PreparedStatement class according to the parameter type, and assigns typeHandler.setParameter (ps, I + 1, value, jdbcType) to the parameters in the SQL statement. } catch (TypeException | SQLException e) {throw new TypeException ("Could not set parameters for mapping:" + parameterMapping + ". Cause: "+ e, e);} at this point, I believe you have a deeper understanding of" what is the function of java's executor package ". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 268

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report