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.DictionaryType;
import io.sc.engine.rule.core.enums.EnumDictionaryItemValueType; import io.sc.engine.rule.core.enums.EnumDictionaryItemValueType;
import io.sc.engine.rule.core.enums.ParameterType; 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.Dictionary;
import io.sc.engine.rule.core.po.dictionary.EnumDictionary; 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.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.Indicator;
import io.sc.engine.rule.core.po.lib.IndicatorLib; import io.sc.engine.rule.core.po.lib.IndicatorLib;
import io.sc.engine.rule.core.po.lib.IndicatorProcessor; 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.Model;
import io.sc.engine.rule.core.po.model.Parameter; 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.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.InOptionParameter;
import io.sc.engine.rule.core.po.model.parameter.IndicatorParameter; import io.sc.engine.rule.core.po.model.parameter.IndicatorParameter;
import io.sc.engine.rule.core.po.resource.ModelResource; import io.sc.engine.rule.core.po.resource.ModelResource;
@ -59,11 +58,6 @@ public class ExecuteUnit4Resource extends ExecuteUnit {
this.libs = libs; this.libs = libs;
} }
static class NameAndValue {
private String name;
private String value;
}
public void replaceParameterPropertiesEnum() throws JsonProcessingException { public void replaceParameterPropertiesEnum() throws JsonProcessingException {
if(resource instanceof ModelResource) { if(resource instanceof ModelResource) {
ModelResource modelResource = (ModelResource) resource; ModelResource modelResource = (ModelResource) resource;
@ -74,19 +68,30 @@ public class ExecuteUnit4Resource extends ExecuteUnit {
} }
for(Parameter parameter : parameters){ for(Parameter parameter : parameters){
if(!StringUtils.hasText(parameter.getProperties())) { continue; } if(!StringUtils.hasText(parameter.getProperties())) { continue; }
List<NameAndValue> nameAndValues =ObjectMapperUtil.json().readValue(parameter.getProperties(), new TypeReference<List<NameAndValue>>() {}); List<ParameterProperty> properties =ObjectMapperUtil.json().readValue(parameter.getProperties(), new TypeReference<List<ParameterProperty>>() {});
if(nameAndValues==null || nameAndValues.isEmpty()) { continue; } if(properties==null || properties.isEmpty()) { continue; }
for(NameAndValue nameAndValue : nameAndValues){ for(ParameterProperty property : properties){
PlaceHolder placeHolder =PlaceHolder.extract(nameAndValue.value); // 替换 value
PlaceHolder placeHolder =PlaceHolder.extract(property.value);
Set<String> enumRefs =placeHolder.getEnumRefs(); Set<String> enumRefs =placeHolder.getEnumRefs();
if(enumRefs==null || enumRefs.isEmpty()) { continue; } if(enumRefs==null || enumRefs.isEmpty()) { continue; }
for(String enumRef : enumRefs){ for(String enumRef : enumRefs){
String enumValue =findEnumValue(enumRef); String enumValue =findEnumValue(enumRef);
if(!StringUtils.hasText(enumValue)){ continue; } 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())){ if(ParameterType.IN_OPTION.equals(parameter.getType())){
@ -298,4 +303,133 @@ public class ExecuteUnit4Resource extends ExecuteUnit {
return Objects.hash(code, version); 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){ if(thread!=null){
return thread.getProgressInfo(); return thread.getProgressInfo();
}else{ }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.export.liquibase.export.tip": "您確定要導出嗎?",
"developer.backend.sql.datasource": "數據源", "developer.backend.sql.datasource": "數據源",
"developer.backend.sql.catalog": "目錄",
"developer.backend.sql.schema": "方案", "developer.backend.sql.schema": "方案",
"developer.backend.sql.action.execute": "執行", "developer.backend.sql.action.execute": "執行",
"developer.backend.sql.action.executeAll": "執行所有", "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.export.liquibase.export.tip": "您确定要导出吗?",
"developer.backend.sql.datasource": "数据源", "developer.backend.sql.datasource": "数据源",
"developer.backend.sql.catalog": "目录",
"developer.backend.sql.schema": "方案", "developer.backend.sql.schema": "方案",
"developer.backend.sql.action.execute": "执行", "developer.backend.sql.action.execute": "执行",
"developer.backend.sql.action.executeAll": "执行所有", "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'), label: $t('developer.backend.export.liquibase.schema'),
type: 'w-select', type: 'w-select',
options: schemaOptionsRef, options: schemaOptionsRef,
onUpdateValue: (args) => {
schemaChanged(valueReactive.datasource, valueReactive.catalog, args.value);
},
}, },
{ {
colSpan: 6, colSpan: 6,
@ -40,8 +37,10 @@
label: $t('developer.backend.export.liquibase.tables'), label: $t('developer.backend.export.liquibase.tables'),
type: 'w-grid-select', type: 'w-grid-select',
multiple: true, multiple: true,
displayValue: 'name',
grid: { grid: {
denseBody: true, toolbarConfigure: { noIcon: false },
hideBottom: true, hideBottom: true,
configButton: true, configButton: true,
checkboxSelection: true, checkboxSelection: true,
@ -54,10 +53,10 @@
(valueReactive.schema || ''), (valueReactive.schema || ''),
), ),
pageable: false, pageable: false,
sortBy: ['type', 'namec', '-lastModifyDate'], sortBy: ['name'],
sortNo: true, sortNo: true,
toolbarConfigure: { noIcon: false },
toolbarActions: ['refresh'], toolbarActions: ['refresh'],
primaryKey: 'name',
columns: [ columns: [
{ name: 'name', label: $t('name') }, { name: 'name', label: $t('name') },
{ name: 'remarks', label: $t('remarks') }, { name: 'remarks', label: $t('remarks') },
@ -145,11 +144,6 @@ const catalogChanged = (datasource: string, catalog: string) => {
} }
schemaOptionsRef.value = schemaOptions; schemaOptionsRef.value = schemaOptions;
tablesOptionsRef.value = []; 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 data = valueReactive;
const config = { const config = {
datasource: data.datasource, datasource: data.datasource,
catalog: data.catalog,
schema: data.schema, schema: data.schema,
tables: [], tables: [],
}; };
@ -192,6 +187,5 @@ const exportData = (e) => {
onMounted(() => { onMounted(() => {
loadDatasource(); loadDatasource();
datasourceChanged('');
}); });
</script> </script>

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

@ -16,6 +16,21 @@
} }
" "
></q-select> ></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 <q-select
v-model="valueReactive.schema" v-model="valueReactive.schema"
:label="$t('developer.backend.sql.schema')" :label="$t('developer.backend.sql.schema')"
@ -50,15 +65,17 @@
<script setup lang="ts"> <script setup lang="ts">
import 'tailwindcss/utilities.css'; import 'tailwindcss/utilities.css';
import { ref, reactive, onMounted } from 'vue'; 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'; import ImportExcel from './import-excel/ImportExcel.vue';
const datasourceOptionsRef = ref([]); const datasourceOptionsRef = ref([]);
const catalogOptionsRef = ref([]);
const schemaOptionsRef = ref([]); const schemaOptionsRef = ref([]);
const importExcelDialogRef = ref(); const importExcelDialogRef = ref();
const valueReactive = reactive({ const valueReactive = reactive({
datasource: undefined, datasource: undefined,
catalog: undefined,
schema: undefined, schema: undefined,
sql: undefined, sql: undefined,
}); });
@ -66,7 +83,7 @@ const valueReactive = reactive({
const loadDatasource = () => { const loadDatasource = () => {
axios.get(Environment.apiContextPath('/api/system/datasource?pageable=false&sortBy=name')).then((response) => { axios.get(Environment.apiContextPath('/api/system/datasource?pageable=false&sortBy=name')).then((response) => {
const data = response?.data.content; const data = response?.data.content;
const datasourceOptions = []; const datasourceOptions = [{ label: $t('default'), value: '' }];
if (data && data.length > 0) { if (data && data.length > 0) {
for (let item of data) { for (let item of data) {
datasourceOptions.push({ label: item.name, value: item.name }); datasourceOptions.push({ label: item.name, value: item.name });
@ -78,7 +95,22 @@ const loadDatasource = () => {
const datasourceChanged = (datasource: string) => { const datasourceChanged = (datasource: string) => {
datasource = datasource || ''; 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 data = response?.data;
const schemaOptions = []; const schemaOptions = [];
if (data && data.length > 0) { if (data && data.length > 0) {
@ -92,6 +124,5 @@ const datasourceChanged = (datasource: string) => {
onMounted(() => { onMounted(() => {
loadDatasource(); loadDatasource();
datasourceChanged('');
}); });
</script> </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()); String[] tableNames =ExportTable.getTableNames(configure.getTables());
progressInfo.setTotalWeight(tableNames.length); progressInfo.setTotalWeight(tableNames.length);
List<Table> tables =MetaDataLoader.newInstance().getTables(dataSource,configure.getCatalog(),configure.getSchema()); List<Table> tables =MetaDataLoader.newInstance().getTables(dataSource,configure.getCatalog(),configure.getSchema(),tableNames);
String outPutDir =OUTPUT_PATH + "/" + configure.getSchema(); String outPutDir =OUTPUT_PATH + getPath(configure.getCatalog(),configure.getSchema());
FileUtil.deldirs(outPutDir); FileUtil.deldirs(outPutDir);
String dataDir =outPutDir + "/data"; String dataDir =outPutDir + "/data";
new File(dataDir).mkdirs(); 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{ 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(); ICSVWriter csvWriter = new CSVWriterBuilder(writer).build();
//写入字段定义信息=============================================================================== //写入字段定义信息===============================================================================
@ -261,4 +261,15 @@ public class LiquibaseDataCsvExporter implements DataExporter {
return string; 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 @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<>(); List<Table> result =new ArrayList<>();
Connection connection =null; Connection connection =null;
ResultSet rs =null; ResultSet rs =null;
try { try {
connection =dataSource.getConnection(); connection =dataSource.getConnection();
DatabaseMetaData databaseMetaData =connection.getMetaData(); DatabaseMetaData databaseMetaData =connection.getMetaData();
rs =databaseMetaData.getTables(catalogName,schemaName,null,new String[]{"TABLE"}); if(tableNames==null || tableNames.length==0) {
while (rs.next()){ rs = databaseMetaData.getTables(catalogName, schemaName, null, new String[]{"TABLE"});
Table table =new 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.setName(rs.getString("TABLE_NAME"));
table.setRemarks(rs.getString("REMARKS")); 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); result.add(table);
} }
}
}
} catch (SQLException e) { } catch (SQLException e) {
throw new MetaDataAccessException(e); throw new MetaDataAccessException(e);
}finally { }finally {
@ -120,40 +137,6 @@ public class MetaDataLoaderImpl implements MetaDataLoader {
return result; 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 { public List<TableSummary> getTableSummary(DataSource dataSource, String catalogName, String schemaName, boolean isCount) throws MetaDataAccessException {
List<Table> tables =this.getTables(dataSource,catalogName,schemaName); List<Table> tables =this.getTables(dataSource,catalogName,schemaName);
if(tables==null || tables.isEmpty()){ if(tables==null || tables.isEmpty()){
@ -181,92 +164,77 @@ public class MetaDataLoaderImpl implements MetaDataLoader {
return result; return result;
} }
public boolean isSelfReference(schemacrawler.schema.Table table) { private void buildSelfReference(Table table){
Collection<schemacrawler.schema.Table> parentTables =table.getRelatedTables(TableRelationshipType.parent); if(table==null) { return; }
if(parentTables!=null && !parentTables.isEmpty()) { List<ForeignKey> foreignKeys =table.getForeignKeys();
for(schemacrawler.schema.Table parentTable : parentTables) { if(foreignKeys==null || foreignKeys.isEmpty()) { return; }
if(parentTable.equals(table)) { for(ForeignKey foreignKey : foreignKeys){
return true; 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){ private Column getColumn(ResultSet rs) throws SQLException {
// Table result =new Table(); String TABLE_CAT =rs.getString("TABLE_CAT"); //table catalog (may be null)
// result.setName(tableName); String TABLE_SCHEM =rs.getString("TABLE_SCHEM"); //table schema (may be null)
// result.setRemarks(tableRemarks); String TABLE_NAME =rs.getString("TABLE_NAME"); //table name (表名称)
// // 处理列 String COLUMN_NAME =rs.getString("COLUMN_NAME"); //column name(列名)
// for(schemacrawler.schema.Column column : table.getColumns()) { int DATA_TYPE =rs.getInt ("DATA_TYPE"); //SQL type from java.sql.Types(列的数据类型)
// result.getColumns().add(from(column)); 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
// Collection<schemacrawler.schema.ForeignKey> foreignKeys =table.getForeignKeys(); int DECIMAL_DIGITS =rs.getInt ("DECIMAL_DIGITS"); //the number of fractional digits. Null is returned for data types where DECIMAL_DIGITS is not applicable.
// for(schemacrawler.schema.ForeignKey foreignKey : foreignKeys){ int NUM_PREC_RADIX =rs.getInt ("NUM_PREC_RADIX"); //Radix (typically either 10 or 2)
// result.getForeignKeys().add(from(foreignKey)); 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)
// for(ForeignKey foreignKey : result.getForeignKeys()){ int SQL_DATA_TYPE =rs.getInt ("SQL_DATA_TYPE"); //unused
// if(foreignKey.getForeignKeyTableName().equalsIgnoreCase(foreignKey.getPrimaryKeyTableName())){ int SQL_DATETIME_SUB =rs.getInt ("SQL_DATETIME_SUB"); //unused
// result.setSelfReferenceForeignKeyColumnName(foreignKey.getForeignKeyColumnName()); int CHAR_OCTET_LENGTH=rs.getInt ("CHAR_OCTET_LENGTH"); //for char types the maximum number of bytes in the column
// result.setSelfReferencePrimaryKeyColumnName(foreignKey.getPrimaryKeyColumnName()); 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)
// Collection<schemacrawler.schema.Index> indexes =table.getIndexes(); //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)
// for(schemacrawler.schema.Index index : indexes){ 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
// result.getIndexes().add(from(index)); String IS_AUTOINCREMENT =rs.getString("IS_AUTOINCREMENT"); //Indicates whether this column is auto incremented
// }
// 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());
List<ColumnReference> columnReferences =foreignKey.getColumnReferences(); Column column =new Column();
if(columnReferences!=null && !columnReferences.isEmpty()) { column.setName(COLUMN_NAME);
for(ColumnReference columnReference : columnReferences){ column.setRemarks(REMARKS);
schemacrawler.schema.Column foreignKeyColumn =columnReference.getForeignKeyColumn(); column.setSqlType(SqlTypeUtil.getSqlTypeName(DATA_TYPE));
schemacrawler.schema.Column primaryKeyColumn =columnReference.getPrimaryKeyColumn(); column.setJavaType(SqlTypeUtil.getJavaType(DATA_TYPE));
result.setForeignKeyColumnName(foreignKeyColumn.getName()); column.setSize(COLUMN_SIZE);
result.setPrimaryKeyColumnName(primaryKeyColumn.getName()); column.setNullable("YES".equalsIgnoreCase(IS_NULLABLE)?true:false);
} column.setAutoIncremented("YES".equalsIgnoreCase(IS_AUTOINCREMENT)?true:false);
} return column;
return result;
} }
private Column from(schemacrawler.schema.Column column){ private List<ForeignKey> getForeignKeys(DataSource dataSource, String catalogName, String schemaName, String tableName) throws MetaDataAccessException {
Column result =new Column(); List<ForeignKey> result =new ArrayList<>();
result.setName(column.getName()); Connection connection =null;
result.setRemarks(column.getRemarks()); ResultSet rs =null;
result.setJavaType(column.getType().getTypeMappedClass()); try {
result.setSqlType(column.getColumnDataType().getJavaSqlType().getName()); connection =dataSource.getConnection();
result.setVendorTypeNumber(column.getColumnDataType().getJavaSqlType().getVendorTypeNumber()); DatabaseMetaData databaseMetaData =connection.getMetaData();
result.setNullable(column.isNullable()); rs =databaseMetaData.getImportedKeys(catalogName,schemaName,tableName);
result.setDefaultValue(column.getDefaultValue()); while (rs.next()){
result.setGenerated(column.isGenerated()); ForeignKey foreignKey =new ForeignKey();
result.setHidden(column.isHidden()); foreignKey.setPrimaryKeyTableName(rs.getString("PKTABLE_NAME"));
result.setAutoIncremented(column.isAutoIncremented()); foreignKey.setPrimaryKeyColumnName(rs.getString("PKCOLUMN_NAME"));
result.setPartOfIndex(column.isPartOfIndex()); foreignKey.setForeignKeyTableName(rs.getString("FKTABLE_NAME"));
result.setPartOfUniqueIndex(column.isPartOfUniqueIndex()); foreignKey.setForeignKeyColumnName(rs.getString("FKCOLUMN_NAME"));
result.setPartOfPrimaryKey(column.isPartOfPrimaryKey()); result.add(foreignKey);
result.setSize(column.getSize());
result.setWidth(column.getWidth());
return result;
} }
} catch (SQLException e) {
private Index from(schemacrawler.schema.Index index){ throw new MetaDataAccessException(e);
Index result =new Index(); }finally {
result.setName(index.getName()); try{rs.close();} catch (SQLException e) {}
result.setUnique(index.isUnique()); try{connection.close();} catch (SQLException e) {}
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));
} }
return result; 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") @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 { 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,catalog,schema);
return jdbcMetaDataLoaderService.getTables(datasource,"platform",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 dataSource 数据源
* @param catalogName 目录名 * @param catalogName 目录名
* @param schemaName Schema 名称 * @param schemaName Schema 名称
* @param tableNames 表名数组
* @return 某个 Schema 下的表对象列表 * @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