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

网站建设汉狮怎么样wordpress购物主题

网站建设汉狮怎么样,wordpress购物主题,智能建站代理,怎么用vps搭建网站在之前的优惠券兑换码需求中,涉及批量写入问题,其中有一个关键的连接配置参数非常重要——rewriteBatchedStatements,当该值配置为true时,Statement将可能对批量插入sql进行重写。 何谓重写?原来提交的批量执行语句&a…

在之前的优惠券兑换码需求中,涉及批量写入问题,其中有一个关键的连接配置参数非常重要——rewriteBatchedStatements,当该值配置为true时,Statement将可能对批量插入sql进行重写。

何谓重写?原来提交的批量执行语句(100条)如下:

INSERT INTO dh_redeem_code (code, status, coupon_id, batch_id) VALUES ('1','0',100,1);
INSERT INTO dh_redeem_code (code, status, coupon_id, batch_id) VALUES ('2','0',100,1);
...
INSERT INTO dh_redeem_code (code, status, coupon_id, batch_id) VALUES ('100','0',100,1);

重写之后的sql语句(1条)如下:

INSERT INTO dh_redeem_code (code, status, coupon_id, batch_id) VALUES 
('1','0',100,1),
('2','0',100,1),
...
('100','0',100,1);

本文将从源码层面来对该参数的作用进行分析。笔者采用的mysql数据库驱动依赖库为mysql-connector-java:8.0.30。

首先,我们来看一段ClientPreparedStatement.executeBatchInternal()方法的代码,这是数据库驱动内部执行批量sql的方法。

if (!this.batchHasPlainStatements && this.rewriteBatchedStatements.getValue()) {if (getQueryInfo().isRewritableWithMultiValuesClause()) {return executeBatchWithMultiValuesClause(batchTimeout);}if (!this.batchHasPlainStatements && this.query.getBatchedArgs() != null&& this.query.getBatchedArgs().size() > 3 /* cost of option setting rt-wise */) {return executePreparedBatchAsMultiStatement(batchTimeout);}
}

关于batchHasPlainStatements属性,如果批处理使用 Statement.addBatch(String) 显示添加sql语句,则该属性值为true,否则为false。原文如下:

/*** Does the batch (if any) contain "plain" statements added by Statement.addBatch(String)?* If so, we can't re-write it to use multi-value or multi-queries.*/
protected boolean batchHasPlainStatements = false;

第一行代码的意思:如果没有使用 Statement.addBatch(String) 显示添加sql语句,并且rewriteBatchedStatements参数值为true,则有可能对批量语句进行重写。

继续往下看,isRewritableWithMultiValuesClause这个属性值为true,则执行executeBatchWithMultiValuesClause方法,该方法实现对sql语句的重写。

对于isRewritableWithMultiValuesClause属性的赋值,QueryInfo类的构造函数中

public QueryInfo(String sql, Session session, String encoding) {// Check if the statement has potential to be rewritten as a multi-values clause statement, i.e., if it is an INSERT or REPLACE statement and// 'rewriteBatchedStatements' is enabled.boolean rewritableAsMultiValues = (isInsert || isReplace) && rewriteBatchedStatements;...        //这里有很长很长很长一段代码this.isRewritableWithMultiValuesClause = rewritableAsMultiValues;
}

从第4行代码看出重写的必要条件:rewriteBatchedStatements值为true,而且必须是插入操作或者REPLACE操作。

再来看看sql语句重写函数executeBatchWithMultiValuesClause(batchTimeout)代码:

batchedStatement = /* FIXME -if we ever care about folks proxying our JdbcConnection */prepareBatchedInsertSQL(locallyScopedConn, numValuesPerBatch);timeoutTask = startQueryTimer(batchedStatement, batchTimeout);numberToExecuteAsMultiValue = numBatchedArgs < numValuesPerBatch ? numBatchedArgs : numBatchedArgs / numValuesPerBatch;int numberArgsToExecute = numberToExecuteAsMultiValue * numValuesPerBatch;for (int i = 0; i < numberArgsToExecute; i++) {if (i != 0 && i % numValuesPerBatch == 0) {try {updateCountRunningTotal += batchedStatement.executeLargeUpdate();} catch (SQLException ex) {sqlEx = handleExceptionForBatch(batchCounter - 1, numValuesPerBatch, updateCounts, ex);}getBatchedGeneratedKeys(batchedStatement);batchedStatement.clearParameters();batchedParamIndex = 1;}batchedParamIndex = setOneBatchedParameterSet(batchedStatement, batchedParamIndex, this.query.getBatchedArgs().get(batchCounter++));
}try {updateCountRunningTotal += batchedStatement.executeLargeUpdate();
} catch (SQLException ex) {sqlEx = handleExceptionForBatch(batchCounter - 1, numValuesPerBatch, updateCounts, ex);
}getBatchedGeneratedKeys(batchedStatement);

上述代码第一行将根据批量sql数量和插入的字段数量,构建带有占位符的sql。随后的语句遍历批量sql,使用实际的插入参数值替换占位符,从而形成一条可执行的批量插入语句。

自此,关于rewriteBatchedStatements的源码分析结束,如果需要数据库驱动重写批量插入,只需要正常使用MybatisPlus的saveBatch方法,并在数据库连接中加上rewriteBatchedStatements=true的配置信息即可。

http://www.yayakq.cn/news/918773/

相关文章:

  • 哪有专业做网站免费制作扫码下单小程序
  • 厦门营销网站制作wordpress做下载型网站6
  • 做网站对程序员说那些需求国内做视频网站需要啥
  • 微网站建设报价表steam交易链接怎么看
  • 缩短网址做钓鱼网站网站建设优化保定
  • 淘宝流量网站网站营销是什么
  • 注册网站需要visa怎么办苏州本地网站建设
  • 小说网站有源码了该怎么做wordpress 恢复 附件
  • 什么网站专做店铺网站制作五个界面
  • 北京做网站建设的公司排名呼和浩特微信小程序公司
  • 免费发布信息不收费的网站功能类似淘宝的网站建设
  • 广州智能建站软件黄山网新科技
  • 郴州网站建设哪家比较好wordpress 获取文章类型
  • 龙岗建设网站公司域名解析网站什么意思
  • wordpress 全站sslwordpress 文章缩进
  • 企业做个网站多少钱做机械设计图纸找什么网站
  • 郑州北环附近网站建设互动平台罗马复兴
  • 万网速成网站有哪些 功能wordpress产品相册
  • wordpress网站维护教程模板网站可以自己买空间吗吗
  • 肇庆广宁住房和城乡建设部网站南京软件外包公司有哪些
  • 站长工具黄提高asp.net网站安全性
  • 90设计网站怎么绑定手机号wordpress用户留言插件
  • 跟换网站域名wordpress .htaccess 固定连接
  • 用ps怎么做网站导航条怎么做个人怎么在百度上打广告
  • 阿里云网站简单建设网站平台设计 问题
  • 电子商务网站推广实训报告珠海自适应网站设计
  • 网站服务器错误怎么办哈尔滨营销网站建设
  • 17网站一起做网店河北网站图片做多大
  • 如何做彩票销售网站做网站后端要学什么
  • 做热图的在线网站学习软件编程