优化isTableNotExist
This commit is contained in:
@@ -580,7 +580,10 @@ public abstract class AbstractDataSqlSource extends AbstractDataSource implement
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isTableNotExist(EntityInfo info, String sqlCode) {
|
protected boolean isTableNotExist(EntityInfo info, Throwable exp, String sqlCode) {
|
||||||
|
if (exp instanceof java.sql.SQLSyntaxErrorException) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return sqlCode != null && !sqlCode.isEmpty() && tableNotExistSqlstates.contains(';' + sqlCode + ';');
|
return sqlCode != null && !sqlCode.isEmpty() && tableNotExistSqlstates.contains(';' + sqlCode + ';');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -416,7 +416,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
} catch (SQLException se) {
|
} catch (SQLException se) {
|
||||||
conn.rollback(prestmt, prestmts);
|
conn.rollback(prestmt, prestmts);
|
||||||
stmtsRef.clear();
|
stmtsRef.clear();
|
||||||
if (!isTableNotExist(info, se.getSQLState())) {
|
if (!isTableNotExist(info, se, se.getSQLState())) {
|
||||||
throw se;
|
throw se;
|
||||||
}
|
}
|
||||||
if (info.getTableStrategy() == null) { //单库单表
|
if (info.getTableStrategy() == null) { //单库单表
|
||||||
@@ -460,7 +460,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
conn.offerUpdateStatement(stmt);
|
conn.offerUpdateStatement(stmt);
|
||||||
} catch (SQLException sqle) { //多进程并发时可能会出现重复建表
|
} catch (SQLException sqle) { //多进程并发时可能会出现重复建表
|
||||||
if (isTableNotExist(info, sqle.getSQLState())) {
|
if (isTableNotExist(info, sqle, sqle.getSQLState())) {
|
||||||
if (newCatalogs.isEmpty()) { //分表的原始表不存在
|
if (newCatalogs.isEmpty()) { //分表的原始表不存在
|
||||||
String[] tableSqls = createTableSqls(info);
|
String[] tableSqls = createTableSqls(info);
|
||||||
if (tableSqls != null) {
|
if (tableSqls != null) {
|
||||||
@@ -514,7 +514,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
conn.offerUpdateStatement(stmt);
|
conn.offerUpdateStatement(stmt);
|
||||||
} catch (SQLException sqle2) {
|
} catch (SQLException sqle2) {
|
||||||
if (isTableNotExist(info, sqle2.getSQLState())) {
|
if (isTableNotExist(info, sqle2, sqle2.getSQLState())) {
|
||||||
String[] tableSqls = createTableSqls(info);
|
String[] tableSqls = createTableSqls(info);
|
||||||
if (tableSqls != null) { //创建原始表
|
if (tableSqls != null) { //创建原始表
|
||||||
stmt = conn.createUpdateStatement();
|
stmt = conn.createUpdateStatement();
|
||||||
@@ -719,7 +719,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
return c;
|
return c;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
conn.rollback(stmt);
|
conn.rollback(stmt);
|
||||||
if (isTableNotExist(info, e.getSQLState())) {
|
if (isTableNotExist(info, e, e.getSQLState())) {
|
||||||
if (info.getTableStrategy() == null) {
|
if (info.getTableStrategy() == null) {
|
||||||
String[] tableSqls = createTableSqls(info);
|
String[] tableSqls = createTableSqls(info);
|
||||||
if (tableSqls != null) {
|
if (tableSqls != null) {
|
||||||
@@ -819,7 +819,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
slowLog(s, sqls);
|
slowLog(s, sqls);
|
||||||
return c;
|
return c;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
if (isTableNotExist(info, e.getSQLState())) {
|
if (isTableNotExist(info, e, e.getSQLState())) {
|
||||||
if (info.getTableStrategy() == null) {
|
if (info.getTableStrategy() == null) {
|
||||||
//单表结构不存在
|
//单表结构不存在
|
||||||
return 0;
|
return 0;
|
||||||
@@ -910,7 +910,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
stmt = conn.createUpdateStatement();
|
stmt = conn.createUpdateStatement();
|
||||||
c = stmt.executeUpdate(copyTableSql);
|
c = stmt.executeUpdate(copyTableSql);
|
||||||
} catch (SQLException se) {
|
} catch (SQLException se) {
|
||||||
if (isTableNotExist(info, se.getSQLState())) { //分表的原始表不存在
|
if (isTableNotExist(info, se, se.getSQLState())) { //分表的原始表不存在
|
||||||
conn.offerUpdateStatement(stmt);
|
conn.offerUpdateStatement(stmt);
|
||||||
final String newTable = info.getTable(pk);
|
final String newTable = info.getTable(pk);
|
||||||
if (newTable.indexOf('.') <= 0) { //分表的原始表不存在
|
if (newTable.indexOf('.') <= 0) { //分表的原始表不存在
|
||||||
@@ -958,7 +958,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
c = stmt.executeUpdate(copyTableSql);
|
c = stmt.executeUpdate(copyTableSql);
|
||||||
} catch (SQLException sqle2) {
|
} catch (SQLException sqle2) {
|
||||||
conn.offerUpdateStatement(stmt);
|
conn.offerUpdateStatement(stmt);
|
||||||
if (isTableNotExist(info, sqle2.getSQLState())) {
|
if (isTableNotExist(info, sqle2, sqle2.getSQLState())) {
|
||||||
if (info.isLoggable(logger, Level.FINEST, sqls[0])) {
|
if (info.isLoggable(logger, Level.FINEST, sqls[0])) {
|
||||||
logger.finest(info.getType().getSimpleName() + " createTable sql=" + Arrays.toString(sqls));
|
logger.finest(info.getType().getSimpleName() + " createTable sql=" + Arrays.toString(sqls));
|
||||||
}
|
}
|
||||||
@@ -1021,7 +1021,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
slowLog(s, sqls);
|
slowLog(s, sqls);
|
||||||
return c;
|
return c;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
if (isTableNotExist(info, e.getSQLState())) {
|
if (isTableNotExist(info, e, e.getSQLState())) {
|
||||||
if (info.getTableStrategy() == null) {
|
if (info.getTableStrategy() == null) {
|
||||||
//单表结构不存在
|
//单表结构不存在
|
||||||
return 0;
|
return 0;
|
||||||
@@ -1136,7 +1136,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
} catch (SQLException se) {
|
} catch (SQLException se) {
|
||||||
conn.rollback(prestmt, prestmts);
|
conn.rollback(prestmt, prestmts);
|
||||||
if (isTableNotExist(info, se.getSQLState())) {
|
if (isTableNotExist(info, se, se.getSQLState())) {
|
||||||
if (info.getTableStrategy() == null) {
|
if (info.getTableStrategy() == null) {
|
||||||
String[] tableSqls = createTableSqls(info);
|
String[] tableSqls = createTableSqls(info);
|
||||||
if (tableSqls != null) {
|
if (tableSqls != null) {
|
||||||
@@ -1350,7 +1350,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
}
|
}
|
||||||
} catch (SQLException se) {
|
} catch (SQLException se) {
|
||||||
conn.rollback(onestmt, prestmts);
|
conn.rollback(onestmt, prestmts);
|
||||||
if (isTableNotExist(info, se.getSQLState())) {
|
if (isTableNotExist(info, se, se.getSQLState())) {
|
||||||
if (info.getTableStrategy() == null) {
|
if (info.getTableStrategy() == null) {
|
||||||
String[] tableSqls = createTableSqls(info);
|
String[] tableSqls = createTableSqls(info);
|
||||||
if (tableSqls != null) {
|
if (tableSqls != null) {
|
||||||
@@ -1467,7 +1467,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
return map;
|
return map;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
map.clear();
|
map.clear();
|
||||||
if (isTableNotExist(info, e.getSQLState())) {
|
if (isTableNotExist(info, e, e.getSQLState())) {
|
||||||
if (info.getTableStrategy() == null) {
|
if (info.getTableStrategy() == null) {
|
||||||
//读操作不自动创建表,可能存在读写分离
|
//读操作不自动创建表,可能存在读写分离
|
||||||
return map;
|
return map;
|
||||||
@@ -1563,7 +1563,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
slowLog(s, sql);
|
slowLog(s, sql);
|
||||||
return rs;
|
return rs;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
if (isTableNotExist(info, e.getSQLState())) {
|
if (isTableNotExist(info, e, e.getSQLState())) {
|
||||||
if (info.getTableStrategy() == null) {
|
if (info.getTableStrategy() == null) {
|
||||||
//读操作不自动创建表,可能存在读写分离
|
//读操作不自动创建表,可能存在读写分离
|
||||||
return defVal;
|
return defVal;
|
||||||
@@ -1654,7 +1654,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
return rs;
|
return rs;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
rs.clear();
|
rs.clear();
|
||||||
if (isTableNotExist(info, e.getSQLState())) {
|
if (isTableNotExist(info, e, e.getSQLState())) {
|
||||||
if (info.getTableStrategy() == null) {
|
if (info.getTableStrategy() == null) {
|
||||||
//读操作不自动创建表,可能存在读写分离
|
//读操作不自动创建表,可能存在读写分离
|
||||||
return rs;
|
return rs;
|
||||||
@@ -1757,7 +1757,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
return rs;
|
return rs;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
rs.clear();
|
rs.clear();
|
||||||
if (isTableNotExist(info, e.getSQLState())) {
|
if (isTableNotExist(info, e, e.getSQLState())) {
|
||||||
if (info.getTableStrategy() == null) {
|
if (info.getTableStrategy() == null) {
|
||||||
//读操作不自动创建表,可能存在读写分离
|
//读操作不自动创建表,可能存在读写分离
|
||||||
return rs;
|
return rs;
|
||||||
@@ -1851,7 +1851,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
slowLog(s, prepareSQL);
|
slowLog(s, prepareSQL);
|
||||||
return rs;
|
return rs;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
if (isTableNotExist(info, e.getSQLState())) {
|
if (isTableNotExist(info, e, e.getSQLState())) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
throw new SourceException(e);
|
throw new SourceException(e);
|
||||||
@@ -1884,7 +1884,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
slowLog(s, sql);
|
slowLog(s, sql);
|
||||||
return rs;
|
return rs;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
if (isTableNotExist(info, e.getSQLState())) {
|
if (isTableNotExist(info, e, e.getSQLState())) {
|
||||||
if (info.getTableStrategy() == null) {
|
if (info.getTableStrategy() == null) {
|
||||||
//读操作不自动创建表,可能存在读写分离
|
//读操作不自动创建表,可能存在读写分离
|
||||||
return null;
|
return null;
|
||||||
@@ -1968,7 +1968,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
slowLog(s, sql);
|
slowLog(s, sql);
|
||||||
return val == null ? defValue : val;
|
return val == null ? defValue : val;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
if (isTableNotExist(info, e.getSQLState())) {
|
if (isTableNotExist(info, e, e.getSQLState())) {
|
||||||
if (info.getTableStrategy() == null) {
|
if (info.getTableStrategy() == null) {
|
||||||
//读操作不自动创建表,可能存在读写分离
|
//读操作不自动创建表,可能存在读写分离
|
||||||
return defValue;
|
return defValue;
|
||||||
@@ -2054,7 +2054,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
slowLog(s, sql);
|
slowLog(s, sql);
|
||||||
return rs;
|
return rs;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
if (isTableNotExist(info, e.getSQLState())) {
|
if (isTableNotExist(info, e, e.getSQLState())) {
|
||||||
if (info.getTableStrategy() == null) {
|
if (info.getTableStrategy() == null) {
|
||||||
//读操作不自动创建表,可能存在读写分离
|
//读操作不自动创建表,可能存在读写分离
|
||||||
return false;
|
return false;
|
||||||
@@ -2142,7 +2142,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
slowLog(s, prepareSQL);
|
slowLog(s, prepareSQL);
|
||||||
return list;
|
return list;
|
||||||
} catch (SQLException se) {
|
} catch (SQLException se) {
|
||||||
if (isTableNotExist(info, se.getSQLState())) {
|
if (isTableNotExist(info, se, se.getSQLState())) {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
throw new SourceException(se);
|
throw new SourceException(se);
|
||||||
@@ -2190,7 +2190,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
slowLog(s, prepareSQL);
|
slowLog(s, prepareSQL);
|
||||||
return Sheet.asSheet(list);
|
return Sheet.asSheet(list);
|
||||||
} catch (SQLException se) {
|
} catch (SQLException se) {
|
||||||
if (isTableNotExist(info, se.getSQLState())) {
|
if (isTableNotExist(info, se, se.getSQLState())) {
|
||||||
return Sheet.asSheet(list);
|
return Sheet.asSheet(list);
|
||||||
}
|
}
|
||||||
throw new SourceException(se);
|
throw new SourceException(se);
|
||||||
@@ -2228,7 +2228,7 @@ public class DataJdbcSource extends AbstractDataSqlSource {
|
|||||||
try {
|
try {
|
||||||
return executeQuerySheet(info, needTotal, flipper, sels, s, conn, mysqlOrPgsql, listSql, countSql);
|
return executeQuerySheet(info, needTotal, flipper, sels, s, conn, mysqlOrPgsql, listSql, countSql);
|
||||||
} catch (SQLException se) {
|
} catch (SQLException se) {
|
||||||
if (isTableNotExist(info, se.getSQLState())) {
|
if (isTableNotExist(info, se, se.getSQLState())) {
|
||||||
if (info.getTableStrategy() == null) {
|
if (info.getTableStrategy() == null) {
|
||||||
//读操作不自动创建表,可能存在读写分离
|
//读操作不自动创建表,可能存在读写分离
|
||||||
return new Sheet<>(0, new ArrayList());
|
return new Sheet<>(0, new ArrayList());
|
||||||
|
|||||||
Reference in New Issue
Block a user