jsqlparser升级到4.7
This commit is contained in:
@@ -646,7 +646,7 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource implement
|
||||
return getSQLAttrValue(info, attr, val);
|
||||
}
|
||||
|
||||
protected DataNativeSqlParser.NativeSqlStatement nativeParse(String nativeSql, Map<String, Object> params) {
|
||||
protected DataNativeSqlStatement nativeParse(String nativeSql, Map<String, Object> params) {
|
||||
if (nativeSqlParser == null) {
|
||||
throw new SourceException("not found DataNativeSqlParser instance");
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import org.redkale.annotation.AutoLoad;
|
||||
import org.redkale.annotation.ResourceListener;
|
||||
import org.redkale.annotation.ResourceType;
|
||||
import org.redkale.service.Local;
|
||||
import org.redkale.source.DataNativeSqlParser.NativeSqlStatement;
|
||||
import org.redkale.util.*;
|
||||
|
||||
/**
|
||||
@@ -2555,7 +2554,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
||||
@Local
|
||||
@Override
|
||||
public int nativeUpdate(String sql, Map<String, Object> params) {
|
||||
NativeSqlStatement sinfo = super.nativeParse(sql, params);
|
||||
DataNativeSqlStatement sinfo = super.nativeParse(sql, params);
|
||||
final long s = System.currentTimeMillis();
|
||||
SourceConnection conn = writePool.pollConnection();
|
||||
Statement stmt = null;
|
||||
@@ -2632,7 +2631,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
||||
@Local
|
||||
@Override
|
||||
public <V> V nativeQuery(String sql, BiConsumer<Object, Object> consumer, Function<DataResultSet, V> handler, Map<String, Object> params) {
|
||||
NativeSqlStatement sinfo = super.nativeParse(sql, params);
|
||||
DataNativeSqlStatement sinfo = super.nativeParse(sql, params);
|
||||
final long s = System.currentTimeMillis();
|
||||
final SourceConnection conn = readPool.pollConnection();
|
||||
try {
|
||||
@@ -2678,7 +2677,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
||||
|
||||
public <V> Sheet<V> nativeQuerySheet(Class<V> type, String sql, Flipper flipper, Map<String, Object> params) {
|
||||
final boolean mysqlOrPgsql = "mysql".equals(dbtype()) || "postgresql".equals(dbtype());
|
||||
NativeSqlStatement sinfo = super.nativeParse(sql, params);
|
||||
DataNativeSqlStatement sinfo = super.nativeParse(sql, params);
|
||||
final long s = System.currentTimeMillis();
|
||||
final SourceConnection conn = readPool.pollConnection();
|
||||
try {
|
||||
|
||||
@@ -5,8 +5,6 @@ package org.redkale.source;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.function.IntFunction;
|
||||
import org.redkale.convert.ConvertDisabled;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.util.RedkaleClassLoader;
|
||||
|
||||
/**
|
||||
@@ -25,11 +23,11 @@ import org.redkale.util.RedkaleClassLoader;
|
||||
*/
|
||||
public interface DataNativeSqlParser {
|
||||
|
||||
NativeSqlStatement parse(IntFunction<String> signFunc, String dbtype, String rawSql, Map<String, Object> params);
|
||||
DataNativeSqlStatement parse(IntFunction<String> signFunc, String dbtype, String rawSql, Map<String, Object> params);
|
||||
|
||||
public static DataNativeSqlParser loadFirst() {
|
||||
if (NativeSqlStatement._first_parser != NativeSqlStatement.PARSER_NIL) {
|
||||
return NativeSqlStatement._first_parser;
|
||||
if (DataNativeSqlStatement._first_parser != DataNativeSqlStatement.PARSER_NIL) {
|
||||
return DataNativeSqlStatement._first_parser;
|
||||
}
|
||||
Iterator<DataNativeSqlParserProvider> it = ServiceLoader.load(DataNativeSqlParserProvider.class).iterator();
|
||||
RedkaleClassLoader.putServiceLoader(DataNativeSqlParserProvider.class);
|
||||
@@ -39,89 +37,8 @@ public interface DataNativeSqlParser {
|
||||
return provider.createInstance();
|
||||
}
|
||||
}
|
||||
NativeSqlStatement._first_parser = null;
|
||||
DataNativeSqlStatement._first_parser = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static class NativeSqlStatement {
|
||||
|
||||
private static final DataNativeSqlParser PARSER_NIL = new DataNativeSqlParser() {
|
||||
@Override
|
||||
public NativeSqlStatement parse(IntFunction<String> signFunc, String dbtype, String rawSql, Map<String, Object> params) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
};
|
||||
|
||||
private static DataNativeSqlParser _first_parser = PARSER_NIL;
|
||||
|
||||
//根据参数值集合重新生成的带?参数可执行的sql
|
||||
protected String nativeSql;
|
||||
|
||||
//根据参数值集合重新生成的带?参数可执行的计算总数sql,用于返回Sheet对象
|
||||
protected String nativeCountSql;
|
||||
|
||||
//需要预编译的$${xxx}、${xxx}参数名, 数量与sql中的?数量一致
|
||||
protected List<String> paramNames;
|
||||
|
||||
//需要预编译的jdbc参数名, 数量与sql中的?数量一致
|
||||
protected List<String> jdbcNames;
|
||||
|
||||
//jdbc参数值集合, paramNames中的key必然会存在
|
||||
protected Map<String, Object> paramValues;
|
||||
|
||||
/**
|
||||
* 是否带有参数
|
||||
*
|
||||
* @return 是否带有参数
|
||||
*/
|
||||
@ConvertDisabled
|
||||
public boolean isEmptyNamed() {
|
||||
return paramNames == null || paramNames.isEmpty();
|
||||
}
|
||||
|
||||
public String getNativeSql() {
|
||||
return nativeSql;
|
||||
}
|
||||
|
||||
public void setNativeSql(String nativeSql) {
|
||||
this.nativeSql = nativeSql;
|
||||
}
|
||||
|
||||
public String getNativeCountSql() {
|
||||
return nativeCountSql;
|
||||
}
|
||||
|
||||
public void setNativeCountSql(String nativeCountSql) {
|
||||
this.nativeCountSql = nativeCountSql;
|
||||
}
|
||||
|
||||
public List<String> getParamNames() {
|
||||
return paramNames;
|
||||
}
|
||||
|
||||
public void setParamNames(List<String> paramNames) {
|
||||
this.paramNames = paramNames;
|
||||
}
|
||||
|
||||
public Map<String, Object> getParamValues() {
|
||||
return paramValues;
|
||||
}
|
||||
|
||||
public void setParamValues(Map<String, Object> paramValues) {
|
||||
this.paramValues = paramValues;
|
||||
}
|
||||
|
||||
public List<String> getJdbcNames() {
|
||||
return jdbcNames;
|
||||
}
|
||||
|
||||
public void setJdbcNames(List<String> jdbcNames) {
|
||||
this.jdbcNames = jdbcNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
102
src/main/java/org/redkale/source/DataNativeSqlStatement.java
Normal file
102
src/main/java/org/redkale/source/DataNativeSqlStatement.java
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.source;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.IntFunction;
|
||||
import org.redkale.convert.ConvertDisabled;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
|
||||
/**
|
||||
*
|
||||
* 原生的sql解析对象 <br>
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public class DataNativeSqlStatement {
|
||||
|
||||
static final DataNativeSqlParser PARSER_NIL = new DataNativeSqlParser() {
|
||||
@Override
|
||||
public DataNativeSqlStatement parse(IntFunction<String> signFunc, String dbtype, String rawSql, Map<String, Object> params) {
|
||||
throw new UnsupportedOperationException("Not supported yet.");
|
||||
}
|
||||
};
|
||||
|
||||
static DataNativeSqlParser _first_parser = PARSER_NIL;
|
||||
|
||||
//根据参数值集合重新生成的带?参数可执行的sql
|
||||
protected String nativeSql;
|
||||
|
||||
//根据参数值集合重新生成的带?参数可执行的计算总数sql,用于返回Sheet对象
|
||||
protected String nativeCountSql;
|
||||
|
||||
//需要预编译的$${xxx}、${xxx}参数名, 数量与sql中的?数量一致
|
||||
protected List<String> paramNames;
|
||||
|
||||
//需要预编译的jdbc参数名, 数量与sql中的?数量一致
|
||||
protected List<String> jdbcNames;
|
||||
|
||||
//jdbc参数值集合, paramNames中的key必然会存在
|
||||
protected Map<String, Object> paramValues;
|
||||
|
||||
/**
|
||||
* 是否带有参数
|
||||
*
|
||||
* @return 是否带有参数
|
||||
*/
|
||||
@ConvertDisabled
|
||||
public boolean isEmptyNamed() {
|
||||
return paramNames == null || paramNames.isEmpty();
|
||||
}
|
||||
|
||||
public String getNativeSql() {
|
||||
return nativeSql;
|
||||
}
|
||||
|
||||
public void setNativeSql(String nativeSql) {
|
||||
this.nativeSql = nativeSql;
|
||||
}
|
||||
|
||||
public String getNativeCountSql() {
|
||||
return nativeCountSql;
|
||||
}
|
||||
|
||||
public void setNativeCountSql(String nativeCountSql) {
|
||||
this.nativeCountSql = nativeCountSql;
|
||||
}
|
||||
|
||||
public List<String> getParamNames() {
|
||||
return paramNames;
|
||||
}
|
||||
|
||||
public void setParamNames(List<String> paramNames) {
|
||||
this.paramNames = paramNames;
|
||||
}
|
||||
|
||||
public Map<String, Object> getParamValues() {
|
||||
return paramValues;
|
||||
}
|
||||
|
||||
public void setParamValues(Map<String, Object> paramValues) {
|
||||
this.paramValues = paramValues;
|
||||
}
|
||||
|
||||
public List<String> getJdbcNames() {
|
||||
return jdbcNames;
|
||||
}
|
||||
|
||||
public void setJdbcNames(List<String> jdbcNames) {
|
||||
this.jdbcNames = jdbcNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return JsonConvert.root().convertTo(this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user