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 Jan 6, 2025
2 parents 3e1deba + 9578e80 commit e3170a3
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 29 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.36</version>
<version>5.6.37</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 @@ -5,6 +5,12 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* @project sqltoy-orm
* @description 针对pojo对象属性提供缓存翻译多注解配置
* @author zhongxuchen
* @version v1.0,Date:2025-1-2
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface Translates {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,24 @@ public class TranslateUtils {
/**
* @date 2018-5-26 优化缓存翻译,提供keyCode1,keyCode2,keyCode3 形式的多代码翻译
* @todo 统一对key进行缓存翻译
* @param extend
* @param translateExtend
* @param dynamicCacheFetch 预留功能,暂时不开放,需再思考一下必要性
* @param translateKeyMap
* @param cacheData
* @param fieldValue
* @return
*/
public static Object translateKey(TranslateExtend extend, DynamicCacheFetch dynamicCacheFetch,
HashMap<String, Object[]> translateKeyMap, Object fieldValue) {
public static Object translateKey(TranslateExtend translateExtend, DynamicCacheFetch dynamicCacheFetch,
HashMap<String, Object[]> cacheData, Object fieldValue) {
String fieldStr = fieldValue.toString();
// 单值翻译
if (extend.splitRegex == null) {
if (extend.keyTemplate != null) {
if (translateExtend.splitRegex == null) {
// ${key}_ZH_CN 用于组合匹配缓存
if (translateExtend.keyTemplate != null) {
// keyTemplate已经提前做了规整,将${key},${},${0} 统一成了{}
fieldStr = extend.keyTemplate.replace("{}", fieldStr);
fieldStr = translateExtend.keyTemplate.replace("{}", fieldStr);
}
// 根据key获取缓存值
Object[] cacheValues = translateKeyMap.get(fieldStr);
Object[] cacheValues = cacheData.get(fieldStr);
// 执行动态缓存获取(暂时不开放)
// if (cacheValues == null && extend.dynamicCache && dynamicCacheFetch != null) {
// cacheValues = dynamicCacheFetch.getCache(extend.cache, extend.cacheSid, extend.cacheProperties,
Expand All @@ -51,29 +52,29 @@ public static Object translateKey(TranslateExtend extend, DynamicCacheFetch dyna
// 未匹配到
if (cacheValues == null || cacheValues.length == 0) {
// 定义未匹配模板则不输出日志
if (extend.uncached != null) {
fieldValue = extend.uncached.replace("${value}", fieldStr);
if (translateExtend.uncached != null) {
fieldValue = translateExtend.uncached.replace("${value}", fieldStr);
} else {
fieldValue = fieldValue.toString();
logger.warn("translate cache:{},cacheType:{}, 对应的key:{}没有设置相应的value!", extend.cache,
extend.cacheType, fieldValue);
logger.warn("translate cache:{},cacheType:{}, 对应的key:{}没有设置相应的value!", translateExtend.cache,
translateExtend.cacheType, fieldValue);
}
} else {
fieldValue = cacheValues[extend.index];
fieldValue = cacheValues[translateExtend.index];
}
return fieldValue;
}
// 将字符串用分隔符切分开进行逐个翻译
String[] keys = StringUtil.splitRegex(fieldStr, extend.splitRegex, true);
String linkSign = extend.linkSign;
String[] keys = StringUtil.splitRegex(fieldStr, translateExtend.splitRegex, true);
String linkSign = translateExtend.linkSign;
StringBuilder result = new StringBuilder();
int index = 0;
Object[] cacheValues;
for (String key : keys) {
if (index > 0) {
result.append(linkSign);
}
cacheValues = translateKeyMap.get(key);
cacheValues = cacheData.get(key);
// 暂时不开放
// if (cacheValues == null && extend.dynamicCache && dynamicCacheFetch != null) {
// cacheValues = dynamicCacheFetch.getCache(extend.cache, extend.cacheSid, extend.cacheProperties,
Expand All @@ -84,15 +85,15 @@ public static Object translateKey(TranslateExtend extend, DynamicCacheFetch dyna
// }
if (cacheValues == null || cacheValues.length == 0) {
// 定义未匹配模板则不输出日志
if (extend.uncached != null) {
result.append(extend.uncached.replace("${value}", key));
if (translateExtend.uncached != null) {
result.append(translateExtend.uncached.replace("${value}", key));
} else {
result.append(key);
logger.warn("translate cache:{},cacheType:{}, 对应的key:{}没有设置相应的value!", extend.cache,
extend.cacheType, key);
logger.warn("translate cache:{},cacheType:{}, 对应的key:{}没有设置相应的value!", translateExtend.cache,
translateExtend.cacheType, key);
}
} else {
result.append(cacheValues[extend.index]);
result.append(cacheValues[translateExtend.index]);
}
index++;
}
Expand All @@ -107,7 +108,7 @@ public static Object translateKey(TranslateExtend extend, DynamicCacheFetch dyna
* @return
*/
public static boolean judgeTranslate(Object sourceValue, String compareType, String[] compareValues) {
//compareValues长度不做校验,解析设置时已经校验必须有值
// compareValues长度不做校验,解析设置时已经校验必须有值
String sourceStr = (sourceValue == null) ? "null" : sourceValue.toString().toLowerCase();
if (compareType.equals("eq")) {
return compareValues[0].equals(sourceStr);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.jupiter.api.Test;
import org.sagacity.sqltoy.config.model.SqlToyConfig;
import org.sagacity.sqltoy.config.model.SqlType;
import org.sagacity.sqltoy.config.model.Translate;
import org.sagacity.sqltoy.utils.FileUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -51,15 +52,23 @@ public void testChinaParamName() throws Exception {
SqlToyConfig sqlToyConfig = SqlConfigParseUtils.parseSqlToyConfig(sql, "mysql", SqlType.search);
System.err.println(JSON.toJSONString(sqlToyConfig));
}

@Test
public void testWith() throws Exception {
String sql = "with t1 (a, b) as not materialized (select * from table),t2(c,d) as materialized(select name from ta) "
+ ""
+ ""
+ "@fast(select * from t1)";
SqlToyConfig sqlToyConfig = SqlConfigParseUtils.parseSqlToyConfig(sql, "mysql", SqlType.search);
System.err.println(sqlToyConfig.getFastSql(null));
System.err.println(sqlToyConfig.getFastWithSql(null));
}

@Test
public void testParseWhere() throws Exception {
String sql = "orderType in 'abc,efg,zgd'";
Translate translate = new Translate("");
SqlXMLConfigParse.parseTranslateWhere(translate, sql);
System.err.println(translate.getExtend().compareColumn);
System.err.println(translate.getExtend().compareType);
System.err.println(JSON.toJSON(translate.getExtend().compareValues));
}
}
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.36</version>
<version>5.6.37</version>

<artifactId>sagacity-sqltoy-solon-plugin</artifactId>
<name>sagacity-sqltoy-solon-plugin</name>
Expand Down
2 changes: 1 addition & 1 deletion trunk/sqltoy-orm-spring-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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.36</version>
<version>5.6.37</version>
<name>sagacity-sqltoy-spring-starter</name>
<artifactId>sagacity-sqltoy-spring-starter</artifactId>
<description>sqltoy springboot starter</description>
Expand Down
2 changes: 1 addition & 1 deletion trunk/sqltoy-orm-spring/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.36</version>
<version>5.6.37</version>
<name>sagacity-sqltoy-spring</name>
<description>sagacity-sqltoy-spring</description>
<artifactId>sagacity-sqltoy-spring</artifactId>
Expand Down

0 comments on commit e3170a3

Please sign in to comment.