Browse Source

feat: support hive jdbc is_auto_increment (#136)

master
vran 3 years ago
committed by GitHub
parent
commit
ba60cf12e1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 26
      plugin/src/main/java/com/databasir/core/meta/repository/impl/jdbc/JdbcColumnMetaRepository.java

26
plugin/src/main/java/com/databasir/core/meta/repository/impl/jdbc/JdbcColumnMetaRepository.java

@ -66,6 +66,7 @@ public class JdbcColumnMetaRepository implements ColumnMetaRepository {
String columnType = columnsResult.getString("TYPE_NAME"); String columnType = columnsResult.getString("TYPE_NAME");
String columnComment = columnsResult.getString("REMARKS"); String columnComment = columnsResult.getString("REMARKS");
int dataType = columnsResult.getInt("DATA_TYPE"); int dataType = columnsResult.getInt("DATA_TYPE");
String autoIncrement = retrieveAutoIncrement(columnsResult);
ColumnMeta columnMeta = ColumnMeta.builder() ColumnMeta columnMeta = ColumnMeta.builder()
.name(columnName) .name(columnName)
.dataType(dataType) .dataType(dataType)
@ -73,7 +74,7 @@ public class JdbcColumnMetaRepository implements ColumnMetaRepository {
.size(columnSize) .size(columnSize)
.decimalDigits(decimalDigits) .decimalDigits(decimalDigits)
.nullable(isNullable) .nullable(isNullable)
.autoIncrement(retrieveAutoIncrement(columnsResult)) .autoIncrement(autoIncrement)
.comment(columnComment) .comment(columnComment)
.defaultValue(defaultValue) .defaultValue(defaultValue)
.isPrimaryKey(primaryKeyColumns.contains(columnName)) .isPrimaryKey(primaryKeyColumns.contains(columnName))
@ -88,17 +89,26 @@ public class JdbcColumnMetaRepository implements ColumnMetaRepository {
} }
private String retrieveAutoIncrement(ResultSet columnsResult) { private String retrieveAutoIncrement(ResultSet columnsResult) {
String isAutoIncrement = null;
try { try {
isAutoIncrement = columnsResult.getString("IS_AUTOINCREMENT"); return retrieveAutoIncrement(columnsResult, "IS_AUTOINCREMENT");
if (isAutoIncrement.trim().equals("")) {
isAutoIncrement = "UNKNOWN";
}
return isAutoIncrement;
} catch (SQLException e) { } catch (SQLException e) {
log.warn("warn: ignore auto increment, error: " + e.getMessage()); log.warn("get is_autoincrement failed, fallback to is_auto_increment, error: " + e.getMessage());
try {
// hive jdbc driver doesn't support is_autoincrement, fallback to is_auto_increment
return retrieveAutoIncrement(columnsResult, "is_auto_increment");
} catch (SQLException ex) {
log.warn("get is_auto_increment failed, error: " + ex.getMessage());
return "UNKNOWN";
}
}
}
private String retrieveAutoIncrement(ResultSet columnsResult, String columnName) throws SQLException {
String isAutoIncrement = columnsResult.getString(columnName);
if (isAutoIncrement.trim().equals("")) {
return "UNKNOWN"; return "UNKNOWN";
} }
return isAutoIncrement;
} }
private List<String> selectPrimaryKeyColumns(DatabaseMetaData meta, private List<String> selectPrimaryKeyColumns(DatabaseMetaData meta,

Loading…
Cancel
Save