当前位置: 首页 > news >正文

视频素材库在哪里找赣州网站优化

视频素材库在哪里找,赣州网站优化,wordpress怎么进,建筑工程公司取名免费一、前言 日常工作中#xff0c;我们用到mybatis的时候#xff0c;都是写一个Mapper接口xml文件/注解形式#xff0c;然后就可以在业务层去调用我们在Mapper接口中定义的CRUD方法#xff0c;很方便#xff0c;但一直都没有去研究过执行逻辑#xff0c;下面附一篇我自己研…一、前言 日常工作中我们用到mybatis的时候都是写一个Mapper接口xml文件/注解形式然后就可以在业务层去调用我们在Mapper接口中定义的CRUD方法很方便但一直都没有去研究过执行逻辑下面附一篇我自己研究的过程。 二、注入过程分析 平时我们在使用时都是直接注解标在Mapper接口上从而去注入一个实例但我们是并没有实现过这个Mapper接口的就很容易想到必然是有一个代理类(MapperProxy)来帮我们执行真正的过程而且既然我们定义了接口那大概率就是JDK动态代理了。 注入的过程也比较简单在我们使用时会注明一个mapper扫描的包路径然后在SqlSessionFactory初始化的过程中会去解析每个mapper接口并将其放在Configuration的MapperRegistry中实际存放位置是在MapperRegistry中MapClass?, MapperProxyFactory? knownMappers。 接下来我们在使用mapper接口时会从knownMappers中去获取到对应的MapperProxyFactory从而去实例化真正的代理类代码如下 public T void addMapper(ClassT type) {if (type.isInterface()) {if (hasMapper(type)) {throw new BindingException(Type type is already known to the MapperRegistry.);}boolean loadCompleted false;try {knownMappers.put(type, new MapperProxyFactoryT(type));// Its important that the type is added before the parser is run// otherwise the binding may automatically be attempted by the// mapper parser. If the type is already known, it wont try.MapperAnnotationBuilder parser new MapperAnnotationBuilder(config, type);parser.parse();loadCompleted true;} finally {if (!loadCompleted) {knownMappers.remove(type);}}}} public T T getMapper(ClassT type, SqlSession sqlSession) {final MapperProxyFactoryT mapperProxyFactory (MapperProxyFactoryT) knownMappers.get(type);if (mapperProxyFactory null) {throw new BindingException(Type type is not known to the MapperRegistry.);}try {//关键步骤里面会使用JDK动态代理创建一个MapperProxyreturn mapperProxyFactory.newInstance(sqlSession);} catch (Exception e) {throw new BindingException(Error getting mapper instance. Cause: e, e);}} public class MapperProxyFactoryT {private final ClassT mapperInterface;private final MapMethod, MapperMethod methodCache new ConcurrentHashMapMethod, MapperMethod();public MapperProxyFactory(ClassT mapperInterface) {this.mapperInterface mapperInterface;}public ClassT getMapperInterface() {return mapperInterface;}public MapMethod, MapperMethod getMethodCache() {return methodCache;}SuppressWarnings(unchecked)protected T newInstance(MapperProxyT mapperProxy) {return (T) Proxy.newProxyInstance(mapperInterface.getClassLoader(), new Class[] { mapperInterface }, mapperProxy);}public T newInstance(SqlSession sqlSession) {final MapperProxyT mapperProxy new MapperProxyT(sqlSession, mapperInterface, methodCache);return newInstance(mapperProxy);}} 三、执行过程分析 综上来看其实我们真正的方法是由MapperProxy来实现的接下来看看它的逻辑我们主要分析查询类的执行流程 /*** 执行入口*/Overridepublic Object invoke(Object proxy, Method method, Object[] args) throws Throwable {try {if (Object.class.equals(method.getDeclaringClass())) {return method.invoke(this, args);} else if (isDefaultMethod(method)) {return invokeDefaultMethod(proxy, method, args);}} catch (Throwable t) {throw ExceptionUtil.unwrapThrowable(t);}//缓存方法final MapperMethod mapperMethod cachedMapperMethod(method);//真正的执行逻辑return mapperMethod.execute(sqlSession, args);}/** * 根据sql类型执行不同的分支 * convertArgsToSqlCommandParam会转换传入的参数 */ public Object execute(SqlSession sqlSession, Object[] args) {Object result;switch (command.getType()) {case INSERT: {Object param method.convertArgsToSqlCommandParam(args);result rowCountResult(sqlSession.insert(command.getName(), param));break;}case UPDATE: {Object param method.convertArgsToSqlCommandParam(args);result rowCountResult(sqlSession.update(command.getName(), param));break;}case DELETE: {Object param method.convertArgsToSqlCommandParam(args);result rowCountResult(sqlSession.delete(command.getName(), param));break;}case SELECT://如果是void方法并且自定义了ResultMap等映射则执行此逻辑if (method.returnsVoid() method.hasResultHandler()) {executeWithResultHandler(sqlSession, args);result null;} else if (method.returnsMany()) {//返参为集合类型result executeForMany(sqlSession, args);} else if (method.returnsMap()) {//返参为Mapresult executeForMap(sqlSession, args);} else if (method.returnsCursor()) {//返参为游标result executeForCursor(sqlSession, args);} else {//返参为单对象Object param method.convertArgsToSqlCommandParam(args);result sqlSession.selectOne(command.getName(), param);}break;case FLUSH:result sqlSession.flushStatements();break;default:throw new BindingException(Unknown execution method for: command.getName());}if (result null method.getReturnType().isPrimitive() !method.returnsVoid()) {throw new BindingException(Mapper method command.getName() attempted to return null from a method with a primitive return type ( method.getReturnType() ).);}return result;} 上面的查询方法都会走到下面这两行代码 //获取sql执行的映射过程对象包含了参数、数据源、返参等 MappedStatement ms configuration.getMappedStatement(statement); //执行查询方法 executor.query(ms, wrapCollection(parameter), rowBounds, handler); 接着会走到执行器executor主要有两类实现 org.apache.ibatis.executor.BaseExecutor基本执行器CachingExecutor带缓存的执行器 public E ListE query(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler) throws SQLException {//获取BoundSql对象包含了解析动态SQl生成的sql语句以及参数映射的封装BoundSql boundSql ms.getBoundSql(parameter);//生成缓存keyCacheKey key createCacheKey(ms, parameter, rowBounds, boundSql);//查询return query(ms, parameter, rowBounds, resultHandler, key, boundSql);} public BoundSql getBoundSql(Object parameterObject) {//调用sqlSource获取BoundSqlsqlSource默认为DynamicSqlSource类型动态SQLBoundSql boundSql sqlSource.getBoundSql(parameterObject);ListParameterMapping parameterMappings boundSql.getParameterMappings();//若参数映射为空手动创建boundSqlif (parameterMappings null || parameterMappings.isEmpty()) {boundSql new BoundSql(configuration, boundSql.getSql(), parameterMap.getParameterMappings(), parameterObject);}// check for nested result maps in parameter mappings (issue #30)for (ParameterMapping pm : boundSql.getParameterMappings()) {String rmId pm.getResultMapId();if (rmId ! null) {ResultMap rm configuration.getResultMap(rmId);if (rm ! null) {hasNestedResultMaps | rm.hasNestedResultMaps();}}}return boundSql;} public BoundSql getBoundSql(Object parameterObject) {//获取上下文对象并将传入的入参对象及数据源标识放入bindingsDynamicContext context new DynamicContext(configuration, parameterObject);//基于动态sql解析成的ListSqlNode contents遍历赋值参数rootSqlNode.apply(context);SqlSourceBuilder sqlSourceParser new SqlSourceBuilder(configuration);Class? parameterType parameterObject null ? Object.class : parameterObject.getClass();SqlSource sqlSource sqlSourceParser.parse(context.getSql(), parameterType, context.getBindings());BoundSql boundSql sqlSource.getBoundSql(parameterObject);for (Map.EntryString, Object entry : context.getBindings().entrySet()) {boundSql.setAdditionalParameter(entry.getKey(), entry.getValue());}return boundSql;} 准备好BoundSql后就该执行真正的查询了主要链路如下
http://www.sadfv.cn/news/338026/

