Skip to content

Commit

Permalink
Merge branch 'dev' into 5.6
Browse files Browse the repository at this point in the history
  • Loading branch information
chenrenfei committed Aug 8, 2024
2 parents e7429a0 + 1a03f80 commit 5bc43bd
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 22 deletions.
2 changes: 1 addition & 1 deletion trunk/sqltoy-orm-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sagframe</groupId>
<version>5.6.16</version>
<version>5.6.17</version>
<name>sagacity-sqltoy</name>
<description>sqltoy core code</description>
<artifactId>sagacity-sqltoy</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,17 @@ public static Serializable updateSaveFetch(final SqlToyContext sqlToyContext, fi
Object[] tempFieldValues = null;
// 条件字段值
Object[] whereParamValues = BeanUtil.reflectBeanToAry(entity, whereFields);
Object tmpVersionValue = null;
// 提取数据版本字段的值
if (entityMeta.getDataVersion() != null) {
tmpVersionValue = BeanUtil.getProperty(entity, entityMeta.getDataVersion().getField());
}
for (int i = 0; i < whereParamValues.length; i++) {
// 唯一性属性值存在空,则表示首次插入
if (StringUtil.isBlank(whereParamValues[i])) {
// 调用默认值、主键策略等
tempFieldValues = processFieldValues(sqlToyContext, entityMeta, entity);
// 重新反射获取主键等字段值
whereParamValues = BeanUtil.reflectBeanToAry(entity, whereFields);
break;
}
Expand All @@ -394,10 +401,10 @@ public static Serializable updateSaveFetch(final SqlToyContext sqlToyContext, fi
? sqlToyContext.getUnifyFieldsHandler()
: null;
final Object[] fieldValues = tempFieldValues;
final Object entityVersion = tmpVersionValue;
final boolean hasUpdateRow = (updateRowHandler == null) ? false : true;
// 组织select * from table for update 语句
String sql = wrapFetchSql(entityMeta, dbType, whereFields, tableName);
SqlToyResult queryParam = new SqlToyResult(sql, whereParamValues);
SqlToyResult queryParam = wrapFetchSql(entityMeta, dbType, whereFields, whereParamValues, tableName);
// 增加sql执行拦截器 update 2022-9-10
queryParam = DialectUtils.doInterceptors(sqlToyContext, null, OperateType.singleTable, queryParam,
entity.getClass(), dbType);
Expand Down Expand Up @@ -427,12 +434,12 @@ public void execute(Object rowData, PreparedStatement pst, ResultSet rs) throws
SqlExecuteStat.debug("执行updateRow", "记录存在调用updateRowHandler.updateRow!");
// 存在数据版本:1、校验当前的版本是否为null(目前跳过);2、对比传递过来的版本值跟数据库中的值是否一致;3、修改数据库中数据版本+1
if (dataVersion != null) {
Object version = BeanUtil.getProperty(entity, dataVersionField);
String nowVersion = finalRs.getString(entityMeta.getColumnName(dataVersionField));
if (version != null && !version.toString().equals(nowVersion)) {
if (entityVersion != null && !entityVersion.toString().equals(nowVersion)) {
throw new IllegalArgumentException("表:" + entityMeta.getTableName()
+ " 存在版本@DataVersion配置,在updateSaveFetch做更新时,属性:" + dataVersionField
+ " 值不等于当前数据库中的值:" + version + "<>" + nowVersion + ",说明数据已经被修改过!");
+ " 值不等于当前数据库中的值:" + entityVersion + "<>" + nowVersion
+ ",说明数据已经被修改过!");
}
// 以日期开头
if (dataVersion.isStartDate()) {
Expand Down Expand Up @@ -721,10 +728,12 @@ private static void setArray(Integer dbType, Connection conn, ResultSet rs, Stri
* @param entityMeta
* @param dbType
* @param uniqueProps
* @param whereParamValues
* @param tableName
* @return
*/
private static String wrapFetchSql(EntityMeta entityMeta, Integer dbType, String[] uniqueProps, String tableName) {
private static SqlToyResult wrapFetchSql(EntityMeta entityMeta, Integer dbType, String[] uniqueProps,
Object[] whereParamValues, String tableName) {
String realTable = entityMeta.getSchemaTable(tableName, dbType);
StringBuilder sql = new StringBuilder("select ");
String columnName;
Expand All @@ -738,22 +747,32 @@ private static String wrapFetchSql(EntityMeta entityMeta, Integer dbType, String
}
sql.append(" from ").append(realTable).append(" where ");
int index = 0;
List<Object> realParamValues = new ArrayList<>();
for (String field : uniqueProps) {
if (index > 0) {
sql.append(" and ");
}
columnName = entityMeta.getColumnName(field);
sql.append(ReservedWordsUtil.convertWord(columnName, dbType)).append("=?");
sql.append(ReservedWordsUtil.convertWord(columnName, dbType));
// update 2024-8-7 rabbit 反馈,条件值为null的场景
if (whereParamValues[index] == null) {
sql.append(" is null ");
} else {
sql.append("=?");
realParamValues.add(whereParamValues[index]);
}
index++;
}
String lastSql;
// 设置锁
if (dbType == DBType.SQLSERVER) {
return SqlServerDialectUtils.lockSql(sql.toString(), realTable, LockMode.UPGRADE);
lastSql = SqlServerDialectUtils.lockSql(sql.toString(), realTable, LockMode.UPGRADE);
} else if (dbType == DBType.DB2) {
return sql.append(" for update with rs").toString();
lastSql = sql.append(" for update with rs").toString();
} else {
return sql.append(" for update").toString();
lastSql = sql.append(" for update").toString();
}
return new SqlToyResult(lastSql, realParamValues.toArray());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1585,6 +1585,7 @@ public static List wrapQueryResult(SqlToyContext sqlToyContext, List queryResult
// update 2021-11-16 支持VO或POJO 属性上@Translate注解,进行缓存翻译
wrapResultTranslate(sqlToyContext, result, resultType);
} else {
// 内部完成了wrapResultTranslate行为
result = hiberarchySet(sqlToyContext, entityMeta, columnFieldMap, queryResultRows, labelNames, resultType,
cascadeModel, hiberarchyClasses, fieldsMap);
}
Expand Down Expand Up @@ -1686,6 +1687,8 @@ private static List hiberarchySet(SqlToyContext sqlToyContext, EntityMeta entity
// 构造主对象集合
List result = BeanUtil.reflectListToBean(sqlToyContext.getTypeHandler(), masterData,
convertRealProps(wrapMapFields(labelNames, fieldsMap, resultType), columnFieldMap), resultType);
// add 2024-8-7 (用户:一颗开心果反馈)在一个查询封装成对象级联平铺模式,主对象上未处理类上@Translate缓存翻译注解
wrapResultTranslate(sqlToyContext, result, resultType);
List<List> oneToOnes = new ArrayList();
List<String> oneToOneProps = new ArrayList<String>();
List<String> oneToOneNotNullField = new ArrayList<String>();
Expand Down Expand Up @@ -1725,6 +1728,7 @@ private static List hiberarchySet(SqlToyContext sqlToyContext, EntityMeta entity
convertRealProps(wrapMapFields(realLabelNames, fieldsMap, cascade.getMappedType()),
columnFieldMap),
cascade.getMappedType());
// 处理OneToOne子类上@Translate注解进行缓存翻译
wrapResultTranslate(sqlToyContext, oneToOneList, cascade.getMappedType());
oneToOnes.add(oneToOneList);
oneToOneProps.add(cascade.getProperty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package org.sagacity.sqltoy.demo.vo;

import java.io.Serializable;
import java.util.Collection;

/**
* @project sagacity-service
Expand Down
2 changes: 1 addition & 1 deletion trunk/sqltoy-orm-solon-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.sagframe</groupId>
<version>5.6.16</version>
<version>5.6.17</version>

<artifactId>sagacity-sqltoy-solon-plugin</artifactId>
<name>sagacity-sqltoy-solon-plugin</name>
Expand Down
10 changes: 5 additions & 5 deletions trunk/sqltoy-orm-spring-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sagframe</groupId>
<version>5.6.16</version>
<version>5.6.17</version>
<name>sagacity-sqltoy-spring-starter</name>
<artifactId>sagacity-sqltoy-spring-starter</artifactId>
<description>sqltoy springboot starter</description>
<url>https://github.com/sagframe/sagacity-sqltoy</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-boot.version>3.2.8</spring-boot.version>
<spring-data-commons.version>3.2.8</spring-data-commons.version>
<spring-data-redis.version>3.2.8</spring-data-redis.version>
<spring-data-mongo.version>4.2.8</spring-data-mongo.version>
<spring-boot.version>3.3.2</spring-boot.version>
<spring-data-commons.version>3.3.2</spring-data-commons.version>
<spring-data-redis.version>3.3.2</spring-data-redis.version>
<spring-data-mongo.version>4.3.2</spring-data-mongo.version>
<mongo.version>3.12.14</mongo.version>
<caffeine.version>3.1.8</caffeine.version>
</properties>
Expand Down
8 changes: 4 additions & 4 deletions trunk/sqltoy-orm-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.sagframe</groupId>
<version>5.6.16</version>
<version>5.6.17</version>
<name>sagacity-sqltoy-spring</name>
<description>sagacity-sqltoy-spring</description>
<artifactId>sagacity-sqltoy-spring</artifactId>
<url>https://github.com/sagframe/sagacity-sqltoy</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring-framework.version>6.1.11</spring-framework.version>
<spring-data-commons.version>3.2.8</spring-data-commons.version>
<spring-data-redis.version>3.2.8</spring-data-redis.version>
<spring-data-mongo.version>4.2.8</spring-data-mongo.version>
<spring-data-commons.version>3.3.2</spring-data-commons.version>
<spring-data-redis.version>3.3.2</spring-data-redis.version>
<spring-data-mongo.version>4.3.2</spring-data-mongo.version>
<mongo.version>3.12.14</mongo.version>
<slf4j.version>2.0.13</slf4j.version>
<caffeine.version>3.1.8</caffeine.version>
Expand Down

0 comments on commit 5bc43bd

Please sign in to comment.