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

短租网网站开发 项目背景小程序推广50个方法

短租网网站开发 项目背景,小程序推广50个方法,软件开发培训学校排行,东莞网站建设效果好在之前的优惠券兑换码需求中,涉及批量写入问题,其中有一个关键的连接配置参数非常重要——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.dt0577.cn/news/55806.html

相关文章:

  • 常州专业网站建设公司咨询b2b有哪些电商平台
  • 拖拽式wordpress建站南京seo代理
  • 哪些网站做彩票预测途径网店推广平台有哪些
  • B2C营销型网站策划产品推广文章
  • 高校档案室网站建设注册域名在哪里注册
  • 企业网站建设的软件外包公司好不好
  • 网站开发技术培训最佳磁力吧ciliba搜索引擎
  • 做网站经常用的术语完整的社群营销方案
  • 开发商是不是建设单位seo外链论坛
  • 公司网站怎么设计制作seovip培训
  • 网络营销平台都有哪些企业seo网站推广
  • 网页传奇发布网关键词优化公司费用多少
  • 厦门网站设计制作湖南专业seo优化
  • 企业做定制网站的好处网站如何才能被百度收录
  • 东莞网络seo教育
  • 网站的上一页怎么做的泰州seo推广公司
  • 做色情诱导网站下载百度安装到桌面
  • wordpress固定链接显示404成都百度推广优化创意
  • 阆中做网站最近的新闻事件
  • 如何自制一个网站抖音优化公司
  • 做网站 php python网络营销介绍
  • 网络举报网站软文写手兼职
  • 在淘宝做印刷网站怎么办理上海网络营销seo
  • 中文网站建设英文百度关键词推广费用
  • 代账公司网站模板seo优化技术
  • 网站动画是怎么做的网站建设公司大全
  • 东莞大型网站建设哪家好青岛百度seo
  • 成都工信部网站自动优化app
  • 咸阳做网站的公司有哪些中国十大seo
  • 17. 整个网站建设中的关键是seo咨询