Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
holmes
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
QA
holmes
Commits
cd1a39af
Commit
cd1a39af
authored
Oct 18, 2021
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fix
parent
a2f3e9ec
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
17 deletions
+19
-17
DbSyncController.java
...java/cn/qg/holmes/controller/effect/DbSyncController.java
+4
-4
DatabaseSyncServiceImpl.java
...g/holmes/service/effect/impl/DatabaseSyncServiceImpl.java
+15
-13
No files found.
src/main/java/cn/qg/holmes/controller/effect/DbSyncController.java
View file @
cd1a39af
...
@@ -119,17 +119,17 @@ public class DbSyncController {
...
@@ -119,17 +119,17 @@ public class DbSyncController {
/**
/**
* 同步表结构
* 同步表结构
* @param
i
p
* @param
targetI
p
* @param
p
ort
* @param
targetP
ort
* @param database
* @param database
* @param table
* @param table
* @return
* @return
*/
*/
@GetMapping
(
"/table/structure"
)
@GetMapping
(
"/table/structure"
)
public
JsonResult
handleTableStructure
(
@RequestParam
String
ip
,
@RequestParam
String
p
ort
,
@RequestParam
String
database
,
@RequestParam
String
table
)
{
public
JsonResult
handleTableStructure
(
@RequestParam
String
targetIp
,
@RequestParam
String
targetP
ort
,
@RequestParam
String
database
,
@RequestParam
String
table
)
{
try
{
try
{
databaseSyncService
.
getSourceDbStructure
(
ip
,
port
,
username
,
password
,
database
,
table
);
databaseSyncService
.
getSourceDbStructure
(
ip
,
port
,
username
,
password
,
database
,
table
);
databaseSyncService
.
syncDbStructureToDest
(
ip
,
p
ort
,
"qa"
,
"qatest"
,
database
,
table
);
databaseSyncService
.
syncDbStructureToDest
(
targetIp
,
targetP
ort
,
"qa"
,
"qatest"
,
database
,
table
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
return
JsonResult
.
buildErrorStateResult
(
"创建表结构失败!"
,
false
);
return
JsonResult
.
buildErrorStateResult
(
"创建表结构失败!"
,
false
);
...
...
src/main/java/cn/qg/holmes/service/effect/impl/DatabaseSyncServiceImpl.java
View file @
cd1a39af
...
@@ -667,7 +667,7 @@ public class DatabaseSyncServiceImpl implements DatabaseSyncService {
...
@@ -667,7 +667,7 @@ public class DatabaseSyncServiceImpl implements DatabaseSyncService {
String
url
=
"jdbc:mysql://"
+
ip
+
":"
+
port
+
"/"
+
dbName
;
String
url
=
"jdbc:mysql://"
+
ip
+
":"
+
port
+
"/"
+
dbName
;
Connection
connection
=
null
;
Connection
connection
=
null
;
Statement
s
tatement
=
null
;
PreparedStatement
preparedS
tatement
=
null
;
try
{
try
{
Class
.
forName
(
driver
);
Class
.
forName
(
driver
);
...
@@ -682,28 +682,29 @@ public class DatabaseSyncServiceImpl implements DatabaseSyncService {
...
@@ -682,28 +682,29 @@ public class DatabaseSyncServiceImpl implements DatabaseSyncService {
String
tableRedisKey
=
dbSyncPrefix
+
dbName
+
":"
+
table
+
":create"
;
String
tableRedisKey
=
dbSyncPrefix
+
dbName
+
":"
+
table
+
":create"
;
if
(!
redisUtils
.
hasKey
(
tableRedisKey
))
{
if
(!
redisUtils
.
hasKey
(
tableRedisKey
))
{
String
sql
=
String
.
format
(
"SHOW CREATE TABLE %s"
,
table
);
String
sql
=
String
.
format
(
"SHOW CREATE TABLE %s"
,
table
);
statement
=
connection
.
createStatement
(
);
preparedStatement
=
connection
.
prepareStatement
(
sql
);
ResultSet
resultSet
=
statement
.
executeQuery
(
sql
);
ResultSet
resultSet
=
preparedStatement
.
executeQuery
(
);
while
(
resultSet
.
next
())
{
while
(
resultSet
.
next
())
{
redisUtils
.
set
(
tableRedisKey
,
resultSet
.
getString
(
2
),
600
);
redisUtils
.
set
(
tableRedisKey
,
resultSet
.
getString
(
2
),
600
);
}
}
resultSet
.
close
();
resultSet
.
close
();
s
tatement
.
clearBatch
();
preparedS
tatement
.
clearBatch
();
}
}
}
}
}
else
{
}
else
{
String
tableRedisKey
=
dbSyncPrefix
+
dbName
+
":"
+
tableName
+
":create"
;
String
tableRedisKey
=
dbSyncPrefix
+
dbName
+
":"
+
tableName
+
":create"
;
if
(!
redisUtils
.
hasKey
(
tableRedisKey
))
{
if
(!
redisUtils
.
hasKey
(
tableRedisKey
))
{
String
sql
=
String
.
format
(
"SHOW CREATE TABLE %s"
,
tableName
);
String
sql
=
String
.
format
(
"SHOW CREATE TABLE %s"
,
tableName
);
ResultSet
resultSet
=
statement
.
executeQuery
(
sql
);
preparedStatement
=
connection
.
prepareStatement
(
sql
);
ResultSet
resultSet
=
preparedStatement
.
executeQuery
();
while
(
resultSet
.
next
())
{
while
(
resultSet
.
next
())
{
redisUtils
.
set
(
tableRedisKey
,
resultSet
.
getString
(
2
),
600
);
redisUtils
.
set
(
tableRedisKey
,
resultSet
.
getString
(
2
),
600
);
}
}
resultSet
.
close
();
resultSet
.
close
();
}
}
s
tatement
.
clearBatch
();
preparedS
tatement
.
clearBatch
();
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
...
@@ -713,14 +714,14 @@ public class DatabaseSyncServiceImpl implements DatabaseSyncService {
...
@@ -713,14 +714,14 @@ public class DatabaseSyncServiceImpl implements DatabaseSyncService {
if
(
connection
!=
null
)
{
if
(
connection
!=
null
)
{
connection
.
close
();
connection
.
close
();
}
}
if
(
s
tatement
!=
null
)
{
if
(
preparedS
tatement
!=
null
)
{
s
tatement
.
close
();
preparedS
tatement
.
close
();
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
return
fals
e
;
return
tru
e
;
}
}
/**
/**
...
@@ -749,10 +750,9 @@ public class DatabaseSyncServiceImpl implements DatabaseSyncService {
...
@@ -749,10 +750,9 @@ public class DatabaseSyncServiceImpl implements DatabaseSyncService {
if
(
"all"
.
equals
(
tableName
))
{
if
(
"all"
.
equals
(
tableName
))
{
String
tableListKey
=
dbSyncPrefix
+
dbName
+
":tableList"
;
String
tableListKey
=
dbSyncPrefix
+
dbName
+
":tableList"
;
//
List<String> tableList = Arrays.asList(redisUtils.get(tableListKey).toString().split(" "));
List
<
String
>
tableList
=
Arrays
.
asList
(
redisUtils
.
get
(
tableListKey
).
toString
().
split
(
" "
));
// 删除key
// 删除key
// redisUtils.del(tableListKey);
redisUtils
.
del
(
tableListKey
);
List
<
String
>
tableList
=
getTableListByDb
(
ip
,
port
,
username
,
password
,
dbName
);
for
(
String
table:
tableList
)
{
for
(
String
table:
tableList
)
{
// 首先删除表
// 首先删除表
String
dropTableSql
=
"DROP TABLE IF EXISTS "
+
table
;
String
dropTableSql
=
"DROP TABLE IF EXISTS "
+
table
;
...
@@ -762,6 +762,7 @@ public class DatabaseSyncServiceImpl implements DatabaseSyncService {
...
@@ -762,6 +762,7 @@ public class DatabaseSyncServiceImpl implements DatabaseSyncService {
// 然后同步表结构
// 然后同步表结构
String
tableRedisKey
=
dbSyncPrefix
+
dbName
+
":"
+
table
+
":create"
;
String
tableRedisKey
=
dbSyncPrefix
+
dbName
+
":"
+
table
+
":create"
;
String
createTableSql
=
redisUtils
.
get
(
tableRedisKey
).
toString
();
String
createTableSql
=
redisUtils
.
get
(
tableRedisKey
).
toString
();
redisUtils
.
del
(
tableRedisKey
);
statement
.
execute
(
createTableSql
);
statement
.
execute
(
createTableSql
);
statement
.
clearBatch
();
statement
.
clearBatch
();
}
}
...
@@ -773,6 +774,7 @@ public class DatabaseSyncServiceImpl implements DatabaseSyncService {
...
@@ -773,6 +774,7 @@ public class DatabaseSyncServiceImpl implements DatabaseSyncService {
// 然后同步表结构
// 然后同步表结构
String
tableRedisKey
=
dbSyncPrefix
+
dbName
+
":"
+
tableName
+
":create"
;
String
tableRedisKey
=
dbSyncPrefix
+
dbName
+
":"
+
tableName
+
":create"
;
String
createTableSql
=
redisUtils
.
get
(
tableRedisKey
).
toString
();
String
createTableSql
=
redisUtils
.
get
(
tableRedisKey
).
toString
();
redisUtils
.
del
(
tableRedisKey
);
statement
.
execute
(
createTableSql
);
statement
.
execute
(
createTableSql
);
statement
.
clearBatch
();
statement
.
clearBatch
();
}
}
...
@@ -791,7 +793,7 @@ public class DatabaseSyncServiceImpl implements DatabaseSyncService {
...
@@ -791,7 +793,7 @@ public class DatabaseSyncServiceImpl implements DatabaseSyncService {
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
}
}
return
fals
e
;
return
tru
e
;
}
}
...
...
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