Browse Source

基础框架发布: 8.2.39

1. 数据库表结构和数据导出时,提升选择表的效能

前端核心发布: 8.2.132
  1. 解决首页和工作台我完成的任务排序的问题
main
wangshaoping 2 days ago
parent
commit
822f7f0063
  1. 1
      io.sc.platform.core/src/main/resources/io/sc/platform/core/i18n/words.properties
  2. 1
      io.sc.platform.core/src/main/resources/io/sc/platform/core/i18n/words_tw_CN.properties
  3. 1
      io.sc.platform.core/src/main/resources/io/sc/platform/core/i18n/words_zh_CN.properties
  4. 3
      io.sc.platform.developer.frontend/src/i18n/messages.json
  5. 3
      io.sc.platform.developer.frontend/src/i18n/messages_tw_CN.json
  6. 3
      io.sc.platform.developer.frontend/src/i18n/messages_zh_CN.json
  7. 38
      io.sc.platform.developer.frontend/src/views/backend/ExportLiquibase.vue
  8. 111
      io.sc.platform.jdbc.liquibase/src/main/java/io/sc/platform/jdbc/liquibase/exporter/CsvExporter.java
  9. 94
      io.sc.platform.jdbc.liquibase/src/main/java/io/sc/platform/jdbc/liquibase/exporter/LiquibaseExporter.java
  10. 32
      io.sc.platform.jdbc.liquibase/src/main/java/io/sc/platform/jdbc/liquibase/exporter/PluginExporter.java
  11. 123
      io.sc.platform.jdbc.liquibase/src/main/java/io/sc/platform/jdbc/liquibase/exporter/SchemaExporter.java
  12. 2
      io.sc.platform.jdbc.liquibase/src/main/resources/META-INF/services/io.sc.platform.jdbc.exporter.DataExporter
  13. 27
      io.sc.platform.jdbc/src/main/java/io/sc/platform/jdbc/exporter/support/DataExportConfigure.java

1
io.sc.platform.core/src/main/resources/io/sc/platform/core/i18n/words.properties

@ -15,6 +15,7 @@ center=Center
changePassword=Change Password
changeRole=Change Role
className=Class
classPath=Class Path
clone=Clone
close=Close
code=Code

1
io.sc.platform.core/src/main/resources/io/sc/platform/core/i18n/words_tw_CN.properties

@ -15,6 +15,7 @@ center=\u4E2D\u5FC3
changePassword=\u4FEE\u6539\u5BC6\u78BC
changeRole=\u5207\u63DB\u89D2\u8272
className=\u985E\u540D
classPath=\u985E\u8DEF\u5F91
clone=\u8907\u88FD
close=\u95DC\u9589
code=\u4EE3\u78BC

1
io.sc.platform.core/src/main/resources/io/sc/platform/core/i18n/words_zh_CN.properties

@ -15,6 +15,7 @@ center=\u4E2D\u5FC3
changePassword=\u4FEE\u6539\u5BC6\u7801
changeRole=\u5207\u6362\u89D2\u8272
className=\u7C7B\u540D
classPath=\u7C7B\u8DEF\u5F84
clone=\u590D\u5236
close=\u5173\u95ED
code=\u4EE3\u7801

3
io.sc.platform.developer.frontend/src/i18n/messages.json

@ -50,6 +50,9 @@
"developer.backend.export.liquibase.catalog": "Catalog",
"developer.backend.export.liquibase.schema": "Schema",
"developer.backend.export.liquibase.tables": "Tables",
"developer.backend.export.liquibase.isExportTableSchemaLiquibaseFile": "Is Export Table Schema Liquibase File?",
"developer.backend.export.liquibase.isExportPlatformLiquibasePluginFile": "Is Export Platform Liquibase Plugin File?",
"developer.backend.export.liquibase.isExportDataCsvFile": "Is Export Data CSV File?",
"developer.backend.export.liquibase.export.tip": "Are you sure to export?",
"developer.backend.sql.datasource": "Datasource",

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

