DataNativeSqlParser优化
This commit is contained in:
@@ -77,6 +77,8 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource implement
|
||||
protected final BiFunction<DataSource, EntityInfo, CompletableFuture<List>> fullloader = (s, i)
|
||||
-> ((CompletableFuture<Sheet>) querySheetDBAsync(i, false, false, false, null, null, (FilterNode) null)).thenApply(e -> e == null ? new ArrayList() : e.list(true));
|
||||
|
||||
protected final Function<Integer, String> signFunc = index -> prepareParamSign(index);
|
||||
|
||||
//超过多少毫秒视为较慢, 会打印警告级别的日志, 默认值: 2000
|
||||
protected long slowmsWarn;
|
||||
|
||||
@@ -642,11 +644,11 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource implement
|
||||
return getSQLAttrValue(info, attr, val);
|
||||
}
|
||||
|
||||
protected DataNativeSqlParser.NativeSqlInfo nativeParse(String prepareSign, String nativeSql, Map<String, Object> params) {
|
||||
protected DataNativeSqlParser.NativeSqlStatement nativeParse(String nativeSql, Map<String, Object> params) {
|
||||
if (nativeSqlParser == null) {
|
||||
throw new SourceException("not found DataNativeSqlParser instance");
|
||||
}
|
||||
return nativeSqlParser.parse(prepareSign, nativeSql, params == null ? Collections.emptyMap() : params);
|
||||
return nativeSqlParser.parse(signFunc, nativeSql, params == null ? Collections.emptyMap() : params);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,7 +18,7 @@ import org.redkale.annotation.*;
|
||||
import org.redkale.annotation.ResourceListener;
|
||||
import org.redkale.annotation.ResourceType;
|
||||
import org.redkale.service.Local;
|
||||
import org.redkale.source.DataNativeSqlParser.NativeSqlInfo;
|
||||
import org.redkale.source.DataNativeSqlParser.NativeSqlStatement;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
@@ -2537,7 +2537,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
||||
|
||||
@Override
|
||||
public int nativeUpdate(String sql, Map<String, Object> params) {
|
||||
NativeSqlInfo sinfo = super.nativeParse("?", sql, params);
|
||||
NativeSqlStatement sinfo = super.nativeParse(sql, params);
|
||||
final long s = System.currentTimeMillis();
|
||||
SourceConnection conn = writePool.pollConnection();
|
||||
try {
|
||||
@@ -2612,7 +2612,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
||||
|
||||
@Override
|
||||
public <V> V nativeQuery(String sql, BiConsumer<Object, Object> consumer, Function<DataResultSet, V> handler, Map<String, Object> params) {
|
||||
NativeSqlInfo sinfo = super.nativeParse("?", sql, params);
|
||||
NativeSqlStatement sinfo = super.nativeParse(sql, params);
|
||||
final long s = System.currentTimeMillis();
|
||||
final SourceConnection conn = readPool.pollConnection();
|
||||
try {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
package org.redkale.source;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import org.redkale.convert.ConvertDisabled;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
@@ -19,13 +20,16 @@ import org.redkale.convert.json.JsonConvert;
|
||||
*/
|
||||
public interface DataNativeSqlParser {
|
||||
|
||||
NativeSqlInfo parse(String prepareSign, String nativeSql, Map<String, Object> params);
|
||||
NativeSqlStatement parse(Function<Integer, String> signFunc, String nativeSql, Map<String, Object> params);
|
||||
|
||||
public static class NativeSqlInfo {
|
||||
public static class NativeSqlStatement {
|
||||
|
||||
//根据参数值集合重新生成的带?参数可执行的sql
|
||||
protected String nativeSql;
|
||||
|
||||
//是否包含InExpression参数名
|
||||
protected boolean existInNamed;
|
||||
|
||||
//需要预编译的参数名, 数量与sql中的?数量一致
|
||||
protected List<String> paramNames;
|
||||
|
||||
@@ -50,6 +54,14 @@ public interface DataNativeSqlParser {
|
||||
this.nativeSql = nativeSql;
|
||||
}
|
||||
|
||||
public boolean isExistInNamed() {
|
||||
return existInNamed;
|
||||
}
|
||||
|
||||
public void setExistInNamed(boolean existInNamed) {
|
||||
this.existInNamed = existInNamed;
|
||||
}
|
||||
|
||||
public List<String> getParamNames() {
|
||||
return paramNames;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user