From a3fb7d5dc06ea656a39ec5fe64da0f3d9d9fc507 Mon Sep 17 00:00:00 2001 From: chenrenfei Date: Tue, 7 Nov 2023 11:50:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- trunk/sqltoy-orm/pom.xml | 4 ++-- .../sqltoy/dialect/utils/DialectUtils.java | 21 ++++++++++++------- .../sagacity/sqltoy/model/QueryExecutor.java | 10 +++++++++ .../model/inner/QueryExecutorExtend.java | 5 +++++ .../plugins/calculator/RowsChainRelative.java | 2 +- trunk/sqltoy-spring-boot-starter/pom.xml | 4 ++-- 6 files changed, 34 insertions(+), 12 deletions(-) diff --git a/trunk/sqltoy-orm/pom.xml b/trunk/sqltoy-orm/pom.xml index b664bb5b7..03a742eae 100644 --- a/trunk/sqltoy-orm/pom.xml +++ b/trunk/sqltoy-orm/pom.xml @@ -3,7 +3,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.sagframe - 5.2.75 + 5.2.76 sagacity-sqltoy sagacity-sqltoy sagacity-sqltoy @@ -19,7 +19,7 @@ 4.5.14 4.4.16 8.10.4 - 2.0.41 + 2.0.42 3.12.14 5.10.0 1.10.0 diff --git a/trunk/sqltoy-orm/src/main/java/org/sagacity/sqltoy/dialect/utils/DialectUtils.java b/trunk/sqltoy-orm/src/main/java/org/sagacity/sqltoy/dialect/utils/DialectUtils.java index acb087b7c..8f0635000 100644 --- a/trunk/sqltoy-orm/src/main/java/org/sagacity/sqltoy/dialect/utils/DialectUtils.java +++ b/trunk/sqltoy-orm/src/main/java/org/sagacity/sqltoy/dialect/utils/DialectUtils.java @@ -248,12 +248,19 @@ public static QueryResult findBySql(final SqlToyContext sqlToyContext, final Sql lastSql = SqlUtilsExt.signSql(lastSql, dbType, sqlToyConfig); // 打印sql SqlExecuteStat.showSql("执行查询", lastSql, paramsValue); - PreparedStatement pst = conn.prepareStatement(lastSql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); - if (fetchSize > 0) { - pst.setFetchSize(fetchSize); - } - if (maxRows > 0) { - pst.setMaxRows(maxRows); + PreparedStatement pst = null; + // 常规单查询语句 + if (!extend.sqlSegment) { + pst = conn.prepareStatement(lastSql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); + if (fetchSize > 0) { + pst.setFetchSize(fetchSize); + } + if (maxRows > 0) { + pst.setMaxRows(maxRows); + } + } else { + // sql段落,含多句sql(正常不使用) + pst = conn.prepareStatement(lastSql); } ResultSet rs = null; return (QueryResult) SqlUtil.preparedStatementProcess(null, pst, rs, new PreparedStatementResultHandler() { @@ -621,7 +628,7 @@ public static Long saveOrUpdateAll(SqlToyContext sqlToyContext, List entities for (int meter = 0; meter < relatedColumnSize; meter++) { relatedColValue[meter] = rowData[relatedColumn[meter]]; } - //这里不做是否为null的校验,因为不明确是新增还是修改 + // 这里不做是否为null的校验,因为不明确是新增还是修改 } // 主键 if (hasId && StringUtil.isBlank(rowData[pkIndex])) { diff --git a/trunk/sqltoy-orm/src/main/java/org/sagacity/sqltoy/model/QueryExecutor.java b/trunk/sqltoy-orm/src/main/java/org/sagacity/sqltoy/model/QueryExecutor.java index f9e9e5e06..f8d28210a 100644 --- a/trunk/sqltoy-orm/src/main/java/org/sagacity/sqltoy/model/QueryExecutor.java +++ b/trunk/sqltoy-orm/src/main/java/org/sagacity/sqltoy/model/QueryExecutor.java @@ -601,6 +601,16 @@ public QueryExecutor showSql(Boolean showSql) { return this; } + /** + * @TODO 是否是sql片段,即不是单独的一句查询(正常无需使用) + * @param sqlSegment + * @return + */ + public QueryExecutor sqlSegment(boolean sqlSegment) { + innerModel.sqlSegment = sqlSegment; + return this; + } + public QueryExecutorExtend getInnerModel() { return innerModel; } diff --git a/trunk/sqltoy-orm/src/main/java/org/sagacity/sqltoy/model/inner/QueryExecutorExtend.java b/trunk/sqltoy-orm/src/main/java/org/sagacity/sqltoy/model/inner/QueryExecutorExtend.java index e158891b3..6e39e1b0f 100644 --- a/trunk/sqltoy-orm/src/main/java/org/sagacity/sqltoy/model/inner/QueryExecutorExtend.java +++ b/trunk/sqltoy-orm/src/main/java/org/sagacity/sqltoy/model/inner/QueryExecutorExtend.java @@ -177,6 +177,11 @@ public class QueryExecutorExtend implements Serializable { */ public Class entityClass = null; + /** + * 是否是sql片段(正常无需使用) + */ + public boolean sqlSegment = false; + // 分表策略配置 public List tableShardings = new ArrayList(); diff --git a/trunk/sqltoy-orm/src/main/java/org/sagacity/sqltoy/plugins/calculator/RowsChainRelative.java b/trunk/sqltoy-orm/src/main/java/org/sagacity/sqltoy/plugins/calculator/RowsChainRelative.java index 662bc2b16..8c926b593 100644 --- a/trunk/sqltoy-orm/src/main/java/org/sagacity/sqltoy/plugins/calculator/RowsChainRelative.java +++ b/trunk/sqltoy-orm/src/main/java/org/sagacity/sqltoy/plugins/calculator/RowsChainRelative.java @@ -168,7 +168,7 @@ public static void process(RowsChainRelativeModel rowsRelative, LabelIndexModel divedData = Double.parseDouble(divedRowList.get(colIndex).toString()); } if (divedData == 0) { - divRowList.set(colIndex + 1, (divData == 0) ? 0 : ""); + divRowList.set(colIndex + 1, (divData == 0) ? 0 : defaultValue); } else { value = new BigDecimal(((divData - ((isIncrement) ? divedData : 0)) * multiply) / divedData) .setScale(radixSize, RoundingMode.FLOOR); diff --git a/trunk/sqltoy-spring-boot-starter/pom.xml b/trunk/sqltoy-spring-boot-starter/pom.xml index 6a5a0b6c8..3c3993517 100644 --- a/trunk/sqltoy-spring-boot-starter/pom.xml +++ b/trunk/sqltoy-spring-boot-starter/pom.xml @@ -4,7 +4,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.sagframe - 5.2.75 + 5.2.76 sagacity-sqltoy-starter sagacity-sqltoy-starter sqltoy springboot starter @@ -12,7 +12,7 @@ UTF-8 2.7.17 - 5.2.75 + 5.2.76