@ -50,6 +50,9 @@
"developer.backend.export.liquibase.catalog": "目錄",
"developer.backend.export.liquibase.schema": "方案",
"developer.backend.export.liquibase.tables": "表",
"developer.backend.export.liquibase.isExportTableSchemaLiquibaseFile": "是否導出表結構 Liquibase 文件?",
"developer.backend.export.liquibase.isExportPlatformLiquibasePluginFile": "是否導出平台 Liquibase 插件文件?",
"developer.backend.export.liquibase.isExportDataCsvFile": "是否導出數據 CSV 文件?",
"developer.backend.export.liquibase.export.tip": "您確定要導出嗎?",
"developer.backend.sql.datasource": "數據源",

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

@ -50,6 +50,9 @@
"developer.backend.export.liquibase.catalog": "目录",
"developer.backend.export.liquibase.schema": "方案",
"developer.backend.export.liquibase.tables": "表",
"developer.backend.export.liquibase.isExportTableSchemaLiquibaseFile": "是否导出表结构 Liquibase 文件?",
"developer.backend.export.liquibase.isExportPlatformLiquibasePluginFile": "是否导出平台 Liquibase 插件文件?",
"developer.backend.export.liquibase.isExportDataCsvFile": "是否导出数据 CSV 文件?",
"developer.backend.export.liquibase.export.tip": "您确定要导出吗?",
"developer.backend.sql.datasource": "数据源",

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

