mirror of
https://gitee.com/dromara/dbswitch.git
synced 2025-09-09 21:49:08 +00:00
I5QFVD:支持选择视图表迁移同步
This commit is contained in:
13
README.md
13
README.md
@@ -132,8 +132,8 @@ sh ./docker-maven-build.sh
|
|||||||
dbswitch:
|
dbswitch:
|
||||||
source:
|
source:
|
||||||
# source database connection information
|
# source database connection information
|
||||||
## support MySQL/MariaDB/DB2/DM/Kingbase8/Oracle/SQLServer/PostgreSQL/Greenplum
|
## support MySQL/MariaDB/DB2/DM/Kingbase8/Oracle/SQLServer/PostgreSQL/Greenplum etc.
|
||||||
## support mutiple source database connection
|
## support multiple source database connection
|
||||||
- url: jdbc:oracle:thin:@172.17.2.10:1521:ORCL
|
- url: jdbc:oracle:thin:@172.17.2.10:1521:ORCL
|
||||||
driver-class-name: 'oracle.jdbc.driver.OracleDriver'
|
driver-class-name: 'oracle.jdbc.driver.OracleDriver'
|
||||||
username: 'system'
|
username: 'system'
|
||||||
@@ -143,20 +143,22 @@ dbswitch:
|
|||||||
fetch-size: 10000
|
fetch-size: 10000
|
||||||
## schema name for query source schemas, separate by ','
|
## schema name for query source schemas, separate by ','
|
||||||
source-schema: 'TANG'
|
source-schema: 'TANG'
|
||||||
|
## table type which include or exclude,option: TABLE,VIEW
|
||||||
|
table-type: 'TABLE'
|
||||||
## table name include from table lists, separate by ','
|
## table name include from table lists, separate by ','
|
||||||
source-includes: ''
|
source-includes: ''
|
||||||
## table name exclude from table lists, separate by ','
|
## table name exclude from table lists, separate by ','
|
||||||
source-excludes: ''
|
source-excludes: ''
|
||||||
## table name convert mapper by regular expression
|
## table name convert mapper by regular expression
|
||||||
regex-table-mapper:
|
regex-table-mapper:
|
||||||
- 'from-pattern': '^'
|
- from-pattern: '^'
|
||||||
'to-value': 'T_'
|
to-value: 'T_'
|
||||||
## columns name convert mapper by regular expression like regex-table-mapper
|
## columns name convert mapper by regular expression like regex-table-mapper
|
||||||
regex-column-mapper:
|
regex-column-mapper:
|
||||||
|
|
||||||
target:
|
target:
|
||||||
# target database connection information
|
# target database connection information
|
||||||
## Best support for Oracle/PostgreSQL/Greenplum/DM/Kingbase8
|
## Best support for Oracle/PostgreSQL/Greenplum/DM etc.
|
||||||
url: jdbc:postgresql://172.17.2.10:5432/test
|
url: jdbc:postgresql://172.17.2.10:5432/test
|
||||||
driver-class-name: org.postgresql.Driver
|
driver-class-name: org.postgresql.Driver
|
||||||
username: tang
|
username: tang
|
||||||
@@ -183,6 +185,7 @@ dbswitch:
|
|||||||
| dbswitch.source[i].password | 来源端连接帐号密码 | tangyibo | 无 |
|
| dbswitch.source[i].password | 来源端连接帐号密码 | tangyibo | 无 |
|
||||||
| dbswitch.source[i].fetch-size | 来源端数据库查询时的fetch_size设置 | 10000 | 需要大于100有效 |
|
| dbswitch.source[i].fetch-size | 来源端数据库查询时的fetch_size设置 | 10000 | 需要大于100有效 |
|
||||||
| dbswitch.source[i].source-schema | 来源端的schema名称 | dbo,test | 多个之间用英文逗号分隔 |
|
| dbswitch.source[i].source-schema | 来源端的schema名称 | dbo,test | 多个之间用英文逗号分隔 |
|
||||||
|
| dbswitch.source[i].table-type | 来源端表的类型 | TABLE | 可选值为:TABLE、VIEW ,分别代表物理表和试图表 |
|
||||||
| dbswitch.source[i].source-includes | 来源端schema下的表中需要包含的表名称 | users1,orgs1 | 支持多个表(多个之间用英文逗号分隔);支持支持正则表达式(不能含有逗号) |
|
| dbswitch.source[i].source-includes | 来源端schema下的表中需要包含的表名称 | users1,orgs1 | 支持多个表(多个之间用英文逗号分隔);支持支持正则表达式(不能含有逗号) |
|
||||||
| dbswitch.source[i].source-excludes | 来源端schema下的表中需要过滤的表名称 | users,orgs | 不包含的表名称,多个之间用英文逗号分隔 |
|
| dbswitch.source[i].source-excludes | 来源端schema下的表中需要过滤的表名称 | users,orgs | 不包含的表名称,多个之间用英文逗号分隔 |
|
||||||
| dbswitch.source[i].regex-table-mapper | 基于正则表达式的表名称映射关系 | [{"from-pattern": "^","to-value": "T_"}] | 为list类型,元素存在顺序关系 |
|
| dbswitch.source[i].regex-table-mapper | 基于正则表达式的表名称映射关系 | [{"from-pattern": "^","to-value": "T_"}] | 为list类型,元素存在顺序关系 |
|
||||||
|
@@ -92,6 +92,20 @@
|
|||||||
:value="item"></el-option>
|
:value="item"></el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item label="源端表类型"
|
||||||
|
label-width="240px"
|
||||||
|
:required=true
|
||||||
|
prop="tableType"
|
||||||
|
style="width:65%">
|
||||||
|
<el-select placeholder="请选择表类型"
|
||||||
|
@change="selectCreateChangedTableType"
|
||||||
|
v-model="createform.tableType">
|
||||||
|
<el-option label="物理表"
|
||||||
|
value="TABLE"></el-option>
|
||||||
|
<el-option label="视图表"
|
||||||
|
value="VIEW"></el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="配置方式"
|
<el-form-item label="配置方式"
|
||||||
label-width="240px"
|
label-width="240px"
|
||||||
:required=true
|
:required=true
|
||||||
@@ -297,6 +311,7 @@
|
|||||||
label="CRON表达式">{{createform.cronExpression}}</el-descriptions-item>
|
label="CRON表达式">{{createform.cronExpression}}</el-descriptions-item>
|
||||||
<el-descriptions-item label="源端数据源">[{{createform.sourceConnectionId}}]{{sourceConnection.name}}</el-descriptions-item>
|
<el-descriptions-item label="源端数据源">[{{createform.sourceConnectionId}}]{{sourceConnection.name}}</el-descriptions-item>
|
||||||
<el-descriptions-item label="源端schema">{{createform.sourceSchema}}</el-descriptions-item>
|
<el-descriptions-item label="源端schema">{{createform.sourceSchema}}</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="源端表类型">{{createform.tableType}}</el-descriptions-item>
|
||||||
<el-descriptions-item label="源端表选择方式">
|
<el-descriptions-item label="源端表选择方式">
|
||||||
<span v-if="createform.includeOrExclude == 'INCLUDE'">
|
<span v-if="createform.includeOrExclude == 'INCLUDE'">
|
||||||
包含表
|
包含表
|
||||||
@@ -434,6 +449,7 @@ export default {
|
|||||||
cronExpression: "",
|
cronExpression: "",
|
||||||
sourceConnectionId: '请选择',
|
sourceConnectionId: '请选择',
|
||||||
sourceSchema: "",
|
sourceSchema: "",
|
||||||
|
tableType: "TABLE",
|
||||||
includeOrExclude: "",
|
includeOrExclude: "",
|
||||||
sourceTables: [],
|
sourceTables: [],
|
||||||
tableNameMapper: [],
|
tableNameMapper: [],
|
||||||
@@ -476,6 +492,14 @@ export default {
|
|||||||
trigger: "change"
|
trigger: "change"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
tableType: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
type: 'string',
|
||||||
|
message: "表类型必须选择",
|
||||||
|
trigger: "change"
|
||||||
|
}
|
||||||
|
],
|
||||||
includeOrExclude: [
|
includeOrExclude: [
|
||||||
{
|
{
|
||||||
required: true,
|
required: true,
|
||||||
@@ -584,16 +608,55 @@ export default {
|
|||||||
},
|
},
|
||||||
selectCreateChangedSourceSchema: function (value) {
|
selectCreateChangedSourceSchema: function (value) {
|
||||||
this.sourceSchemaTables = [];
|
this.sourceSchemaTables = [];
|
||||||
this.$http.get(
|
if ('TABLE' === this.createform.tableType) {
|
||||||
"/dbswitch/admin/api/v1/connection/tables/get/" + this.createform.sourceConnectionId + "?schema=" + value
|
this.$http.get(
|
||||||
).then(res => {
|
"/dbswitch/admin/api/v1/connection/tables/get/" + this.createform.sourceConnectionId + "?schema=" + value
|
||||||
if (0 === res.data.code) {
|
).then(res => {
|
||||||
this.sourceSchemaTables = res.data.data;
|
if (0 === res.data.code) {
|
||||||
} else {
|
this.sourceSchemaTables = res.data.data;
|
||||||
this.$message.error("查询来源端数据库在制定Schema下的表列表失败," + res.data.message);
|
} else {
|
||||||
this.sourceSchemaTables = [];
|
this.$message.error("查询来源端数据库在指定Schema下的物理表列表失败," + res.data.message);
|
||||||
}
|
this.sourceSchemaTables = [];
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.$http.get(
|
||||||
|
"/dbswitch/admin/api/v1/connection/views/get/" + this.createform.sourceConnectionId + "?schema=" + value
|
||||||
|
).then(res => {
|
||||||
|
if (0 === res.data.code) {
|
||||||
|
this.sourceSchemaTables = res.data.data;
|
||||||
|
} else {
|
||||||
|
this.$message.error("查询来源端数据库在指定Schema下的视图表列表失败," + res.data.message);
|
||||||
|
this.sourceSchemaTables = [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
selectCreateChangedTableType: function (value) {
|
||||||
|
this.sourceSchemaTables = [];
|
||||||
|
if ('TABLE' === value) {
|
||||||
|
this.$http.get(
|
||||||
|
"/dbswitch/admin/api/v1/connection/tables/get/" + this.createform.sourceConnectionId + "?schema=" + this.createform.sourceSchema
|
||||||
|
).then(res => {
|
||||||
|
if (0 === res.data.code) {
|
||||||
|
this.sourceSchemaTables = res.data.data;
|
||||||
|
} else {
|
||||||
|
this.$message.error("查询来源端数据库在指定Schema下的物理表列表失败," + res.data.message);
|
||||||
|
this.sourceSchemaTables = [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.$http.get(
|
||||||
|
"/dbswitch/admin/api/v1/connection/views/get/" + this.createform.sourceConnectionId + "?schema=" + this.createform.sourceSchema
|
||||||
|
).then(res => {
|
||||||
|
if (0 === res.data.code) {
|
||||||
|
this.sourceSchemaTables = res.data.data;
|
||||||
|
} else {
|
||||||
|
this.$message.error("查询来源端数据库在指定Schema下的视图表列表失败," + res.data.message);
|
||||||
|
this.sourceSchemaTables = [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
selectChangedTargetConnection: function (value) {
|
selectChangedTargetConnection: function (value) {
|
||||||
this.targetConnection = this.connectionNameList.find(
|
this.targetConnection = this.connectionNameList.find(
|
||||||
@@ -752,6 +815,7 @@ export default {
|
|||||||
config: {
|
config: {
|
||||||
sourceConnectionId: this.createform.sourceConnectionId,
|
sourceConnectionId: this.createform.sourceConnectionId,
|
||||||
sourceSchema: this.createform.sourceSchema,
|
sourceSchema: this.createform.sourceSchema,
|
||||||
|
tableType: this.createform.tableType,
|
||||||
includeOrExclude: this.createform.includeOrExclude,
|
includeOrExclude: this.createform.includeOrExclude,
|
||||||
sourceTables: this.createform.sourceTables,
|
sourceTables: this.createform.sourceTables,
|
||||||
targetConnectionId: this.createform.targetConnectionId,
|
targetConnectionId: this.createform.targetConnectionId,
|
||||||
|
@@ -92,6 +92,20 @@
|
|||||||
:value="item"></el-option>
|
:value="item"></el-option>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<el-form-item label="源端表类型"
|
||||||
|
label-width="240px"
|
||||||
|
:required=true
|
||||||
|
prop="tableType"
|
||||||
|
style="width:65%">
|
||||||
|
<el-select placeholder="请选择表类型"
|
||||||
|
@change="selectUpdateChangedTableType"
|
||||||
|
v-model="updateform.tableType">
|
||||||
|
<el-option label="物理表"
|
||||||
|
value="TABLE"></el-option>
|
||||||
|
<el-option label="视图表"
|
||||||
|
value="VIEW"></el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="配置方式"
|
<el-form-item label="配置方式"
|
||||||
label-width="240px"
|
label-width="240px"
|
||||||
:required=true
|
:required=true
|
||||||
@@ -297,6 +311,7 @@
|
|||||||
label="CRON表达式">{{updateform.cronExpression}}</el-descriptions-item>
|
label="CRON表达式">{{updateform.cronExpression}}</el-descriptions-item>
|
||||||
<el-descriptions-item label="源端数据源">[{{updateform.sourceConnectionId}}]{{sourceConnection.name}}</el-descriptions-item>
|
<el-descriptions-item label="源端数据源">[{{updateform.sourceConnectionId}}]{{sourceConnection.name}}</el-descriptions-item>
|
||||||
<el-descriptions-item label="源端schema">{{updateform.sourceSchema}}</el-descriptions-item>
|
<el-descriptions-item label="源端schema">{{updateform.sourceSchema}}</el-descriptions-item>
|
||||||
|
<el-descriptions-item label="源端表类型">{{updateform.tableType}}</el-descriptions-item>
|
||||||
<el-descriptions-item label="源端表选择方式">
|
<el-descriptions-item label="源端表选择方式">
|
||||||
<span v-if="updateform.includeOrExclude == 'INCLUDE'">
|
<span v-if="updateform.includeOrExclude == 'INCLUDE'">
|
||||||
包含表
|
包含表
|
||||||
@@ -440,6 +455,7 @@ export default {
|
|||||||
cronExpression: "",
|
cronExpression: "",
|
||||||
sourceConnectionId: '请选择',
|
sourceConnectionId: '请选择',
|
||||||
sourceSchema: "",
|
sourceSchema: "",
|
||||||
|
tableType:"TABLE",
|
||||||
includeOrExclude: "",
|
includeOrExclude: "",
|
||||||
sourceTables: [],
|
sourceTables: [],
|
||||||
tableNameMapper: [],
|
tableNameMapper: [],
|
||||||
@@ -482,6 +498,14 @@ export default {
|
|||||||
trigger: "change"
|
trigger: "change"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
tableType: [
|
||||||
|
{
|
||||||
|
required: true,
|
||||||
|
type: 'string',
|
||||||
|
message: "表类型必须选择",
|
||||||
|
trigger: "change"
|
||||||
|
}
|
||||||
|
],
|
||||||
includeOrExclude: [
|
includeOrExclude: [
|
||||||
{
|
{
|
||||||
required: true,
|
required: true,
|
||||||
@@ -589,6 +613,7 @@ export default {
|
|||||||
cronExpression: detail.cronExpression,
|
cronExpression: detail.cronExpression,
|
||||||
sourceConnectionId: detail.configuration.sourceConnectionId,
|
sourceConnectionId: detail.configuration.sourceConnectionId,
|
||||||
sourceSchema: detail.configuration.sourceSchema,
|
sourceSchema: detail.configuration.sourceSchema,
|
||||||
|
tableType: detail.configuration.tableType,
|
||||||
includeOrExclude: detail.configuration.includeOrExclude,
|
includeOrExclude: detail.configuration.includeOrExclude,
|
||||||
sourceTables: detail.configuration.sourceTables,
|
sourceTables: detail.configuration.sourceTables,
|
||||||
tableNameMapper: detail.configuration.tableNameMapper,
|
tableNameMapper: detail.configuration.tableNameMapper,
|
||||||
@@ -632,16 +657,55 @@ export default {
|
|||||||
},
|
},
|
||||||
selectUpdateChangedSourceSchema: function (value) {
|
selectUpdateChangedSourceSchema: function (value) {
|
||||||
this.sourceSchemaTables = [];
|
this.sourceSchemaTables = [];
|
||||||
this.$http.get(
|
if ('TABLE' === this.updateform.tableType) {
|
||||||
"/dbswitch/admin/api/v1/connection/tables/get/" + this.updateform.sourceConnectionId + "?schema=" + value
|
this.$http.get(
|
||||||
).then(res => {
|
"/dbswitch/admin/api/v1/connection/tables/get/" + this.updateform.sourceConnectionId + "?schema=" + value
|
||||||
if (0 === res.data.code) {
|
).then(res => {
|
||||||
this.sourceSchemaTables = res.data.data;
|
if (0 === res.data.code) {
|
||||||
} else {
|
this.sourceSchemaTables = res.data.data;
|
||||||
this.$message.error("查询来源端数据库在制定Schema下的表列表失败," + res.data.message);
|
} else {
|
||||||
this.sourceSchemaTables = [];
|
this.$message.error("查询来源端数据库在指定Schema下的物理表列表失败," + res.data.message);
|
||||||
}
|
this.sourceSchemaTables = [];
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.$http.get(
|
||||||
|
"/dbswitch/admin/api/v1/connection/views/get/" + this.updateform.sourceConnectionId + "?schema=" + value
|
||||||
|
).then(res => {
|
||||||
|
if (0 === res.data.code) {
|
||||||
|
this.sourceSchemaTables = res.data.data;
|
||||||
|
} else {
|
||||||
|
this.$message.error("查询来源端数据库在指定Schema下的视图表列表失败," + res.data.message);
|
||||||
|
this.sourceSchemaTables = [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
selectUpdateChangedTableType: function (value) {
|
||||||
|
this.sourceSchemaTables = [];
|
||||||
|
if ('TABLE' === value) {
|
||||||
|
this.$http.get(
|
||||||
|
"/dbswitch/admin/api/v1/connection/tables/get/" + this.updateform.sourceConnectionId + "?schema=" + this.updateform.sourceSchema
|
||||||
|
).then(res => {
|
||||||
|
if (0 === res.data.code) {
|
||||||
|
this.sourceSchemaTables = res.data.data;
|
||||||
|
} else {
|
||||||
|
this.$message.error("查询来源端数据库在指定Schema下的物理表列表失败," + res.data.message);
|
||||||
|
this.sourceSchemaTables = [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.$http.get(
|
||||||
|
"/dbswitch/admin/api/v1/connection/views/get/" + this.updateform.sourceConnectionId + "?schema=" + this.updateform.sourceSchema
|
||||||
|
).then(res => {
|
||||||
|
if (0 === res.data.code) {
|
||||||
|
this.sourceSchemaTables = res.data.data;
|
||||||
|
} else {
|
||||||
|
this.$message.error("查询来源端数据库在指定Schema下的视图表列表失败," + res.data.message);
|
||||||
|
this.sourceSchemaTables = [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
selectChangedTargetConnection: function (value) {
|
selectChangedTargetConnection: function (value) {
|
||||||
this.targetConnection = this.connectionNameList.find(
|
this.targetConnection = this.connectionNameList.find(
|
||||||
@@ -809,6 +873,7 @@ export default {
|
|||||||
config: {
|
config: {
|
||||||
sourceConnectionId: this.updateform.sourceConnectionId,
|
sourceConnectionId: this.updateform.sourceConnectionId,
|
||||||
sourceSchema: this.updateform.sourceSchema,
|
sourceSchema: this.updateform.sourceSchema,
|
||||||
|
tableType: this.updateform.tableType,
|
||||||
includeOrExclude: this.updateform.includeOrExclude,
|
includeOrExclude: this.updateform.includeOrExclude,
|
||||||
sourceTables: this.updateform.sourceTables,
|
sourceTables: this.updateform.sourceTables,
|
||||||
targetConnectionId: this.updateform.targetConnectionId,
|
targetConnectionId: this.updateform.targetConnectionId,
|
||||||
|
@@ -42,6 +42,7 @@ public class AssignmentDetailConverter extends
|
|||||||
config.setSourceConnectionId(srcConn.getId());
|
config.setSourceConnectionId(srcConn.getId());
|
||||||
config.setSourceConnectionName(srcConn.getName());
|
config.setSourceConnectionName(srcConn.getName());
|
||||||
config.setSourceSchema(taskConfig.getSourceSchema());
|
config.setSourceSchema(taskConfig.getSourceSchema());
|
||||||
|
config.setTableType(taskConfig.getTableType());
|
||||||
config.setIncludeOrExclude(taskConfig.getExcluded()
|
config.setIncludeOrExclude(taskConfig.getExcluded()
|
||||||
? IncludeExcludeEnum.EXCLUDE
|
? IncludeExcludeEnum.EXCLUDE
|
||||||
: IncludeExcludeEnum.INCLUDE);
|
: IncludeExcludeEnum.INCLUDE);
|
||||||
|
@@ -79,13 +79,21 @@ public class DbConnectionController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@TokenCheck
|
@TokenCheck
|
||||||
@ApiOperation(value = "查询连接在制定Schema下的所有表列表")
|
@ApiOperation(value = "查询连接在制定Schema下的所有物理表列表")
|
||||||
@GetMapping(value = "/tables/get/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
@GetMapping(value = "/tables/get/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
public Result getSchemaTables(@PathVariable("id") Long id,
|
public Result getSchemaTables(@PathVariable("id") Long id,
|
||||||
@RequestParam("schema") String schema) {
|
@RequestParam("schema") String schema) {
|
||||||
return databaseConnectionService.getSchemaTables(id, schema);
|
return databaseConnectionService.getSchemaTables(id, schema);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TokenCheck
|
||||||
|
@ApiOperation(value = "查询连接在制定Schema下的所有视图表列表")
|
||||||
|
@GetMapping(value = "/views/get/{id}", produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
|
public Result getSchemaViews(@PathVariable("id") Long id,
|
||||||
|
@RequestParam("schema") String schema) {
|
||||||
|
return databaseConnectionService.getSchemaViews(id, schema);
|
||||||
|
}
|
||||||
|
|
||||||
@TokenCheck
|
@TokenCheck
|
||||||
@LogOperate(name = "数据库连接", description = "'添加的数据库连接标题为:'+#request.name")
|
@LogOperate(name = "数据库连接", description = "'添加的数据库连接标题为:'+#request.name")
|
||||||
@ApiOperation(value = "添加连接")
|
@ApiOperation(value = "添加连接")
|
||||||
|
@@ -13,7 +13,7 @@ import com.alibaba.fastjson.JSON;
|
|||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.gitee.dbswitch.admin.common.response.Result;
|
import com.gitee.dbswitch.admin.common.response.Result;
|
||||||
import com.gitee.dbswitch.admin.config.SwaggerConfig;
|
import com.gitee.dbswitch.admin.config.SwaggerConfig;
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||||
import com.gitee.dbswitch.core.model.DatabaseDescription;
|
import com.gitee.dbswitch.core.model.DatabaseDescription;
|
||||||
import com.gitee.dbswitch.core.model.TableDescription;
|
import com.gitee.dbswitch.core.model.TableDescription;
|
||||||
@@ -395,7 +395,7 @@ public class StructureController {
|
|||||||
List<ColumnDescription> columnDescs = migrationService
|
List<ColumnDescription> columnDescs = migrationService
|
||||||
.queryTableColumnMeta(src_model, src_table);
|
.queryTableColumnMeta(src_model, src_table);
|
||||||
List<String> primaryKeys = migrationService.queryTablePrimaryKeys(src_model, src_table);
|
List<String> primaryKeys = migrationService.queryTablePrimaryKeys(src_model, src_table);
|
||||||
DatabaseTypeEnum targetDatabaseType = DatabaseTypeEnum.valueOf(target.trim().toUpperCase());
|
ProductTypeEnum targetDatabaseType = ProductTypeEnum.valueOf(target.trim().toUpperCase());
|
||||||
String sql = migrationService
|
String sql = migrationService
|
||||||
.getDDLCreateTableSQL(targetDatabaseType, columnDescs, primaryKeys, dest_model, dest_table,
|
.getDDLCreateTableSQL(targetDatabaseType, columnDescs, primaryKeys, dest_model, dest_table,
|
||||||
false);
|
false);
|
||||||
|
@@ -12,6 +12,7 @@ package com.gitee.dbswitch.admin.entity;
|
|||||||
import com.gitee.dbswitch.admin.handler.ListPatternHandler;
|
import com.gitee.dbswitch.admin.handler.ListPatternHandler;
|
||||||
import com.gitee.dbswitch.admin.handler.ListTypeHandler;
|
import com.gitee.dbswitch.admin.handler.ListTypeHandler;
|
||||||
import com.gitee.dbswitch.common.entity.PatternMapper;
|
import com.gitee.dbswitch.common.entity.PatternMapper;
|
||||||
|
import com.gitee.dbswitch.common.type.DBTableType;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.persistence.Column;
|
import javax.persistence.Column;
|
||||||
@@ -43,6 +44,9 @@ public class AssignmentConfigEntity {
|
|||||||
@Column(name = "source_schema")
|
@Column(name = "source_schema")
|
||||||
private String sourceSchema;
|
private String sourceSchema;
|
||||||
|
|
||||||
|
@Column(name = "table_type")
|
||||||
|
private DBTableType tableType;
|
||||||
|
|
||||||
@Column(name = "source_tables")
|
@Column(name = "source_tables")
|
||||||
@ColumnType(typeHandler = ListTypeHandler.class)
|
@ColumnType(typeHandler = ListTypeHandler.class)
|
||||||
private List<String> sourceTables;
|
private List<String> sourceTables;
|
||||||
|
@@ -17,6 +17,7 @@ import com.gitee.dbswitch.admin.type.IncludeExcludeEnum;
|
|||||||
import com.gitee.dbswitch.admin.type.ScheduleModeEnum;
|
import com.gitee.dbswitch.admin.type.ScheduleModeEnum;
|
||||||
import com.gitee.dbswitch.admin.util.CronExprUtils;
|
import com.gitee.dbswitch.admin.util.CronExprUtils;
|
||||||
import com.gitee.dbswitch.common.entity.PatternMapper;
|
import com.gitee.dbswitch.common.entity.PatternMapper;
|
||||||
|
import com.gitee.dbswitch.common.type.DBTableType;
|
||||||
import com.gitee.dbswitch.common.util.PatterNameUtils;
|
import com.gitee.dbswitch.common.util.PatterNameUtils;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@@ -41,6 +42,7 @@ public class AssigmentCreateRequest {
|
|||||||
|
|
||||||
private Long sourceConnectionId;
|
private Long sourceConnectionId;
|
||||||
private String sourceSchema;
|
private String sourceSchema;
|
||||||
|
private DBTableType tableType;
|
||||||
private IncludeExcludeEnum includeOrExclude;
|
private IncludeExcludeEnum includeOrExclude;
|
||||||
private List<String> sourceTables;
|
private List<String> sourceTables;
|
||||||
private Long targetConnectionId;
|
private Long targetConnectionId;
|
||||||
@@ -59,7 +61,7 @@ public class AssigmentCreateRequest {
|
|||||||
assignment.setDescription(description);
|
assignment.setDescription(description);
|
||||||
assignment.setScheduleMode(scheduleMode);
|
assignment.setScheduleMode(scheduleMode);
|
||||||
if (ScheduleModeEnum.SYSTEM_SCHEDULED == this.getScheduleMode()) {
|
if (ScheduleModeEnum.SYSTEM_SCHEDULED == this.getScheduleMode()) {
|
||||||
CronExprUtils.checkCronExpressionValid(this.getCronExpression(), 120);
|
CronExprUtils.checkCronExpressionValid(this.getCronExpression(), CronExprUtils.MIN_INTERVAL_SECONDS);
|
||||||
assignment.setCronExpression(this.getCronExpression());
|
assignment.setCronExpression(this.getCronExpression());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,7 +69,7 @@ public class AssigmentCreateRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AssignmentConfigEntity toAssignmentConfig(Long assignmentId) {
|
public AssignmentConfigEntity toAssignmentConfig(Long assignmentId) {
|
||||||
if (config.getSourceConnectionId().equals(config.getTargetConnectionId())) {
|
if (Objects.equals(config.getSourceConnectionId(), config.getTargetConnectionId())) {
|
||||||
throw new DbswitchException(ResultCode.ERROR_INVALID_ASSIGNMENT_CONFIG, "源端与目标端不能相同");
|
throw new DbswitchException(ResultCode.ERROR_INVALID_ASSIGNMENT_CONFIG, "源端与目标端不能相同");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,6 +77,7 @@ public class AssigmentCreateRequest {
|
|||||||
assignmentConfigEntity.setAssignmentId(assignmentId);
|
assignmentConfigEntity.setAssignmentId(assignmentId);
|
||||||
assignmentConfigEntity.setSourceConnectionId(this.getConfig().getSourceConnectionId());
|
assignmentConfigEntity.setSourceConnectionId(this.getConfig().getSourceConnectionId());
|
||||||
assignmentConfigEntity.setSourceSchema(this.getConfig().getSourceSchema());
|
assignmentConfigEntity.setSourceSchema(this.getConfig().getSourceSchema());
|
||||||
|
assignmentConfigEntity.setTableType(this.getConfig().getTableType());
|
||||||
assignmentConfigEntity.setSourceTables(this.getConfig().getSourceTables());
|
assignmentConfigEntity.setSourceTables(this.getConfig().getSourceTables());
|
||||||
assignmentConfigEntity.setExcluded(
|
assignmentConfigEntity.setExcluded(
|
||||||
this.getConfig().getIncludeOrExclude() == IncludeExcludeEnum.EXCLUDE
|
this.getConfig().getIncludeOrExclude() == IncludeExcludeEnum.EXCLUDE
|
||||||
|
@@ -17,6 +17,7 @@ import com.gitee.dbswitch.admin.type.IncludeExcludeEnum;
|
|||||||
import com.gitee.dbswitch.admin.type.ScheduleModeEnum;
|
import com.gitee.dbswitch.admin.type.ScheduleModeEnum;
|
||||||
import com.gitee.dbswitch.admin.util.CronExprUtils;
|
import com.gitee.dbswitch.admin.util.CronExprUtils;
|
||||||
import com.gitee.dbswitch.common.entity.PatternMapper;
|
import com.gitee.dbswitch.common.entity.PatternMapper;
|
||||||
|
import com.gitee.dbswitch.common.type.DBTableType;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -39,6 +40,7 @@ public class AssigmentUpdateRequest {
|
|||||||
|
|
||||||
private Long sourceConnectionId;
|
private Long sourceConnectionId;
|
||||||
private String sourceSchema;
|
private String sourceSchema;
|
||||||
|
private DBTableType tableType;
|
||||||
private IncludeExcludeEnum includeOrExclude;
|
private IncludeExcludeEnum includeOrExclude;
|
||||||
private List<String> sourceTables;
|
private List<String> sourceTables;
|
||||||
private Long targetConnectionId;
|
private Long targetConnectionId;
|
||||||
@@ -57,7 +59,7 @@ public class AssigmentUpdateRequest {
|
|||||||
assignment.setDescription(description);
|
assignment.setDescription(description);
|
||||||
assignment.setScheduleMode(scheduleMode);
|
assignment.setScheduleMode(scheduleMode);
|
||||||
if (ScheduleModeEnum.SYSTEM_SCHEDULED == this.getScheduleMode()) {
|
if (ScheduleModeEnum.SYSTEM_SCHEDULED == this.getScheduleMode()) {
|
||||||
CronExprUtils.checkCronExpressionValid(this.getCronExpression(), 120);
|
CronExprUtils.checkCronExpressionValid(this.getCronExpression(), CronExprUtils.MIN_INTERVAL_SECONDS);
|
||||||
assignment.setCronExpression(this.getCronExpression());
|
assignment.setCronExpression(this.getCronExpression());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,7 +67,7 @@ public class AssigmentUpdateRequest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public AssignmentConfigEntity toAssignmentConfig(Long assignmentId) {
|
public AssignmentConfigEntity toAssignmentConfig(Long assignmentId) {
|
||||||
if (config.getSourceConnectionId() == config.getTargetConnectionId()) {
|
if (Objects.equals(config.getSourceConnectionId(), config.getTargetConnectionId())) {
|
||||||
throw new DbswitchException(ResultCode.ERROR_INVALID_ASSIGNMENT_CONFIG, "源端与目标端不能相同");
|
throw new DbswitchException(ResultCode.ERROR_INVALID_ASSIGNMENT_CONFIG, "源端与目标端不能相同");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +75,7 @@ public class AssigmentUpdateRequest {
|
|||||||
assignmentConfigEntity.setAssignmentId(assignmentId);
|
assignmentConfigEntity.setAssignmentId(assignmentId);
|
||||||
assignmentConfigEntity.setSourceConnectionId(this.getConfig().getSourceConnectionId());
|
assignmentConfigEntity.setSourceConnectionId(this.getConfig().getSourceConnectionId());
|
||||||
assignmentConfigEntity.setSourceSchema(this.getConfig().getSourceSchema());
|
assignmentConfigEntity.setSourceSchema(this.getConfig().getSourceSchema());
|
||||||
|
assignmentConfigEntity.setTableType(this.getConfig().getTableType());
|
||||||
assignmentConfigEntity.setSourceTables(this.getConfig().getSourceTables());
|
assignmentConfigEntity.setSourceTables(this.getConfig().getSourceTables());
|
||||||
assignmentConfigEntity.setExcluded(
|
assignmentConfigEntity.setExcluded(
|
||||||
this.getConfig().getIncludeOrExclude() == IncludeExcludeEnum.EXCLUDE
|
this.getConfig().getIncludeOrExclude() == IncludeExcludeEnum.EXCLUDE
|
||||||
|
@@ -13,6 +13,7 @@ import com.fasterxml.jackson.annotation.JsonFormat;
|
|||||||
import com.gitee.dbswitch.admin.type.IncludeExcludeEnum;
|
import com.gitee.dbswitch.admin.type.IncludeExcludeEnum;
|
||||||
import com.gitee.dbswitch.admin.type.ScheduleModeEnum;
|
import com.gitee.dbswitch.admin.type.ScheduleModeEnum;
|
||||||
import com.gitee.dbswitch.common.entity.PatternMapper;
|
import com.gitee.dbswitch.common.entity.PatternMapper;
|
||||||
|
import com.gitee.dbswitch.common.type.DBTableType;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
@@ -68,6 +69,9 @@ public class AssignmentDetailResponse {
|
|||||||
@ApiModelProperty("源端数据源的Schema")
|
@ApiModelProperty("源端数据源的Schema")
|
||||||
private String sourceSchema;
|
private String sourceSchema;
|
||||||
|
|
||||||
|
@ApiModelProperty("源端表类型")
|
||||||
|
private DBTableType tableType;
|
||||||
|
|
||||||
@ApiModelProperty("表明配置方式")
|
@ApiModelProperty("表明配置方式")
|
||||||
private IncludeExcludeEnum includeOrExclude;
|
private IncludeExcludeEnum includeOrExclude;
|
||||||
|
|
||||||
|
@@ -26,7 +26,7 @@ import com.gitee.dbswitch.admin.model.response.DbConnectionNameResponse;
|
|||||||
import com.gitee.dbswitch.admin.type.SupportDbTypeEnum;
|
import com.gitee.dbswitch.admin.type.SupportDbTypeEnum;
|
||||||
import com.gitee.dbswitch.admin.util.JDBCURL;
|
import com.gitee.dbswitch.admin.util.JDBCURL;
|
||||||
import com.gitee.dbswitch.admin.util.PageUtils;
|
import com.gitee.dbswitch.admin.util.PageUtils;
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.service.IMetaDataByJdbcService;
|
import com.gitee.dbswitch.core.service.IMetaDataByJdbcService;
|
||||||
import com.gitee.dbswitch.core.service.impl.MetaDataByJdbcServiceImpl;
|
import com.gitee.dbswitch.core.service.impl.MetaDataByJdbcServiceImpl;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -71,7 +71,7 @@ public class DbConnectionService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DatabaseTypeEnum prd = DatabaseTypeEnum.valueOf(dbConn.getType().getName().toUpperCase());
|
ProductTypeEnum prd = ProductTypeEnum.valueOf(dbConn.getType().getName().toUpperCase());
|
||||||
IMetaDataByJdbcService metaDataService = new MetaDataByJdbcServiceImpl(prd);
|
IMetaDataByJdbcService metaDataService = new MetaDataByJdbcServiceImpl(prd);
|
||||||
return metaDataService;
|
return metaDataService;
|
||||||
}
|
}
|
||||||
@@ -144,6 +144,21 @@ public class DbConnectionService {
|
|||||||
return Result.success(tables);
|
return Result.success(tables);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Result<List<String>> getSchemaViews(Long id, String schema) {
|
||||||
|
DatabaseConnectionEntity dbConn = getDatabaseConnectionById(id);
|
||||||
|
IMetaDataByJdbcService metaDataService = getMetaDataCoreService(dbConn);
|
||||||
|
List<String> tables = Optional.ofNullable(
|
||||||
|
metaDataService.queryTableList(dbConn.getUrl(),
|
||||||
|
dbConn.getUsername(),
|
||||||
|
dbConn.getPassword(),
|
||||||
|
schema))
|
||||||
|
.orElseGet(ArrayList::new).stream()
|
||||||
|
.filter(t -> t.isViewTable())
|
||||||
|
.map(t -> t.getTableName())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
return Result.success(tables);
|
||||||
|
}
|
||||||
|
|
||||||
public Result<DbConnectionDetailResponse> addDatabaseConnection(
|
public Result<DbConnectionDetailResponse> addDatabaseConnection(
|
||||||
DbConnectionCreateRequest request) {
|
DbConnectionCreateRequest request) {
|
||||||
if (StringUtils.isBlank(request.getName())) {
|
if (StringUtils.isBlank(request.getName())) {
|
||||||
|
@@ -40,8 +40,7 @@ import org.springframework.scheduling.quartz.QuartzJobBean;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* 如果你使用了@PersistJobDataAfterExecution注解,则强烈建议你同时使用@DisallowConcurrentExecution注
|
* 如果你使用了@PersistJobDataAfterExecution注解,则强烈建议你同时使用@DisallowConcurrentExecution注 解,因为当同一个job(JobDetail)的两个实例被并发执行时,由于竞争,JobDataMap中存储的数据很可能是不确定的。
|
||||||
* 解,因为当同一个job(JobDetail)的两个实例被并发执行时,由于竞争,JobDataMap中存储的数据很可能是不确定的。
|
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -61,7 +60,7 @@ public class JobExecutorService extends QuartzJobBean implements InterruptableJo
|
|||||||
/**
|
/**
|
||||||
* 作为一个是否被中断的标识
|
* 作为一个是否被中断的标识
|
||||||
*/
|
*/
|
||||||
private boolean interrupted = false;
|
private volatile boolean interrupted = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 记录当前线程
|
* 记录当前线程
|
||||||
@@ -106,7 +105,7 @@ public class JobExecutorService extends QuartzJobBean implements InterruptableJo
|
|||||||
currentThread = Thread.currentThread();
|
currentThread = Thread.currentThread();
|
||||||
JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
|
JobDataMap jobDataMap = context.getJobDetail().getJobDataMap();
|
||||||
if (interrupted) {
|
if (interrupted) {
|
||||||
log.info("Quartz task id:{} interrupted", jobDataMap.getLong(TASK_ID));
|
log.info("Quartz task id:{} interrupted when thread begin", jobDataMap.getLong(TASK_ID));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,6 +118,10 @@ public class JobExecutorService extends QuartzJobBean implements InterruptableJo
|
|||||||
try {
|
try {
|
||||||
ReentrantLock lock = mutexes.get(taskId.toString(), ReentrantLock::new);
|
ReentrantLock lock = mutexes.get(taskId.toString(), ReentrantLock::new);
|
||||||
while (!lock.tryLock(1, TimeUnit.SECONDS)) {
|
while (!lock.tryLock(1, TimeUnit.SECONDS)) {
|
||||||
|
if (interrupted) {
|
||||||
|
log.info("Quartz task id:{} interrupted when get lock", jobDataMap.getLong(TASK_ID));
|
||||||
|
return;
|
||||||
|
}
|
||||||
TimeUnit.SECONDS.sleep(1);
|
TimeUnit.SECONDS.sleep(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +148,7 @@ public class JobExecutorService extends QuartzJobBean implements InterruptableJo
|
|||||||
|
|
||||||
MigrationService mainService = new MigrationService(properties);
|
MigrationService mainService = new MigrationService(properties);
|
||||||
if (interrupted) {
|
if (interrupted) {
|
||||||
log.info("Quartz task id:{} interrupted", jobDataMap.getLong(TASK_ID));
|
log.info("Quartz task id:{} interrupted when prepare stage", jobDataMap.getLong(TASK_ID));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,7 +15,7 @@ import java.util.Collection;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class CacheUtils {
|
public final class CacheUtils {
|
||||||
|
|
||||||
// 缓存时间 2 hours
|
// 缓存时间 2 hours
|
||||||
public static final long CACHE_DURATION_SECONDS = 7200;
|
public static final long CACHE_DURATION_SECONDS = 7200;
|
||||||
|
@@ -21,6 +21,8 @@ import org.quartz.CronExpression;
|
|||||||
*/
|
*/
|
||||||
public final class CronExprUtils {
|
public final class CronExprUtils {
|
||||||
|
|
||||||
|
public static final int MIN_INTERVAL_SECONDS = 120;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 检查CRON表达式的有效性
|
* 检查CRON表达式的有效性
|
||||||
*
|
*
|
||||||
@@ -33,7 +35,7 @@ public final class CronExprUtils {
|
|||||||
try {
|
try {
|
||||||
expression = new CronExpression(cronExpression);
|
expression = new CronExpression(cronExpression);
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
throw new DbswitchException(ResultCode.ERROR_INVALID_ARGUMENT, String.format("正则表达式%s无效"));
|
throw new DbswitchException(ResultCode.ERROR_INVALID_ARGUMENT, String.format("cron表达式%s无效"));
|
||||||
}
|
}
|
||||||
Date nextDate = expression.getNextValidTimeAfter(new Date(System.currentTimeMillis()));
|
Date nextDate = expression.getNextValidTimeAfter(new Date(System.currentTimeMillis()));
|
||||||
if (null == nextDate) {
|
if (null == nextDate) {
|
||||||
|
@@ -24,7 +24,7 @@ import java.util.regex.Pattern;
|
|||||||
* @date 2021-11-20 22:54:21
|
* @date 2021-11-20 22:54:21
|
||||||
* @since 1.0
|
* @since 1.0
|
||||||
*/
|
*/
|
||||||
public class JDBCURL {
|
public final class JDBCURL {
|
||||||
|
|
||||||
public static final String PROP_HOST = "host"; //$NON-NLS-1$
|
public static final String PROP_HOST = "host"; //$NON-NLS-1$
|
||||||
public static final String PROP_PORT = "port"; //$NON-NLS-1$
|
public static final String PROP_PORT = "port"; //$NON-NLS-1$
|
||||||
|
@@ -0,0 +1,65 @@
|
|||||||
|
// Copyright tang. All rights reserved.
|
||||||
|
// https://gitee.com/inrgihc/dbswitch
|
||||||
|
//
|
||||||
|
// Use of this source code is governed by a BSD-style license
|
||||||
|
//
|
||||||
|
// Author: tang (inrgihc@126.com)
|
||||||
|
// Date : 2020/1/2
|
||||||
|
// Location: beijing , china
|
||||||
|
/////////////////////////////////////////////////////////////
|
||||||
|
package com.gitee.dbswitch.admin.util;
|
||||||
|
|
||||||
|
import com.google.common.cache.Cache;
|
||||||
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
|
public final class LockUtils {
|
||||||
|
|
||||||
|
private static final Cache<String, ReentrantLock> mutexes = CacheBuilder
|
||||||
|
.newBuilder()
|
||||||
|
.expireAfterWrite(24 * 60L, TimeUnit.MINUTES) // 缓存时间
|
||||||
|
.build();
|
||||||
|
|
||||||
|
public static <T> T runInLock(String key, int timeout, TimeUnit timeUnit, Callable<T> callable) {
|
||||||
|
ReentrantLock lock = null;
|
||||||
|
boolean locked = false;
|
||||||
|
try {
|
||||||
|
lock = mutexes.get(key, ReentrantLock::new);
|
||||||
|
locked = lock.tryLock(timeout, timeUnit);
|
||||||
|
if (!locked) {
|
||||||
|
throw new RuntimeException("Acquire lock timeout");
|
||||||
|
}
|
||||||
|
return callable.call();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} finally {
|
||||||
|
if (lock != null && locked) {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void runInLock(String key, int timeout, TimeUnit timeUnit, Runnable runnable) {
|
||||||
|
ReentrantLock lock = null;
|
||||||
|
boolean locked = false;
|
||||||
|
try {
|
||||||
|
lock = mutexes.get(key, ReentrantLock::new);
|
||||||
|
locked = lock.tryLock(timeout, timeUnit);
|
||||||
|
if (!locked) {
|
||||||
|
throw new RuntimeException("Acquire lock timeout");
|
||||||
|
}
|
||||||
|
runnable.run();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
} finally {
|
||||||
|
if (lock != null && locked) {
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private LockUtils() {
|
||||||
|
}
|
||||||
|
}
|
@@ -19,7 +19,7 @@ import java.util.function.Supplier;
|
|||||||
/**
|
/**
|
||||||
* 分页工具类
|
* 分页工具类
|
||||||
*/
|
*/
|
||||||
public class PageUtils {
|
public final class PageUtils {
|
||||||
|
|
||||||
public static <E> PageResult<E> getPage(Supplier<List<E>> method, Integer pageNum,
|
public static <E> PageResult<E> getPage(Supplier<List<E>> method, Integer pageNum,
|
||||||
Integer pageSize) {
|
Integer pageSize) {
|
||||||
|
@@ -19,7 +19,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
|||||||
* 获取Servlet服务器的HTTP参数相关工具类
|
* 获取Servlet服务器的HTTP参数相关工具类
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ServletUtils {
|
public final class ServletUtils {
|
||||||
|
|
||||||
public static HttpServletRequest getHttpServletRequest() {
|
public static HttpServletRequest getHttpServletRequest() {
|
||||||
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
||||||
|
@@ -18,7 +18,7 @@ import org.springframework.stereotype.Component;
|
|||||||
* Spring容器获取BEAN工具类
|
* Spring容器获取BEAN工具类
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
public class SpringUtils implements ApplicationContextAware {
|
public final class SpringUtils implements ApplicationContextAware {
|
||||||
|
|
||||||
private static ApplicationContext applicationContext;
|
private static ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
@@ -19,7 +19,7 @@ import org.springframework.util.StringUtils;
|
|||||||
* Token工具类
|
* Token工具类
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class TokenUtils {
|
public final class TokenUtils {
|
||||||
|
|
||||||
private static final char[] hexCode = "0123456789abcdefgh".toCharArray();
|
private static final char[] hexCode = "0123456789abcdefgh".toCharArray();
|
||||||
|
|
||||||
|
@@ -14,7 +14,7 @@ import java.util.UUID;
|
|||||||
/**
|
/**
|
||||||
* UUID工具类
|
* UUID工具类
|
||||||
*/
|
*/
|
||||||
public class UuidUtils {
|
public final class UuidUtils {
|
||||||
|
|
||||||
public static String generateUuid() {
|
public static String generateUuid() {
|
||||||
return UUID.randomUUID().toString().replace("-", "");
|
return UUID.randomUUID().toString().replace("-", "");
|
||||||
|
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE `DBSWITCH_ASSIGNMENT_CONFIG`
|
||||||
|
ADD COLUMN `table_type` VARCHAR(32) NULL DEFAULT 'TABLE' COMMENT '表类型:TABLE;VIEW' AFTER `source_schema`;
|
@@ -12,11 +12,11 @@ package com.gitee.dbswitch.common.type;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据库类型的枚举定义
|
* 数据库产品类型的枚举定义
|
||||||
*
|
*
|
||||||
* @author Tang
|
* @author Tang
|
||||||
*/
|
*/
|
||||||
public enum DatabaseTypeEnum {
|
public enum ProductTypeEnum {
|
||||||
/**
|
/**
|
||||||
* 未知数据库类型
|
* 未知数据库类型
|
||||||
*/
|
*/
|
||||||
@@ -100,7 +100,7 @@ public enum DatabaseTypeEnum {
|
|||||||
|
|
||||||
private int index;
|
private int index;
|
||||||
|
|
||||||
DatabaseTypeEnum(int idx) {
|
ProductTypeEnum(int idx) {
|
||||||
this.index = idx;
|
this.index = idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,12 +110,12 @@ public enum DatabaseTypeEnum {
|
|||||||
|
|
||||||
public boolean noCommentStatement() {
|
public boolean noCommentStatement() {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
DatabaseTypeEnum.MYSQL,
|
ProductTypeEnum.MYSQL,
|
||||||
DatabaseTypeEnum.MARIADB,
|
ProductTypeEnum.MARIADB,
|
||||||
DatabaseTypeEnum.GBASE8A,
|
ProductTypeEnum.GBASE8A,
|
||||||
DatabaseTypeEnum.HIVE,
|
ProductTypeEnum.HIVE,
|
||||||
DatabaseTypeEnum.SQLITE3,
|
ProductTypeEnum.SQLITE3,
|
||||||
DatabaseTypeEnum.SYBASE
|
ProductTypeEnum.SYBASE
|
||||||
).contains(this);
|
).contains(this);
|
||||||
}
|
}
|
||||||
|
|
@@ -9,7 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.common.util;
|
package com.gitee.dbswitch.common.util;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
@@ -25,42 +25,42 @@ import javax.sql.DataSource;
|
|||||||
*/
|
*/
|
||||||
public final class DatabaseAwareUtils {
|
public final class DatabaseAwareUtils {
|
||||||
|
|
||||||
private static final Map<String, DatabaseTypeEnum> productNameMap;
|
private static final Map<String, ProductTypeEnum> productNameMap;
|
||||||
|
|
||||||
private static final Map<String, DatabaseTypeEnum> driverNameMap;
|
private static final Map<String, ProductTypeEnum> driverNameMap;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
productNameMap = new HashMap<>();
|
productNameMap = new HashMap<>();
|
||||||
driverNameMap = new HashMap<>();
|
driverNameMap = new HashMap<>();
|
||||||
|
|
||||||
productNameMap.put("Greenplum", DatabaseTypeEnum.GREENPLUM);
|
productNameMap.put("Greenplum", ProductTypeEnum.GREENPLUM);
|
||||||
productNameMap.put("Microsoft SQL Server", DatabaseTypeEnum.SQLSERVER);
|
productNameMap.put("Microsoft SQL Server", ProductTypeEnum.SQLSERVER);
|
||||||
productNameMap.put("DM DBMS", DatabaseTypeEnum.DM);
|
productNameMap.put("DM DBMS", ProductTypeEnum.DM);
|
||||||
productNameMap.put("KingbaseES", DatabaseTypeEnum.KINGBASE);
|
productNameMap.put("KingbaseES", ProductTypeEnum.KINGBASE);
|
||||||
productNameMap.put("Apache Hive", DatabaseTypeEnum.HIVE);
|
productNameMap.put("Apache Hive", ProductTypeEnum.HIVE);
|
||||||
productNameMap.put("MySQL", DatabaseTypeEnum.MYSQL);
|
productNameMap.put("MySQL", ProductTypeEnum.MYSQL);
|
||||||
productNameMap.put("MariaDB", DatabaseTypeEnum.MARIADB);
|
productNameMap.put("MariaDB", ProductTypeEnum.MARIADB);
|
||||||
productNameMap.put("Oracle", DatabaseTypeEnum.ORACLE);
|
productNameMap.put("Oracle", ProductTypeEnum.ORACLE);
|
||||||
productNameMap.put("PostgreSQL", DatabaseTypeEnum.POSTGRESQL);
|
productNameMap.put("PostgreSQL", ProductTypeEnum.POSTGRESQL);
|
||||||
productNameMap.put("DB2 for Unix/Windows", DatabaseTypeEnum.DB2);
|
productNameMap.put("DB2 for Unix/Windows", ProductTypeEnum.DB2);
|
||||||
productNameMap.put("Hive", DatabaseTypeEnum.HIVE);
|
productNameMap.put("Hive", ProductTypeEnum.HIVE);
|
||||||
productNameMap.put("SQLite", DatabaseTypeEnum.SQLITE3);
|
productNameMap.put("SQLite", ProductTypeEnum.SQLITE3);
|
||||||
productNameMap.put("OSCAR", DatabaseTypeEnum.OSCAR);
|
productNameMap.put("OSCAR", ProductTypeEnum.OSCAR);
|
||||||
productNameMap.put("GBase", DatabaseTypeEnum.GBASE8A);
|
productNameMap.put("GBase", ProductTypeEnum.GBASE8A);
|
||||||
productNameMap.put("Adaptive Server Enterprise", DatabaseTypeEnum.SYBASE);
|
productNameMap.put("Adaptive Server Enterprise", ProductTypeEnum.SYBASE);
|
||||||
|
|
||||||
driverNameMap.put("MySQL Connector Java", DatabaseTypeEnum.MYSQL);
|
driverNameMap.put("MySQL Connector Java", ProductTypeEnum.MYSQL);
|
||||||
driverNameMap.put("MariaDB Connector/J", DatabaseTypeEnum.MARIADB);
|
driverNameMap.put("MariaDB Connector/J", ProductTypeEnum.MARIADB);
|
||||||
driverNameMap.put("Oracle JDBC driver", DatabaseTypeEnum.ORACLE);
|
driverNameMap.put("Oracle JDBC driver", ProductTypeEnum.ORACLE);
|
||||||
driverNameMap.put("PostgreSQL JDBC Driver", DatabaseTypeEnum.POSTGRESQL);
|
driverNameMap.put("PostgreSQL JDBC Driver", ProductTypeEnum.POSTGRESQL);
|
||||||
driverNameMap.put("Kingbase8 JDBC Driver", DatabaseTypeEnum.KINGBASE);
|
driverNameMap.put("Kingbase8 JDBC Driver", ProductTypeEnum.KINGBASE);
|
||||||
driverNameMap.put("IBM Data Server Driver for JDBC and SQLJ", DatabaseTypeEnum.DB2);
|
driverNameMap.put("IBM Data Server Driver for JDBC and SQLJ", ProductTypeEnum.DB2);
|
||||||
driverNameMap.put("dm.jdbc.driver.DmDriver", DatabaseTypeEnum.DM);
|
driverNameMap.put("dm.jdbc.driver.DmDriver", ProductTypeEnum.DM);
|
||||||
driverNameMap.put("Hive JDBC", DatabaseTypeEnum.HIVE);
|
driverNameMap.put("Hive JDBC", ProductTypeEnum.HIVE);
|
||||||
driverNameMap.put("SQLite JDBC", DatabaseTypeEnum.SQLITE3);
|
driverNameMap.put("SQLite JDBC", ProductTypeEnum.SQLITE3);
|
||||||
driverNameMap.put("OSCAR JDBC DRIVER", DatabaseTypeEnum.OSCAR);
|
driverNameMap.put("OSCAR JDBC DRIVER", ProductTypeEnum.OSCAR);
|
||||||
driverNameMap.put("GBase JDBC Driver", DatabaseTypeEnum.GBASE8A);
|
driverNameMap.put("GBase JDBC Driver", ProductTypeEnum.GBASE8A);
|
||||||
driverNameMap.put("jConnect (TM) for JDBC (TM)", DatabaseTypeEnum.SYBASE);
|
driverNameMap.put("jConnect (TM) for JDBC (TM)", ProductTypeEnum.SYBASE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,7 +69,7 @@ public final class DatabaseAwareUtils {
|
|||||||
* @param dataSource 数据源
|
* @param dataSource 数据源
|
||||||
* @return 数据库产品名称字符串
|
* @return 数据库产品名称字符串
|
||||||
*/
|
*/
|
||||||
public static DatabaseTypeEnum getDatabaseTypeByDataSource(DataSource dataSource) {
|
public static ProductTypeEnum getDatabaseTypeByDataSource(DataSource dataSource) {
|
||||||
try (Connection connection = dataSource.getConnection()) {
|
try (Connection connection = dataSource.getConnection()) {
|
||||||
String productName = connection.getMetaData().getDatabaseProductName();
|
String productName = connection.getMetaData().getDatabaseProductName();
|
||||||
String driverName = connection.getMetaData().getDriverName();
|
String driverName = connection.getMetaData().getDriverName();
|
||||||
@@ -77,7 +77,7 @@ public final class DatabaseAwareUtils {
|
|||||||
return driverNameMap.get(driverName);
|
return driverNameMap.get(driverName);
|
||||||
}
|
}
|
||||||
|
|
||||||
DatabaseTypeEnum type = productNameMap.get(productName);
|
ProductTypeEnum type = productNameMap.get(productName);
|
||||||
if (null == type) {
|
if (null == type) {
|
||||||
throw new IllegalStateException("Unable to detect database type from data source instance");
|
throw new IllegalStateException("Unable to detect database type from data source instance");
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.core.database;
|
package com.gitee.dbswitch.core.database;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.common.util.DbswitchStrUtils;
|
import com.gitee.dbswitch.common.util.DbswitchStrUtils;
|
||||||
import com.gitee.dbswitch.common.util.HivePrepareUtils;
|
import com.gitee.dbswitch.common.util.HivePrepareUtils;
|
||||||
import com.gitee.dbswitch.common.util.TypeConvertUtils;
|
import com.gitee.dbswitch.common.util.TypeConvertUtils;
|
||||||
@@ -171,7 +171,7 @@ public abstract class AbstractDatabase implements IDatabaseInterface {
|
|||||||
data.setColumns(new ArrayList<>());
|
data.setColumns(new ArrayList<>());
|
||||||
data.setRows(new ArrayList<>());
|
data.setRows(new ArrayList<>());
|
||||||
try (Statement st = connection.createStatement()) {
|
try (Statement st = connection.createStatement()) {
|
||||||
if (getDatabaseType() == DatabaseTypeEnum.HIVE) {
|
if (getDatabaseType() == ProductTypeEnum.HIVE) {
|
||||||
HivePrepareUtils.prepare(connection, schemaName, tableName);
|
HivePrepareUtils.prepare(connection, schemaName, tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,7 +259,7 @@ public abstract class AbstractDatabase implements IDatabaseInterface {
|
|||||||
protected List<ColumnDescription> getSelectSqlColumnMeta(Connection connection, String querySQL) {
|
protected List<ColumnDescription> getSelectSqlColumnMeta(Connection connection, String querySQL) {
|
||||||
List<ColumnDescription> ret = new ArrayList<>();
|
List<ColumnDescription> ret = new ArrayList<>();
|
||||||
try (Statement st = connection.createStatement()) {
|
try (Statement st = connection.createStatement()) {
|
||||||
if (getDatabaseType() == DatabaseTypeEnum.HIVE) {
|
if (getDatabaseType() == ProductTypeEnum.HIVE) {
|
||||||
HivePrepareUtils.setResultSetColumnNameNotUnique(connection);
|
HivePrepareUtils.setResultSetColumnNameNotUnique(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.core.database;
|
package com.gitee.dbswitch.core.database;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.database.impl.DatabaseDB2Impl;
|
import com.gitee.dbswitch.core.database.impl.DatabaseDB2Impl;
|
||||||
import com.gitee.dbswitch.core.database.impl.DatabaseDmImpl;
|
import com.gitee.dbswitch.core.database.impl.DatabaseDmImpl;
|
||||||
import com.gitee.dbswitch.core.database.impl.DatabaseGbase8aImpl;
|
import com.gitee.dbswitch.core.database.impl.DatabaseGbase8aImpl;
|
||||||
@@ -36,32 +36,32 @@ import java.util.concurrent.Callable;
|
|||||||
*/
|
*/
|
||||||
public final class DatabaseFactory {
|
public final class DatabaseFactory {
|
||||||
|
|
||||||
private static final Map<DatabaseTypeEnum, Callable<AbstractDatabase>> DATABASE_MAPPER
|
private static final Map<ProductTypeEnum, Callable<AbstractDatabase>> DATABASE_MAPPER
|
||||||
= new HashMap<DatabaseTypeEnum, Callable<AbstractDatabase>>() {
|
= new HashMap<ProductTypeEnum, Callable<AbstractDatabase>>() {
|
||||||
|
|
||||||
private static final long serialVersionUID = 9202705534880971997L;
|
private static final long serialVersionUID = 9202705534880971997L;
|
||||||
|
|
||||||
{
|
{
|
||||||
put(DatabaseTypeEnum.MYSQL, DatabaseMysqlImpl::new);
|
put(ProductTypeEnum.MYSQL, DatabaseMysqlImpl::new);
|
||||||
put(DatabaseTypeEnum.MARIADB, DatabaseMariaDBImpl::new);
|
put(ProductTypeEnum.MARIADB, DatabaseMariaDBImpl::new);
|
||||||
put(DatabaseTypeEnum.ORACLE, DatabaseOracleImpl::new);
|
put(ProductTypeEnum.ORACLE, DatabaseOracleImpl::new);
|
||||||
put(DatabaseTypeEnum.SQLSERVER2000, DatabaseSqlserver2000Impl::new);
|
put(ProductTypeEnum.SQLSERVER2000, DatabaseSqlserver2000Impl::new);
|
||||||
put(DatabaseTypeEnum.SQLSERVER, DatabaseSqlserverImpl::new);
|
put(ProductTypeEnum.SQLSERVER, DatabaseSqlserverImpl::new);
|
||||||
put(DatabaseTypeEnum.POSTGRESQL, DatabasePostgresImpl::new);
|
put(ProductTypeEnum.POSTGRESQL, DatabasePostgresImpl::new);
|
||||||
put(DatabaseTypeEnum.GREENPLUM, DatabaseGreenplumImpl::new);
|
put(ProductTypeEnum.GREENPLUM, DatabaseGreenplumImpl::new);
|
||||||
put(DatabaseTypeEnum.DB2, DatabaseDB2Impl::new);
|
put(ProductTypeEnum.DB2, DatabaseDB2Impl::new);
|
||||||
put(DatabaseTypeEnum.DM, DatabaseDmImpl::new);
|
put(ProductTypeEnum.DM, DatabaseDmImpl::new);
|
||||||
put(DatabaseTypeEnum.SYBASE, DatabaseSybaseImpl::new);
|
put(ProductTypeEnum.SYBASE, DatabaseSybaseImpl::new);
|
||||||
put(DatabaseTypeEnum.KINGBASE, DatabaseKingbaseImpl::new);
|
put(ProductTypeEnum.KINGBASE, DatabaseKingbaseImpl::new);
|
||||||
put(DatabaseTypeEnum.OSCAR, DatabaseOscarImpl::new);
|
put(ProductTypeEnum.OSCAR, DatabaseOscarImpl::new);
|
||||||
put(DatabaseTypeEnum.GBASE8A, DatabaseGbase8aImpl::new);
|
put(ProductTypeEnum.GBASE8A, DatabaseGbase8aImpl::new);
|
||||||
put(DatabaseTypeEnum.SYBASE, DatabaseSybaseImpl::new);
|
put(ProductTypeEnum.SYBASE, DatabaseSybaseImpl::new);
|
||||||
put(DatabaseTypeEnum.HIVE, DatabaseHiveImpl::new);
|
put(ProductTypeEnum.HIVE, DatabaseHiveImpl::new);
|
||||||
put(DatabaseTypeEnum.SQLITE3, DatabaseSqliteImpl::new);
|
put(ProductTypeEnum.SQLITE3, DatabaseSqliteImpl::new);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static AbstractDatabase getDatabaseInstance(DatabaseTypeEnum type) {
|
public static AbstractDatabase getDatabaseInstance(ProductTypeEnum type) {
|
||||||
Callable<AbstractDatabase> callable = DATABASE_MAPPER.get(type);
|
Callable<AbstractDatabase> callable = DATABASE_MAPPER.get(type);
|
||||||
if (null != callable) {
|
if (null != callable) {
|
||||||
try {
|
try {
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.core.database;
|
package com.gitee.dbswitch.core.database;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||||
import com.gitee.dbswitch.core.model.ColumnMetaData;
|
import com.gitee.dbswitch.core.model.ColumnMetaData;
|
||||||
import com.gitee.dbswitch.core.model.SchemaTableData;
|
import com.gitee.dbswitch.core.model.SchemaTableData;
|
||||||
@@ -29,7 +29,7 @@ public interface IDatabaseInterface {
|
|||||||
*
|
*
|
||||||
* @return 数据库类型
|
* @return 数据库类型
|
||||||
*/
|
*/
|
||||||
DatabaseTypeEnum getDatabaseType();
|
ProductTypeEnum getDatabaseType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取数据库的JDBC驱动类
|
* 获取数据库的JDBC驱动类
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
package com.gitee.dbswitch.core.database.impl;
|
package com.gitee.dbswitch.core.database.impl;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.constant.Const;
|
import com.gitee.dbswitch.common.constant.Const;
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||||
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
||||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||||
@@ -49,8 +49,8 @@ public class DatabaseDB2Impl extends AbstractDatabase implements IDatabaseInterf
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseTypeEnum getDatabaseType() {
|
public ProductTypeEnum getDatabaseType() {
|
||||||
return DatabaseTypeEnum.DB2;
|
return ProductTypeEnum.DB2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
package com.gitee.dbswitch.core.database.impl;
|
package com.gitee.dbswitch.core.database.impl;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.constant.Const;
|
import com.gitee.dbswitch.common.constant.Const;
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||||
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
||||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||||
@@ -41,8 +41,8 @@ public class DatabaseDmImpl extends AbstractDatabase implements IDatabaseInterfa
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseTypeEnum getDatabaseType() {
|
public ProductTypeEnum getDatabaseType() {
|
||||||
return DatabaseTypeEnum.DM;
|
return ProductTypeEnum.DM;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.core.database.impl;
|
package com.gitee.dbswitch.core.database.impl;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支持GBase8a数据库的元信息实现
|
* 支持GBase8a数据库的元信息实现
|
||||||
@@ -23,8 +23,8 @@ public class DatabaseGbase8aImpl extends DatabaseMysqlImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseTypeEnum getDatabaseType() {
|
public ProductTypeEnum getDatabaseType() {
|
||||||
return DatabaseTypeEnum.GBASE8A;
|
return ProductTypeEnum.GBASE8A;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -10,7 +10,7 @@
|
|||||||
package com.gitee.dbswitch.core.database.impl;
|
package com.gitee.dbswitch.core.database.impl;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.constant.Const;
|
import com.gitee.dbswitch.common.constant.Const;
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||||
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
||||||
import com.gitee.dbswitch.core.database.constant.PostgresqlConst;
|
import com.gitee.dbswitch.core.database.constant.PostgresqlConst;
|
||||||
@@ -54,8 +54,8 @@ public class DatabaseGreenplumImpl extends AbstractDatabase implements IDatabase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseTypeEnum getDatabaseType() {
|
public ProductTypeEnum getDatabaseType() {
|
||||||
return DatabaseTypeEnum.GREENPLUM;
|
return ProductTypeEnum.GREENPLUM;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
package com.gitee.dbswitch.core.database.impl;
|
package com.gitee.dbswitch.core.database.impl;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.constant.Const;
|
import com.gitee.dbswitch.common.constant.Const;
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.common.util.HivePrepareUtils;
|
import com.gitee.dbswitch.common.util.HivePrepareUtils;
|
||||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||||
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
||||||
@@ -37,8 +37,8 @@ public class DatabaseHiveImpl extends AbstractDatabase implements IDatabaseInter
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseTypeEnum getDatabaseType() {
|
public ProductTypeEnum getDatabaseType() {
|
||||||
return DatabaseTypeEnum.HIVE;
|
return ProductTypeEnum.HIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -115,7 +115,7 @@ public class DatabaseHiveImpl extends AbstractDatabase implements IDatabaseInter
|
|||||||
// nothing more we can do here by catch the exception.
|
// nothing more we can do here by catch the exception.
|
||||||
}
|
}
|
||||||
cd.setSigned(signed);
|
cd.setSigned(signed);
|
||||||
cd.setDbType(DatabaseTypeEnum.HIVE);
|
cd.setDbType(ProductTypeEnum.HIVE);
|
||||||
|
|
||||||
ret.add(cd);
|
ret.add(cd);
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
package com.gitee.dbswitch.core.database.impl;
|
package com.gitee.dbswitch.core.database.impl;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.constant.Const;
|
import com.gitee.dbswitch.common.constant.Const;
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||||
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
||||||
import com.gitee.dbswitch.core.database.constant.PostgresqlConst;
|
import com.gitee.dbswitch.core.database.constant.PostgresqlConst;
|
||||||
@@ -42,8 +42,8 @@ public class DatabaseKingbaseImpl extends AbstractDatabase implements IDatabaseI
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseTypeEnum getDatabaseType() {
|
public ProductTypeEnum getDatabaseType() {
|
||||||
return DatabaseTypeEnum.KINGBASE;
|
return ProductTypeEnum.KINGBASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -9,9 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.core.database.impl;
|
package com.gitee.dbswitch.core.database.impl;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 支持MariaDB数据库的元信息实现
|
* 支持MariaDB数据库的元信息实现
|
||||||
@@ -25,8 +23,8 @@ public class DatabaseMariaDBImpl extends DatabaseMysqlImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseTypeEnum getDatabaseType() {
|
public ProductTypeEnum getDatabaseType() {
|
||||||
return DatabaseTypeEnum.MARIADB;
|
return ProductTypeEnum.MARIADB;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
package com.gitee.dbswitch.core.database.impl;
|
package com.gitee.dbswitch.core.database.impl;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.constant.Const;
|
import com.gitee.dbswitch.common.constant.Const;
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||||
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
||||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||||
@@ -48,23 +48,19 @@ public class DatabaseMysqlImpl extends AbstractDatabase implements IDatabaseInte
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseTypeEnum getDatabaseType() {
|
public ProductTypeEnum getDatabaseType() {
|
||||||
return DatabaseTypeEnum.MYSQL;
|
return ProductTypeEnum.MYSQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> querySchemaList(Connection connection) {
|
public List<String> querySchemaList(Connection connection) {
|
||||||
String mysqlJdbcUrl = null;
|
|
||||||
try {
|
try {
|
||||||
mysqlJdbcUrl = connection.getMetaData().getURL();
|
String mysqlJdbcUrl = connection.getMetaData().getURL();
|
||||||
|
Map<String, String> data = JdbcUrlUtils.findParamsByMySqlJdbcUrl(mysqlJdbcUrl);
|
||||||
|
return Collections.singletonList(data.get("schema"));
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String> data = JdbcUrlUtils.findParamsByMySqlJdbcUrl(mysqlJdbcUrl);
|
|
||||||
List<String> ret = new ArrayList<String>();
|
|
||||||
ret.add(data.get("schema"));
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
package com.gitee.dbswitch.core.database.impl;
|
package com.gitee.dbswitch.core.database.impl;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.constant.Const;
|
import com.gitee.dbswitch.common.constant.Const;
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||||
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
||||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||||
@@ -23,7 +23,6 @@ import java.sql.SQLException;
|
|||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
@@ -57,8 +56,8 @@ public class DatabaseOracleImpl extends AbstractDatabase implements IDatabaseInt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseTypeEnum getDatabaseType() {
|
public ProductTypeEnum getDatabaseType() {
|
||||||
return DatabaseTypeEnum.ORACLE;
|
return ProductTypeEnum.ORACLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
package com.gitee.dbswitch.core.database.impl;
|
package com.gitee.dbswitch.core.database.impl;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.constant.Const;
|
import com.gitee.dbswitch.common.constant.Const;
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||||
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
||||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||||
@@ -41,8 +41,8 @@ public class DatabaseOscarImpl extends AbstractDatabase implements IDatabaseInte
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseTypeEnum getDatabaseType() {
|
public ProductTypeEnum getDatabaseType() {
|
||||||
return DatabaseTypeEnum.OSCAR;
|
return ProductTypeEnum.OSCAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
package com.gitee.dbswitch.core.database.impl;
|
package com.gitee.dbswitch.core.database.impl;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.constant.Const;
|
import com.gitee.dbswitch.common.constant.Const;
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||||
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
||||||
import com.gitee.dbswitch.core.database.constant.PostgresqlConst;
|
import com.gitee.dbswitch.core.database.constant.PostgresqlConst;
|
||||||
@@ -58,8 +58,8 @@ public class DatabasePostgresImpl extends AbstractDatabase implements IDatabaseI
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseTypeEnum getDatabaseType() {
|
public ProductTypeEnum getDatabaseType() {
|
||||||
return DatabaseTypeEnum.POSTGRESQL;
|
return ProductTypeEnum.POSTGRESQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
package com.gitee.dbswitch.core.database.impl;
|
package com.gitee.dbswitch.core.database.impl;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.constant.Const;
|
import com.gitee.dbswitch.common.constant.Const;
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||||
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
||||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||||
@@ -36,8 +36,8 @@ public class DatabaseSqliteImpl extends AbstractDatabase implements IDatabaseInt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseTypeEnum getDatabaseType() {
|
public ProductTypeEnum getDatabaseType() {
|
||||||
return DatabaseTypeEnum.SQLITE3;
|
return ProductTypeEnum.SQLITE3;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.core.database.impl;
|
package com.gitee.dbswitch.core.database.impl;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
||||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||||
import com.gitee.dbswitch.core.model.TableDescription;
|
import com.gitee.dbswitch.core.model.TableDescription;
|
||||||
@@ -33,8 +33,8 @@ public class DatabaseSqlserver2000Impl extends DatabaseSqlserverImpl implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseTypeEnum getDatabaseType() {
|
public ProductTypeEnum getDatabaseType() {
|
||||||
return DatabaseTypeEnum.SQLSERVER2000;
|
return ProductTypeEnum.SQLSERVER2000;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
package com.gitee.dbswitch.core.database.impl;
|
package com.gitee.dbswitch.core.database.impl;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.constant.Const;
|
import com.gitee.dbswitch.common.constant.Const;
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||||
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
||||||
import com.gitee.dbswitch.core.database.constant.SQLServerConst;
|
import com.gitee.dbswitch.core.database.constant.SQLServerConst;
|
||||||
@@ -63,8 +63,8 @@ public class DatabaseSqlserverImpl extends AbstractDatabase implements IDatabase
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseTypeEnum getDatabaseType() {
|
public ProductTypeEnum getDatabaseType() {
|
||||||
return DatabaseTypeEnum.SQLSERVER;
|
return ProductTypeEnum.SQLSERVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getDatabaseMajorVersion(Connection connection) {
|
private int getDatabaseMajorVersion(Connection connection) {
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
package com.gitee.dbswitch.core.database.impl;
|
package com.gitee.dbswitch.core.database.impl;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.constant.Const;
|
import com.gitee.dbswitch.common.constant.Const;
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||||
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
import com.gitee.dbswitch.core.database.IDatabaseInterface;
|
||||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||||
@@ -68,8 +68,8 @@ public class DatabaseSybaseImpl extends AbstractDatabase implements IDatabaseInt
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseTypeEnum getDatabaseType() {
|
public ProductTypeEnum getDatabaseType() {
|
||||||
return DatabaseTypeEnum.SYBASE;
|
return ProductTypeEnum.SYBASE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCatalogName(Connection connection){
|
private void setCatalogName(Connection connection){
|
||||||
@@ -118,7 +118,7 @@ public class DatabaseSybaseImpl extends AbstractDatabase implements IDatabaseInt
|
|||||||
public String getTableDDL(Connection connection, String schemaName, String tableName) {
|
public String getTableDDL(Connection connection, String schemaName, String tableName) {
|
||||||
List<ColumnDescription> columnDescriptions = queryTableColumnMeta(connection, schemaName, tableName);
|
List<ColumnDescription> columnDescriptions = queryTableColumnMeta(connection, schemaName, tableName);
|
||||||
List<String> pks = queryTablePrimaryKeys(connection, schemaName, tableName);
|
List<String> pks = queryTablePrimaryKeys(connection, schemaName, tableName);
|
||||||
return GenerateSqlUtils.getDDLCreateTableSQL(DatabaseTypeEnum.SYBASE,
|
return GenerateSqlUtils.getDDLCreateTableSQL(ProductTypeEnum.SYBASE,
|
||||||
columnDescriptions, pks, schemaName, tableName, false);
|
columnDescriptions, pks, schemaName, tableName, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.core.model;
|
package com.gitee.dbswitch.core.model;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据库列描述符信息定义(Column Description)
|
* 数据库列描述符信息定义(Column Description)
|
||||||
@@ -30,7 +30,7 @@ public class ColumnDescription {
|
|||||||
private boolean isNullable;
|
private boolean isNullable;
|
||||||
private String remarks;
|
private String remarks;
|
||||||
private boolean signed = false;
|
private boolean signed = false;
|
||||||
private DatabaseTypeEnum dbtype;
|
private ProductTypeEnum dbtype;
|
||||||
|
|
||||||
public String getFieldName() {
|
public String getFieldName() {
|
||||||
if (null != this.fieldName) {
|
if (null != this.fieldName) {
|
||||||
@@ -128,11 +128,11 @@ public class ColumnDescription {
|
|||||||
this.signed = signed;
|
this.signed = signed;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DatabaseTypeEnum getDbType() {
|
public ProductTypeEnum getDbType() {
|
||||||
return this.dbtype;
|
return this.dbtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDbType(DatabaseTypeEnum dbtype) {
|
public void setDbType(ProductTypeEnum dbtype) {
|
||||||
this.dbtype = dbtype;
|
this.dbtype = dbtype;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.core.model;
|
package com.gitee.dbswitch.core.model;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -349,7 +349,7 @@ public class ColumnMetaData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we're dealing with PostgreSQL and double precision types
|
// If we're dealing with PostgreSQL and double precision types
|
||||||
if (desc.getDbType() == DatabaseTypeEnum.POSTGRESQL && type == java.sql.Types.DOUBLE
|
if (desc.getDbType() == ProductTypeEnum.POSTGRESQL && type == java.sql.Types.DOUBLE
|
||||||
&& precision >= 16
|
&& precision >= 16
|
||||||
&& length >= 16) {
|
&& length >= 16) {
|
||||||
precision = -1;
|
precision = -1;
|
||||||
@@ -358,7 +358,7 @@ public class ColumnMetaData {
|
|||||||
|
|
||||||
// MySQL: max resolution is double precision floating point (double)
|
// MySQL: max resolution is double precision floating point (double)
|
||||||
// The (12,31) that is given back is not correct
|
// The (12,31) that is given back is not correct
|
||||||
if (desc.getDbType() == DatabaseTypeEnum.MYSQL) {
|
if (desc.getDbType() == ProductTypeEnum.MYSQL) {
|
||||||
if (precision >= length) {
|
if (precision >= length) {
|
||||||
precision = -1;
|
precision = -1;
|
||||||
length = -1;
|
length = -1;
|
||||||
@@ -366,7 +366,7 @@ public class ColumnMetaData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If we're dealing with Hive and double/float precision types
|
// If we're dealing with Hive and double/float precision types
|
||||||
if (desc.getDbType() == DatabaseTypeEnum.HIVE) {
|
if (desc.getDbType() == ProductTypeEnum.HIVE) {
|
||||||
if (type == java.sql.Types.DOUBLE
|
if (type == java.sql.Types.DOUBLE
|
||||||
&& precision >= 15
|
&& precision >= 15
|
||||||
&& length >= 15) {
|
&& length >= 15) {
|
||||||
@@ -402,8 +402,8 @@ public class ColumnMetaData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (desc.getDbType() == DatabaseTypeEnum.POSTGRESQL
|
if (desc.getDbType() == ProductTypeEnum.POSTGRESQL
|
||||||
|| desc.getDbType() == DatabaseTypeEnum.GREENPLUM) {
|
|| desc.getDbType() == ProductTypeEnum.GREENPLUM) {
|
||||||
// undefined size => arbitrary precision
|
// undefined size => arbitrary precision
|
||||||
if (type == java.sql.Types.NUMERIC && length == 0 && precision == 0) {
|
if (type == java.sql.Types.NUMERIC && length == 0 && precision == 0) {
|
||||||
valtype = ColumnMetaData.TYPE_BIGNUMBER;
|
valtype = ColumnMetaData.TYPE_BIGNUMBER;
|
||||||
@@ -412,7 +412,7 @@ public class ColumnMetaData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (desc.getDbType() == DatabaseTypeEnum.ORACLE) {
|
if (desc.getDbType() == ProductTypeEnum.ORACLE) {
|
||||||
if (precision == 0 && length == 38) {
|
if (precision == 0 && length == 38) {
|
||||||
valtype = ColumnMetaData.TYPE_INTEGER;
|
valtype = ColumnMetaData.TYPE_INTEGER;
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.core.model;
|
package com.gitee.dbswitch.core.model;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据库连接描述符信息定义(Database Description)
|
* 数据库连接描述符信息定义(Database Description)
|
||||||
@@ -18,7 +18,7 @@ import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
|||||||
*/
|
*/
|
||||||
public class DatabaseDescription {
|
public class DatabaseDescription {
|
||||||
|
|
||||||
protected DatabaseTypeEnum type;
|
protected ProductTypeEnum type;
|
||||||
protected String host;
|
protected String host;
|
||||||
protected int port;
|
protected int port;
|
||||||
/**
|
/**
|
||||||
@@ -32,7 +32,7 @@ public class DatabaseDescription {
|
|||||||
|
|
||||||
public DatabaseDescription(String dbtype, String host, int port, String mode, String dbname,
|
public DatabaseDescription(String dbtype, String host, int port, String mode, String dbname,
|
||||||
String charset, String username, String password) {
|
String charset, String username, String password) {
|
||||||
this.type = DatabaseTypeEnum.valueOf(dbtype.toUpperCase());
|
this.type = ProductTypeEnum.valueOf(dbtype.toUpperCase());
|
||||||
this.host = host;
|
this.host = host;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
@@ -42,7 +42,7 @@ public class DatabaseDescription {
|
|||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DatabaseTypeEnum getType() {
|
public ProductTypeEnum getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
package com.gitee.dbswitch.core.service;
|
package com.gitee.dbswitch.core.service;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||||
import com.gitee.dbswitch.core.model.SchemaTableData;
|
import com.gitee.dbswitch.core.model.SchemaTableData;
|
||||||
import com.gitee.dbswitch.core.model.SchemaTableMeta;
|
import com.gitee.dbswitch.core.model.SchemaTableMeta;
|
||||||
@@ -131,7 +131,7 @@ public interface IMetaDataByDatasourceService {
|
|||||||
* @param autoIncr 是否允许主键自增
|
* @param autoIncr 是否允许主键自增
|
||||||
* @return 对应数据库的DDL建表语句
|
* @return 对应数据库的DDL建表语句
|
||||||
*/
|
*/
|
||||||
List<String> getDDLCreateTableSQL(DatabaseTypeEnum type, List<ColumnDescription> fieldNames,
|
List<String> getDDLCreateTableSQL(ProductTypeEnum type, List<ColumnDescription> fieldNames,
|
||||||
List<String> primaryKeys, String schemaName, String tableName, String tableRemarks,
|
List<String> primaryKeys, String schemaName, String tableName, String tableRemarks,
|
||||||
boolean autoIncr);
|
boolean autoIncr);
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.core.service;
|
package com.gitee.dbswitch.core.service;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||||
import com.gitee.dbswitch.core.model.DatabaseDescription;
|
import com.gitee.dbswitch.core.model.DatabaseDescription;
|
||||||
import com.gitee.dbswitch.core.model.SchemaTableData;
|
import com.gitee.dbswitch.core.model.SchemaTableData;
|
||||||
@@ -126,6 +126,6 @@ public interface IMetaDataByDescriptionService {
|
|||||||
* @param autoIncr 是否允许主键自增
|
* @param autoIncr 是否允许主键自增
|
||||||
* @return 对应数据库的DDL建表语句
|
* @return 对应数据库的DDL建表语句
|
||||||
*/
|
*/
|
||||||
String getDDLCreateTableSQL(DatabaseTypeEnum type, List<ColumnDescription> fieldNames,
|
String getDDLCreateTableSQL(ProductTypeEnum type, List<ColumnDescription> fieldNames,
|
||||||
List<String> primaryKeys, String schemaName, String tableName, boolean autoIncr);
|
List<String> primaryKeys, String schemaName, String tableName, boolean autoIncr);
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.core.service;
|
package com.gitee.dbswitch.core.service;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||||
import com.gitee.dbswitch.core.model.SchemaTableData;
|
import com.gitee.dbswitch.core.model.SchemaTableData;
|
||||||
import com.gitee.dbswitch.core.model.SchemaTableMeta;
|
import com.gitee.dbswitch.core.model.SchemaTableMeta;
|
||||||
@@ -28,7 +28,7 @@ public interface IMetaDataByJdbcService {
|
|||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
DatabaseTypeEnum getDatabaseType();
|
ProductTypeEnum getDatabaseType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取数据库的schema模式列表
|
* 获取数据库的schema模式列表
|
||||||
@@ -165,6 +165,6 @@ public interface IMetaDataByJdbcService {
|
|||||||
* @param autoIncr 是否允许主键自增
|
* @param autoIncr 是否允许主键自增
|
||||||
* @return 对应数据库的DDL建表语句
|
* @return 对应数据库的DDL建表语句
|
||||||
*/
|
*/
|
||||||
String getDDLCreateTableSQL(DatabaseTypeEnum type, List<ColumnDescription> fieldNames,
|
String getDDLCreateTableSQL(ProductTypeEnum type, List<ColumnDescription> fieldNames,
|
||||||
List<String> primaryKeys, String schemaName, String tableName, boolean autoIncr);
|
List<String> primaryKeys, String schemaName, String tableName, boolean autoIncr);
|
||||||
}
|
}
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.core.service.impl;
|
package com.gitee.dbswitch.core.service.impl;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.common.util.DatabaseAwareUtils;
|
import com.gitee.dbswitch.common.util.DatabaseAwareUtils;
|
||||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||||
import com.gitee.dbswitch.core.database.DatabaseFactory;
|
import com.gitee.dbswitch.core.database.DatabaseFactory;
|
||||||
@@ -40,7 +40,7 @@ public class MetaDataByDataSourceServiceImpl implements IMetaDataByDatasourceSer
|
|||||||
this(dataSource, DatabaseAwareUtils.getDatabaseTypeByDataSource(dataSource));
|
this(dataSource, DatabaseAwareUtils.getDatabaseTypeByDataSource(dataSource));
|
||||||
}
|
}
|
||||||
|
|
||||||
public MetaDataByDataSourceServiceImpl(DataSource dataSource, DatabaseTypeEnum type) {
|
public MetaDataByDataSourceServiceImpl(DataSource dataSource, ProductTypeEnum type) {
|
||||||
this.dataSource = dataSource;
|
this.dataSource = dataSource;
|
||||||
this.database = DatabaseFactory.getDatabaseInstance(type);
|
this.database = DatabaseFactory.getDatabaseInstance(type);
|
||||||
}
|
}
|
||||||
@@ -188,7 +188,7 @@ public class MetaDataByDataSourceServiceImpl implements IMetaDataByDatasourceSer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getDDLCreateTableSQL(DatabaseTypeEnum type,
|
public List<String> getDDLCreateTableSQL(ProductTypeEnum type,
|
||||||
List<ColumnDescription> fieldNames, List<String> primaryKeys, String schemaName,
|
List<ColumnDescription> fieldNames, List<String> primaryKeys, String schemaName,
|
||||||
String tableName, String tableRemarks, boolean autoIncr) {
|
String tableName, String tableRemarks, boolean autoIncr) {
|
||||||
return GenerateSqlUtils.getDDLCreateTableSQL(
|
return GenerateSqlUtils.getDDLCreateTableSQL(
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.core.service.impl;
|
package com.gitee.dbswitch.core.service.impl;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||||
import com.gitee.dbswitch.core.database.DatabaseFactory;
|
import com.gitee.dbswitch.core.database.DatabaseFactory;
|
||||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||||
@@ -204,7 +204,7 @@ public class MetaDataByDescriptionServiceImpl implements IMetaDataByDescriptionS
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDDLCreateTableSQL(DatabaseTypeEnum type, List<ColumnDescription> fieldNames,
|
public String getDDLCreateTableSQL(ProductTypeEnum type, List<ColumnDescription> fieldNames,
|
||||||
List<String> primaryKeys, String schemaName, String tableName, boolean autoIncr) {
|
List<String> primaryKeys, String schemaName, String tableName, boolean autoIncr) {
|
||||||
return GenerateSqlUtils.getDDLCreateTableSQL(
|
return GenerateSqlUtils.getDDLCreateTableSQL(
|
||||||
type, fieldNames, primaryKeys, schemaName, tableName, autoIncr);
|
type, fieldNames, primaryKeys, schemaName, tableName, autoIncr);
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.core.service.impl;
|
package com.gitee.dbswitch.core.service.impl;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||||
import com.gitee.dbswitch.core.database.DatabaseFactory;
|
import com.gitee.dbswitch.core.database.DatabaseFactory;
|
||||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||||
@@ -31,16 +31,16 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class MetaDataByJdbcServiceImpl implements IMetaDataByJdbcService {
|
public class MetaDataByJdbcServiceImpl implements IMetaDataByJdbcService {
|
||||||
|
|
||||||
protected DatabaseTypeEnum dbType;
|
protected ProductTypeEnum dbType;
|
||||||
protected AbstractDatabase database;
|
protected AbstractDatabase database;
|
||||||
|
|
||||||
public MetaDataByJdbcServiceImpl(DatabaseTypeEnum type) {
|
public MetaDataByJdbcServiceImpl(ProductTypeEnum type) {
|
||||||
this.dbType = type;
|
this.dbType = type;
|
||||||
this.database = DatabaseFactory.getDatabaseInstance(type);
|
this.database = DatabaseFactory.getDatabaseInstance(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DatabaseTypeEnum getDatabaseType() {
|
public ProductTypeEnum getDatabaseType() {
|
||||||
return this.dbType;
|
return this.dbType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ public class MetaDataByJdbcServiceImpl implements IMetaDataByJdbcService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDDLCreateTableSQL(DatabaseTypeEnum type, List<ColumnDescription> fieldNames,
|
public String getDDLCreateTableSQL(ProductTypeEnum type, List<ColumnDescription> fieldNames,
|
||||||
List<String> primaryKeys, String schemaName, String tableName, boolean autoIncr) {
|
List<String> primaryKeys, String schemaName, String tableName, boolean autoIncr) {
|
||||||
return GenerateSqlUtils.getDDLCreateTableSQL(
|
return GenerateSqlUtils.getDDLCreateTableSQL(
|
||||||
type, fieldNames, primaryKeys, schemaName, tableName, autoIncr);
|
type, fieldNames, primaryKeys, schemaName, tableName, autoIncr);
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
package com.gitee.dbswitch.core.util;
|
package com.gitee.dbswitch.core.util;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.constant.Const;
|
import com.gitee.dbswitch.common.constant.Const;
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||||
import com.gitee.dbswitch.core.database.DatabaseFactory;
|
import com.gitee.dbswitch.core.database.DatabaseFactory;
|
||||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||||
@@ -29,7 +29,7 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
public final class GenerateSqlUtils {
|
public final class GenerateSqlUtils {
|
||||||
|
|
||||||
public static String getDDLCreateTableSQL(
|
public static String getDDLCreateTableSQL(
|
||||||
DatabaseTypeEnum type,
|
ProductTypeEnum type,
|
||||||
List<ColumnDescription> fieldNames,
|
List<ColumnDescription> fieldNames,
|
||||||
List<String> primaryKeys,
|
List<String> primaryKeys,
|
||||||
String schemaName,
|
String schemaName,
|
||||||
@@ -56,7 +56,7 @@ public final class GenerateSqlUtils {
|
|||||||
boolean withRemarks,
|
boolean withRemarks,
|
||||||
String tableRemarks,
|
String tableRemarks,
|
||||||
boolean autoIncr) {
|
boolean autoIncr) {
|
||||||
DatabaseTypeEnum type = db.getDatabaseType();
|
ProductTypeEnum type = db.getDatabaseType();
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
List<String> pks = fieldNames.stream()
|
List<String> pks = fieldNames.stream()
|
||||||
.filter((cd) -> primaryKeys.contains(cd.getFieldName()))
|
.filter((cd) -> primaryKeys.contains(cd.getFieldName()))
|
||||||
@@ -87,7 +87,7 @@ public final class GenerateSqlUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sb.append(")");
|
sb.append(")");
|
||||||
if (DatabaseTypeEnum.MYSQL == type) {
|
if (ProductTypeEnum.MYSQL == type) {
|
||||||
sb.append("ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin");
|
sb.append("ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin");
|
||||||
if (withRemarks && StringUtils.isNotBlank(tableRemarks)) {
|
if (withRemarks && StringUtils.isNotBlank(tableRemarks)) {
|
||||||
sb.append(String.format(" COMMENT='%s' ", tableRemarks.replace("'", "\\'")));
|
sb.append(String.format(" COMMENT='%s' ", tableRemarks.replace("'", "\\'")));
|
||||||
@@ -98,7 +98,7 @@ public final class GenerateSqlUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> getDDLCreateTableSQL(
|
public static List<String> getDDLCreateTableSQL(
|
||||||
DatabaseTypeEnum type,
|
ProductTypeEnum type,
|
||||||
List<ColumnDescription> fieldNames,
|
List<ColumnDescription> fieldNames,
|
||||||
List<String> primaryKeys,
|
List<String> primaryKeys,
|
||||||
String schemaName,
|
String schemaName,
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
package com.gitee.dbswitch.core.util;
|
package com.gitee.dbswitch.core.util;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
import com.gitee.dbswitch.core.database.AbstractDatabase;
|
||||||
import com.gitee.dbswitch.core.database.DatabaseFactory;
|
import com.gitee.dbswitch.core.database.DatabaseFactory;
|
||||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||||
@@ -10,7 +10,7 @@ import java.util.List;
|
|||||||
public final class PostgresUtils {
|
public final class PostgresUtils {
|
||||||
|
|
||||||
public static String getTableDDL(Connection connection, String schema, String table) {
|
public static String getTableDDL(Connection connection, String schema, String table) {
|
||||||
AbstractDatabase db = DatabaseFactory.getDatabaseInstance(DatabaseTypeEnum.POSTGRESQL);
|
AbstractDatabase db = DatabaseFactory.getDatabaseInstance(ProductTypeEnum.POSTGRESQL);
|
||||||
List<ColumnDescription> columnDescriptions = db.queryTableColumnMeta(connection, schema, table);
|
List<ColumnDescription> columnDescriptions = db.queryTableColumnMeta(connection, schema, table);
|
||||||
List<String> pks = db.queryTablePrimaryKeys(connection, schema, table);
|
List<String> pks = db.queryTablePrimaryKeys(connection, schema, table);
|
||||||
return GenerateSqlUtils.getDDLCreateTableSQL(
|
return GenerateSqlUtils.getDDLCreateTableSQL(
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
package com.gitee.dbswitch.data.entity;
|
package com.gitee.dbswitch.data.entity;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.entity.PatternMapper;
|
import com.gitee.dbswitch.common.entity.PatternMapper;
|
||||||
|
import com.gitee.dbswitch.common.type.DBTableType;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -26,6 +27,7 @@ public class SourceDataSourceProperties {
|
|||||||
|
|
||||||
private Integer fetchSize = 5000;
|
private Integer fetchSize = 5000;
|
||||||
private String sourceSchema = "";
|
private String sourceSchema = "";
|
||||||
|
private String tableType = "TABLE";
|
||||||
private String sourceIncludes = "";
|
private String sourceIncludes = "";
|
||||||
private String sourceExcludes = "";
|
private String sourceExcludes = "";
|
||||||
private List<PatternMapper> regexTableMapper;
|
private List<PatternMapper> regexTableMapper;
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.data.handler;
|
package com.gitee.dbswitch.data.handler;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.common.util.DatabaseAwareUtils;
|
import com.gitee.dbswitch.common.util.DatabaseAwareUtils;
|
||||||
import com.gitee.dbswitch.common.util.PatterNameUtils;
|
import com.gitee.dbswitch.common.util.PatterNameUtils;
|
||||||
import com.gitee.dbswitch.core.model.ColumnDescription;
|
import com.gitee.dbswitch.core.model.ColumnDescription;
|
||||||
@@ -64,7 +64,7 @@ public class MigrationHandler implements Supplier<Long> {
|
|||||||
|
|
||||||
// 来源端
|
// 来源端
|
||||||
private final HikariDataSource sourceDataSource;
|
private final HikariDataSource sourceDataSource;
|
||||||
private DatabaseTypeEnum sourceProductType;
|
private ProductTypeEnum sourceProductType;
|
||||||
private String sourceSchemaName;
|
private String sourceSchemaName;
|
||||||
private String sourceTableName;
|
private String sourceTableName;
|
||||||
private String sourceTableRemarks;
|
private String sourceTableRemarks;
|
||||||
@@ -75,7 +75,7 @@ public class MigrationHandler implements Supplier<Long> {
|
|||||||
|
|
||||||
// 目的端
|
// 目的端
|
||||||
private final HikariDataSource targetDataSource;
|
private final HikariDataSource targetDataSource;
|
||||||
private DatabaseTypeEnum targetProductType;
|
private ProductTypeEnum targetProductType;
|
||||||
private String targetSchemaName;
|
private String targetSchemaName;
|
||||||
private String targetTableName;
|
private String targetTableName;
|
||||||
private List<ColumnDescription> targetColumnDescriptions;
|
private List<ColumnDescription> targetColumnDescriptions;
|
||||||
@@ -247,7 +247,7 @@ public class MigrationHandler implements Supplier<Long> {
|
|||||||
if (!targetPrimaryKeys.isEmpty() && !dbTargetPks.isEmpty()
|
if (!targetPrimaryKeys.isEmpty() && !dbTargetPks.isEmpty()
|
||||||
&& targetPrimaryKeys.containsAll(dbTargetPks)
|
&& targetPrimaryKeys.containsAll(dbTargetPks)
|
||||||
&& dbTargetPks.containsAll(targetPrimaryKeys)) {
|
&& dbTargetPks.containsAll(targetPrimaryKeys)) {
|
||||||
if (targetProductType == DatabaseTypeEnum.MYSQL
|
if (targetProductType == ProductTypeEnum.MYSQL
|
||||||
&& !DatabaseAwareUtils.isMysqlInnodbStorageEngine(
|
&& !DatabaseAwareUtils.isMysqlInnodbStorageEngine(
|
||||||
targetSchemaName, targetTableName, targetDataSource)) {
|
targetSchemaName, targetTableName, targetDataSource)) {
|
||||||
return doFullCoverSynchronize(writer);
|
return doFullCoverSynchronize(writer);
|
||||||
|
@@ -33,6 +33,7 @@ import java.util.regex.Pattern;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.util.StopWatch;
|
import org.springframework.util.StopWatch;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据迁移主逻辑类
|
* 数据迁移主逻辑类
|
||||||
@@ -119,10 +120,13 @@ public class MigrationService {
|
|||||||
if (tableList.isEmpty()) {
|
if (tableList.isEmpty()) {
|
||||||
log.warn("### Find source database table list empty for schema name is : {}", schema);
|
log.warn("### Find source database table list empty for schema name is : {}", schema);
|
||||||
} else {
|
} else {
|
||||||
|
String allTableType = sourceProperties.getTableType();
|
||||||
for (TableDescription td : tableList) {
|
for (TableDescription td : tableList) {
|
||||||
// 当没有配置迁移的表是,默认为所有物理表(不含有视图表)
|
// 当没有配置迁移的表名时,默认为根据类型同步所有
|
||||||
if (includes.isEmpty() && DBTableType.VIEW.name().equals(td.getTableType())) {
|
if (includes.isEmpty()) {
|
||||||
continue;
|
if (null != allTableType && !allTableType.equals(td.getTableType())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String tableName = td.getTableName();
|
String tableName = td.getTableName();
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
dbswitch:
|
dbswitch:
|
||||||
source:
|
source:
|
||||||
# source database connection information
|
# source database connection information
|
||||||
## support MySQL/MariaDB/DB2/DM/Kingbase8/Oracle/SQLServer/PostgreSQL/Greenplum
|
## support MySQL/MariaDB/DB2/DM/Kingbase8/Oracle/SQLServer/PostgreSQL/Greenplum etc.
|
||||||
## support mutiple source database connection
|
## support multiple source database connection
|
||||||
- url: jdbc:oracle:thin:@172.17.2.10:1521:ORCL
|
- url: jdbc:oracle:thin:@172.17.2.10:1521:ORCL
|
||||||
driver-class-name: 'oracle.jdbc.driver.OracleDriver'
|
driver-class-name: 'oracle.jdbc.driver.OracleDriver'
|
||||||
username: 'system'
|
username: 'system'
|
||||||
@@ -12,20 +12,22 @@ dbswitch:
|
|||||||
fetch-size: 10000
|
fetch-size: 10000
|
||||||
## schema name for query source schemas, separate by ','
|
## schema name for query source schemas, separate by ','
|
||||||
source-schema: 'TANG'
|
source-schema: 'TANG'
|
||||||
|
## table type which include or exclude,option: TABLE,VIEW
|
||||||
|
table-type: 'TABLE'
|
||||||
## table name include from table lists, separate by ','
|
## table name include from table lists, separate by ','
|
||||||
source-includes: ''
|
source-includes: ''
|
||||||
## table name exclude from table lists, separate by ','
|
## table name exclude from table lists, separate by ','
|
||||||
source-excludes: ''
|
source-excludes: ''
|
||||||
## table name convert mapper by regular expression
|
## table name convert mapper by regular expression
|
||||||
regex-table-mapper:
|
regex-table-mapper:
|
||||||
- 'from-pattern': '^'
|
- from-pattern: '^'
|
||||||
'to-value': 'T_'
|
to-value: 'T_'
|
||||||
## columns name convert mapper by regular expression like regex-table-mapper
|
## columns name convert mapper by regular expression like regex-table-mapper
|
||||||
regex-column-mapper:
|
regex-column-mapper:
|
||||||
|
|
||||||
target:
|
target:
|
||||||
# target database connection information
|
# target database connection information
|
||||||
## Best support for Oracle/PostgreSQL/Greenplum/DM/Kingbase8
|
## Best support for Oracle/PostgreSQL/Greenplum/DM etc.
|
||||||
url: jdbc:postgresql://172.17.2.10:5432/test
|
url: jdbc:postgresql://172.17.2.10:5432/test
|
||||||
driver-class-name: org.postgresql.Driver
|
driver-class-name: org.postgresql.Driver
|
||||||
username: tang
|
username: tang
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.dbcommon.database;
|
package com.gitee.dbswitch.dbcommon.database;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.common.util.DatabaseAwareUtils;
|
import com.gitee.dbswitch.common.util.DatabaseAwareUtils;
|
||||||
import com.gitee.dbswitch.dbcommon.database.impl.DB2DatabaseOperator;
|
import com.gitee.dbswitch.dbcommon.database.impl.DB2DatabaseOperator;
|
||||||
import com.gitee.dbswitch.dbcommon.database.impl.DmDatabaseOperator;
|
import com.gitee.dbswitch.dbcommon.database.impl.DmDatabaseOperator;
|
||||||
@@ -35,27 +35,27 @@ import javax.sql.DataSource;
|
|||||||
*/
|
*/
|
||||||
public final class DatabaseOperatorFactory {
|
public final class DatabaseOperatorFactory {
|
||||||
|
|
||||||
private static final Map<DatabaseTypeEnum, Function<DataSource, IDatabaseOperator>> DATABASE_OPERATOR_MAPPER
|
private static final Map<ProductTypeEnum, Function<DataSource, IDatabaseOperator>> DATABASE_OPERATOR_MAPPER
|
||||||
= new HashMap<DatabaseTypeEnum, Function<DataSource, IDatabaseOperator>>() {
|
= new HashMap<ProductTypeEnum, Function<DataSource, IDatabaseOperator>>() {
|
||||||
|
|
||||||
private static final long serialVersionUID = -5278835613240515265L;
|
private static final long serialVersionUID = -5278835613240515265L;
|
||||||
|
|
||||||
{
|
{
|
||||||
put(DatabaseTypeEnum.MYSQL, MysqlDatabaseOperator::new);
|
put(ProductTypeEnum.MYSQL, MysqlDatabaseOperator::new);
|
||||||
put(DatabaseTypeEnum.MARIADB, MysqlDatabaseOperator::new);
|
put(ProductTypeEnum.MARIADB, MysqlDatabaseOperator::new);
|
||||||
put(DatabaseTypeEnum.ORACLE, OracleDatabaseOperator::new);
|
put(ProductTypeEnum.ORACLE, OracleDatabaseOperator::new);
|
||||||
put(DatabaseTypeEnum.SQLSERVER, SqlServerDatabaseOperator::new);
|
put(ProductTypeEnum.SQLSERVER, SqlServerDatabaseOperator::new);
|
||||||
put(DatabaseTypeEnum.SQLSERVER2000, SqlServerDatabaseOperator::new);
|
put(ProductTypeEnum.SQLSERVER2000, SqlServerDatabaseOperator::new);
|
||||||
put(DatabaseTypeEnum.POSTGRESQL, PostgreSqlDatabaseOperator::new);
|
put(ProductTypeEnum.POSTGRESQL, PostgreSqlDatabaseOperator::new);
|
||||||
put(DatabaseTypeEnum.GREENPLUM, GreenplumDatabaseOperator::new);
|
put(ProductTypeEnum.GREENPLUM, GreenplumDatabaseOperator::new);
|
||||||
put(DatabaseTypeEnum.DB2, DB2DatabaseOperator::new);
|
put(ProductTypeEnum.DB2, DB2DatabaseOperator::new);
|
||||||
put(DatabaseTypeEnum.DM, DmDatabaseOperator::new);
|
put(ProductTypeEnum.DM, DmDatabaseOperator::new);
|
||||||
put(DatabaseTypeEnum.SYBASE, SybaseDatabaseOperator::new);
|
put(ProductTypeEnum.SYBASE, SybaseDatabaseOperator::new);
|
||||||
put(DatabaseTypeEnum.KINGBASE, KingbaseDatabaseOperator::new);
|
put(ProductTypeEnum.KINGBASE, KingbaseDatabaseOperator::new);
|
||||||
put(DatabaseTypeEnum.OSCAR, OscarDatabaseOperator::new);
|
put(ProductTypeEnum.OSCAR, OscarDatabaseOperator::new);
|
||||||
put(DatabaseTypeEnum.GBASE8A, MysqlDatabaseOperator::new);
|
put(ProductTypeEnum.GBASE8A, MysqlDatabaseOperator::new);
|
||||||
put(DatabaseTypeEnum.HIVE, HiveDatabaseOperator::new);
|
put(ProductTypeEnum.HIVE, HiveDatabaseOperator::new);
|
||||||
put(DatabaseTypeEnum.SQLITE3, SqliteDatabaseOperator::new);
|
put(ProductTypeEnum.SQLITE3, SqliteDatabaseOperator::new);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ public final class DatabaseOperatorFactory {
|
|||||||
* @return 指定类型的数据库读取器
|
* @return 指定类型的数据库读取器
|
||||||
*/
|
*/
|
||||||
public static IDatabaseOperator createDatabaseOperator(DataSource dataSource) {
|
public static IDatabaseOperator createDatabaseOperator(DataSource dataSource) {
|
||||||
DatabaseTypeEnum type = DatabaseAwareUtils.getDatabaseTypeByDataSource(dataSource);
|
ProductTypeEnum type = DatabaseAwareUtils.getDatabaseTypeByDataSource(dataSource);
|
||||||
if (!DATABASE_OPERATOR_MAPPER.containsKey(type)) {
|
if (!DATABASE_OPERATOR_MAPPER.containsKey(type)) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
String.format("[dbcommon] Unsupported database type (%s)", type));
|
String.format("[dbcommon] Unsupported database type (%s)", type));
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.dbsynch;
|
package com.gitee.dbswitch.dbsynch;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.common.util.DatabaseAwareUtils;
|
import com.gitee.dbswitch.common.util.DatabaseAwareUtils;
|
||||||
import com.gitee.dbswitch.dbsynch.db2.DB2DatabaseSyncImpl;
|
import com.gitee.dbswitch.dbsynch.db2.DB2DatabaseSyncImpl;
|
||||||
import com.gitee.dbswitch.dbsynch.dm.DmDatabaseSyncImpl;
|
import com.gitee.dbswitch.dbsynch.dm.DmDatabaseSyncImpl;
|
||||||
@@ -34,26 +34,26 @@ import javax.sql.DataSource;
|
|||||||
*/
|
*/
|
||||||
public final class DatabaseSynchronizeFactory {
|
public final class DatabaseSynchronizeFactory {
|
||||||
|
|
||||||
private static final Map<DatabaseTypeEnum, Function<DataSource, IDatabaseSynchronize>> DATABASE_SYNC_MAPPER
|
private static final Map<ProductTypeEnum, Function<DataSource, IDatabaseSynchronize>> DATABASE_SYNC_MAPPER
|
||||||
= new HashMap<DatabaseTypeEnum, Function<DataSource, IDatabaseSynchronize>>() {
|
= new HashMap<ProductTypeEnum, Function<DataSource, IDatabaseSynchronize>>() {
|
||||||
|
|
||||||
private static final long serialVersionUID = -2359773637275934408L;
|
private static final long serialVersionUID = -2359773637275934408L;
|
||||||
|
|
||||||
{
|
{
|
||||||
put(DatabaseTypeEnum.MYSQL, MySqlDatabaseSyncImpl::new);
|
put(ProductTypeEnum.MYSQL, MySqlDatabaseSyncImpl::new);
|
||||||
put(DatabaseTypeEnum.MARIADB, MySqlDatabaseSyncImpl::new);
|
put(ProductTypeEnum.MARIADB, MySqlDatabaseSyncImpl::new);
|
||||||
put(DatabaseTypeEnum.ORACLE, OracleDatabaseSyncImpl::new);
|
put(ProductTypeEnum.ORACLE, OracleDatabaseSyncImpl::new);
|
||||||
put(DatabaseTypeEnum.SQLSERVER, SqlServerDatabaseSyncImpl::new);
|
put(ProductTypeEnum.SQLSERVER, SqlServerDatabaseSyncImpl::new);
|
||||||
put(DatabaseTypeEnum.SQLSERVER2000, SqlServerDatabaseSyncImpl::new);
|
put(ProductTypeEnum.SQLSERVER2000, SqlServerDatabaseSyncImpl::new);
|
||||||
put(DatabaseTypeEnum.POSTGRESQL, PostgresqlDatabaseSyncImpl::new);
|
put(ProductTypeEnum.POSTGRESQL, PostgresqlDatabaseSyncImpl::new);
|
||||||
put(DatabaseTypeEnum.GREENPLUM, GreenplumDatabaseSyncImpl::new);
|
put(ProductTypeEnum.GREENPLUM, GreenplumDatabaseSyncImpl::new);
|
||||||
put(DatabaseTypeEnum.DB2, DB2DatabaseSyncImpl::new);
|
put(ProductTypeEnum.DB2, DB2DatabaseSyncImpl::new);
|
||||||
put(DatabaseTypeEnum.DM, DmDatabaseSyncImpl::new);
|
put(ProductTypeEnum.DM, DmDatabaseSyncImpl::new);
|
||||||
put(DatabaseTypeEnum.SYBASE, SybaseDatabaseSyncImpl::new);
|
put(ProductTypeEnum.SYBASE, SybaseDatabaseSyncImpl::new);
|
||||||
put(DatabaseTypeEnum.KINGBASE, KingbaseDatabaseSyncImpl::new);
|
put(ProductTypeEnum.KINGBASE, KingbaseDatabaseSyncImpl::new);
|
||||||
put(DatabaseTypeEnum.OSCAR, OscarDatabaseSyncImpl::new);
|
put(ProductTypeEnum.OSCAR, OscarDatabaseSyncImpl::new);
|
||||||
put(DatabaseTypeEnum.GBASE8A, MySqlDatabaseSyncImpl::new);
|
put(ProductTypeEnum.GBASE8A, MySqlDatabaseSyncImpl::new);
|
||||||
put(DatabaseTypeEnum.SQLITE3, Sqlite3DatabaseSyncImpl::new);
|
put(ProductTypeEnum.SQLITE3, Sqlite3DatabaseSyncImpl::new);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ public final class DatabaseSynchronizeFactory {
|
|||||||
* @return 同步器对象
|
* @return 同步器对象
|
||||||
*/
|
*/
|
||||||
public static IDatabaseSynchronize createDatabaseWriter(DataSource dataSource) {
|
public static IDatabaseSynchronize createDatabaseWriter(DataSource dataSource) {
|
||||||
DatabaseTypeEnum type = DatabaseAwareUtils.getDatabaseTypeByDataSource(dataSource);
|
ProductTypeEnum type = DatabaseAwareUtils.getDatabaseTypeByDataSource(dataSource);
|
||||||
if (!DATABASE_SYNC_MAPPER.containsKey(type)) {
|
if (!DATABASE_SYNC_MAPPER.containsKey(type)) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
String.format("[dbsynch] Unsupported database type (%s)", type));
|
String.format("[dbsynch] Unsupported database type (%s)", type));
|
||||||
|
@@ -9,7 +9,7 @@
|
|||||||
/////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////
|
||||||
package com.gitee.dbswitch.dbwriter;
|
package com.gitee.dbswitch.dbwriter;
|
||||||
|
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.common.util.DatabaseAwareUtils;
|
import com.gitee.dbswitch.common.util.DatabaseAwareUtils;
|
||||||
import com.gitee.dbswitch.dbwriter.db2.DB2WriterImpl;
|
import com.gitee.dbswitch.dbwriter.db2.DB2WriterImpl;
|
||||||
import com.gitee.dbswitch.dbwriter.dm.DmWriterImpl;
|
import com.gitee.dbswitch.dbwriter.dm.DmWriterImpl;
|
||||||
@@ -33,27 +33,27 @@ import javax.sql.DataSource;
|
|||||||
*/
|
*/
|
||||||
public class DatabaseWriterFactory {
|
public class DatabaseWriterFactory {
|
||||||
|
|
||||||
private static final Map<DatabaseTypeEnum, Function<DataSource, IDatabaseWriter>> DATABASE_WRITER_MAPPER
|
private static final Map<ProductTypeEnum, Function<DataSource, IDatabaseWriter>> DATABASE_WRITER_MAPPER
|
||||||
= new HashMap<DatabaseTypeEnum, Function<DataSource, IDatabaseWriter>>() {
|
= new HashMap<ProductTypeEnum, Function<DataSource, IDatabaseWriter>>() {
|
||||||
|
|
||||||
private static final long serialVersionUID = 3365136872693503697L;
|
private static final long serialVersionUID = 3365136872693503697L;
|
||||||
|
|
||||||
{
|
{
|
||||||
put(DatabaseTypeEnum.MYSQL, MySqlWriterImpl::new);
|
put(ProductTypeEnum.MYSQL, MySqlWriterImpl::new);
|
||||||
put(DatabaseTypeEnum.MARIADB, MySqlWriterImpl::new);
|
put(ProductTypeEnum.MARIADB, MySqlWriterImpl::new);
|
||||||
put(DatabaseTypeEnum.ORACLE, OracleWriterImpl::new);
|
put(ProductTypeEnum.ORACLE, OracleWriterImpl::new);
|
||||||
put(DatabaseTypeEnum.SQLSERVER, SqlServerWriterImpl::new);
|
put(ProductTypeEnum.SQLSERVER, SqlServerWriterImpl::new);
|
||||||
put(DatabaseTypeEnum.SQLSERVER2000, SqlServerWriterImpl::new);
|
put(ProductTypeEnum.SQLSERVER2000, SqlServerWriterImpl::new);
|
||||||
put(DatabaseTypeEnum.POSTGRESQL, GreenplumCopyWriterImpl::new);
|
put(ProductTypeEnum.POSTGRESQL, GreenplumCopyWriterImpl::new);
|
||||||
put(DatabaseTypeEnum.GREENPLUM, GreenplumCopyWriterImpl::new);
|
put(ProductTypeEnum.GREENPLUM, GreenplumCopyWriterImpl::new);
|
||||||
put(DatabaseTypeEnum.DB2, DB2WriterImpl::new);
|
put(ProductTypeEnum.DB2, DB2WriterImpl::new);
|
||||||
put(DatabaseTypeEnum.DM, DmWriterImpl::new);
|
put(ProductTypeEnum.DM, DmWriterImpl::new);
|
||||||
put(DatabaseTypeEnum.SYBASE, SybaseWriterImpl::new);
|
put(ProductTypeEnum.SYBASE, SybaseWriterImpl::new);
|
||||||
//对于kingbase当前只能使用insert模式
|
//对于kingbase当前只能使用insert模式
|
||||||
put(DatabaseTypeEnum.KINGBASE, KingbaseInsertWriterImpl::new);
|
put(ProductTypeEnum.KINGBASE, KingbaseInsertWriterImpl::new);
|
||||||
put(DatabaseTypeEnum.OSCAR, OscarWriterImpl::new);
|
put(ProductTypeEnum.OSCAR, OscarWriterImpl::new);
|
||||||
put(DatabaseTypeEnum.GBASE8A, MySqlWriterImpl::new);
|
put(ProductTypeEnum.GBASE8A, MySqlWriterImpl::new);
|
||||||
put(DatabaseTypeEnum.SQLITE3, Sqlite3WriterImpl::new);
|
put(ProductTypeEnum.SQLITE3, Sqlite3WriterImpl::new);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -75,9 +75,9 @@ public class DatabaseWriterFactory {
|
|||||||
* @return 写入器对象
|
* @return 写入器对象
|
||||||
*/
|
*/
|
||||||
public static IDatabaseWriter createDatabaseWriter(DataSource dataSource, boolean insert) {
|
public static IDatabaseWriter createDatabaseWriter(DataSource dataSource, boolean insert) {
|
||||||
DatabaseTypeEnum type = DatabaseAwareUtils.getDatabaseTypeByDataSource(dataSource);
|
ProductTypeEnum type = DatabaseAwareUtils.getDatabaseTypeByDataSource(dataSource);
|
||||||
if (insert) {
|
if (insert) {
|
||||||
if (DatabaseTypeEnum.POSTGRESQL.equals(type) || DatabaseTypeEnum.GREENPLUM.equals(type)) {
|
if (ProductTypeEnum.POSTGRESQL.equals(type) || ProductTypeEnum.GREENPLUM.equals(type)) {
|
||||||
return new com.gitee.dbswitch.dbwriter.gpdb.GreenplumInsertWriterImpl(dataSource);
|
return new com.gitee.dbswitch.dbwriter.gpdb.GreenplumInsertWriterImpl(dataSource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
package com.gitee.dbswitch.sql.service;
|
package com.gitee.dbswitch.sql.service;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SQL语言共分为四大类:数据查询语言DQL,数据操纵语言DML,数据定义语言DDL,数据控制语言DCL
|
* SQL语言共分为四大类:数据查询语言DQL,数据操纵语言DML,数据定义语言DDL,数据控制语言DCL
|
||||||
@@ -34,7 +34,7 @@ public interface ISqlConvertService {
|
|||||||
* @param sql 待转换的SQL语句
|
* @param sql 待转换的SQL语句
|
||||||
* @return 转换为指定数据库类型后的SQL语句
|
* @return 转换为指定数据库类型后的SQL语句
|
||||||
*/
|
*/
|
||||||
public String dmlSentence(String sql, DatabaseTypeEnum target);
|
public String dmlSentence(String sql, ProductTypeEnum target);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 指定源数据库到目的数据库的DQL/DML类SQL的转换
|
* 指定源数据库到目的数据库的DQL/DML类SQL的转换
|
||||||
@@ -44,7 +44,7 @@ public interface ISqlConvertService {
|
|||||||
* @param sql 待转换的SQL语句
|
* @param sql 待转换的SQL语句
|
||||||
* @return 转换为目的数据库类型后的SQL语句
|
* @return 转换为目的数据库类型后的SQL语句
|
||||||
*/
|
*/
|
||||||
public String dmlSentence(DatabaseTypeEnum source, DatabaseTypeEnum target, String sql);
|
public String dmlSentence(ProductTypeEnum source, ProductTypeEnum target, String sql);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 标准DDL类SQL的转换
|
* 标准DDL类SQL的转换
|
||||||
@@ -60,7 +60,7 @@ public interface ISqlConvertService {
|
|||||||
* @param sql 待转换的SQL语句
|
* @param sql 待转换的SQL语句
|
||||||
* @return 转换为指定数据库类型后的SQL语句
|
* @return 转换为指定数据库类型后的SQL语句
|
||||||
*/
|
*/
|
||||||
public String ddlSentence(String sql, DatabaseTypeEnum target);
|
public String ddlSentence(String sql, ProductTypeEnum target);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 指定源数据库到目的数据库的DDL类SQL的转换
|
* 指定源数据库到目的数据库的DDL类SQL的转换
|
||||||
@@ -70,7 +70,7 @@ public interface ISqlConvertService {
|
|||||||
* @param sql 待转换的SQL语句
|
* @param sql 待转换的SQL语句
|
||||||
* @return 转换为目的数据库类型后的SQL语句
|
* @return 转换为目的数据库类型后的SQL语句
|
||||||
*/
|
*/
|
||||||
public String ddlSentence(DatabaseTypeEnum source, DatabaseTypeEnum target, String sql);
|
public String ddlSentence(ProductTypeEnum source, ProductTypeEnum target, String sql);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 标准DCL类SQL的转换
|
* 标准DCL类SQL的转换
|
||||||
@@ -88,5 +88,5 @@ public interface ISqlConvertService {
|
|||||||
* @param sql 待转换的SQL语句
|
* @param sql 待转换的SQL语句
|
||||||
* @return 转换为目的数据库类型后的SQL语句
|
* @return 转换为目的数据库类型后的SQL语句
|
||||||
*/
|
*/
|
||||||
public String dclSentence(DatabaseTypeEnum source, DatabaseTypeEnum target, String sql);
|
public String dclSentence(ProductTypeEnum source, ProductTypeEnum target, String sql);
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,7 @@ import com.gitee.dbswitch.sql.calcite.TheMssqlSqlDialect;
|
|||||||
import com.gitee.dbswitch.sql.calcite.TheMysqlSqlDialect;
|
import com.gitee.dbswitch.sql.calcite.TheMysqlSqlDialect;
|
||||||
import com.gitee.dbswitch.sql.calcite.TheOracleSqlDialect;
|
import com.gitee.dbswitch.sql.calcite.TheOracleSqlDialect;
|
||||||
import com.gitee.dbswitch.sql.calcite.ThePostgresqlSqlDialect;
|
import com.gitee.dbswitch.sql.calcite.ThePostgresqlSqlDialect;
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.sql.service.ISqlConvertService;
|
import com.gitee.dbswitch.sql.service.ISqlConvertService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -40,7 +40,7 @@ public class CalciteSqlConvertServiceImpl implements ISqlConvertService {
|
|||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(CalciteSqlConvertServiceImpl.class);
|
private static final Logger logger = LoggerFactory.getLogger(CalciteSqlConvertServiceImpl.class);
|
||||||
|
|
||||||
private Lex getDatabaseLex(DatabaseTypeEnum type) {
|
private Lex getDatabaseLex(ProductTypeEnum type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MYSQL:
|
case MYSQL:
|
||||||
return Lex.MYSQL;
|
return Lex.MYSQL;
|
||||||
@@ -55,7 +55,7 @@ public class CalciteSqlConvertServiceImpl implements ISqlConvertService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private SqlDialect getDatabaseDialect(DatabaseTypeEnum type) {
|
private SqlDialect getDatabaseDialect(ProductTypeEnum type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MYSQL:
|
case MYSQL:
|
||||||
return TheMysqlSqlDialect.DEFAULT;
|
return TheMysqlSqlDialect.DEFAULT;
|
||||||
@@ -94,7 +94,7 @@ public class CalciteSqlConvertServiceImpl implements ISqlConvertService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String dmlSentence(String sql, DatabaseTypeEnum target) {
|
public String dmlSentence(String sql, ProductTypeEnum target) {
|
||||||
logger.info("DML SQL: [{}] {} ", target.name(), sql);
|
logger.info("DML SQL: [{}] {} ", target.name(), sql);
|
||||||
SqlParser.Config config = SqlParser.configBuilder().build();
|
SqlParser.Config config = SqlParser.configBuilder().build();
|
||||||
SqlParser parser = SqlParser.create(sql, config);
|
SqlParser parser = SqlParser.create(sql, config);
|
||||||
@@ -109,7 +109,7 @@ public class CalciteSqlConvertServiceImpl implements ISqlConvertService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String dmlSentence(DatabaseTypeEnum source, DatabaseTypeEnum target, String sql) {
|
public String dmlSentence(ProductTypeEnum source, ProductTypeEnum target, String sql) {
|
||||||
logger.info("DML SQL: [{}->{}] {} ", source.name(), target.name(), sql);
|
logger.info("DML SQL: [{}->{}] {} ", source.name(), target.name(), sql);
|
||||||
SqlParser.Config config = SqlParser.configBuilder().setLex(this.getDatabaseLex(source)).build();
|
SqlParser.Config config = SqlParser.configBuilder().setLex(this.getDatabaseLex(source)).build();
|
||||||
SqlParser parser = SqlParser.create(sql, config);
|
SqlParser parser = SqlParser.create(sql, config);
|
||||||
@@ -149,7 +149,7 @@ public class CalciteSqlConvertServiceImpl implements ISqlConvertService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String ddlSentence(String sql, DatabaseTypeEnum target) {
|
public String ddlSentence(String sql, ProductTypeEnum target) {
|
||||||
logger.info("DDL SQL: [{}] {} ", target.name(), sql);
|
logger.info("DDL SQL: [{}] {} ", target.name(), sql);
|
||||||
SqlParser.Config config = SqlParser.configBuilder()
|
SqlParser.Config config = SqlParser.configBuilder()
|
||||||
.setParserFactory(SqlDdlParserImpl.FACTORY)
|
.setParserFactory(SqlDdlParserImpl.FACTORY)
|
||||||
@@ -168,7 +168,7 @@ public class CalciteSqlConvertServiceImpl implements ISqlConvertService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String ddlSentence(DatabaseTypeEnum source, DatabaseTypeEnum target, String sql) {
|
public String ddlSentence(ProductTypeEnum source, ProductTypeEnum target, String sql) {
|
||||||
logger.info("DDL SQL: [{}->{}] {} ", source.name(), target.name(), sql);
|
logger.info("DDL SQL: [{}->{}] {} ", source.name(), target.name(), sql);
|
||||||
SqlParser.Config config = SqlParser.configBuilder()
|
SqlParser.Config config = SqlParser.configBuilder()
|
||||||
.setParserFactory(SqlDdlParserImpl.FACTORY)
|
.setParserFactory(SqlDdlParserImpl.FACTORY)
|
||||||
@@ -193,7 +193,7 @@ public class CalciteSqlConvertServiceImpl implements ISqlConvertService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String dclSentence(DatabaseTypeEnum source,DatabaseTypeEnum target,String sql) {
|
public String dclSentence(ProductTypeEnum source, ProductTypeEnum target,String sql) {
|
||||||
throw new RuntimeException("Unimplement!");
|
throw new RuntimeException("Unimplement!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -11,7 +11,7 @@ package com.gitee.dbswitch.sql.service.impl;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import com.gitee.dbswitch.common.type.DatabaseTypeEnum;
|
import com.gitee.dbswitch.common.type.ProductTypeEnum;
|
||||||
import com.gitee.dbswitch.sql.service.ISqlGeneratorService;
|
import com.gitee.dbswitch.sql.service.ISqlGeneratorService;
|
||||||
import com.gitee.dbswitch.sql.ddl.AbstractDatabaseDialect;
|
import com.gitee.dbswitch.sql.ddl.AbstractDatabaseDialect;
|
||||||
import com.gitee.dbswitch.sql.ddl.AbstractSqlDdlOperator;
|
import com.gitee.dbswitch.sql.ddl.AbstractSqlDdlOperator;
|
||||||
@@ -33,16 +33,16 @@ import com.gitee.dbswitch.sql.ddl.sql.impl.PostgresDialectImpl;
|
|||||||
*/
|
*/
|
||||||
public class MyselfSqlGeneratorServiceImpl implements ISqlGeneratorService {
|
public class MyselfSqlGeneratorServiceImpl implements ISqlGeneratorService {
|
||||||
|
|
||||||
private static final Map<DatabaseTypeEnum, String> DATABASE_MAPPER = new HashMap<DatabaseTypeEnum, String>();
|
private static final Map<ProductTypeEnum, String> DATABASE_MAPPER = new HashMap<ProductTypeEnum, String>();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
DATABASE_MAPPER.put(DatabaseTypeEnum.MYSQL, MySqlDialectImpl.class.getName());
|
DATABASE_MAPPER.put(ProductTypeEnum.MYSQL, MySqlDialectImpl.class.getName());
|
||||||
DATABASE_MAPPER.put(DatabaseTypeEnum.ORACLE, OracleDialectImpl.class.getName());
|
DATABASE_MAPPER.put(ProductTypeEnum.ORACLE, OracleDialectImpl.class.getName());
|
||||||
DATABASE_MAPPER.put(DatabaseTypeEnum.POSTGRESQL, PostgresDialectImpl.class.getName());
|
DATABASE_MAPPER.put(ProductTypeEnum.POSTGRESQL, PostgresDialectImpl.class.getName());
|
||||||
DATABASE_MAPPER.put(DatabaseTypeEnum.GREENPLUM, GreenplumDialectImpl.class.getName());
|
DATABASE_MAPPER.put(ProductTypeEnum.GREENPLUM, GreenplumDialectImpl.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AbstractDatabaseDialect getDatabaseInstance(DatabaseTypeEnum type) {
|
public static AbstractDatabaseDialect getDatabaseInstance(ProductTypeEnum type) {
|
||||||
if (DATABASE_MAPPER.containsKey(type)) {
|
if (DATABASE_MAPPER.containsKey(type)) {
|
||||||
String className = DATABASE_MAPPER.get(type);
|
String className = DATABASE_MAPPER.get(type);
|
||||||
try {
|
try {
|
||||||
@@ -57,7 +57,7 @@ public class MyselfSqlGeneratorServiceImpl implements ISqlGeneratorService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String createTable(String dbType, TableDefinition t) {
|
public String createTable(String dbType, TableDefinition t) {
|
||||||
DatabaseTypeEnum type = DatabaseTypeEnum.valueOf(dbType.toUpperCase());
|
ProductTypeEnum type = ProductTypeEnum.valueOf(dbType.toUpperCase());
|
||||||
AbstractDatabaseDialect dialect = getDatabaseInstance(type);
|
AbstractDatabaseDialect dialect = getDatabaseInstance(type);
|
||||||
AbstractSqlDdlOperator operator = new DdlSqlCreateTable(t);
|
AbstractSqlDdlOperator operator = new DdlSqlCreateTable(t);
|
||||||
return operator.toSqlString(dialect);
|
return operator.toSqlString(dialect);
|
||||||
@@ -65,7 +65,7 @@ public class MyselfSqlGeneratorServiceImpl implements ISqlGeneratorService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String alterTable(String dbType, String handle, TableDefinition t){
|
public String alterTable(String dbType, String handle, TableDefinition t){
|
||||||
DatabaseTypeEnum type = DatabaseTypeEnum.valueOf(dbType.toUpperCase());
|
ProductTypeEnum type = ProductTypeEnum.valueOf(dbType.toUpperCase());
|
||||||
AbstractDatabaseDialect dialect = getDatabaseInstance(type);
|
AbstractDatabaseDialect dialect = getDatabaseInstance(type);
|
||||||
AbstractSqlDdlOperator operator = new DdlSqlAlterTable(t,handle);
|
AbstractSqlDdlOperator operator = new DdlSqlAlterTable(t,handle);
|
||||||
return operator.toSqlString(dialect);
|
return operator.toSqlString(dialect);
|
||||||
@@ -73,7 +73,7 @@ public class MyselfSqlGeneratorServiceImpl implements ISqlGeneratorService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String dropTable(String dbType, TableDefinition t) {
|
public String dropTable(String dbType, TableDefinition t) {
|
||||||
DatabaseTypeEnum type = DatabaseTypeEnum.valueOf(dbType.toUpperCase());
|
ProductTypeEnum type = ProductTypeEnum.valueOf(dbType.toUpperCase());
|
||||||
AbstractDatabaseDialect dialect = getDatabaseInstance(type);
|
AbstractDatabaseDialect dialect = getDatabaseInstance(type);
|
||||||
AbstractSqlDdlOperator operator = new DdlSqlDropTable(t);
|
AbstractSqlDdlOperator operator = new DdlSqlDropTable(t);
|
||||||
return operator.toSqlString(dialect);
|
return operator.toSqlString(dialect);
|
||||||
@@ -81,7 +81,7 @@ public class MyselfSqlGeneratorServiceImpl implements ISqlGeneratorService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String truncateTable(String dbType, TableDefinition t) {
|
public String truncateTable(String dbType, TableDefinition t) {
|
||||||
DatabaseTypeEnum type = DatabaseTypeEnum.valueOf(dbType.toUpperCase());
|
ProductTypeEnum type = ProductTypeEnum.valueOf(dbType.toUpperCase());
|
||||||
AbstractDatabaseDialect dialect = getDatabaseInstance(type);
|
AbstractDatabaseDialect dialect = getDatabaseInstance(type);
|
||||||
AbstractSqlDdlOperator operator = new DdlSqlTruncateTable(t);
|
AbstractSqlDdlOperator operator = new DdlSqlTruncateTable(t);
|
||||||
return operator.toSqlString(dialect);
|
return operator.toSqlString(dialect);
|
||||||
|
Reference in New Issue
Block a user