Browse Source

基础框架发布: 8.2.35

1) 提升数据导出显示表列表的速度

前端核心发布: 8.2.128
 1)
main
wangshaoping 3 weeks ago
parent
commit
8a9e8a7ea9
  1. 160
      io.sc.engine.rule.core/src/main/java/io/sc/engine/rule/core/code/ExecuteUnit4Resource.java
  2. 2
      io.sc.platform.core/src/main/java/io/sc/platform/core/service/impl/ProgressableThreadServiceImpl.java
  3. 1
      io.sc.platform.developer.frontend/src/i18n/messages_tw_CN.json
  4. 1
      io.sc.platform.developer.frontend/src/i18n/messages_zh_CN.json
  5. 18
      io.sc.platform.developer.frontend/src/views/backend/ExportLiquibase.vue
  6. 39
      io.sc.platform.developer.frontend/src/views/backend/sql/Sql.vue
  7. 17
      io.sc.platform.jdbc.liquibase/src/main/java/io/sc/platform/jdbc/liquibase/exporter/LiquibaseDataCsvExporter.java
  8. 202
      io.sc.platform.jdbc.schemacrawler/src/main/java/io/sc/platform/jdbc/schemacrawler/MetaDataLoaderImpl.java
  9. 3
      io.sc.platform.jdbc/src/main/java/io/sc/platform/jdbc/controller/JdbcMetaDataLoaderWebController.java
  10. 3
      io.sc.platform.jdbc/src/main/java/io/sc/platform/jdbc/meta/MetaDataLoader.java

160
io.sc.engine.rule.core/src/main/java/io/sc/engine/rule/core/code/ExecuteUnit4Resource.java