@ -1,6 +1,7 @@
<template>
<div>
<w-form
ref="formRef"
v-model="valueReactive"
:cols-num="12"
:fields="[
@ -36,8 +37,8 @@
name: 'tables',
label: $t('developer.backend.export.liquibase.tables'),
type: 'w-grid-select',
requiredIf: true,
multiple: true,
displayValue: 'name',
grid: {
toolbarConfigure: { noIcon: false },
@ -66,6 +67,27 @@
},
},
{ colSpan: 12, name: 'sql', label: $t('SQL'), type: 'w-code-mirror', toolbar: false, lang: 'sql' },
{
colSpan: 12,
name: 'isExportDataCsvFile',
label: $t('developer.backend.export.liquibase.isExportDataCsvFile'),
type: 'w-checkbox',
modelValue: true,
},
{
colSpan: 12,
name: 'isExportTableSchemaLiquibaseFile',
label: $t('developer.backend.export.liquibase.isExportTableSchemaLiquibaseFile'),
type: 'w-checkbox',
modelValue: true,
},
{
colSpan: 12,
name: 'isExportPlatformLiquibasePluginFile',
label: $t('developer.backend.export.liquibase.isExportPlatformLiquibasePluginFile'),
type: 'w-checkbox',
modelValue: true,
},
]"
>
</w-form>
@ -91,6 +113,7 @@ import { ref, reactive, onMounted, onUpdated } from 'vue';
import { t, axios, Environment, DialogManager, Downloader } from 'platform-core';
const formRef = ref();
const progressBtnRef = ref();
const datasourceOptionsRef = ref([]);
const catalogOptionsRef = ref([]);
@ -103,6 +126,10 @@ const valueReactive = reactive({
schema: undefined,
tables: [],
sql: undefined,
outputFileName: undefined,
isExportDataCsvFile: true,
isExportTableSchemaLiquibaseFile: true,
isExportPlatformLiquibasePluginFile: true,
});
const loadDatasource = () => {
@ -168,6 +195,10 @@ const schemaChanged = (datasource: string, catalog: string, schema: string) => {
};
const exportData = (e) => {
formRef.value.validate().then((value) => {
if (!value) {
return;
}
DialogManager.confirm(t('developer.backend.export.liquibase.export.tip'), () => {
const data = valueReactive;
const config = {
@ -175,6 +206,10 @@ const exportData = (e) => {
catalog: data.catalog,
schema: data.schema,
tables: [],
outputFileName: data.outputFileName,
isExportDataCsvFile: data.isExportDataCsvFile,
isExportTableSchemaLiquibaseFile: data.isExportTableSchemaLiquibaseFile,
isExportPlatformLiquibasePluginFile: data.isExportPlatformLiquibasePluginFile,
};
const length = data.tables.length;
const sql = length === 1 ? data.sql : '';
@ -185,6 +220,7 @@ const exportData = (e) => {
progressBtnRef.value.start();
});
});
});
};
onMounted(() => {

111
io.sc.platform.jdbc.liquibase/src/main/java/io/sc/platform/jdbc/liquibase/exporter/LiquibaseDataCsvExporter.java → io.sc.platform.jdbc.liquibase/src/main/java/io/sc/platform/jdbc/liquibase/exporter/CsvExporter.java

@ -1,10 +1,6 @@
package io.sc.platform.jdbc.liquibase.exporter;
import io.sc.platform.core.DirectoryManager;
import io.sc.platform.core.enums.ProgressStatus;
import io.sc.platform.core.support.ProgressInfo;
import io.sc.platform.core.util.ZipUtil;
import io.sc.platform.jdbc.exporter.DataExporter;
import io.sc.platform.jdbc.exporter.support.DataExportConfigure;
import io.sc.platform.jdbc.exporter.support.ExportTable;
import io.sc.platform.jdbc.liquibase.exporter.support.ParentChildRecord;
@ -12,7 +8,6 @@ import io.sc.platform.jdbc.meta.MetaDataLoader;
import io.sc.platform.jdbc.meta.support.Column;
import io.sc.platform.jdbc.meta.support.Table;
import io.sc.platform.jdbc.util.SqlTypeUtil;
import io.sc.platform.util.DateUtil;
import io.sc.platform.util.FileUtil;
import io.sc.platform.util.WriterUtil;
import liquibase.repackaged.com.opencsv.CSVWriterBuilder;
@ -27,46 +22,39 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.sql.*;
import java.util.Date;
import java.util.*;
import java.util.stream.Collectors;
public class LiquibaseDataCsvExporter implements DataExporter {
private static final Logger log = LoggerFactory.getLogger(LiquibaseDataCsvExporter.class);
private static final String OUTPUT_PATH = DirectoryManager.getInstance().getByName("dir.work.web.export") + "/liquibase";
@Override
public void exportData(DataSource dataSource, DataExportConfigure configure, ProgressInfo progressInfo, Locale locale) throws Exception{
progressInfo.setStatus(ProgressStatus.RUNNING);
progressInfo.setStartDatetime(new Date());
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Locale;
public class CsvExporter {
private static final Logger log = LoggerFactory.getLogger(CsvExporter.class);
public void export(String outputBasePath,DataSource dataSource, DataExportConfigure configure, ProgressInfo progressInfo, Locale locale) throws Exception{
String outputDir =outputBasePath + "/src/main/resources/liquibase/data";
FileUtil.deldirs(outputDir);
new File(outputDir).mkdirs();
String[] tableNames = ExportTable.getTableNames(configure.getTables());
progressInfo.setTotalWeight(tableNames.length);
// 获取需要操作的表信息
List<Table> tables = MetaDataLoader.newInstance().getTablesWithDetail(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();
StringBuilder changeSetSb =new StringBuilder();
// 导出 csv 数据文件
for(Table table : tables){
progressInfo.setMessageKey(table.getName());
writeChangeSet(changeSetSb,table);
writeTable(dataSource,table,configure,progressInfo,locale);
writeTable(outputDir,dataSource,table,configure,progressInfo,locale);
progressInfo.addWeight(1);
}
FileUtil.writeString(outPutDir + "/liquibase.xml",createLiquibaseFileContent(getLiquibaseChangeLogXmlFileName(configure),changeSetSb));
ZipUtil.zip(outPutDir);
// 设置结果为导出的 zip 文件全路径
progressInfo.setResult(outPutDir + ".zip");
//执行完毕
progressInfo.done();
// 导出 liquibase 用于导入 csv 数据文件的 changelog 文件
StringBuilder changeSetSb =new StringBuilder();
for(Table table : tables){
changeSetSb.append(LiquibaseExporter.generateImportCsvDataLiquiabaseChangeSet(table));
}
String xmlFileName =LiquibaseExporter.getLiquibaseChangeLogXmlFileName(configure) + "_DATA";
FileUtil.writeString(outputDir + "/" + xmlFileName + ".xml",LiquibaseExporter.generateLiquibaseFileContent(xmlFileName,changeSetSb));
}
private void writeTable(DataSource dataSource,Table table,DataExportConfigure configure,ProgressInfo progressInfo, Locale locale) throws Exception{
BufferedWriter writer = WriterUtil.bufferedWriter(OUTPUT_PATH + getPath(configure.getCatalog(),configure.getSchema()) + "/data/" + table.getName() + ".csv");
private void writeTable(String outputDir,DataSource dataSource,Table table,DataExportConfigure configure,ProgressInfo progressInfo, Locale locale) throws Exception{
BufferedWriter writer = WriterUtil.bufferedWriter(outputDir + "/" + table.getName() + ".csv");
ICSVWriter csvWriter = new CSVWriterBuilder(writer).build();
//写入字段定义信息===============================================================================
@ -209,45 +197,6 @@ public class LiquibaseDataCsvExporter implements DataExporter {
log.info("[" + table.getName() + "] : " + count + " completed");
}
private String createLiquibaseFileContent(String id,StringBuilder content){
StringBuilder sb =new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append("\n");
sb.append("<databaseChangeLog").append("\n");
sb.append("\t").append("xmlns=\"http://www.liquibase.org/xml/ns/dbchangelog\"").append("\n");
sb.append("\t").append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"").append("\n");
sb.append("\t").append("xmlns:ext=\"http://www.liquibase.org/xml/ns/dbchangelog-ext\"").append("\n");
sb.append("\t").append("xsi:schemaLocation=\"").append("\n");
sb.append("\t\t").append("http://www.liquibase.org/xml/ns/dbchangelog").append("\n");
sb.append("\t\t").append("http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.1.xsd").append("\n");
sb.append("\t\t").append("http://www.liquibase.org/xml/ns/dbchangelog-ext").append("\n");
sb.append("\t\t").append("http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd").append("\n");
sb.append("\">").append("\n");
sb.append("\t").append("<changeSet id=\"").append(id).append("\" author=\"platform\">").append("\n");
sb.append(content);
sb.append("\t").append("</changeSet>").append("\n");
sb.append("</databaseChangeLog>");
return sb.toString();
}
private void writeChangeSet(StringBuilder sb,Table table){
sb.append("\t\t").append("<customChange class=\"io.sc.platform.jdbc.liquibase.task.CsvImportTaskChange\">").append("\n");
sb.append("\t\t\t").append("<param name=\"dataFile\" value=\"classpath:/liquibase/data/").append(table.getName()).append(".csv").append("\"/>").append("\n");
sb.append("\t\t").append("</customChange>").append("\n");
sb.append("\n");
}
public String getLiquibaseChangeLogXmlFileName(DataExportConfigure configure) {
String[] tableNames = Arrays.stream(configure.getTables()).map(ExportTable::getName).collect(Collectors.toList()).toArray(new String[]{});
String description =null;
if(tableNames.length==1) {
description =tableNames[0].toUpperCase();
}else {
description =tableNames[0].toUpperCase() + " And More " + (tableNames.length-1) + " Tables";
}
return "LIQUIBASE_" + DateUtil.formatDate(new Date(),"yyyy.MM.dd_HH.mm.ss") + "__" + description;
}
private String transformString(String string){
if(string==null){
return null;
@ -260,16 +209,4 @@ public class LiquibaseDataCsvExporter implements DataExporter {
//string =string.replace("\r","\\\\r");
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;
}
}

94
io.sc.platform.jdbc.liquibase/src/main/java/io/sc/platform/jdbc/liquibase/exporter/LiquibaseExporter.java

@ -0,0 +1,94 @@
package io.sc.platform.jdbc.liquibase.exporter;
import io.sc.platform.core.DirectoryManager;
import io.sc.platform.core.enums.ProgressStatus;
import io.sc.platform.core.support.ProgressInfo;
import io.sc.platform.core.util.ZipUtil;
import io.sc.platform.jdbc.exporter.DataExporter;
import io.sc.platform.jdbc.exporter.support.DataExportConfigure;
import io.sc.platform.jdbc.exporter.support.ExportTable;
import io.sc.platform.jdbc.meta.support.Table;
import io.sc.platform.util.DateUtil;
import org.springframework.util.StringUtils;
import javax.sql.DataSource;
import java.util.Arrays;
import java.util.Date;
import java.util.Locale;
import java.util.stream.Collectors;
public class LiquibaseExporter implements DataExporter {
private static final String OUTPUT_PATH = DirectoryManager.getInstance().getByName("dir.work.web.export") + "/liquibase";
@Override
public void exportData(DataSource dataSource, DataExportConfigure configure, ProgressInfo progressInfo, Locale locale) throws Exception{
String[] tableNames =ExportTable.getTableNames(configure.getTables());
progressInfo.setStatus(ProgressStatus.RUNNING);
progressInfo.setStartDatetime(new Date());
progressInfo.setTotalWeight(tableNames.length);
String catalogOrSchemaName ="";
if(StringUtils.hasText(configure.getCatalog())){
catalogOrSchemaName ="/" + configure.getCatalog().trim();
}
if(StringUtils.hasText(configure.getSchema())){
catalogOrSchemaName ="/" + configure.getSchema().trim();
}
String outputDir =OUTPUT_PATH + catalogOrSchemaName;
new CsvExporter().export(outputDir,dataSource,configure,progressInfo,locale);
new SchemaExporter().export(outputDir,dataSource,configure,progressInfo,locale);
new PluginExporter().export(outputDir,dataSource,configure,progressInfo,locale);
ZipUtil.zip(outputDir);
// 设置结果为导出的 zip 文件全路径
progressInfo.setResult(outputDir + ".zip");
//执行完毕
progressInfo.done();
}
public static String generateLiquibaseFileContent(String id,StringBuilder content){
StringBuilder sb =new StringBuilder();
sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>").append("\n");
sb.append("<databaseChangeLog").append("\n");
sb.append("\t").append("xmlns=\"http://www.liquibase.org/xml/ns/dbchangelog\"").append("\n");
sb.append("\t").append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"").append("\n");
sb.append("\t").append("xmlns:ext=\"http://www.liquibase.org/xml/ns/dbchangelog-ext\"").append("\n");
sb.append("\t").append("xsi:schemaLocation=\"").append("\n");
sb.append("\t\t").append("http://www.liquibase.org/xml/ns/dbchangelog").append("\n");
sb.append("\t\t").append("http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd").append("\n");
sb.append("\t\t").append("http://www.liquibase.org/xml/ns/dbchangelog-ext").append("\n");
sb.append("\t\t").append("http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd").append("\n");
sb.append("\">").append("\n");
sb.append("\t").append("<changeSet id=\"").append(id).append("\" author=\"platform\">").append("\n");
sb.append(content);
sb.append("\t").append("</changeSet>").append("\n");
sb.append("</databaseChangeLog>");
return sb.toString();
}
public static String generateImportCsvDataLiquiabaseChangeSet(Table table){
StringBuilder sb =new StringBuilder();
sb.append("\t\t").append("<customChange class=\"io.sc.platform.jdbc.liquibase.task.CsvImportTaskChange\">").append("\n");
sb.append("\t\t\t").append("<param name=\"dataFile\" value=\"classpath:/liquibase/data/").append(table.getName()).append(".csv").append("\"/>").append("\n");
sb.append("\t\t").append("</customChange>").append("\n");
sb.append("\n");
return sb.toString();
}
public static String getLiquibaseChangeLogXmlFileName(DataExportConfigure configure) {
String[] tableNames = Arrays.stream(configure.getTables()).map(ExportTable::getName).collect(Collectors.toList()).toArray(new String[]{});
String description =null;
if(tableNames.length==1) {
description =tableNames[0].toUpperCase();
}else {
description =tableNames[0].toUpperCase() + "_And_More_" + (tableNames.length-1) + "_Tables";
}
return "LIQUIBASE_" + DateUtil.formatDate(new Date(),"yyyy.MM.dd") + "__" + description;
}
}

32
io.sc.platform.jdbc.liquibase/src/main/java/io/sc/platform/jdbc/liquibase/exporter/PluginExporter.java

@ -0,0 +1,32 @@
package io.sc.platform.jdbc.liquibase.exporter;
import io.sc.platform.core.support.ProgressInfo;
import io.sc.platform.jdbc.exporter.support.DataExportConfigure;
import io.sc.platform.util.FileUtil;
import javax.sql.DataSource;
import java.io.File;
import java.util.Locale;
public class PluginExporter {
public void export(String outputBasePath, DataSource dataSource, DataExportConfigure configure, ProgressInfo progressInfo, Locale locale) throws Exception {
String outputDir =outputBasePath + "/src/main/resources/META-INF/platform/plugins";
FileUtil.deldirs(outputDir);
new File(outputDir).mkdirs();
StringBuilder sb =new StringBuilder();
sb.append("[").append("\n");
sb.append(" {").append("\n");
sb.append(" \"category\": \"install\"").append(",\n");
sb.append(" \"order\": 100000").append(",\n");
sb.append(" \"description\": \"\"").append(",\n");
sb.append(" \"locations\": [").append("\n");
sb.append(" \"").append("classpath:/liquibase/schema/").append(LiquibaseExporter.getLiquibaseChangeLogXmlFileName(configure)).append("_DDL.xml\"").append(",\n");
sb.append(" \"").append("classpath:/liquibase/data/").append(LiquibaseExporter.getLiquibaseChangeLogXmlFileName(configure)).append("_DATA.xml\"").append("\n");
sb.append(" ]").append("\n");
sb.append(" }").append("\n");
sb.append("]").append("\n");
FileUtil.writeString(outputDir + "/liquibase.json",sb.toString());
}
}

123
io.sc.platform.jdbc.liquibase/src/main/java/io/sc/platform/jdbc/liquibase/exporter/SchemaExporter.java

@ -0,0 +1,123 @@
package io.sc.platform.jdbc.liquibase.exporter;
import io.sc.platform.core.Environment;
import io.sc.platform.core.support.ProgressInfo;
import io.sc.platform.jdbc.exporter.support.DataExportConfigure;
import io.sc.platform.jdbc.exporter.support.ExportTable;
import io.sc.platform.jdbc.meta.MetaDataLoader;
import io.sc.platform.jdbc.meta.support.Column;
import io.sc.platform.jdbc.meta.support.Index;
import io.sc.platform.jdbc.meta.support.Table;
import io.sc.platform.util.FileUtil;
import io.sc.platform.util.WriterUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.sql.DataSource;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import java.io.File;
import java.util.List;
import java.util.Locale;
public class SchemaExporter {
private static final Logger log = LoggerFactory.getLogger(SchemaExporter.class);
public void export(String outputBasePath, DataSource dataSource, DataExportConfigure configure, ProgressInfo progressInfo, Locale locale) throws Exception{
String outputDir =outputBasePath + "/src/main/resources/liquibase/schema";
FileUtil.deldirs(outputDir);
new File(outputDir).mkdirs();
String[] tableNames = ExportTable.getTableNames(configure.getTables());
XMLStreamWriter writer = WriterUtil.xmlStreamWriter(outputDir + "/" + LiquibaseExporter.getLiquibaseChangeLogXmlFileName(configure) + "_DDL.xml");
writeHeader(writer,LiquibaseExporter.getLiquibaseChangeLogXmlFileName(configure));
List<Table> tables = MetaDataLoader.newInstance().getTablesWithDetail(dataSource,configure.getCatalog(),configure.getSchema(),tableNames);
for(Table table : tables){
writeTable(table,writer);
}
writeTail(writer);
writer.flush();
writer.close();
}
private void writeHeader(XMLStreamWriter writer,String changeSetId) throws XMLStreamException {
writer.writeStartDocument(Environment.DEFAULT_CHARSET_NAME,"1.0");
writer.writeStartElement("databaseChangeLog"); //start databaseChangeLog
writer.writeAttribute("xmlns", "http://www.liquibase.org/xml/ns/dbchangelog");
writer.writeAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
writer.writeAttribute("xmlns:ext", "http://www.liquibase.org/xml/ns/dbchangelog-ext");
writer.writeAttribute("xsi:schemaLocation", "http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.9.xsd http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd");
writer.writeStartElement("changeSet"); //start changeSet
writer.writeAttribute("id", changeSetId);
writer.writeAttribute("author", "platform");
}
private void writeTail(XMLStreamWriter writer) throws XMLStreamException {
writer.writeEndElement(); //end changeSet
writer.writeEndElement(); //end databaseChangeLog
writer.writeEndDocument();
}
private void writeTable(Table table, XMLStreamWriter writer) throws XMLStreamException {
// create table
writer.writeStartElement("createTable"); //start createTable
writer.writeAttribute("tableName", table.getName().toUpperCase());
writer.writeAttribute("remarks", table.getRemarks());
List<Column> columns =table.getColumns();
for(Column column : columns){
writer.writeStartElement("column"); //start column
writer.writeAttribute("name",column.getName());
writer.writeAttribute("type", getLiquibaseJavaSqlType(column));
writer.writeAttribute("remarks", column.getRemarks());
if(column.isPartOfPrimaryKey()) {
writer.writeStartElement("constraints");
writer.writeAttribute("primaryKey", "true");
writer.writeEndElement();
}
writer.writeEndElement(); //end column
}
writer.writeEndElement(); //end createTable
// create index
List<Index> indexes =table.getIndexes();
for(Index index : indexes){
for(Column column : index.getColumns()){
if(!column.isPartOfPrimaryKey()) {
writer.writeStartElement("createIndex"); //start createIndex
writer.writeAttribute("tableName",table.getName());
writer.writeAttribute("indexName",index.getName());
writer.writeStartElement("column"); //start column
writer.writeAttribute("name", column.getName());
writer.writeEndElement(); //end column
writer.writeEndElement(); //end createIndex
}
}
}
}
private String getLiquibaseJavaSqlType(Column column) {
String type =column.getSqlType();
if("java.sql.Types.VARCHAR".equals(type) || "java.sql.Types.NVARCHAR".equals(type)) {
if(column.getSize()>=2000) {
type ="java.sql.Types.CLOB";
}else {
type ="NVARCHAR(" + column.getSize() + ")";
}
}else if("java.sql.Types.LONGVARCHAR".equals(type)){
type ="CLOB";
}else if("java.sql.Types.TIMESTAMP".equals(type)) {
type ="DATETIME";
}else if("java.sql.Types.NUMERIC".equals(type)) {
type ="java.sql.Types.NUMERIC" + column.getWidth();
}else if("java.sql.Types.DECIMAL".equals(type)) {
type ="java.sql.Types.DECIMAL" + column.getWidth();
}else if("java.sql.Types.INTEGER".equals(type)){
type ="INTEGER";
}
return type;
}
}

2
io.sc.platform.jdbc.liquibase/src/main/resources/META-INF/services/io.sc.platform.jdbc.exporter.DataExporter

@ -1 +1 @@
io.sc.platform.jdbc.liquibase.exporter.LiquibaseDataCsvExporter
io.sc.platform.jdbc.liquibase.exporter.LiquibaseExporter

27
io.sc.platform.jdbc/src/main/java/io/sc/platform/jdbc/exporter/support/DataExportConfigure.java

@ -7,6 +7,9 @@ public class DataExportConfigure {
private String catalog;
private String schema;
private ExportTable[] tables;
private boolean isExportDataCsvFile;
private boolean isExportTableSchemaLiquibaseFile;
private boolean isExportPlatformLiquibasePluginFile;
private int fetchSize =1000;
public String getSql(String tableName){
@ -53,6 +56,30 @@ public class DataExportConfigure {
this.tables = tables;
}
public boolean isExportDataCsvFile() {
return isExportDataCsvFile;
}
public void setExportDataCsvFile(boolean exportDataCsvFile) {
isExportDataCsvFile = exportDataCsvFile;
}
public boolean isExportTableSchemaLiquibaseFile() {
return isExportTableSchemaLiquibaseFile;
}
public void setExportTableSchemaLiquibaseFile(boolean exportTableSchemaLiquibaseFile) {
isExportTableSchemaLiquibaseFile = exportTableSchemaLiquibaseFile;
}
public boolean isExportPlatformLiquibasePluginFile() {
return isExportPlatformLiquibasePluginFile;
}
public void setExportPlatformLiquibasePluginFile(boolean exportPlatformLiquibasePluginFile) {
isExportPlatformLiquibasePluginFile = exportPlatformLiquibasePluginFile;
}
public int getFetchSize() {
return fetchSize;
}

Loading…
Cancel
Save