Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jz-dmp-cmdexectool
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
姚本章
jz-dmp-cmdexectool
Commits
4e1937ae
Commit
4e1937ae
authored
Mar 08, 2021
by
mcb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit
parent
ef06f173
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
62 deletions
+106
-62
SyncParameters.java
...mdexectool/scheduler/common/task/sync/SyncParameters.java
+106
-62
No files found.
src/main/java/com/jz/dmp/cmdexectool/scheduler/common/task/sync/SyncParameters.java
View file @
4e1937ae
...
...
@@ -9,6 +9,7 @@ import com.jz.dmp.cmdexectool.entity.DmpSyncingDatasource;
import
com.jz.dmp.cmdexectool.mapper.DmpSyncingDatasourceDao
;
import
com.jz.dmp.cmdexectool.scheduler.common.process.ResourceInfo
;
import
com.jz.dmp.cmdexectool.scheduler.common.task.AbstractParameters
;
import
com.jz.dmp.cmdexectool.scheduler.dao.datasource.MyBaseDataSource
;
import
org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer
;
import
java.util.ArrayList
;
...
...
@@ -62,6 +63,26 @@ public class SyncParameters extends AbstractParameters {
*/
private
List
<
ResourceInfo
>
resourceList
;
/**
* 前导语句
*/
private
List
<
String
>
preStatements
;
/**
* 后导语句
*/
private
List
<
String
>
posStatements
;
/**
* 源数据源
*/
private
MyBaseDataSource
sourceBaseDataSource
;
/**
* 目标数据源
*/
private
MyBaseDataSource
targetBaseDataSource
;
public
SyncParameters
(
String
script
,
DmpProjectConfigInfoDto
projectConfigInfoDto
,
DmpSyncingDatasourceDao
dmpSyncingDatasourceDao
,
FreeMarkerConfigurer
freeMarkerConfig
)
throws
Exception
{
source
=
""
;
env
=
""
;
...
...
@@ -84,53 +105,39 @@ public class SyncParameters extends AbstractParameters {
Integer
sourceId
=
Integer
.
valueOf
((
String
)
sourceObj
.
get
(
"sourceDbId"
));
DmpSyncingDatasource
dmpSyncingDatasource
=
dmpSyncingDatasourceDao
.
queryById
(
sourceId
);
Integer
sourceTypeId
=
dmpSyncingDatasource
.
getDatasourceType
();
String
source_table_name
=
String
.
valueOf
(
sourceObj
.
get
(
"registerTableName"
));
String
[]
registerTableName
=
((
String
)
sourceObj
.
get
(
"registerTableName"
)).
split
(
","
);
//target information
Integer
targetDbId
=
Integer
.
valueOf
((
String
)
targetObj
.
get
(
"targetDbId"
));
DmpSyncingDatasource
targetDatasource
=
dmpSyncingDatasourceDao
.
queryById
(
targetDbId
);
Integer
targetTypeId
=
dmpSyncingDatasource
.
getDatasourceType
();
//Jdbc(MySQL、Oracle、SqlServer、PostgreSQL、Informix、DB2)
if
((
sourceTypeId
==
DatasouceTypeConstant
.
MySQL
||
sourceTypeId
==
DatasouceTypeConstant
.
Oracle
||
sourceTypeId
==
DatasouceTypeConstant
.
SqlServer
||
sourceTypeId
==
DatasouceTypeConstant
.
PostgreSQL
||
sourceTypeId
==
DatasouceTypeConstant
.
Informix
||
sourceTypeId
==
DatasouceTypeConstant
.
DB2
))
{
String
targetTable
=
String
.
valueOf
(
targetObj
.
get
(
"targetTable"
));
//目标表
String
postImportStatement
=
String
.
valueOf
(
targetObj
.
get
(
"postImportStatement"
));
//导入后语句
String
preImportStatement
=
String
.
valueOf
(
targetObj
.
get
(
"preImportStatement"
));
//导入前语句
preStatements
=
new
ArrayList
<
String
>();
preStatements
.
add
(
preImportStatement
);
posStatements
=
new
ArrayList
<
String
>();
posStatements
.
add
(
postImportStatement
);
//产生 Jdbc(MySQL、Oracle、SqlServer、PostgreSQL、Informix、DB2) source
if
((
sourceTypeId
==
DatasouceTypeConstant
.
MySQL
||
sourceTypeId
==
DatasouceTypeConstant
.
Oracle
||
sourceTypeId
==
DatasouceTypeConstant
.
SqlServer
||
sourceTypeId
==
DatasouceTypeConstant
.
PostgreSQL
||
sourceTypeId
==
DatasouceTypeConstant
.
Informix
||
sourceTypeId
==
DatasouceTypeConstant
.
DB2
))
{
//source
for
(
String
tableName
:
registerTableName
)
{
Map
jdbcModel
=
new
HashMap
();
jdbcModel
.
put
(
"driver"
,
dmpSyncingDatasource
.
getDriverClassName
());
jdbcModel
.
put
(
"url"
,
dmpSyncingDatasource
.
getJdbcUrl
());
jdbcModel
.
put
(
"table"
,
tableName
);
jdbcModel
.
put
(
"result_table_name"
,
tableName
);
jdbcModel
.
put
(
"user"
,
dmpSyncingDatasource
.
getUserName
());
jdbcModel
.
put
(
"password"
,
dmpSyncingDatasource
.
getPassword
());
jdbcModel
.
put
(
"partitionColumn"
,
""
);
jdbcModel
.
put
(
"numPartitions"
,
""
);
jdbcModel
.
put
(
"lowerBound"
,
""
);
jdbcModel
.
put
(
"upperBound"
,
""
);
source
=
source
+
FreeMarkerUtils
.
freemakerJson
(
CommConstant
.
WATERDROP_FTL_SOURCE_JDBC
,
jdbcModel
,
freeMarkerConfig
);
}
}
//Jdbc(MySQL、Oracle、SqlServer、PostgreSQL、Informix、DB2)
if
((
targetTypeId
==
DatasouceTypeConstant
.
MySQL
||
targetTypeId
==
DatasouceTypeConstant
.
Oracle
||
targetTypeId
==
DatasouceTypeConstant
.
SqlServer
||
targetTypeId
==
DatasouceTypeConstant
.
PostgreSQL
||
targetTypeId
==
DatasouceTypeConstant
.
Informix
||
targetTypeId
==
DatasouceTypeConstant
.
DB2
))
{
//sink
Map
jdbcSinkModel
=
new
HashMap
();
jdbcSinkModel
.
put
(
"driver"
,
targetDatasource
.
getDriverClassName
());
jdbcSinkModel
.
put
(
"url"
,
targetDatasource
.
getJdbcUrl
());
//# 存储模式,支持overwrite、append、update、ignore、error
jdbcSinkModel
.
put
(
"save_mode"
,
targetObj
.
get
(
"targetInsertMergeOverwrite"
));
//当存储模式是 overwrite时,仅清除表中数据
if
(
null
!=
targetObj
.
get
(
"targetInsertMergeOverwrite"
))
{
if
(
"overwrite"
.
equals
(
targetObj
.
get
(
"targetInsertMergeOverwrite"
)))
{
jdbcSinkModel
.
put
(
"truncate"
,
"true"
);
}
else
{
jdbcSinkModel
.
put
(
"truncate"
,
"false"
);
}
getJdbcSource
(
dmpSyncingDatasource
,
registerTableName
,
freeMarkerConfig
);
}
jdbcSinkModel
.
put
(
"dbtable"
,
targetObj
.
get
(
"targetTable"
));
//目标表
jdbcSinkModel
.
put
(
"user"
,
targetDatasource
.
getUserName
());
jdbcSinkModel
.
put
(
"password"
,
targetDatasource
.
getPassword
());
sink
=
FreeMarkerUtils
.
freemakerJson
(
CommConstant
.
WATERDROP_FTL_SINK_JDBC
,
jdbcSinkModel
,
freeMarkerConfig
);
//产生 Jdbc(MySQL、Oracle、SqlServer、PostgreSQL、Informix、DB2) sink
if
((
targetTypeId
==
DatasouceTypeConstant
.
MySQL
||
targetTypeId
==
DatasouceTypeConstant
.
Oracle
||
targetTypeId
==
DatasouceTypeConstant
.
SqlServer
||
targetTypeId
==
DatasouceTypeConstant
.
PostgreSQL
||
targetTypeId
==
DatasouceTypeConstant
.
Informix
||
targetTypeId
==
DatasouceTypeConstant
.
DB2
))
{
getJdbcSink
(
targetDatasource
,
targetObj
,
freeMarkerConfig
);
}
//transform
if
(
mappingObj
.
size
()
>
0
&&
null
!=
mappingObj
)
{
...
...
@@ -140,15 +147,14 @@ public class SyncParameters extends AbstractParameters {
sourceField
+=
","
+
item
.
get
(
"sourceField"
);
targetField
+=
","
+
item
.
get
(
"sourceField"
)
+
" as "
+
item
.
get
(
"targetField"
);
}
//for (String tableName : registerTableName) {
Map
sqlModel
=
new
HashMap
();
StringBuilder
sql
=
new
StringBuilder
()
.
append
(
" select "
)
.
append
(
" "
+
sourceField
.
substring
(
1
)
+
" "
)
.
append
(
" from "
)
.
append
(
" $t "
);
//.append(" " + registerTableName[0]);
sqlModel
.
put
(
"sql"
,
sql
);
sqlModel
.
put
(
"source_table_name"
,
source_table_name
);
//String table_name = registerTableName[0] + "_view";
//sqlModel.put("table_name", table_name);
transform
=
transform
+
FreeMarkerUtils
.
freemakerJson
(
CommConstant
.
WATERDROP_FTL_TRANSFORM_SQL
,
sqlModel
,
freeMarkerConfig
);
...
...
@@ -159,10 +165,10 @@ public class SyncParameters extends AbstractParameters {
.
append
(
" "
+
targetField
.
substring
(
1
)
+
" "
)
.
append
(
" from "
)
.
append
(
" $t "
);
//.append(" " + table_name);
targetModel
.
put
(
"sql"
,
targetSql
);
targetModel
.
put
(
"source_table_name"
,
targetTable
);
transform
=
transform
+
FreeMarkerUtils
.
freemakerJson
(
CommConstant
.
WATERDROP_FTL_TRANSFORM_SQL
,
targetModel
,
freeMarkerConfig
);
//}
}
/*if (mappingObj.size() > 0 && null != mappingObj) {
for (Map<String, Object> item : mappingObj) {
...
...
@@ -227,6 +233,44 @@ public class SyncParameters extends AbstractParameters {
waterdropScript
=
FreeMarkerUtils
.
freemakerJson
(
CommConstant
.
WATERDROP_FTL
,
waterdropModel
,
freeMarkerConfig
);
}
public
void
getJdbcSource
(
DmpSyncingDatasource
dmpSyncingDatasource
,
String
[]
registerTableName
,
FreeMarkerConfigurer
freeMarkerConfig
)
{
for
(
String
tableName
:
registerTableName
)
{
Map
jdbcModel
=
new
HashMap
();
jdbcModel
.
put
(
"driver"
,
dmpSyncingDatasource
.
getDriverClassName
());
jdbcModel
.
put
(
"url"
,
dmpSyncingDatasource
.
getJdbcUrl
());
jdbcModel
.
put
(
"table"
,
tableName
);
jdbcModel
.
put
(
"result_table_name"
,
tableName
);
jdbcModel
.
put
(
"user"
,
dmpSyncingDatasource
.
getUserName
());
jdbcModel
.
put
(
"password"
,
dmpSyncingDatasource
.
getPassword
());
jdbcModel
.
put
(
"partitionColumn"
,
""
);
jdbcModel
.
put
(
"numPartitions"
,
""
);
jdbcModel
.
put
(
"lowerBound"
,
""
);
jdbcModel
.
put
(
"upperBound"
,
""
);
source
=
source
+
FreeMarkerUtils
.
freemakerJson
(
CommConstant
.
WATERDROP_FTL_SOURCE_JDBC
,
jdbcModel
,
freeMarkerConfig
);
}
}
public
void
getJdbcSink
(
DmpSyncingDatasource
targetDatasource
,
Map
<
String
,
Object
>
targetObj
,
FreeMarkerConfigurer
freeMarkerConfig
){
//sink
Map
jdbcSinkModel
=
new
HashMap
();
jdbcSinkModel
.
put
(
"driver"
,
targetDatasource
.
getDriverClassName
());
jdbcSinkModel
.
put
(
"url"
,
targetDatasource
.
getJdbcUrl
());
//# 存储模式,支持overwrite、append、update、ignore、error
jdbcSinkModel
.
put
(
"save_mode"
,
targetObj
.
get
(
"targetInsertMergeOverwrite"
));
//当存储模式是 overwrite时,仅清除表中数据
if
(
null
!=
targetObj
.
get
(
"targetInsertMergeOverwrite"
))
{
if
(
"overwrite"
.
equals
(
targetObj
.
get
(
"targetInsertMergeOverwrite"
)))
{
jdbcSinkModel
.
put
(
"truncate"
,
"true"
);
}
else
{
jdbcSinkModel
.
put
(
"truncate"
,
"false"
);
}
}
jdbcSinkModel
.
put
(
"dbtable"
,
targetObj
.
get
(
"targetTable"
));
//目标表
jdbcSinkModel
.
put
(
"user"
,
targetDatasource
.
getUserName
());
jdbcSinkModel
.
put
(
"password"
,
targetDatasource
.
getPassword
());
sink
=
FreeMarkerUtils
.
freemakerJson
(
CommConstant
.
WATERDROP_FTL_SINK_JDBC
,
jdbcSinkModel
,
freeMarkerConfig
);
}
@Override
public
boolean
checkParameters
()
{
return
waterdropScript
!=
null
&&
!
waterdropScript
.
isEmpty
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment