From 06b1cbacfa7352d20a1d00e3aa079bdd3a9c0470 Mon Sep 17 00:00:00 2001
From: zhongxuchen
Date: Mon, 13 May 2024 23:05:17 +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-core/pom.xml | 4 +-
.../sqltoy/config/SqlConfigParseUtils.java | 2 +-
.../sqltoy/config/SqlScriptLoader.java | 12 ++++--
.../org/sagacity/sqltoy/dao/LightDao.java | 28 ++++++-------
.../plugins/id/macro/AbstractMacro.java | 4 +-
.../sqltoy/plugins/id/macro/MacroUtils.java | 9 ++--
.../sqltoy/plugins/id/macro/impl/Case.java | 3 +-
.../plugins/id/macro/impl/DateFormat.java | 3 +-
.../sqltoy/plugins/id/macro/impl/Include.java | 41 ++++++++++++++++++-
.../sqltoy/plugins/id/macro/impl/SqlLoop.java | 3 +-
.../plugins/id/macro/impl/SubString.java | 3 +-
.../sqltoy/translate/DynamicCacheFetch.java | 2 +-
.../org/sagacity/sqltoy/utils/BeanUtil.java | 3 +-
.../sagacity/sqltoy/utils/CollectionUtil.java | 15 ++++---
.../sagacity/sqltoy/utils/MacroIfLogic.java | 11 +++--
.../sagacity/sqltoy/utils/MapperUtils.java | 1 +
.../sqltoy/plugins/MacroUtilsTest.java | 8 ++--
.../sagacity/sqltoy/plugins/SqlLoopTest.java | 6 +--
.../sqltoy/utils/StringUtilsTest.java | 5 ++-
19 files changed, 112 insertions(+), 51 deletions(-)
diff --git a/trunk/sqltoy-orm-core/pom.xml b/trunk/sqltoy-orm-core/pom.xml
index 0ff0d6f59..69c67657c 100644
--- a/trunk/sqltoy-orm-core/pom.xml
+++ b/trunk/sqltoy-orm-core/pom.xml
@@ -14,8 +14,8 @@
3.10.8
4.5.14
4.4.16
- 8.13.3
- 2.0.49
+ 8.13.4
+ 2.0.50
3.12.14
5.10.2
1.10.2
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/config/SqlConfigParseUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/config/SqlConfigParseUtils.java
index 9646003b1..89aa29f28 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/config/SqlConfigParseUtils.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/config/SqlConfigParseUtils.java
@@ -705,7 +705,7 @@ private static String processLoop(String queryStr, String[] paramsNamed, Object[
keyValues.put(paramsNamed[i], paramsValue[i]);
}
// 这里是借用业务主键生成里面的宏处理模式来解决
- return MacroUtils.replaceMacros(queryStr, keyValues, null, false, macros);
+ return MacroUtils.replaceMacros(queryStr, keyValues, null, false, macros, null);
}
/**
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/config/SqlScriptLoader.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/config/SqlScriptLoader.java
index 4cf02e709..ee82e01f0 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/config/SqlScriptLoader.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/config/SqlScriptLoader.java
@@ -36,6 +36,8 @@
* @modify Date:2020-04-22 增加System.out
* 对sql文件加载的打印输出,避免有些开发在开发阶段不知道设置日志级别为debug从而看不到输出
* @modify Date:2023-8-19 增加了@include(:scriptName) 模式
+ * @modify Date:2024-5-13 @include(id="sqlId")
+ * 增强兼容sqlId根据dialect方言找sqlId_dialect模式
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public class SqlScriptLoader {
@@ -103,9 +105,10 @@ public class SqlScriptLoader {
/**
* 增加路径验证提示,最易配错导致无法加载sql文件
+ *
* @param sqlResourcesDir
*/
- public static void checkSqlResourcesDir(String sqlResourcesDir){
+ public static void checkSqlResourcesDir(String sqlResourcesDir) {
if (StringUtil.isNotBlank(sqlResourcesDir)
&& (sqlResourcesDir.toLowerCase().contains(".sql.xml") || sqlResourcesDir.contains("*"))) {
throw new IllegalArgumentException("\n您的配置:spring.sqltoy.sqlResourcesDir=" + sqlResourcesDir + " 不正确!\n"
@@ -279,7 +282,8 @@ public SqlToyConfig getSqlConfig(String sqlKey, SqlType sqlType, String dialect,
result.clearDialectSql();
}
// 替换include的实际sql
- String sql = MacroUtils.replaceMacros(result.getSql(), (Map) sqlCache, paramValues, false, macros);
+ String sql = MacroUtils.replaceMacros(result.getSql(), (Map) sqlCache, paramValues, false, macros,
+ dialect);
// 重新解析sql内容
SqlToyConfig tmpConfig = SqlConfigParseUtils.parseSqlToyConfig(sql, realDialect, sqlType);
result.setHasUnion(tmpConfig.isHasUnion());
@@ -294,7 +298,7 @@ public SqlToyConfig getSqlConfig(String sqlKey, SqlType sqlType, String dialect,
String countSql = result.getCountSql(null);
if (countSql != null && StringUtil.matches(countSql, SqlToyConstants.INCLUDE_PATTERN)) {
- countSql = MacroUtils.replaceMacros(countSql, (Map) sqlCache, paramValues, false, macros);
+ countSql = MacroUtils.replaceMacros(countSql, (Map) sqlCache, paramValues, false, macros, dialect);
countSql = FunctionUtils.getDialectSql(countSql, realDialect);
countSql = ReservedWordsUtil.convertSql(countSql, DataSourceUtils.getDBType(realDialect));
result.setCountSql(countSql);
@@ -313,7 +317,7 @@ public SqlToyConfig getSqlConfig(String sqlKey, SqlType sqlType, String dialect,
// 替换include的实际sql
if (hasInclude) {
isParamInclude = StringUtil.matches(sqlKey, SqlToyConstants.INCLUDE_PARAM_PATTERN);
- String sql = MacroUtils.replaceMacros(sqlKey, (Map) sqlCache, paramValues, false, macros);
+ String sql = MacroUtils.replaceMacros(sqlKey, (Map) sqlCache, paramValues, false, macros, dialect);
result = SqlConfigParseUtils.parseSqlToyConfig(sql, realDialect, sqlType);
} else {
result = SqlConfigParseUtils.parseSqlToyConfig(sqlKey, realDialect, sqlType);
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dao/LightDao.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dao/LightDao.java
index 41c5632fc..5f20f95f7 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dao/LightDao.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/dao/LightDao.java
@@ -81,7 +81,8 @@ public interface LightDao {
public Store store();
/**
- * @TODO 提供链式操作模式保存操作集合
+ * @TODO 提供链式操作模式保存操作集合,如:lightDao.save().dataSource(xxx).one(entity)
+ * lightDao.save().dataSource(xxx).many(entities)
* @return
*/
public Save save();
@@ -533,7 +534,8 @@ public List loadByIds(final Class entityClass, fi
/**
* @TODO 根据QueryExecutor来链式操作灵活定义查询sql、条件、数据源等
- * @param query new QueryExecutor(sql).names().values().filters() 链式设置查询
+ * @param query new QueryExecutor(sql).dataSource().names().values().filters()
+ * 链式设置查询
* @return
*/
public Object loadByQuery(final QueryExecutor query);
@@ -584,7 +586,7 @@ public List loadByIds(final Class entityClass, fi
* @todo 通过QueryExecutor来构造查询逻辑进行分页查询
* @param page
* @param queryExecutor 范例:new
- * QueryExecutor(sql).names(xxx).values(xxx).filters()
+ * QueryExecutor(sql).dataSource(dataSource).names(xxx).values(xxx).filters()
* 链式设置查询
* @return
*/
@@ -641,7 +643,9 @@ public List findTop(final String sqlOrSqlId, final Serializable entity, f
final double topSize);
/*
- * 用QueryExecutor组织查询逻辑,findTopByQuery(new QueryExecutor(sqlOrSqlId,MapKit.keys(...).values(...)).resultType(resultDTO),10)
+ * 用QueryExecutor组织查询逻辑,findTopByQuery(new
+ * QueryExecutor(sqlOrSqlId,MapKit.keys(...).values(...)).resultType(resultDTO),
+ * 10)
*/
public QueryResult findTopByQuery(final QueryExecutor queryExecutor, final double topSize);
@@ -788,17 +792,11 @@ public List findRandom(final String sqlOrSqlId, final Map
* @todo 对数据集合通过反调函数对具体属性进行翻译
*
* sqlToyLazyDao.translate(staffVOs, "staffIdName", new
- * TranslateHandler() {
- * //告知key值
- * public Object getKey(Object row) {
- * return ((StaffInfoVO)row).getStaffId();
- * }
- * // 将翻译后的名称值设置到对应的属性上
- * public void setName(Object row, String name) {
- * ((StaffInfoVO)row).setStaffName(name);
- * }
- * });
- *
+ * TranslateHandler() { //告知key值 public Object getKey(Object row) { return
+ * ((StaffInfoVO)row).getStaffId(); } // 将翻译后的名称值设置到对应的属性上 public void
+ * setName(Object row, String name) {
+ * ((StaffInfoVO)row).setStaffName(name); } });
+ *
* @param dataSet 数据集合
* @param cacheName 缓存名称
* @param cacheType 例如数据字典存在分类的缓存填写字典分类,其它的如员工、机构等填null
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/AbstractMacro.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/AbstractMacro.java
index f07329eeb..71c740bee 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/AbstractMacro.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/AbstractMacro.java
@@ -18,8 +18,10 @@ public abstract class AbstractMacro {
* @param keyValues 宏涉及的参数名称和对应的值
* @param paramValues sql语句中的参数属性名称和值对象(2023-08-18 新增)
* @param preSql 宏前面部分的sql,用于特定场景参考(目前主要是@loop循环判null场景)
+ * @param extSign 扩展标记(备用)
* @return
*/
- public abstract String execute(String[] params, Map keyValues, Object paramValues, String preSql);
+ public abstract String execute(String[] params, Map keyValues, Object paramValues, String preSql,
+ String extSign);
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/MacroUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/MacroUtils.java
index 057c02a53..e9b76a2da 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/MacroUtils.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/MacroUtils.java
@@ -64,7 +64,7 @@ public class MacroUtils {
* @return
*/
public static String replaceMacros(String hasMacroStr, Map keyValues) {
- return replaceMacros(hasMacroStr, keyValues, null, false, macros);
+ return replaceMacros(hasMacroStr, keyValues, null, false, macros, null);
}
/**
@@ -75,10 +75,11 @@ public static String replaceMacros(String hasMacroStr, Map keyVa
* @param isOuter(isOuter 当@abc(@do(),xxx):为true表示从最外层的macro@abce,false则会先执行@do()
* 然后再执行@abc())
* @param macros
+ * @param extSign 扩展标记,目前主要给@include使用,传递dialect
* @return
*/
public static String replaceMacros(String hasMacroStr, Map keyValues, Object paramsValues,
- boolean isOuter, Map macros) {
+ boolean isOuter, Map macros, String extSign) {
if (StringUtil.isBlank(hasMacroStr)) {
return hasMacroStr;
}
@@ -121,14 +122,14 @@ public static String replaceMacros(String hasMacroStr, Map keyVa
// 调用转换器进行计算
AbstractMacro macro = macros.get(macroName);
String result = macro.execute(StringUtil.splitExcludeSymMark(macroParam, ",", filters), keyValues,
- paramsValues, preSql);
+ paramsValues, preSql, extSign);
// 最外层是转换器,则将转结果直接以对象方式返回
if (hasMacroStr.trim().equals(macroStr.trim())) {
return result;
}
String macroResult = (result == null) ? "" : result;
hasMacroStr = replaceStr(hasMacroStr, macroStr, macroResult, macroIndex);
- return replaceMacros(hasMacroStr, keyValues, paramsValues, isOuter, macros);
+ return replaceMacros(hasMacroStr, keyValues, paramsValues, isOuter, macros, extSign);
}
return hasMacroStr;
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/Case.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/Case.java
index f7a893b98..da33f3690 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/Case.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/Case.java
@@ -24,7 +24,8 @@ public class Case extends AbstractMacro {
* org.sagacity.sqltoy.plugins.id.macro.AbstractMacro#execute(java.lang.Object)
*/
@Override
- public String execute(String[] params, Map keyValues, Object paramValues, String preSql) {
+ public String execute(String[] params, Map keyValues, Object paramValues, String preSql,
+ String extSign) {
if (params == null) {
return "";
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/DateFormat.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/DateFormat.java
index 76cd7a10b..ac737649d 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/DateFormat.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/DateFormat.java
@@ -25,7 +25,8 @@ public class DateFormat extends AbstractMacro {
* org.sagacity.sqltoy.plugins.id.macro.AbstractMacro#execute(java.lang.Object)
*/
@Override
- public String execute(String[] params, Map keyValues, Object paramValues, String preSql) {
+ public String execute(String[] params, Map keyValues, Object paramValues, String preSql,
+ String extSign) {
Object dateValue = null;
String fmt = "yyMMdd";
if (params != null) {
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/Include.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/Include.java
index 779c2678e..8f62697fa 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/Include.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/Include.java
@@ -6,6 +6,7 @@
import org.sagacity.sqltoy.config.model.SqlToyConfig;
import org.sagacity.sqltoy.plugins.id.macro.AbstractMacro;
import org.sagacity.sqltoy.utils.BeanUtil;
+import org.sagacity.sqltoy.utils.DataSourceUtils.Dialect;
import org.sagacity.sqltoy.utils.StringUtil;
/**
@@ -21,7 +22,8 @@
public class Include extends AbstractMacro {
@Override
- public String execute(String[] params, Map keyValues, Object paramValues, String preSql) {
+ public String execute(String[] params, Map keyValues, Object paramValues, String preSql,
+ String dialect) {
if (params.length == 0) {
return "";
}
@@ -47,7 +49,7 @@ public String execute(String[] params, Map keyValues, Object par
// 输出sql
return paramValue.toString();
}
- SqlToyConfig sqlToyConfig = (SqlToyConfig) keyValues.get(sqlId);
+ SqlToyConfig sqlToyConfig = getSqlToyConfig(keyValues, sqlId, dialect);
if (sqlToyConfig == null) {
return "(sqlId='" + sqlId + "' not exists!)";
}
@@ -59,4 +61,39 @@ public String execute(String[] params, Map keyValues, Object par
return sqlToyConfig.getSql();
}
+ /**
+ * @TODO 增加对数据库方言的适配
+ * @param sqlCache
+ * @param sqlId
+ * @param dialect
+ * @return
+ */
+ private SqlToyConfig getSqlToyConfig(Map sqlCache, String sqlId, String dialect) {
+ SqlToyConfig result = null;
+ if (StringUtil.isNotBlank(dialect)) {
+ // sqlId_dialect
+ result = (SqlToyConfig) sqlCache.get(sqlId.concat("_").concat(dialect));
+ // dialect_sqlId
+ if (result == null) {
+ result = (SqlToyConfig) sqlCache.get(dialect.concat("_").concat(sqlId));
+ }
+ // 兼容一下sqlserver的命名
+ if (result == null && dialect.equals(Dialect.SQLSERVER)) {
+ result = (SqlToyConfig) sqlCache.get(sqlId.concat("_mssql"));
+ if (result == null) {
+ result = (SqlToyConfig) sqlCache.get("mssql_".concat(sqlId));
+ }
+ } // 兼容一下postgres的命名
+ if (result == null && dialect.equals(Dialect.POSTGRESQL)) {
+ result = (SqlToyConfig) sqlCache.get(sqlId.concat("_postgres"));
+ if (result == null) {
+ result = (SqlToyConfig) sqlCache.get("postgres_".concat(sqlId));
+ }
+ }
+ }
+ if (result == null) {
+ result = (SqlToyConfig) sqlCache.get(sqlId);
+ }
+ return result;
+ }
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/SqlLoop.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/SqlLoop.java
index 8503583e3..df8d2e0bd 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/SqlLoop.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/SqlLoop.java
@@ -58,7 +58,8 @@ public SqlLoop(boolean skipBlank) {
}
@Override
- public String execute(String[] params, Map keyValues, Object paramValues, String preSql) {
+ public String execute(String[] params, Map keyValues, Object paramValues, String preSql,
+ String extSign) {
if (params == null || params.length < 2 || keyValues == null || keyValues.size() == 0) {
return " ";
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/SubString.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/SubString.java
index ee2ddf57a..11c02c326 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/SubString.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/plugins/id/macro/impl/SubString.java
@@ -17,7 +17,8 @@
public class SubString extends AbstractMacro {
@Override
- public String execute(String[] params, Map keyValues, Object paramValues, String preSql) {
+ public String execute(String[] params, Map keyValues, Object paramValues, String preSql,
+ String extSign) {
if (params == null || params.length < 3) {
return "";
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/translate/DynamicCacheFetch.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/translate/DynamicCacheFetch.java
index 18091fea1..5073f89a5 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/translate/DynamicCacheFetch.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/translate/DynamicCacheFetch.java
@@ -7,7 +7,7 @@
/**
* @project sagacity-sqltoy
- * @description 针对localCache提供动态从redis或数据库获取值并放入缓存的机制
+ * @description 针对localCache提供动态从redis或数据库获取值并放入缓存的机制(目前还未实现)
* @author zhongxuchen
* @version v1.0, Date:2024年1月18日
* @modify 2024年1月18日,修改说明
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/BeanUtil.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/BeanUtil.java
index d962e2ba4..423ba1137 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/BeanUtil.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/BeanUtil.java
@@ -1019,6 +1019,7 @@ private static Date oracleDateConvert(Object obj) throws Exception {
* @param datas
* @param props
* @return
+ * @throws RuntimeException
*/
public static List reflectBeansToList(List datas, String[] props) throws RuntimeException {
return reflectBeansToList(datas, props, null);
@@ -1029,7 +1030,7 @@ public static List reflectBeansToList(List datas, String[] props) throws Runtime
* @param datas
* @param propertyName
* @return
- * @throws Exception
+ * @throws RuntimeException
*/
public static Object[] sliceToArray(List datas, String propertyName) throws RuntimeException {
List sliceList = reflectBeansToList(datas, new String[] { propertyName }, null);
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/CollectionUtil.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/CollectionUtil.java
index 7356bf4f2..82528ad96 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/CollectionUtil.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/CollectionUtil.java
@@ -360,7 +360,7 @@ public static int judgeObjectDimen(Object obj) {
if (obj == null) {
return -1;
}
-
+ Object firstCellValue;
if (obj instanceof Collection || obj.getClass().isArray() || obj instanceof Map) {
result = 1;
if (obj instanceof Collection) {
@@ -368,7 +368,9 @@ public static int judgeObjectDimen(Object obj) {
if (tmp.isEmpty()) {
return result;
}
- if (((List) obj).get(0) != null && ((List) obj).get(0) instanceof List) {
+ firstCellValue = ((List) obj).get(0);
+ if (firstCellValue != null && (firstCellValue instanceof Collection
+ || firstCellValue.getClass().isArray() || firstCellValue instanceof Map)) {
result = 2;
}
} else if (obj.getClass().isArray()) {
@@ -376,7 +378,9 @@ public static int judgeObjectDimen(Object obj) {
if (tmp.length == 0) {
return result;
}
- if (tmp[0] != null && tmp[0].getClass().isArray()) {
+ firstCellValue = tmp[0];
+ if (firstCellValue != null && (firstCellValue instanceof Collection
+ || firstCellValue.getClass().isArray() || firstCellValue instanceof Map)) {
result = 2;
}
} else if (obj instanceof Map) {
@@ -384,8 +388,9 @@ public static int judgeObjectDimen(Object obj) {
if (tmp.isEmpty()) {
return result;
}
- Object setItem = tmp.values().iterator().next();
- if (setItem.getClass().isArray() || setItem instanceof Collection || setItem instanceof Map) {
+ firstCellValue = tmp.values().iterator().next();
+ if (firstCellValue != null && (firstCellValue instanceof Collection
+ || firstCellValue.getClass().isArray() || firstCellValue instanceof Map)) {
result = 2;
}
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/MacroIfLogic.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/MacroIfLogic.java
index b394adabb..a8a56e2d4 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/MacroIfLogic.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/MacroIfLogic.java
@@ -203,7 +203,7 @@ private static String evalSimpleExpress(String evalExpression, List paramValues,
*/
public static boolean compare(Object value, String compareType, String compareValue) {
// 剔除首尾字符串标志符号
- compareValue = clearChar(compareValue);
+ compareValue = removeStartEndQuote(compareValue);
// 只支持加减运算
String append = "0";
String[] calculateStr = { "+", "-" };
@@ -232,7 +232,7 @@ public static boolean compare(Object value, String compareType, String compareVa
compareValue = DateUtil.formatDate(DateUtil.addSecond(new Date(), Double.parseDouble(append)), dayFmt);
type = "date";
}
- String valueStr = (value == null) ? "null" : clearChar(value.toString());
+ String valueStr = (value == null) ? "null" : removeStartEndQuote(value.toString());
if ("time".equals(type)) {
valueStr = DateUtil.formatDate(value, dayTimeFmt);
} else if ("date".equals(type)) {
@@ -497,7 +497,12 @@ private static boolean between(Object param, String valueStr, String beginContra
return false;
}
- private static String clearChar(String source) {
+ /**
+ * @TODO 去除字符串首尾的单引号或双引号
+ * @param source
+ * @return
+ */
+ private static String removeStartEndQuote(String source) {
if (source == null) {
return source;
}
diff --git a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/MapperUtils.java b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/MapperUtils.java
index 607d3c02a..661d3f5e1 100644
--- a/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/MapperUtils.java
+++ b/trunk/sqltoy-orm-core/src/main/java/org/sagacity/sqltoy/utils/MapperUtils.java
@@ -29,6 +29,7 @@
* @modify 2022-10-19 支持对象的多级父类属性的映射
* @modify 2023-05-01 支持多级子对象映射,代码全面改造完全工具类化,无需再依赖SqlToyContext
* @modify 2024-03-15 支持DTO<-->POJO 双向映射中@SqlToyFieldAlias,由gleam反馈
+ * @modify 2024-05-10 进一步强化对象间映射,增加指定属性映射fieldsMap参数
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public class MapperUtils {
diff --git a/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/plugins/MacroUtilsTest.java b/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/plugins/MacroUtilsTest.java
index 8918dab07..4ee546a70 100644
--- a/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/plugins/MacroUtilsTest.java
+++ b/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/plugins/MacroUtilsTest.java
@@ -36,7 +36,7 @@ public void testReplaceMacros() {
keyValues.put(paramsNamed[i], paramsValue[i]);
}
- String result = MacroUtils.replaceMacros(sql, keyValues, null, false, macros);
+ String result = MacroUtils.replaceMacros(sql, keyValues, null, false, macros, null);
System.err.println(result);
}
@@ -54,7 +54,7 @@ public void testReplaceMacros1() {
keyValues.put(paramsNamed[i], paramsValue[i]);
}
- String result = MacroUtils.replaceMacros(sql, keyValues, null, false, macros);
+ String result = MacroUtils.replaceMacros(sql, keyValues, null, false, macros, null);
System.err.println(result);
}
@@ -73,7 +73,7 @@ public void testReplaceMacros2() {
keyValues.put(paramsNamed[i], paramsValue[i]);
}
- String result = MacroUtils.replaceMacros(sql, keyValues, null, false, macros);
+ String result = MacroUtils.replaceMacros(sql, keyValues, null, false, macros, null);
System.err.println(result);
}
@@ -96,7 +96,7 @@ public void testCase() {
// for (int i = 0; i < paramsNamed.length; i++) {
// keyValues.put(paramsNamed[i], paramsValue[i]);
// }
- String result = MacroUtils.replaceMacros(sql, keyValues, null, false, macros);
+ String result = MacroUtils.replaceMacros(sql, keyValues, null, false, macros, null);
System.err.println(result);
}
diff --git a/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/plugins/SqlLoopTest.java b/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/plugins/SqlLoopTest.java
index d7503a61e..d5b7968cf 100644
--- a/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/plugins/SqlLoopTest.java
+++ b/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/plugins/SqlLoopTest.java
@@ -32,7 +32,7 @@ public void testSqlLoop() {
IgnoreKeyCaseMap keyValues = new IgnoreKeyCaseMap();
keyValues.put("staffInfos", staffInfos);
keyValues.put("status", 1);
- String result = sqlLoop.execute(params, keyValues, null, null);
+ String result = sqlLoop.execute(params, keyValues, null, null, null);
System.err.print(result);
}
@@ -50,7 +50,7 @@ public void testSqlLoopStr() {
String[] params = { "staffInfos", " and staffId=':staffInfos[i]'" };
IgnoreKeyCaseMap keyValues = new IgnoreKeyCaseMap();
keyValues.put("staffInfos", staffInfos);
- String result = sqlLoop.execute(params, keyValues, null, null);
+ String result = sqlLoop.execute(params, keyValues, null, null, null);
System.err.print(result);
}
@@ -64,7 +64,7 @@ public void testSqlLoopLike() {
String[] params = { "staffInfos", " and staffId like '%:staffInfos[i]%'" };
IgnoreKeyCaseMap keyValues = new IgnoreKeyCaseMap();
keyValues.put("staffInfos", staffInfos);
- String result = sqlLoop.execute(params, keyValues, null, null);
+ String result = sqlLoop.execute(params, keyValues, null, null, null);
System.err.print(result);
}
diff --git a/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/utils/StringUtilsTest.java b/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/utils/StringUtilsTest.java
index 9675afed3..2e25c981b 100644
--- a/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/utils/StringUtilsTest.java
+++ b/trunk/sqltoy-orm-core/src/test/java/org/sagacity/sqltoy/utils/StringUtilsTest.java
@@ -5,6 +5,7 @@
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
@@ -12,7 +13,7 @@
import org.junit.jupiter.api.Test;
import org.sagacity.sqltoy.SqlToyConstants;
-import org.sagacity.sqltoy.config.SqlConfigParseUtils;
+import org.sagacity.sqltoy.config.model.SqlToyConfig;
import org.sagacity.sqltoy.utils.DataSourceUtils.DBType;
import com.alibaba.fastjson.JSON;
@@ -193,6 +194,8 @@ public void testReplace2() {
@Test
public void testMatchInclude() {
+ Map sqlCache =new HashMap<>();
+ System.err.println((SqlToyConfig) sqlCache.get("test_id"));
String sql = "select * from table @include(id=\"adb\")";
System.err.println(StringUtil.matches(sql, SqlToyConstants.INCLUDE_PATTERN));
sql = "select * from table @include( :itemList[0].id )";