相关文章:

  • 百度搜索网站图片做网页怎么在网站播放视频
  • 佛山高端网站制作公司哪家好免费素材图库
  • wordpress网站入口开发个网站需要多少钱
  • 长沙口碑最好网站建设公司排行榜固始网站制作
  • 手机网站建设最新报价google网站打不开
  • 太原做网站需要多少钱北京画册设计制作公司
  • 酒店网站设计公司liunx安装wordpress
  • 网站的建设包括以下几个阶段厦门旅游攻略
  • 装修设计公司网站网站建设分金手指专业三十
  • 网站新闻发布后前台不显示seo挖关键词
  • 搜索建站网网站开发阶段流程图
  • 电子商务网站成本网站开发策划方案
  • 专门做童装的网站有哪些WordPress登录ip
  • 重庆黄埔seo整站优化湖南营销推广网站多少费用
  • 我做动作你来猜的网站wordpress 蜘蛛爬行插件
  • 如何建立像百度一样的网站wordpress 企业主题
  • 领手工在家做的网站免费注册企业邮箱域名
  • html5公司网站欣赏酒类网站建设策划书
  • ps做网站显示内容参考安丘住房建设局网站
  • 免费开源网站建设系统一键搭建网站
  • 模板网站建设公司WordPress文章中的编辑去掉
  • 做自媒体可以搬运国外网站新闻吗ppt模板下载免费版软件
  • 资讯网站做app小说网站开发php
  • 建筑公司网站大全网站的维护方案
  • 网站建设上传和下载wordpress php 5.3.x
  • 建设部网站 造价工程师为拟建设的网站申请一个域名
  • 图书类网站开发的背景凡客商城
  • 网站怎么做防盗上海seo方案
  • 网站绩效营销南山电商网站建设
  • 郑州英语网站建设怎么在wordpress中套用同行网页