@ -6,10 +6,10 @@ import com.fasterxml.jackson.core.type.TypeReference;
import io.sc.engine.rule.core.enums.DictionaryType;
import io.sc.engine.rule.core.enums.EnumDictionaryItemValueType;
import io.sc.engine.rule.core.enums.ParameterType;
import io.sc.engine.rule.core.enums.QualitativeAdditionComponentType;
import io.sc.engine.rule.core.po.dictionary.Dictionary;
import io.sc.engine.rule.core.po.dictionary.EnumDictionary;
import io.sc.engine.rule.core.po.dictionary.EnumItem;
import io.sc.engine.rule.core.po.function.Function;
import io.sc.engine.rule.core.po.lib.Indicator;
import io.sc.engine.rule.core.po.lib.IndicatorLib;
import io.sc.engine.rule.core.po.lib.IndicatorProcessor;
@ -17,7 +17,6 @@ import io.sc.engine.rule.core.po.lib.Lib;
import io.sc.engine.rule.core.po.model.Model;
import io.sc.engine.rule.core.po.model.Parameter;
import io.sc.engine.rule.core.po.model.ParameterInOptionItem;
import io.sc.engine.rule.core.po.model.ParameterProcessor;
import io.sc.engine.rule.core.po.model.parameter.InOptionParameter;
import io.sc.engine.rule.core.po.model.parameter.IndicatorParameter;
import io.sc.engine.rule.core.po.resource.ModelResource;
@ -59,11 +58,6 @@ public class ExecuteUnit4Resource extends ExecuteUnit {
this.libs = libs;
}
static class NameAndValue {
private String name;
private String value;
}
public void replaceParameterPropertiesEnum() throws JsonProcessingException {
if(resource instanceof ModelResource) {
ModelResource modelResource = (ModelResource) resource;
@ -74,19 +68,30 @@ public class ExecuteUnit4Resource extends ExecuteUnit {
}
for(Parameter parameter : parameters){
if(!StringUtils.hasText(parameter.getProperties())) { continue; }
List<NameAndValue> nameAndValues =ObjectMapperUtil.json().readValue(parameter.getProperties(), new TypeReference<List<NameAndValue>>() {});
if(nameAndValues==null || nameAndValues.isEmpty()) { continue; }
for(NameAndValue nameAndValue : nameAndValues){
PlaceHolder placeHolder =PlaceHolder.extract(nameAndValue.value);
List<ParameterProperty> properties =ObjectMapperUtil.json().readValue(parameter.getProperties(), new TypeReference<List<ParameterProperty>>() {});
if(properties==null || properties.isEmpty()) { continue; }
for(ParameterProperty property : properties){
// 替换 value
PlaceHolder placeHolder =PlaceHolder.extract(property.value);
Set<String> enumRefs =placeHolder.getEnumRefs();
if(enumRefs==null || enumRefs.isEmpty()) { continue; }
for(String enumRef : enumRefs){
String enumValue =findEnumValue(enumRef);
if(!StringUtils.hasText(enumValue)){ continue; }
nameAndValue.value =nameAndValue.value.replace("#{" + enumRef.replace(".","}.#{") + "}",enumValue);
property.value =property.value.replace("#{" + enumRef.replace(".","}.#{") + "}",enumValue);
}
// 替换 prompt
placeHolder =PlaceHolder.extract(property.prompt);
enumRefs =placeHolder.getEnumRefs();
if(enumRefs==null || enumRefs.isEmpty()) { continue; }
for(String enumRef : enumRefs){
String enumValue =findEnumValue(enumRef);
if(!StringUtils.hasText(enumValue)){ continue; }
property.prompt =property.prompt.replace("#{" + enumRef.replace(".","}.#{") + "}",enumValue);
}
parameter.setProperties(ObjectMapperUtil.json().writeValueAsString(nameAndValues));
}
parameter.setProperties(ObjectMapperUtil.json().writeValueAsString(properties));
// 处理选项参数的选项
if(ParameterType.IN_OPTION.equals(parameter.getType())){
@ -298,4 +303,133 @@ public class ExecuteUnit4Resource extends ExecuteUnit {
return Objects.hash(code, version);
}
}
static class ParameterProperty {
String name;
String value;
QualitativeAdditionComponentType componentType;
Boolean required;
String label;
Integer valueScale;
String minValue;
String maxValue;
Integer textareaHeight;
Integer textMinLength;
Integer textMaxLength;
String attachmentExtendNames;
Integer attachmentMaxCount;
String prompt;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public QualitativeAdditionComponentType getComponentType() {
return componentType;
}
public void setComponentType(QualitativeAdditionComponentType componentType) {
this.componentType = componentType;
}
public Boolean getRequired() {
return required;
}
public void setRequired(Boolean required) {
this.required = required;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public Integer getValueScale() {
return valueScale;
}
public void setValueScale(Integer valueScale) {
this.valueScale = valueScale;
}
public String getMinValue() {
return minValue;
}
public void setMinValue(String minValue) {
this.minValue = minValue;
}
public String getMaxValue() {
return maxValue;
}
public void setMaxValue(String maxValue) {
this.maxValue = maxValue;
}
public Integer getTextareaHeight() {
return textareaHeight;
}
public void setTextareaHeight(Integer textareaHeight) {
this.textareaHeight = textareaHeight;
}
public Integer getTextMinLength() {
return textMinLength;
}
public void setTextMinLength(Integer textMinLength) {
this.textMinLength = textMinLength;
}
public Integer getTextMaxLength() {
return textMaxLength;
}
public void setTextMaxLength(Integer textMaxLength) {
this.textMaxLength = textMaxLength;
}
public String getAttachmentExtendNames() {
return attachmentExtendNames;
}
public void setAttachmentExtendNames(String attachmentExtendNames) {
this.attachmentExtendNames = attachmentExtendNames;
}
public Integer getAttachmentMaxCount() {
return attachmentMaxCount;
}
public void setAttachmentMaxCount(Integer attachmentMaxCount) {
this.attachmentMaxCount = attachmentMaxCount;
}
public String getPrompt() {
return prompt;
}
public void setPrompt(String prompt) {
this.prompt = prompt;
}
}
}

2
io.sc.platform.core/src/main/java/io/sc/platform/core/service/impl/ProgressableThreadServiceImpl.java

@ -61,7 +61,7 @@ public class ProgressableThreadServiceImpl implements ProgressableThreadService
if(thread!=null){
return thread.getProgressInfo();
}else{
throw new ProgressableThreadNotExistsException();
return null;
}
}
}

1
io.sc.platform.developer.frontend/src/i18n/messages_tw_CN.json

@ -52,6 +52,7 @@
"developer.backend.export.liquibase.export.tip": "您確定要導出嗎?",
"developer.backend.sql.datasource": "數據源",
"developer.backend.sql.catalog": "目錄",
"developer.backend.sql.schema": "方案",
"developer.backend.sql.action.execute": "執行",
"developer.backend.sql.action.executeAll": "執行所有",

1
io.sc.platform.developer.frontend/src/i18n/messages_zh_CN.json

@ -52,6 +52,7 @@
"developer.backend.export.liquibase.export.tip": "您确定要导出吗?",
"developer.backend.sql.datasource": "数据源",
"developer.backend.sql.catalog": "目录",
"developer.backend.sql.schema": "方案",
"developer.backend.sql.action.execute": "执行",
"developer.backend.sql.action.executeAll": "执行所有",

18
io.sc.platform.developer.frontend/src/views/backend/ExportLiquibase.vue

@ -30,9 +30,6 @@
label: $t('developer.backend.export.liquibase.schema'),
type: 'w-select',
options: schemaOptionsRef,
onUpdateValue: (args) => {
schemaChanged(valueReactive.datasource, valueReactive.catalog, args.value);
},
},
{
colSpan: 6,
@ -40,8 +37,10 @@
label: $t('developer.backend.export.liquibase.tables'),
type: 'w-grid-select',
multiple: true,
displayValue: 'name',
grid: {
denseBody: true,
toolbarConfigure: { noIcon: false },
hideBottom: true,
configButton: true,
checkboxSelection: true,
@ -54,10 +53,10 @@
(valueReactive.schema || ''),
),
pageable: false,
sortBy: ['type', 'namec', '-lastModifyDate'],
sortBy: ['name'],
sortNo: true,
toolbarConfigure: { noIcon: false },
toolbarActions: ['refresh'],
primaryKey: 'name',
columns: [
{ name: 'name', label: $t('name') },
{ name: 'remarks', label: $t('remarks') },
@ -145,11 +144,6 @@ const catalogChanged = (datasource: string, catalog: string) => {
}
schemaOptionsRef.value = schemaOptions;
tablesOptionsRef.value = [];
if (schemaOptions.length === 0) {
schemaChanged(datasource, catalog, '');
} else if (schemaOptions.length === 1) {
schemaChanged(datasource, catalog, schemaOptions[0]);
}
});
};
@ -176,6 +170,7 @@ const exportData = (e) => {
const data = valueReactive;
const config = {
datasource: data.datasource,
catalog: data.catalog,
schema: data.schema,
tables: [],
};
@ -192,6 +187,5 @@ const exportData = (e) => {
onMounted(() => {
loadDatasource();
datasourceChanged('');
});
</script>

39
io.sc.platform.developer.frontend/src/views/backend/sql/Sql.vue

@ -16,6 +16,21 @@
}
"
></q-select>
<q-select
v-model="valueReactive.catalog"
:label="$t('developer.backend.sql.catalog')"
outlined
dense
emit-value
map-options
:options="catalogOptionsRef"
style="width: 200px"
@update:model-value="
(value) => {
catalogChanged(valueReactive.datasource, value);
}
"
></q-select>
<q-select
v-model="valueReactive.schema"
:label="$t('developer.backend.sql.schema')"
@ -50,15 +65,17 @@
<script setup lang="ts">
import 'tailwindcss/utilities.css';
import { ref, reactive, onMounted } from 'vue';
import { axios, Environment } from 'platform-core';
import { $t, axios, Environment } from 'platform-core';
import ImportExcel from './import-excel/ImportExcel.vue';
const datasourceOptionsRef = ref([]);
const catalogOptionsRef = ref([]);
const schemaOptionsRef = ref([]);
const importExcelDialogRef = ref();
const valueReactive = reactive({
datasource: undefined,
catalog: undefined,
schema: undefined,
sql: undefined,
});
@ -66,7 +83,7 @@ const valueReactive = reactive({
const loadDatasource = () => {
axios.get(Environment.apiContextPath('/api/system/datasource?pageable=false&sortBy=name')).then((response) => {
const data = response?.data.content;
const datasourceOptions = [];
const datasourceOptions = [{ label: $t('default'), value: '' }];
if (data && data.length > 0) {
for (let item of data) {
datasourceOptions.push({ label: item.name, value: item.name });
@ -78,7 +95,22 @@ const loadDatasource = () => {
const datasourceChanged = (datasource: string) => {
datasource = datasource || '';
axios.get(Environment.apiContextPath('/api/jdbc/metadata/getSchemas?datasource=' + datasource)).then((response) => {
axios.get(Environment.apiContextPath('/api/jdbc/metadata/getCatalogs?datasource=' + datasource)).then((response) => {
const data = response?.data;
const catalogOptions = [];
if (data && data.length > 0) {
for (let item of data) {
catalogOptions.push({ label: item.name, value: item.name });
}
}
catalogOptionsRef.value = catalogOptions;
schemaOptionsRef.value = [];
});
};
const catalogChanged = (datasource: string, catalog: string) => {
datasource = datasource || '';
axios.get(Environment.apiContextPath('/api/jdbc/metadata/getSchemas?datasource=' + datasource + '&catalog=' + catalog)).then((response) => {
const data = response?.data;
const schemaOptions = [];
if (data && data.length > 0) {
@ -92,6 +124,5 @@ const datasourceChanged = (datasource: string) => {
onMounted(() => {
loadDatasource();
datasourceChanged('');
});
</script>

17
io.sc.platform.jdbc.liquibase/src/main/java/io/sc/platform/jdbc/liquibase/exporter/LiquibaseDataCsvExporter.java

@ -43,8 +43,8 @@ public class LiquibaseDataCsvExporter implements DataExporter {
String[] tableNames =ExportTable.getTableNames(configure.getTables());
progressInfo.setTotalWeight(tableNames.length);
List<Table> tables =MetaDataLoader.newInstance().getTables(dataSource,configure.getCatalog(),configure.getSchema());
String outPutDir =OUTPUT_PATH + "/" + configure.getSchema();
List<Table> tables =MetaDataLoader.newInstance().getTables(dataSource,configure.getCatalog(),configure.getSchema(),tableNames);
String outPutDir =OUTPUT_PATH + getPath(configure.getCatalog(),configure.getSchema());
FileUtil.deldirs(outPutDir);
String dataDir =outPutDir + "/data";
new File(dataDir).mkdirs();
@ -66,7 +66,7 @@ public class LiquibaseDataCsvExporter implements DataExporter {
}
private void writeTable(DataSource dataSource,Table table,DataExportConfigure configure,ProgressInfo progressInfo, Locale locale) throws Exception{
BufferedWriter writer = WriterUtil.bufferedWriter(OUTPUT_PATH + "/" + configure.getSchema() + "/data/" + table.getName() + ".csv");
BufferedWriter writer = WriterUtil.bufferedWriter(OUTPUT_PATH + getPath(configure.getCatalog(),configure.getSchema()) + "/data/" + table.getName() + ".csv");
ICSVWriter csvWriter = new CSVWriterBuilder(writer).build();
//写入字段定义信息===============================================================================
@ -261,4 +261,15 @@ public class LiquibaseDataCsvExporter implements DataExporter {
return string;
}
private String getPath(String catalog,String schema){
String catalogOrSchemaName ="";
if(StringUtils.hasText(catalog)){
catalogOrSchemaName ="/" + catalog;
}
if(StringUtils.hasText(schema)){
catalogOrSchemaName ="/" + schema;
}
return catalogOrSchemaName;
}
}

202
io.sc.platform.jdbc.schemacrawler/src/main/java/io/sc/platform/jdbc/schemacrawler/MetaDataLoaderImpl.java

@ -75,21 +75,38 @@ public class MetaDataLoaderImpl implements MetaDataLoader {
}
@Override
public List<Table> getTables(DataSource dataSource, String catalogName, String schemaName) throws MetaDataAccessException {
public List<Table> getTables(DataSource dataSource, String catalogName, String schemaName,String... tableNames) throws MetaDataAccessException {
List<Table> result =new ArrayList<>();
Connection connection =null;
ResultSet rs =null;
try {
connection =dataSource.getConnection();
DatabaseMetaData databaseMetaData =connection.getMetaData();
rs =databaseMetaData.getTables(catalogName,schemaName,null,new String[]{"TABLE"});
while (rs.next()){
Table table =new Table();
if(tableNames==null || tableNames.length==0) {
rs = databaseMetaData.getTables(catalogName, schemaName, null, new String[]{"TABLE"});
while (rs.next()) {
Table table = new Table();
table.setName(rs.getString("TABLE_NAME"));
table.setRemarks(rs.getString("REMARKS"));
table.setColumns(getColumns(dataSource, catalogName, schemaName, table.getName()));
table.setForeignKeys(getForeignKeys(dataSource, catalogName, schemaName, table.getName()));
buildSelfReference(table);
result.add(table);
}
}else{
for(String tableName : tableNames){
rs = databaseMetaData.getTables(catalogName, schemaName, tableName, new String[]{"TABLE"});
while (rs.next()) {
Table table = new Table();
table.setName(rs.getString("TABLE_NAME"));
table.setRemarks(rs.getString("REMARKS"));
table.setColumns(getColumns(dataSource,catalogName,schemaName,table.getName()));
table.setColumns(getColumns(dataSource, catalogName, schemaName, table.getName()));
table.setForeignKeys(getForeignKeys(dataSource, catalogName, schemaName, table.getName()));
buildSelfReference(table);
result.add(table);
}
}
}
} catch (SQLException e) {
throw new MetaDataAccessException(e);
}finally {
@ -120,40 +137,6 @@ public class MetaDataLoaderImpl implements MetaDataLoader {
return result;
}
private Column getColumn(ResultSet rs) throws SQLException {
String TABLE_CAT =rs.getString("TABLE_CAT"); //table catalog (may be null)
String TABLE_SCHEM =rs.getString("TABLE_SCHEM"); //table schema (may be null)
String TABLE_NAME =rs.getString("TABLE_NAME"); //table name (表名称)
String COLUMN_NAME =rs.getString("COLUMN_NAME"); //column name(列名)
int DATA_TYPE =rs.getInt ("DATA_TYPE"); //SQL type from java.sql.Types(列的数据类型)
String TYPE_NAME =rs.getString("TYPE_NAME"); //Data source dependent type name, for a UDT the type name is fully qualified
int COLUMN_SIZE =rs.getInt ("COLUMN_SIZE"); //column size
int BUFFER_LENGTH =rs.getInt ("BUFFER_LENGTH"); //is not used
int DECIMAL_DIGITS =rs.getInt ("DECIMAL_DIGITS"); //the number of fractional digits. Null is returned for data types where DECIMAL_DIGITS is not applicable.
int NUM_PREC_RADIX =rs.getInt ("NUM_PREC_RADIX"); //Radix (typically either 10 or 2)
int NULLABLE =rs.getInt ("NULLABLE"); //is NULL allowed.
String REMARKS =rs.getString("REMARKS"); //comment describing column (may be null)
String COLUMN_DEF =rs.getString("COLUMN_DEF"); //default value for the column, (may be null)
int SQL_DATA_TYPE =rs.getInt ("SQL_DATA_TYPE"); //unused
int SQL_DATETIME_SUB =rs.getInt ("SQL_DATETIME_SUB"); //unused
int CHAR_OCTET_LENGTH=rs.getInt ("CHAR_OCTET_LENGTH"); //for char types the maximum number of bytes in the column
int ORDINAL_POSITION =rs.getInt ("ORDINAL_POSITION"); //index of column in table (starting at 1)
String IS_NULLABLE =rs.getString("IS_NULLABLE"); //ISO rules are used to determine the nullability for a column.
//String SCOPE_CATLOG =rs.getString("SCOPE_CATLOG"); //catalog of table that is the scope of a reference attribute (null if DATA_TYPE isn't REF)
//String SCOPE_SCHEMA =rs.getString("SCOPE_SCHEMA"); //schema of table that is the scope of a reference attribute (null if the DATA_TYPE isn't REF)
//String SCOPE_TABLE =rs.getString("SCOPE_TABLE"); //table name that this the scope of a reference attribure (null if the DATA_TYPE isn't REF)
String SOURCE_DATA_TYPE =rs.getString("SOURCE_DATA_TYPE"); //source type of a distinct type or user-generated Ref type, SQL type from java.sql.Types
String IS_AUTOINCREMENT =rs.getString("IS_AUTOINCREMENT"); //Indicates whether this column is auto incremented
Column column =new Column();
column.setName(COLUMN_NAME);
column.setRemarks(REMARKS);
column.setSqlType(SqlTypeUtil.getSqlTypeName(DATA_TYPE));
column.setJavaType(SqlTypeUtil.getJavaType(DATA_TYPE));
return column;
}
public List<TableSummary> getTableSummary(DataSource dataSource, String catalogName, String schemaName, boolean isCount) throws MetaDataAccessException {
List<Table> tables =this.getTables(dataSource,catalogName,schemaName);
if(tables==null || tables.isEmpty()){
@ -181,92 +164,77 @@ public class MetaDataLoaderImpl implements MetaDataLoader {
return result;
}
public boolean isSelfReference(schemacrawler.schema.Table table) {
Collection<schemacrawler.schema.Table> parentTables =table.getRelatedTables(TableRelationshipType.parent);
if(parentTables!=null && !parentTables.isEmpty()) {
for(schemacrawler.schema.Table parentTable : parentTables) {
if(parentTable.equals(table)) {
return true;
}
private void buildSelfReference(Table table){
if(table==null) { return; }
List<ForeignKey> foreignKeys =table.getForeignKeys();
if(foreignKeys==null || foreignKeys.isEmpty()) { return; }
for(ForeignKey foreignKey : foreignKeys){
if(table.getName().equals(foreignKey.getPrimaryKeyTableName())){
table.setSelfReference(true);
table.setSelfReferencePrimaryKeyColumnName(foreignKey.getPrimaryKeyColumnName());
table.setSelfReferenceForeignKeyColumnName(foreignKey.getForeignKeyColumnName());
return;
}
}
return false;
}
private Table from(DatabaseMetaData databaseMetaData,String tableName,String tableRemarks){
// Table result =new Table();
// result.setName(tableName);
// result.setRemarks(tableRemarks);
// // 处理列
// for(schemacrawler.schema.Column column : table.getColumns()) {
// result.getColumns().add(from(column));
// }
// // 处理外键
// Collection<schemacrawler.schema.ForeignKey> foreignKeys =table.getForeignKeys();
// for(schemacrawler.schema.ForeignKey foreignKey : foreignKeys){
// result.getForeignKeys().add(from(foreignKey));
// }
// // 处理自引用
// for(ForeignKey foreignKey : result.getForeignKeys()){
// if(foreignKey.getForeignKeyTableName().equalsIgnoreCase(foreignKey.getPrimaryKeyTableName())){
// result.setSelfReferenceForeignKeyColumnName(foreignKey.getForeignKeyColumnName());
// result.setSelfReferencePrimaryKeyColumnName(foreignKey.getPrimaryKeyColumnName());
// }
// }
// // 处理索引
// Collection<schemacrawler.schema.Index> indexes =table.getIndexes();
// for(schemacrawler.schema.Index index : indexes){
// result.getIndexes().add(from(index));
// }
// return result;
return null;
}
private ForeignKey from(schemacrawler.schema.ForeignKey foreignKey){
ForeignKey result =new ForeignKey();
result.setForeignKeyTableName(foreignKey.getForeignKeyTable().getName());
result.setPrimaryKeyTableName(foreignKey.getPrimaryKeyTable().getName());
private Column getColumn(ResultSet rs) throws SQLException {
String TABLE_CAT =rs.getString("TABLE_CAT"); //table catalog (may be null)
String TABLE_SCHEM =rs.getString("TABLE_SCHEM"); //table schema (may be null)
String TABLE_NAME =rs.getString("TABLE_NAME"); //table name (表名称)
String COLUMN_NAME =rs.getString("COLUMN_NAME"); //column name(列名)
int DATA_TYPE =rs.getInt ("DATA_TYPE"); //SQL type from java.sql.Types(列的数据类型)
String TYPE_NAME =rs.getString("TYPE_NAME"); //Data source dependent type name, for a UDT the type name is fully qualified
int COLUMN_SIZE =rs.getInt ("COLUMN_SIZE"); //column size
int BUFFER_LENGTH =rs.getInt ("BUFFER_LENGTH"); //is not used
int DECIMAL_DIGITS =rs.getInt ("DECIMAL_DIGITS"); //the number of fractional digits. Null is returned for data types where DECIMAL_DIGITS is not applicable.
int NUM_PREC_RADIX =rs.getInt ("NUM_PREC_RADIX"); //Radix (typically either 10 or 2)
int NULLABLE =rs.getInt ("NULLABLE"); //is NULL allowed.
String REMARKS =rs.getString("REMARKS"); //comment describing column (may be null)
String COLUMN_DEF =rs.getString("COLUMN_DEF"); //default value for the column, (may be null)
int SQL_DATA_TYPE =rs.getInt ("SQL_DATA_TYPE"); //unused
int SQL_DATETIME_SUB =rs.getInt ("SQL_DATETIME_SUB"); //unused
int CHAR_OCTET_LENGTH=rs.getInt ("CHAR_OCTET_LENGTH"); //for char types the maximum number of bytes in the column
int ORDINAL_POSITION =rs.getInt ("ORDINAL_POSITION"); //index of column in table (starting at 1)
String IS_NULLABLE =rs.getString("IS_NULLABLE"); //ISO rules are used to determine the nullability for a column.
//String SCOPE_CATLOG =rs.getString("SCOPE_CATLOG"); //catalog of table that is the scope of a reference attribute (null if DATA_TYPE isn't REF)
//String SCOPE_SCHEMA =rs.getString("SCOPE_SCHEMA"); //schema of table that is the scope of a reference attribute (null if the DATA_TYPE isn't REF)
//String SCOPE_TABLE =rs.getString("SCOPE_TABLE"); //table name that this the scope of a reference attribure (null if the DATA_TYPE isn't REF)
String SOURCE_DATA_TYPE =rs.getString("SOURCE_DATA_TYPE"); //source type of a distinct type or user-generated Ref type, SQL type from java.sql.Types
String IS_AUTOINCREMENT =rs.getString("IS_AUTOINCREMENT"); //Indicates whether this column is auto incremented
List<ColumnReference> columnReferences =foreignKey.getColumnReferences();
if(columnReferences!=null && !columnReferences.isEmpty()) {
for(ColumnReference columnReference : columnReferences){
schemacrawler.schema.Column foreignKeyColumn =columnReference.getForeignKeyColumn();
schemacrawler.schema.Column primaryKeyColumn =columnReference.getPrimaryKeyColumn();
result.setForeignKeyColumnName(foreignKeyColumn.getName());
result.setPrimaryKeyColumnName(primaryKeyColumn.getName());
}
}
return result;
Column column =new Column();
column.setName(COLUMN_NAME);
column.setRemarks(REMARKS);
column.setSqlType(SqlTypeUtil.getSqlTypeName(DATA_TYPE));
column.setJavaType(SqlTypeUtil.getJavaType(DATA_TYPE));
column.setSize(COLUMN_SIZE);
column.setNullable("YES".equalsIgnoreCase(IS_NULLABLE)?true:false);
column.setAutoIncremented("YES".equalsIgnoreCase(IS_AUTOINCREMENT)?true:false);
return column;
}
private Column from(schemacrawler.schema.Column column){
Column result =new Column();
result.setName(column.getName());
result.setRemarks(column.getRemarks());
result.setJavaType(column.getType().getTypeMappedClass());
result.setSqlType(column.getColumnDataType().getJavaSqlType().getName());
result.setVendorTypeNumber(column.getColumnDataType().getJavaSqlType().getVendorTypeNumber());
result.setNullable(column.isNullable());
result.setDefaultValue(column.getDefaultValue());
result.setGenerated(column.isGenerated());
result.setHidden(column.isHidden());
result.setAutoIncremented(column.isAutoIncremented());
result.setPartOfIndex(column.isPartOfIndex());
result.setPartOfUniqueIndex(column.isPartOfUniqueIndex());
result.setPartOfPrimaryKey(column.isPartOfPrimaryKey());
result.setSize(column.getSize());
result.setWidth(column.getWidth());
return result;
private List<ForeignKey> getForeignKeys(DataSource dataSource, String catalogName, String schemaName, String tableName) throws MetaDataAccessException {
List<ForeignKey> result =new ArrayList<>();
Connection connection =null;
ResultSet rs =null;
try {
connection =dataSource.getConnection();
DatabaseMetaData databaseMetaData =connection.getMetaData();
rs =databaseMetaData.getImportedKeys(catalogName,schemaName,tableName);
while (rs.next()){
ForeignKey foreignKey =new ForeignKey();
foreignKey.setPrimaryKeyTableName(rs.getString("PKTABLE_NAME"));
foreignKey.setPrimaryKeyColumnName(rs.getString("PKCOLUMN_NAME"));
foreignKey.setForeignKeyTableName(rs.getString("FKTABLE_NAME"));
foreignKey.setForeignKeyColumnName(rs.getString("FKCOLUMN_NAME"));
result.add(foreignKey);
}
private Index from(schemacrawler.schema.Index index){
Index result =new Index();
result.setName(index.getName());
result.setUnique(index.isUnique());
result.setIndexType(IndexType.from(index.getIndexType().id()));
List<schemacrawler.schema.IndexColumn> columns =index.getColumns();
for(schemacrawler.schema.IndexColumn column : columns){
result.getColumns().add(from(column));
} catch (SQLException e) {
throw new MetaDataAccessException(e);
}finally {
try{rs.close();} catch (SQLException e) {}
try{connection.close();} catch (SQLException e) {}
}
return result;
}

3
io.sc.platform.jdbc/src/main/java/io/sc/platform/jdbc/controller/JdbcMetaDataLoaderWebController.java

@ -29,7 +29,6 @@ public class JdbcMetaDataLoaderWebController {
@GetMapping("getTables")
public List<Table> getTables(@RequestParam(name="datasource",required = false)String datasource, @RequestParam(name="catalog",required = false)String catalog,@RequestParam(name="schema")String schema) throws Exception {
//return jdbcMetaDataLoaderService.getTables(datasource,catalog,schema);
return jdbcMetaDataLoaderService.getTables(datasource,"platform",schema);
return jdbcMetaDataLoaderService.getTables(datasource,catalog,schema);
}
}

3
io.sc.platform.jdbc/src/main/java/io/sc/platform/jdbc/meta/MetaDataLoader.java

@ -52,9 +52,10 @@ public interface MetaDataLoader {
* @param dataSource 数据源
* @param catalogName 目录名
* @param schemaName Schema 名称
* @param tableNames 表名数组
* @return 某个 Schema 下的表对象列表
*/
public List<Table> getTables(DataSource dataSource, String catalogName, String schemaName) throws MetaDataAccessException;
public List<Table> getTables(DataSource dataSource, String catalogName, String schemaName,String... tableNames) throws MetaDataAccessException;
/**
* 获取列对象列表

Loading…
Cancel
Save