未验证 提交 da283c2f 编写于 作者: X xiaoyu 提交者: GitHub

fix oracle bug. (#5908)

上级 5f07d25c
......@@ -53,17 +53,17 @@ public final class ColumnMetaDataLoader {
* @throws SQLException SQL exception
*/
public static Collection<ColumnMetaData> load(final Connection connection, final String table, final String databaseType) throws SQLException {
if (!isTableExist(connection, connection.getCatalog(), table)) {
if (!isTableExist(connection, connection.getCatalog(), table, databaseType)) {
return Collections.emptyList();
}
Collection<ColumnMetaData> result = new LinkedList<>();
Collection<String> primaryKeys = loadPrimaryKeys(connection, table);
Collection<String> primaryKeys = loadPrimaryKeys(connection, table, databaseType);
List<String> columnNames = new ArrayList<>();
List<Integer> columnTypes = new ArrayList<>();
List<String> columnTypeNames = new ArrayList<>();
List<Boolean> isPrimaryKeys = new ArrayList<>();
List<Boolean> isCaseSensitives = new ArrayList<>();
try (ResultSet resultSet = connection.getMetaData().getColumns(connection.getCatalog(), JdbcUtil.getSchema(connection), table, "%")) {
try (ResultSet resultSet = connection.getMetaData().getColumns(connection.getCatalog(), JdbcUtil.getSchema(connection, databaseType), table, "%")) {
while (resultSet.next()) {
String columnName = resultSet.getString(COLUMN_NAME);
columnTypes.add(resultSet.getInt(DATA_TYPE));
......@@ -104,15 +104,15 @@ public final class ColumnMetaDataLoader {
return "SELECT * FROM " + delimiterLeft + table + delimiterRight + " WHERE 1 != 1";
}
private static boolean isTableExist(final Connection connection, final String catalog, final String table) throws SQLException {
try (ResultSet resultSet = connection.getMetaData().getTables(catalog, JdbcUtil.getSchema(connection), table, null)) {
private static boolean isTableExist(final Connection connection, final String catalog, final String table, final String databaseType) throws SQLException {
try (ResultSet resultSet = connection.getMetaData().getTables(catalog, JdbcUtil.getSchema(connection, databaseType), table, null)) {
return resultSet.next();
}
}
private static Collection<String> loadPrimaryKeys(final Connection connection, final String table) throws SQLException {
private static Collection<String> loadPrimaryKeys(final Connection connection, final String table, final String databaseType) throws SQLException {
Collection<String> result = new HashSet<>();
try (ResultSet resultSet = connection.getMetaData().getPrimaryKeys(connection.getCatalog(), JdbcUtil.getSchema(connection), table)) {
try (ResultSet resultSet = connection.getMetaData().getPrimaryKeys(connection.getCatalog(), JdbcUtil.getSchema(connection, databaseType), table)) {
while (resultSet.next()) {
result.add(resultSet.getString(COLUMN_NAME));
}
......
......@@ -40,12 +40,13 @@ public final class IndexMetaDataLoader {
*
* @param connection connection
* @param table table name
* @param databaseType databaseType
* @return index meta data list
* @throws SQLException SQL exception
*/
public static Collection<IndexMetaData> load(final Connection connection, final String table) throws SQLException {
public static Collection<IndexMetaData> load(final Connection connection, final String table, final String databaseType) throws SQLException {
Collection<IndexMetaData> result = new HashSet<>();
try (ResultSet resultSet = connection.getMetaData().getIndexInfo(connection.getCatalog(), JdbcUtil.getSchema(connection), table, false, false)) {
try (ResultSet resultSet = connection.getMetaData().getIndexInfo(connection.getCatalog(), JdbcUtil.getSchema(connection, databaseType), table, false, false)) {
while (resultSet.next()) {
String indexName = resultSet.getString(INDEX_NAME);
if (null != indexName) {
......
......@@ -65,7 +65,7 @@ public final class SchemaMetaDataLoader {
public static SchemaMetaData load(final DataSource dataSource, final int maxConnectionCount, final String databaseType) throws SQLException {
List<String> tableNames;
try (Connection connection = dataSource.getConnection()) {
tableNames = loadAllTableNames(connection);
tableNames = loadAllTableNames(connection, databaseType);
}
log.info("Loading {} tables' meta data.", tableNames.size());
if (0 == tableNames.size()) {
......@@ -81,15 +81,15 @@ public final class SchemaMetaDataLoader {
try (Connection con = connection) {
Map<String, TableMetaData> result = new LinkedHashMap<>();
for (String each : tables) {
result.put(each, new TableMetaData(ColumnMetaDataLoader.load(con, each, databaseType), IndexMetaDataLoader.load(con, each)));
result.put(each, new TableMetaData(ColumnMetaDataLoader.load(con, each, databaseType), IndexMetaDataLoader.load(con, each, databaseType)));
}
return result;
}
}
private static List<String> loadAllTableNames(final Connection connection) throws SQLException {
private static List<String> loadAllTableNames(final Connection connection, final String databaseType) throws SQLException {
List<String> result = new LinkedList<>();
try (ResultSet resultSet = connection.getMetaData().getTables(connection.getCatalog(), JdbcUtil.getSchema(connection), null, new String[]{TABLE_TYPE})) {
try (ResultSet resultSet = connection.getMetaData().getTables(connection.getCatalog(), JdbcUtil.getSchema(connection, databaseType), null, new String[]{TABLE_TYPE})) {
while (resultSet.next()) {
String table = resultSet.getString(TABLE_NAME);
if (!isSystemTable(table)) {
......
......@@ -43,7 +43,7 @@ public final class TableMetaDataLoader {
*/
public static TableMetaData load(final DataSource dataSource, final String table, final String databaseType) throws SQLException {
try (Connection connection = dataSource.getConnection()) {
return new TableMetaData(ColumnMetaDataLoader.load(connection, table, databaseType), IndexMetaDataLoader.load(connection, table));
return new TableMetaData(ColumnMetaDataLoader.load(connection, table, databaseType), IndexMetaDataLoader.load(connection, table, databaseType));
}
}
}
......@@ -29,11 +29,15 @@ public class JdbcUtil {
* Get schema.
*
* @param connection connection
* @param databaseType database type
* @return schema
*/
public static String getSchema(final Connection connection) {
public static String getSchema(final Connection connection, final String databaseType) {
String result = null;
try {
if ("Oracle".equals(databaseType)) {
return null;
}
result = connection.getSchema();
} catch (final SQLException ignore) {
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册