DataNativeSqlInfo
This commit is contained in:
@@ -20,7 +20,6 @@ import org.redkale.inject.ResourceEvent;
|
|||||||
import org.redkale.service.Local;
|
import org.redkale.service.Local;
|
||||||
import static org.redkale.source.DataSources.*;
|
import static org.redkale.source.DataSources.*;
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
import org.redkale.annotation.ResourceChanged;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DataSource的JDBC实现类
|
* DataSource的JDBC实现类
|
||||||
@@ -148,7 +147,8 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> List<PreparedStatement> prepareInsertEntityStatements(JdbcConnection conn, EntityInfo<T> info, Map<String, PrepareInfo<T>> prepareInfos, T... entitys) throws SQLException {
|
protected <T> List<PreparedStatement> prepareInsertEntityStatements(JdbcConnection conn,
|
||||||
|
EntityInfo<T> info, Map<String, PrepareInfo<T>> prepareInfos, T... entitys) throws SQLException {
|
||||||
Attribute<T, Serializable>[] attrs = info.insertAttributes;
|
Attribute<T, Serializable>[] attrs = info.insertAttributes;
|
||||||
final List<PreparedStatement> prestmts = new ArrayList<>();
|
final List<PreparedStatement> prestmts = new ArrayList<>();
|
||||||
for (Map.Entry<String, PrepareInfo<T>> en : prepareInfos.entrySet()) {
|
for (Map.Entry<String, PrepareInfo<T>> en : prepareInfos.entrySet()) {
|
||||||
@@ -165,7 +165,8 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
return prestmts;
|
return prestmts;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> PreparedStatement prepareInsertEntityStatement(JdbcConnection conn, String sql, EntityInfo<T> info, T... entitys) throws SQLException {
|
protected <T> PreparedStatement prepareInsertEntityStatement(JdbcConnection conn, String sql,
|
||||||
|
EntityInfo<T> info, T... entitys) throws SQLException {
|
||||||
Attribute<T, Serializable>[] attrs = info.insertAttributes;
|
Attribute<T, Serializable>[] attrs = info.insertAttributes;
|
||||||
final PreparedStatement prestmt = info.isAutoGenerated()
|
final PreparedStatement prestmt = info.isAutoGenerated()
|
||||||
? conn.prepareUpdateStatement(sql, Statement.RETURN_GENERATED_KEYS)
|
? conn.prepareUpdateStatement(sql, Statement.RETURN_GENERATED_KEYS)
|
||||||
@@ -177,7 +178,8 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
return prestmt;
|
return prestmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> List<PreparedStatement> prepareUpdateEntityStatements(JdbcConnection conn, EntityInfo<T> info, Map<String, PrepareInfo<T>> prepareInfos, T... entitys) throws SQLException {
|
protected <T> List<PreparedStatement> prepareUpdateEntityStatements(JdbcConnection conn,
|
||||||
|
EntityInfo<T> info, Map<String, PrepareInfo<T>> prepareInfos, T... entitys) throws SQLException {
|
||||||
Attribute<T, Serializable> primary = info.primary;
|
Attribute<T, Serializable> primary = info.primary;
|
||||||
Attribute<T, Serializable>[] attrs = info.updateAttributes;
|
Attribute<T, Serializable>[] attrs = info.updateAttributes;
|
||||||
final List<PreparedStatement> prestmts = new ArrayList<>();
|
final List<PreparedStatement> prestmts = new ArrayList<>();
|
||||||
@@ -194,7 +196,8 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
return prestmts;
|
return prestmts;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> PreparedStatement prepareUpdateEntityStatement(JdbcConnection conn, String prepareSQL, EntityInfo<T> info, T... entitys) throws SQLException {
|
protected <T> PreparedStatement prepareUpdateEntityStatement(JdbcConnection conn,
|
||||||
|
String prepareSQL, EntityInfo<T> info, T... entitys) throws SQLException {
|
||||||
Attribute<T, Serializable> primary = info.primary;
|
Attribute<T, Serializable> primary = info.primary;
|
||||||
Attribute<T, Serializable>[] attrs = info.updateAttributes;
|
Attribute<T, Serializable>[] attrs = info.updateAttributes;
|
||||||
final PreparedStatement prestmt = conn.prepareUpdateStatement(prepareSQL);
|
final PreparedStatement prestmt = conn.prepareUpdateStatement(prepareSQL);
|
||||||
@@ -206,7 +209,8 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
return prestmt;
|
return prestmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected <T> int bindStatementParameters(JdbcConnection conn, PreparedStatement prestmt, EntityInfo<T> info, Attribute<T, Serializable>[] attrs, T entity) throws SQLException {
|
protected <T> int bindStatementParameters(JdbcConnection conn, PreparedStatement prestmt,
|
||||||
|
EntityInfo<T> info, Attribute<T, Serializable>[] attrs, T entity) throws SQLException {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Attribute<T, Serializable> attr : attrs) {
|
for (Attribute<T, Serializable> attr : attrs) {
|
||||||
Object val = getEntityAttrValue(info, attr, entity);
|
Object val = getEntityAttrValue(info, attr, entity);
|
||||||
@@ -340,7 +344,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> int insertDBStatement(List<Statement> stmtsRef, final JdbcConnection conn, final EntityInfo<T> info, T... entitys) throws SQLException {
|
private <T> int insertDBStatement(List<Statement> stmtsRef, JdbcConnection conn, EntityInfo<T> info, T... entitys) throws SQLException {
|
||||||
final long s = System.currentTimeMillis();
|
final long s = System.currentTimeMillis();
|
||||||
int c = 0;
|
int c = 0;
|
||||||
String presql = null;
|
String presql = null;
|
||||||
@@ -479,7 +483,9 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
try {
|
try {
|
||||||
stmt = conn.createUpdateStatement();
|
stmt = conn.createUpdateStatement();
|
||||||
for (String newCatalog : newCatalogs) {
|
for (String newCatalog : newCatalogs) {
|
||||||
stmt.addBatch(("postgresql".equals(dbtype()) ? "CREATE SCHEMA IF NOT EXISTS " : "CREATE DATABASE IF NOT EXISTS ") + newCatalog);
|
stmt.addBatch(("postgresql".equals(dbtype())
|
||||||
|
? "CREATE SCHEMA IF NOT EXISTS "
|
||||||
|
: "CREATE DATABASE IF NOT EXISTS ") + newCatalog);
|
||||||
}
|
}
|
||||||
stmt.executeBatch();
|
stmt.executeBatch();
|
||||||
conn.offerUpdateStatement(stmt);
|
conn.offerUpdateStatement(stmt);
|
||||||
@@ -648,12 +654,14 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T> CompletableFuture<Integer> deleteDBAsync(final EntityInfo<T> info, String[] tables, Flipper flipper, FilterNode node, Map<String, List<Serializable>> pkmap, final String... sqls) {
|
protected <T> CompletableFuture<Integer> deleteDBAsync(final EntityInfo<T> info, String[] tables,
|
||||||
|
Flipper flipper, FilterNode node, Map<String, List<Serializable>> pkmap, final String... sqls) {
|
||||||
return supplyAsync(() -> deleteDB(info, tables, flipper, node, pkmap, sqls));
|
return supplyAsync(() -> deleteDB(info, tables, flipper, node, pkmap, sqls));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T> int deleteDB(EntityInfo<T> info, String[] tables, Flipper flipper, FilterNode node, Map<String, List<Serializable>> pkmap, String... sqls) {
|
protected <T> int deleteDB(EntityInfo<T> info, String[] tables, Flipper flipper,
|
||||||
|
FilterNode node, Map<String, List<Serializable>> pkmap, String... sqls) {
|
||||||
JdbcConnection conn = null;
|
JdbcConnection conn = null;
|
||||||
List<Statement> stmtsRef = new ArrayList<>();
|
List<Statement> stmtsRef = new ArrayList<>();
|
||||||
try {
|
try {
|
||||||
@@ -670,7 +678,8 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> int deleteDBStatement(List<Statement> stmtsRef, final JdbcConnection conn, final EntityInfo<T> info, String[] tables, Flipper flipper, FilterNode node, Map<String, List<Serializable>> pkmap, String... sqls) throws SQLException {
|
private <T> int deleteDBStatement(List<Statement> stmtsRef, final JdbcConnection conn, final EntityInfo<T> info,
|
||||||
|
String[] tables, Flipper flipper, FilterNode node, Map<String, List<Serializable>> pkmap, String... sqls) throws SQLException {
|
||||||
final long s = System.currentTimeMillis();
|
final long s = System.currentTimeMillis();
|
||||||
Statement stmt = null;
|
Statement stmt = null;
|
||||||
try {
|
try {
|
||||||
@@ -731,7 +740,8 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (logger.isLoggable(Level.FINE)) {
|
if (logger.isLoggable(Level.FINE)) {
|
||||||
logger.log(Level.FINE, "delete, old-tables: " + Arrays.toString(oldTables) + ", new-tables: " + (pkmap != null ? pkmap.keySet() : Arrays.toString(tables)));
|
logger.log(Level.FINE, "delete, old-tables: " + Arrays.toString(oldTables)
|
||||||
|
+ ", new-tables: " + (pkmap != null ? pkmap.keySet() : Arrays.toString(tables)));
|
||||||
}
|
}
|
||||||
if ((pkmap != null ? pkmap.size() : tables.length) == 0) { //分表全部不存在
|
if ((pkmap != null ? pkmap.size() : tables.length) == 0) { //分表全部不存在
|
||||||
return 0;
|
return 0;
|
||||||
@@ -907,7 +917,9 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
c = stmt.executeUpdate(copyTableSql);
|
c = stmt.executeUpdate(copyTableSql);
|
||||||
} else { //需要先建库
|
} else { //需要先建库
|
||||||
String newCatalog = newTable.substring(0, newTable.indexOf('.'));
|
String newCatalog = newTable.substring(0, newTable.indexOf('.'));
|
||||||
String catalogSql = ("postgresql".equals(dbtype()) ? "CREATE SCHEMA IF NOT EXISTS " : "CREATE DATABASE IF NOT EXISTS ") + newCatalog;
|
String catalogSql = ("postgresql".equals(dbtype())
|
||||||
|
? "CREATE SCHEMA IF NOT EXISTS "
|
||||||
|
: "CREATE DATABASE IF NOT EXISTS ") + newCatalog;
|
||||||
try {
|
try {
|
||||||
if (info.isLoggable(logger, Level.FINEST, catalogSql)) {
|
if (info.isLoggable(logger, Level.FINEST, catalogSql)) {
|
||||||
logger.finest(info.getType().getSimpleName() + " createCatalog sql=" + catalogSql);
|
logger.finest(info.getType().getSimpleName() + " createCatalog sql=" + catalogSql);
|
||||||
@@ -1066,7 +1078,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> int updateEntityDBStatement(List<Statement> stmtsRef, final JdbcConnection conn, final EntityInfo<T> info, T... entitys) throws SQLException {
|
private <T> int updateEntityDBStatement(List<Statement> stmtsRef, JdbcConnection conn, EntityInfo<T> info, T... entitys) throws SQLException {
|
||||||
final long s = System.currentTimeMillis();
|
final long s = System.currentTimeMillis();
|
||||||
String presql = null;
|
String presql = null;
|
||||||
PreparedStatement prestmt = null;
|
PreparedStatement prestmt = null;
|
||||||
@@ -1245,7 +1257,9 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T> int updateColumnDBStatement(List<Statement> stmtsRef, final JdbcConnection conn, final EntityInfo<T> info, Flipper flipper, UpdateSqlInfo sql) throws SQLException { //String sql, boolean prepared, Object... blobs) {
|
private <T> int updateColumnDBStatement(List<Statement> stmtsRef, final JdbcConnection conn,
|
||||||
|
final EntityInfo<T> info, Flipper flipper, UpdateSqlInfo sql) throws SQLException { //String sql, boolean prepared, Object... blobs) {
|
||||||
|
|
||||||
final long s = System.currentTimeMillis();
|
final long s = System.currentTimeMillis();
|
||||||
int c = -1;
|
int c = -1;
|
||||||
String firstTable = null;
|
String firstTable = null;
|
||||||
@@ -1355,7 +1369,8 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
sql.tables = Utility.remove(sql.tables, t);
|
sql.tables = Utility.remove(sql.tables, t);
|
||||||
}
|
}
|
||||||
if (logger.isLoggable(Level.FINE)) {
|
if (logger.isLoggable(Level.FINE)) {
|
||||||
logger.log(Level.FINE, "updateColumn, old-tables: " + Arrays.toString(oldTables) + ", new-tables: " + Arrays.toString(sql.tables));
|
logger.log(Level.FINE, "updateColumn, old-tables: " + Arrays.toString(oldTables)
|
||||||
|
+ ", new-tables: " + Arrays.toString(sql.tables));
|
||||||
}
|
}
|
||||||
if (sql.tables.length == 0) { //分表全部不存在
|
if (sql.tables.length == 0) { //分表全部不存在
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1397,12 +1412,14 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T, N extends Number> CompletableFuture<Map<String, N>> getNumberMapDBAsync(EntityInfo<T> info, String[] tables, String sql, FilterNode node, FilterFuncColumn... columns) {
|
protected <T, N extends Number> CompletableFuture<Map<String, N>> getNumberMapDBAsync(EntityInfo<T> info,
|
||||||
|
String[] tables, String sql, FilterNode node, FilterFuncColumn... columns) {
|
||||||
return supplyAsync(() -> getNumberMapDB(info, tables, sql, node, columns));
|
return supplyAsync(() -> getNumberMapDB(info, tables, sql, node, columns));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T, N extends Number> Map<String, N> getNumberMapDB(EntityInfo<T> info, String[] tables, String sql, FilterNode node, FilterFuncColumn... columns) {
|
protected <T, N extends Number> Map<String, N> getNumberMapDB(EntityInfo<T> info,
|
||||||
|
String[] tables, String sql, FilterNode node, FilterFuncColumn... columns) {
|
||||||
JdbcConnection conn = null;
|
JdbcConnection conn = null;
|
||||||
final Map map = new HashMap<>();
|
final Map map = new HashMap<>();
|
||||||
final long s = System.currentTimeMillis();
|
final long s = System.currentTimeMillis();
|
||||||
@@ -1499,12 +1516,14 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T> CompletableFuture<Number> getNumberResultDBAsync(EntityInfo<T> info, String[] tables, String sql, FilterFunc func, Number defVal, String column, FilterNode node) {
|
protected <T> CompletableFuture<Number> getNumberResultDBAsync(EntityInfo<T> info, String[] tables,
|
||||||
|
String sql, FilterFunc func, Number defVal, String column, FilterNode node) {
|
||||||
return supplyAsync(() -> getNumberResultDB(info, tables, sql, func, defVal, column, node));
|
return supplyAsync(() -> getNumberResultDB(info, tables, sql, func, defVal, column, node));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T> Number getNumberResultDB(EntityInfo<T> info, String[] tables, String sql, FilterFunc func, Number defVal, String column, FilterNode node) {
|
protected <T> Number getNumberResultDB(EntityInfo<T> info, String[] tables,
|
||||||
|
String sql, FilterFunc func, Number defVal, String column, FilterNode node) {
|
||||||
JdbcConnection conn = null;
|
JdbcConnection conn = null;
|
||||||
final long s = System.currentTimeMillis();
|
final long s = System.currentTimeMillis();
|
||||||
Statement stmt = null;
|
Statement stmt = null;
|
||||||
@@ -1547,7 +1566,8 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
tables = Utility.remove(tables, t);
|
tables = Utility.remove(tables, t);
|
||||||
}
|
}
|
||||||
if (logger.isLoggable(Level.FINE)) {
|
if (logger.isLoggable(Level.FINE)) {
|
||||||
logger.log(Level.FINE, "getNumberResult, old-tables: " + Arrays.toString(oldTables) + ", new-tables: " + Arrays.toString(tables));
|
logger.log(Level.FINE, "getNumberResult, old-tables: " + Arrays.toString(oldTables)
|
||||||
|
+ ", new-tables: " + Arrays.toString(tables));
|
||||||
}
|
}
|
||||||
if (tables.length == 0) { //分表全部不存在
|
if (tables.length == 0) { //分表全部不存在
|
||||||
return defVal;
|
return defVal;
|
||||||
@@ -1587,12 +1607,14 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T, K extends Serializable, N extends Number> CompletableFuture<Map<K, N>> queryColumnMapDBAsync(EntityInfo<T> info, String[] tables, String sql, String keyColumn, FilterFunc func, String funcColumn, FilterNode node) {
|
protected <T, K extends Serializable, N extends Number> CompletableFuture<Map<K, N>> queryColumnMapDBAsync(EntityInfo<T> info,
|
||||||
|
String[] tables, String sql, String keyColumn, FilterFunc func, String funcColumn, FilterNode node) {
|
||||||
return supplyAsync(() -> queryColumnMapDB(info, tables, sql, keyColumn, func, funcColumn, node));
|
return supplyAsync(() -> queryColumnMapDB(info, tables, sql, keyColumn, func, funcColumn, node));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMapDB(EntityInfo<T> info, String[] tables, String sql, String keyColumn, FilterFunc func, String funcColumn, FilterNode node) {
|
protected <T, K extends Serializable, N extends Number> Map<K, N> queryColumnMapDB(EntityInfo<T> info, String[] tables,
|
||||||
|
String sql, String keyColumn, FilterFunc func, String funcColumn, FilterNode node) {
|
||||||
JdbcConnection conn = null;
|
JdbcConnection conn = null;
|
||||||
final long s = System.currentTimeMillis();
|
final long s = System.currentTimeMillis();
|
||||||
Map<K, N> rs = new LinkedHashMap<>();
|
Map<K, N> rs = new LinkedHashMap<>();
|
||||||
@@ -1673,12 +1695,14 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T, K extends Serializable, N extends Number> CompletableFuture<Map<K[], N[]>> queryColumnMapDBAsync(EntityInfo<T> info, String[] tables, String sql, final ColumnNode[] funcNodes, final String[] groupByColumns, final FilterNode node) {
|
protected <T, K extends Serializable, N extends Number> CompletableFuture<Map<K[], N[]>> queryColumnMapDBAsync(EntityInfo<T> info,
|
||||||
|
String[] tables, String sql, final ColumnNode[] funcNodes, final String[] groupByColumns, final FilterNode node) {
|
||||||
return supplyAsync(() -> queryColumnMapDB(info, tables, sql, funcNodes, groupByColumns, node));
|
return supplyAsync(() -> queryColumnMapDB(info, tables, sql, funcNodes, groupByColumns, node));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T, K extends Serializable, N extends Number> Map<K[], N[]> queryColumnMapDB(EntityInfo<T> info, String[] tables, String sql, final ColumnNode[] funcNodes, final String[] groupByColumns, final FilterNode node) {
|
protected <T, K extends Serializable, N extends Number> Map<K[], N[]> queryColumnMapDB(EntityInfo<T> info, String[] tables,
|
||||||
|
String sql, final ColumnNode[] funcNodes, final String[] groupByColumns, final FilterNode node) {
|
||||||
JdbcConnection conn = null;
|
JdbcConnection conn = null;
|
||||||
Map rs = new LinkedHashMap<>();
|
Map rs = new LinkedHashMap<>();
|
||||||
final long s = System.currentTimeMillis();
|
final long s = System.currentTimeMillis();
|
||||||
@@ -1818,12 +1842,14 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T> CompletableFuture<T> findDBAsync(EntityInfo<T> info, String[] tables, String sql, boolean onlypk, SelectColumn selects, Serializable pk, FilterNode node) {
|
protected <T> CompletableFuture<T> findDBAsync(EntityInfo<T> info, String[] tables, String sql, boolean onlypk,
|
||||||
|
SelectColumn selects, Serializable pk, FilterNode node) {
|
||||||
return supplyAsync(() -> findDB(info, tables, sql, onlypk, selects, pk, node));
|
return supplyAsync(() -> findDB(info, tables, sql, onlypk, selects, pk, node));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T> T findDB(EntityInfo<T> info, String[] tables, String sql, boolean onlypk, SelectColumn selects, Serializable pk, FilterNode node) {
|
protected <T> T findDB(EntityInfo<T> info, String[] tables, String sql, boolean onlypk,
|
||||||
|
SelectColumn selects, Serializable pk, FilterNode node) {
|
||||||
JdbcConnection conn = null;
|
JdbcConnection conn = null;
|
||||||
final long s = System.currentTimeMillis();
|
final long s = System.currentTimeMillis();
|
||||||
PreparedStatement prestmt = null;
|
PreparedStatement prestmt = null;
|
||||||
@@ -1896,12 +1922,14 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T> CompletableFuture<Serializable> findColumnDBAsync(EntityInfo<T> info, final String[] tables, String sql, boolean onlypk, String column, Serializable defValue, Serializable pk, FilterNode node) {
|
protected <T> CompletableFuture<Serializable> findColumnDBAsync(EntityInfo<T> info, final String[] tables,
|
||||||
|
String sql, boolean onlypk, String column, Serializable defValue, Serializable pk, FilterNode node) {
|
||||||
return supplyAsync(() -> findColumnDB(info, tables, sql, onlypk, column, defValue, pk, node));
|
return supplyAsync(() -> findColumnDB(info, tables, sql, onlypk, column, defValue, pk, node));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T> Serializable findColumnDB(EntityInfo<T> info, String[] tables, String sql, boolean onlypk, String column, Serializable defValue, Serializable pk, FilterNode node) {
|
protected <T> Serializable findColumnDB(EntityInfo<T> info, String[] tables,
|
||||||
|
String sql, boolean onlypk, String column, Serializable defValue, Serializable pk, FilterNode node) {
|
||||||
JdbcConnection conn = null;
|
JdbcConnection conn = null;
|
||||||
final long s = System.currentTimeMillis();
|
final long s = System.currentTimeMillis();
|
||||||
PreparedStatement prestmt = null;
|
PreparedStatement prestmt = null;
|
||||||
@@ -1983,7 +2011,8 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T> CompletableFuture<Boolean> existsDBAsync(EntityInfo<T> info, final String[] tables, String sql, boolean onlypk, Serializable pk, FilterNode node) {
|
protected <T> CompletableFuture<Boolean> existsDBAsync(EntityInfo<T> info, final String[] tables,
|
||||||
|
String sql, boolean onlypk, Serializable pk, FilterNode node) {
|
||||||
return supplyAsync(() -> existsDB(info, tables, sql, onlypk, pk, node));
|
return supplyAsync(() -> existsDB(info, tables, sql, onlypk, pk, node));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2117,7 +2146,8 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T> CompletableFuture<Sheet<T>> querySheetDBAsync(EntityInfo<T> info, final boolean readCache, boolean needTotal, final boolean distinct, SelectColumn selects, Flipper flipper, FilterNode node) {
|
protected <T> CompletableFuture<Sheet<T>> querySheetDBAsync(EntityInfo<T> info, final boolean readCache,
|
||||||
|
boolean needTotal, final boolean distinct, SelectColumn selects, Flipper flipper, FilterNode node) {
|
||||||
return supplyAsync(() -> querySheetDB(info, readCache, needTotal, distinct, selects, flipper, node));
|
return supplyAsync(() -> querySheetDB(info, readCache, needTotal, distinct, selects, flipper, node));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2156,7 +2186,8 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected <T> Sheet<T> querySheetDB(EntityInfo<T> info, final boolean readCache, boolean needTotal, final boolean distinct, SelectColumn selects, Flipper flipper, FilterNode node) {
|
protected <T> Sheet<T> querySheetDB(EntityInfo<T> info, final boolean readCache, boolean needTotal,
|
||||||
|
final boolean distinct, SelectColumn selects, Flipper flipper, FilterNode node) {
|
||||||
if (!needTotal && !distinct && selects == null && flipper == null && node == null && info.getTableStrategy() == null) {
|
if (!needTotal && !distinct && selects == null && flipper == null && node == null && info.getTableStrategy() == null) {
|
||||||
return querySheetFullListDB(info);
|
return querySheetFullListDB(info);
|
||||||
}
|
}
|
||||||
@@ -2310,14 +2341,16 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
String listSubSql;
|
String listSubSql;
|
||||||
StringBuilder union = new StringBuilder();
|
StringBuilder union = new StringBuilder();
|
||||||
if (tables.length == 1) {
|
if (tables.length == 1) {
|
||||||
listSubSql = "SELECT " + (distinct ? "DISTINCT " : "") + info.getQueryColumns("a", selects) + " FROM " + tables[0] + " a" + joinAndWhere;
|
listSubSql = "SELECT " + (distinct ? "DISTINCT " : "") + info.getQueryColumns("a", selects)
|
||||||
|
+ " FROM " + tables[0] + " a" + joinAndWhere;
|
||||||
} else {
|
} else {
|
||||||
int b = 0;
|
int b = 0;
|
||||||
for (String table : tables) {
|
for (String table : tables) {
|
||||||
if (union.length() > 0) {
|
if (union.length() > 0) {
|
||||||
union.append(" UNION ALL ");
|
union.append(" UNION ALL ");
|
||||||
}
|
}
|
||||||
union.append("SELECT ").append(info.getQueryColumns("a", selects)).append(" FROM ").append(table).append(" a").append(joinAndWhere);
|
union.append("SELECT ").append(info.getQueryColumns("a", selects))
|
||||||
|
.append(" FROM ").append(table).append(" a").append(joinAndWhere);
|
||||||
}
|
}
|
||||||
listSubSql = "SELECT " + (distinct ? "DISTINCT " : "") + info.getQueryColumns("a", selects) + " FROM (" + (union) + ") a";
|
listSubSql = "SELECT " + (distinct ? "DISTINCT " : "") + info.getQueryColumns("a", selects) + " FROM (" + (union) + ") a";
|
||||||
}
|
}
|
||||||
@@ -2329,15 +2362,18 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (readCache && info.isLoggable(logger, Level.FINEST, listSql)) {
|
if (readCache && info.isLoggable(logger, Level.FINEST, listSql)) {
|
||||||
logger.finest(info.getType().getSimpleName() + " query sql=" + listSql + (flipper == null || flipper.getLimit() < 1 ? "" : (" LIMIT " + flipper.getLimit() + " OFFSET " + flipper.getOffset())));
|
logger.finest(info.getType().getSimpleName() + " query sql=" + listSql
|
||||||
|
+ (flipper == null || flipper.getLimit() < 1 ? "" : (" LIMIT " + flipper.getLimit() + " OFFSET " + flipper.getOffset())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mysqlOrPgsql && needTotal) {
|
if (mysqlOrPgsql && needTotal) {
|
||||||
String countSubSql;
|
String countSubSql;
|
||||||
if (tables.length == 1) {
|
if (tables.length == 1) {
|
||||||
countSubSql = "SELECT " + (distinct ? "DISTINCT COUNT(" + info.getQueryColumns("a", selects) + ")" : "COUNT(*)") + " FROM " + tables[0] + " a" + joinAndWhere;
|
countSubSql = "SELECT " + (distinct ? "DISTINCT COUNT(" + info.getQueryColumns("a", selects) + ")" : "COUNT(*)")
|
||||||
|
+ " FROM " + tables[0] + " a" + joinAndWhere;
|
||||||
} else {
|
} else {
|
||||||
countSubSql = "SELECT " + (distinct ? "DISTINCT COUNT(" + info.getQueryColumns("a", selects) + ")" : "COUNT(*)") + " FROM (" + (union) + ") a";
|
countSubSql = "SELECT " + (distinct ? "DISTINCT COUNT(" + info.getQueryColumns("a", selects) + ")" : "COUNT(*)")
|
||||||
|
+ " FROM (" + (union) + ") a";
|
||||||
}
|
}
|
||||||
countSql = countSubSql;
|
countSql = countSubSql;
|
||||||
if (readCache && info.isLoggable(logger, Level.FINEST, countSql)) {
|
if (readCache && info.isLoggable(logger, Level.FINEST, countSql)) {
|
||||||
@@ -2498,7 +2534,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
try {
|
try {
|
||||||
conn.setAutoCommit(true);
|
conn.setAutoCommit(true);
|
||||||
if (logger.isLoggable(Level.FINEST)) {
|
if (logger.isLoggable(Level.FINEST)) {
|
||||||
logger.finest("executeQuery sql=" + sql);
|
logger.finest("nativeQuery sql=" + sql);
|
||||||
}
|
}
|
||||||
final Statement stmt = conn.createQueryStatement();
|
final Statement stmt = conn.createQueryStatement();
|
||||||
if (consumer != null) {
|
if (consumer != null) {
|
||||||
@@ -2526,7 +2562,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
try {
|
try {
|
||||||
conn.setAutoCommit(true);
|
conn.setAutoCommit(true);
|
||||||
if (logger.isLoggable(Level.FINEST)) {
|
if (logger.isLoggable(Level.FINEST)) {
|
||||||
logger.finest("executeQuery sql=" + sinfo.getNativeSql());
|
logger.finest("nativeQuery sql=" + sinfo.getNativeSql());
|
||||||
}
|
}
|
||||||
V rs;
|
V rs;
|
||||||
if (sinfo.isEmptyNamed()) {
|
if (sinfo.isEmptyNamed()) {
|
||||||
@@ -2570,7 +2606,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
try {
|
try {
|
||||||
conn.setAutoCommit(true);
|
conn.setAutoCommit(true);
|
||||||
if (logger.isLoggable(Level.FINEST)) {
|
if (logger.isLoggable(Level.FINEST)) {
|
||||||
logger.finest("executeQuery sql=" + sinfo.nativeSql);
|
logger.finest("nativeQuerySheet sql=" + sinfo.nativeSql);
|
||||||
}
|
}
|
||||||
long total = -1;
|
long total = -1;
|
||||||
List<V> list;
|
List<V> list;
|
||||||
@@ -2633,7 +2669,8 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <V> CompletableFuture<V> nativeQueryAsync(String sql, BiConsumer<Object, Object> consumer, Function<DataResultSet, V> handler, Map<String, Object> params) {
|
public <V> CompletableFuture<V> nativeQueryAsync(String sql, BiConsumer<Object, Object> consumer,
|
||||||
|
Function<DataResultSet, V> handler, Map<String, Object> params) {
|
||||||
return supplyAsync(() -> nativeQuery(sql, consumer, handler, params));
|
return supplyAsync(() -> nativeQuery(sql, consumer, handler, params));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2912,7 +2949,8 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
for (ResourceEvent event : events) {
|
for (ResourceEvent event : events) {
|
||||||
if (event.name().equals(DATA_SOURCE_URL) || event.name().endsWith("." + DATA_SOURCE_URL)) {
|
if (event.name().equals(DATA_SOURCE_URL) || event.name().endsWith("." + DATA_SOURCE_URL)) {
|
||||||
newUrl = event.newValue().toString();
|
newUrl = event.newValue().toString();
|
||||||
} else if (event.name().equals(DATA_SOURCE_CONNECT_TIMEOUT_SECONDS) || event.name().endsWith("." + DATA_SOURCE_CONNECT_TIMEOUT_SECONDS)) {
|
} else if (event.name().equals(DATA_SOURCE_CONNECT_TIMEOUT_SECONDS)
|
||||||
|
|| event.name().endsWith("." + DATA_SOURCE_CONNECT_TIMEOUT_SECONDS)) {
|
||||||
newConnectTimeoutSeconds = Integer.decode(event.newValue().toString());
|
newConnectTimeoutSeconds = Integer.decode(event.newValue().toString());
|
||||||
} else if (event.name().equals(DATA_SOURCE_USER) || event.name().endsWith("." + DATA_SOURCE_USER)) {
|
} else if (event.name().equals(DATA_SOURCE_USER) || event.name().endsWith("." + DATA_SOURCE_USER)) {
|
||||||
newUser = event.newValue().toString();
|
newUser = event.newValue().toString();
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public class DataNativeSqlInfo {
|
|||||||
//sql类型
|
//sql类型
|
||||||
protected SqlMode sqlMode;
|
protected SqlMode sqlMode;
|
||||||
|
|
||||||
|
//根参数名, 如bean.userid、bean.username的根参数名为: bean
|
||||||
protected final List<String> rootParamNames = new ArrayList<>();
|
protected final List<String> rootParamNames = new ArrayList<>();
|
||||||
|
|
||||||
@ConvertDisabled
|
@ConvertDisabled
|
||||||
@@ -52,6 +53,6 @@ public class DataNativeSqlInfo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum SqlMode {
|
public enum SqlMode {
|
||||||
SELECT, INSERT, DELETE, UPDATE, UPSERT, OTHERS;
|
SELECT, INSERT, DELETE, UPDATE, OTHERS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user