fix: cursor over limit when sync (#114)
* fix: cursor over limit when sync * fix: code checkstyle
This commit is contained in:
parent
c1f7d1e99d
commit
137923c740
|
@ -35,7 +35,7 @@ public class DatabaseTypeController {
|
||||||
|
|
||||||
@GetMapping(Routes.DatabaseType.LIST_PAGE)
|
@GetMapping(Routes.DatabaseType.LIST_PAGE)
|
||||||
public JsonData<Page<DatabaseTypePageResponse>> listPage(@PageableDefault(sort = "id", direction = DESC)
|
public JsonData<Page<DatabaseTypePageResponse>> listPage(@PageableDefault(sort = "id", direction = DESC)
|
||||||
Pageable page,
|
Pageable page,
|
||||||
DatabaseTypePageCondition condition) {
|
DatabaseTypePageCondition condition) {
|
||||||
Page<DatabaseTypePageResponse> data = databaseTypeService.findByPage(page, condition);
|
Page<DatabaseTypePageResponse> data = databaseTypeService.findByPage(page, condition);
|
||||||
return JsonData.ok(data);
|
return JsonData.ok(data);
|
||||||
|
|
|
@ -169,6 +169,8 @@ public interface Routes {
|
||||||
String CREATE = BASE + "/database_types";
|
String CREATE = BASE + "/database_types";
|
||||||
|
|
||||||
String RESOLVE_DRIVER_CLASS_NAME = BASE + "/database_types/driver_class_name";
|
String RESOLVE_DRIVER_CLASS_NAME = BASE + "/database_types/driver_class_name";
|
||||||
|
|
||||||
|
String UPLOAD_DRIVER = BASE + "/database_types/upload_driver";
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MockData {
|
interface MockData {
|
||||||
|
|
|
@ -36,52 +36,56 @@ public class JdbcColumnMetaRepository implements ColumnMetaRepository {
|
||||||
columnsResult = connection.getMetaData()
|
columnsResult = connection.getMetaData()
|
||||||
.getColumns(databaseName, tableCondition.getSchemaName(), tableName, null);
|
.getColumns(databaseName, tableCondition.getSchemaName(), tableName, null);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.warn("warn: ignore columns in " + databaseName + "." + tableName);
|
log.warn("warn: ignore columns in " + databaseName + "." + tableName + ", error: " + e.getMessage());
|
||||||
return columnDocs;
|
return columnDocs;
|
||||||
}
|
}
|
||||||
while (columnsResult.next()) {
|
try {
|
||||||
String columnName = columnsResult.getString("COLUMN_NAME");
|
while (columnsResult.next()) {
|
||||||
if (tableCondition.columnIsIgnored(columnName)) {
|
String columnName = columnsResult.getString("COLUMN_NAME");
|
||||||
if (log.isWarnEnabled()) {
|
if (tableCondition.columnIsIgnored(columnName)) {
|
||||||
log.warn("ignore column: " + columnName);
|
if (log.isWarnEnabled()) {
|
||||||
}
|
log.warn("ignore column: " + columnName);
|
||||||
} else {
|
}
|
||||||
String defaultValue = columnsResult.getString("COLUMN_DEF");
|
|
||||||
String isNullable = columnsResult.getString("IS_NULLABLE");
|
|
||||||
if (isNullable.trim().equals("")) {
|
|
||||||
isNullable = "UNKNOWN";
|
|
||||||
}
|
|
||||||
String isAutoIncrement = columnsResult.getString("IS_AUTOINCREMENT");
|
|
||||||
if (isAutoIncrement.trim().equals("")) {
|
|
||||||
isAutoIncrement = "UNKNOWN";
|
|
||||||
}
|
|
||||||
if (defaultValue != null && defaultValue.trim().equals("")) {
|
|
||||||
defaultValue = "'" + defaultValue + "'";
|
|
||||||
}
|
|
||||||
Integer decimalDigits;
|
|
||||||
if (columnsResult.getObject("DECIMAL_DIGITS") == null) {
|
|
||||||
decimalDigits = null;
|
|
||||||
} else {
|
} else {
|
||||||
decimalDigits = columnsResult.getInt("DECIMAL_DIGITS");
|
String defaultValue = columnsResult.getString("COLUMN_DEF");
|
||||||
|
String isNullable = columnsResult.getString("IS_NULLABLE");
|
||||||
|
if (isNullable.trim().equals("")) {
|
||||||
|
isNullable = "UNKNOWN";
|
||||||
|
}
|
||||||
|
String isAutoIncrement = columnsResult.getString("IS_AUTOINCREMENT");
|
||||||
|
if (isAutoIncrement.trim().equals("")) {
|
||||||
|
isAutoIncrement = "UNKNOWN";
|
||||||
|
}
|
||||||
|
if (defaultValue != null && defaultValue.trim().equals("")) {
|
||||||
|
defaultValue = "'" + defaultValue + "'";
|
||||||
|
}
|
||||||
|
Integer decimalDigits;
|
||||||
|
if (columnsResult.getObject("DECIMAL_DIGITS") == null) {
|
||||||
|
decimalDigits = null;
|
||||||
|
} else {
|
||||||
|
decimalDigits = columnsResult.getInt("DECIMAL_DIGITS");
|
||||||
|
}
|
||||||
|
Integer columnSize = columnsResult.getInt("COLUMN_SIZE");
|
||||||
|
String columnType = columnsResult.getString("TYPE_NAME");
|
||||||
|
String columnComment = columnsResult.getString("REMARKS");
|
||||||
|
int dataType = columnsResult.getInt("DATA_TYPE");
|
||||||
|
ColumnMeta columnMeta = ColumnMeta.builder()
|
||||||
|
.name(columnName)
|
||||||
|
.dataType(dataType)
|
||||||
|
.type(columnType)
|
||||||
|
.size(columnSize)
|
||||||
|
.decimalDigits(decimalDigits)
|
||||||
|
.nullable(isNullable)
|
||||||
|
.autoIncrement(isAutoIncrement)
|
||||||
|
.comment(columnComment)
|
||||||
|
.defaultValue(defaultValue)
|
||||||
|
.isPrimaryKey(primaryKeyColumns.contains(columnName))
|
||||||
|
.build();
|
||||||
|
columnDocs.add(columnMeta);
|
||||||
}
|
}
|
||||||
Integer columnSize = columnsResult.getInt("COLUMN_SIZE");
|
|
||||||
String columnType = columnsResult.getString("TYPE_NAME");
|
|
||||||
String columnComment = columnsResult.getString("REMARKS");
|
|
||||||
int dataType = columnsResult.getInt("DATA_TYPE");
|
|
||||||
ColumnMeta columnMeta = ColumnMeta.builder()
|
|
||||||
.name(columnName)
|
|
||||||
.dataType(dataType)
|
|
||||||
.type(columnType)
|
|
||||||
.size(columnSize)
|
|
||||||
.decimalDigits(decimalDigits)
|
|
||||||
.nullable(isNullable)
|
|
||||||
.autoIncrement(isAutoIncrement)
|
|
||||||
.comment(columnComment)
|
|
||||||
.defaultValue(defaultValue)
|
|
||||||
.isPrimaryKey(primaryKeyColumns.contains(columnName))
|
|
||||||
.build();
|
|
||||||
columnDocs.add(columnMeta);
|
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
columnsResult.close();
|
||||||
}
|
}
|
||||||
return columnDocs;
|
return columnDocs;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,12 @@ public class JdbcForeignKeyMetaRepository implements ForeignKeyMetaRepository {
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.warn("warn: ignore foreign keys in " + databaseName + "." + tableName + ", " + e.getMessage());
|
log.warn("warn: ignore foreign keys in " + databaseName + "." + tableName + ", " + e.getMessage());
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
keyResult.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.warn("warn: close key result error " + databaseName + "." + tableName + ", " + e.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return foreignKeys;
|
return foreignKeys;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,27 +31,31 @@ public class JdbcIndexMetaRepository implements IndexMetaRepository {
|
||||||
indexResults = connection.getMetaData()
|
indexResults = connection.getMetaData()
|
||||||
.getIndexInfo(databaseName, condition.getSchemaName(), tableName, false, false);
|
.getIndexInfo(databaseName, condition.getSchemaName(), tableName, false, false);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.warn("warn: ignore " + databaseName + "." + tableName);
|
log.warn("warn: ignore " + databaseName + "." + tableName + ", error=" + e.getMessage());
|
||||||
return indexMetas;
|
return indexMetas;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, IndexMeta> pojoGroupByName = new HashMap<>();
|
Map<String, IndexMeta> pojoGroupByName = new HashMap<>();
|
||||||
while (indexResults.next()) {
|
try {
|
||||||
Boolean nonUnique = indexResults.getBoolean("NON_UNIQUE");
|
while (indexResults.next()) {
|
||||||
String indexName = indexResults.getString("INDEX_NAME");
|
Boolean nonUnique = indexResults.getBoolean("NON_UNIQUE");
|
||||||
String columnName = indexResults.getString("COLUMN_NAME");
|
String indexName = indexResults.getString("INDEX_NAME");
|
||||||
if (pojoGroupByName.containsKey(indexName)) {
|
String columnName = indexResults.getString("COLUMN_NAME");
|
||||||
pojoGroupByName.get(indexName).getColumnNames().add(columnName);
|
if (pojoGroupByName.containsKey(indexName)) {
|
||||||
} else {
|
pojoGroupByName.get(indexName).getColumnNames().add(columnName);
|
||||||
List<String> columns = new ArrayList<>();
|
} else {
|
||||||
columns.add(columnName);
|
List<String> columns = new ArrayList<>();
|
||||||
IndexMeta indexMeta = IndexMeta.builder()
|
columns.add(columnName);
|
||||||
.name(indexName)
|
IndexMeta indexMeta = IndexMeta.builder()
|
||||||
.columnNames(columns)
|
.name(indexName)
|
||||||
.isUniqueKey(Objects.equals(nonUnique, false))
|
.columnNames(columns)
|
||||||
.build();
|
.isUniqueKey(Objects.equals(nonUnique, false))
|
||||||
pojoGroupByName.put(indexName, indexMeta);
|
.build();
|
||||||
|
pojoGroupByName.put(indexName, indexMeta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
indexResults.close();
|
||||||
}
|
}
|
||||||
return new ArrayList<>(pojoGroupByName.values());
|
return new ArrayList<>(pojoGroupByName.values());
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,34 +40,39 @@ public class JdbcTableMetaRepository implements TableMetaRepository {
|
||||||
String databaseName = condition.getDatabaseName();
|
String databaseName = condition.getDatabaseName();
|
||||||
ResultSet tablesResult = connection.getMetaData()
|
ResultSet tablesResult = connection.getMetaData()
|
||||||
.getTables(databaseName, condition.getSchemaName(), null, new String[]{"TABLE"});
|
.getTables(databaseName, condition.getSchemaName(), null, new String[]{"TABLE"});
|
||||||
while (tablesResult.next()) {
|
try {
|
||||||
String tableName = tablesResult.getString("TABLE_NAME");
|
while (tablesResult.next()) {
|
||||||
if (condition.tableIsIgnored(tableName)) {
|
String tableName = tablesResult.getString("TABLE_NAME");
|
||||||
if (log.isWarnEnabled()) {
|
if (condition.tableIsIgnored(tableName)) {
|
||||||
log.warn("ignored table: " + databaseName + "." + tableName);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
String tableType = tablesResult.getString("TABLE_TYPE");
|
|
||||||
String tableComment = tablesResult.getString("REMARKS");
|
|
||||||
TableCondition tableCondition = TableCondition.of(condition, tableName);
|
|
||||||
List<ColumnMeta> columns = columnMetaRepository.selectColumns(connection, tableCondition);
|
|
||||||
if (columns.isEmpty()) {
|
|
||||||
if (log.isWarnEnabled()) {
|
if (log.isWarnEnabled()) {
|
||||||
log.warn("ignored table: " + databaseName + "." + tableName + ", caused by get empty columns");
|
log.warn("ignored table: " + databaseName + "." + tableName);
|
||||||
}
|
}
|
||||||
continue;
|
} else {
|
||||||
|
String tableType = tablesResult.getString("TABLE_TYPE");
|
||||||
|
String tableComment = tablesResult.getString("REMARKS");
|
||||||
|
TableCondition tableCondition = TableCondition.of(condition, tableName);
|
||||||
|
List<ColumnMeta> columns = columnMetaRepository.selectColumns(connection, tableCondition);
|
||||||
|
if (columns.isEmpty()) {
|
||||||
|
if (log.isWarnEnabled()) {
|
||||||
|
log.warn("ignored table: " + databaseName + "." + tableName
|
||||||
|
+ ", caused by get empty columns");
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
TableMeta tableMeta = TableMeta.builder()
|
||||||
|
.name(tableName)
|
||||||
|
.type(tableType)
|
||||||
|
.comment(tableComment)
|
||||||
|
.columns(columns)
|
||||||
|
.foreignKeys(foreignKeyMetaRepository.selectForeignKeys(connection, tableCondition))
|
||||||
|
.indexes(indexMetaRepository.selectIndexes(connection, tableCondition))
|
||||||
|
.triggers(triggerMetaRepository.selectTriggers(connection, tableCondition))
|
||||||
|
.build();
|
||||||
|
tableMetas.add(tableMeta);
|
||||||
}
|
}
|
||||||
TableMeta tableMeta = TableMeta.builder()
|
|
||||||
.name(tableName)
|
|
||||||
.type(tableType)
|
|
||||||
.comment(tableComment)
|
|
||||||
.columns(columns)
|
|
||||||
.foreignKeys(foreignKeyMetaRepository.selectForeignKeys(connection, tableCondition))
|
|
||||||
.indexes(indexMetaRepository.selectIndexes(connection, tableCondition))
|
|
||||||
.triggers(triggerMetaRepository.selectTriggers(connection, tableCondition))
|
|
||||||
.build();
|
|
||||||
tableMetas.add(tableMeta);
|
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
tablesResult.close();
|
||||||
}
|
}
|
||||||
return tableMetas;
|
return tableMetas;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue