Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
neo4jRelation
Overview
Overview
Details
Activity
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
qiuchaofei
neo4jRelation
Commits
2fd8c237
Commit
2fd8c237
authored
Nov 12, 2021
by
mahx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改TempNode创建
parent
645ccfa1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
88 additions
and
40 deletions
+88
-40
MetaDataController.java
...adata/metadataRelation/controller/MetaDataController.java
+5
-4
TempNode.java
...om/keymobile/metadata/metadataRelation/pojo/TempNode.java
+36
-6
TempNodeRepository.java
...data/metadataRelation/respository/TempNodeRepository.java
+11
-3
IMetadataService.java
...e/metadata/metadataRelation/service/IMetadataService.java
+1
-2
MetadataServiceImpl.java
...ta/metadataRelation/service/impl/MetadataServiceImpl.java
+33
-23
MongoDbServiceImpl.java
...ata/metadataRelation/service/impl/MongoDbServiceImpl.java
+2
-2
No files found.
src/main/java/com/keymobile/metadata/metadataRelation/controller/MetaDataController.java
View file @
2fd8c237
...
@@ -550,6 +550,7 @@ public class MetaDataController {
...
@@ -550,6 +550,7 @@ public class MetaDataController {
logger
.
info
(
"开始同步元数据:从mongo到neo4j"
);
logger
.
info
(
"开始同步元数据:从mongo到neo4j"
);
String
flag
=
"success"
;
String
flag
=
"success"
;
metadataService
.
syschroRelationFromMongo
(
catalogName
);
metadataService
.
syschroRelationFromMongo
(
catalogName
);
metadataService
.
deleteTempNodeByCatalogName
(
catalogName
);
metadataService
.
createTempNode
(
catalogName
);
metadataService
.
createTempNode
(
catalogName
);
return
flag
;
return
flag
;
}
}
...
@@ -560,8 +561,8 @@ public class MetaDataController {
...
@@ -560,8 +561,8 @@ public class MetaDataController {
}
}
@PostMapping
(
"/removeTempRelation"
)
@PostMapping
(
"/removeTempRelation"
)
public
void
removeTempRelation
(
@RequestParam
String
sql
Id
,
@RequestParam
String
catalogName
)
{
public
void
removeTempRelation
(
@RequestParam
String
etlScript
Id
,
@RequestParam
String
catalogName
)
{
mongoDbService
.
removeTempRelation
(
sql
Id
,
catalogName
);
mongoDbService
.
removeTempRelation
(
etlScript
Id
,
catalogName
);
}
}
@PostMapping
(
"/createTempNode"
)
@PostMapping
(
"/createTempNode"
)
...
@@ -570,8 +571,8 @@ public class MetaDataController {
...
@@ -570,8 +571,8 @@ public class MetaDataController {
}
}
@PostMapping
(
"/deleteTempNode"
)
@PostMapping
(
"/deleteTempNode"
)
public
void
deleteTempNode
(
@RequestParam
String
sqlId
)
{
public
void
deleteTempNode
(
@RequestParam
String
catalogName
)
{
metadataService
.
deleteTempNode
(
sqlId
);
metadataService
.
deleteTempNode
ByCatalogName
(
catalogName
);
}
}
...
...
src/main/java/com/keymobile/metadata/metadataRelation/pojo/TempNode.java
View file @
2fd8c237
...
@@ -10,16 +10,46 @@ import org.neo4j.ogm.annotation.NodeEntity;
...
@@ -10,16 +10,46 @@ import org.neo4j.ogm.annotation.NodeEntity;
@NodeEntity
(
label
=
"TempNode"
)
@NodeEntity
(
label
=
"TempNode"
)
public
class
TempNode
extends
BaseNode
{
public
class
TempNode
extends
BaseNode
{
private
String
sqlId
;
private
String
metadataId
;
private
String
metadataId
;
public
String
getSqlId
()
{
private
String
etlScriptId
;
return
sqlId
;
private
String
etlJobId
;
private
String
catalogName
;
private
Long
parentId
;
public
String
getEtlScriptId
()
{
return
etlScriptId
;
}
public
void
setEtlScriptId
(
String
etlScriptId
)
{
this
.
etlScriptId
=
etlScriptId
;
}
public
String
getEtlJobId
()
{
return
etlJobId
;
}
public
void
setEtlJobId
(
String
etlJobId
)
{
this
.
etlJobId
=
etlJobId
;
}
public
String
getCatalogName
()
{
return
catalogName
;
}
public
void
setCatalogName
(
String
catalogName
)
{
this
.
catalogName
=
catalogName
;
}
public
Long
getParentId
()
{
return
parentId
;
}
}
public
void
set
SqlId
(
String
sql
Id
)
{
public
void
set
ParentId
(
Long
parent
Id
)
{
this
.
sqlId
=
sql
Id
;
this
.
parentId
=
parent
Id
;
}
}
public
String
getMetadataId
()
{
public
String
getMetadataId
()
{
...
...
src/main/java/com/keymobile/metadata/metadataRelation/respository/TempNodeRepository.java
View file @
2fd8c237
package
com
.
keymobile
.
metadata
.
metadataRelation
.
respository
;
package
com
.
keymobile
.
metadata
.
metadataRelation
.
respository
;
import
java.util.List
;
import
com.keymobile.metadata.metadataRelation.pojo.TempNode
;
import
com.keymobile.metadata.metadataRelation.pojo.TempNode
;
import
org.springframework.data.neo4j.annotation.Query
;
import
org.springframework.data.neo4j.annotation.Query
;
import
org.springframework.data.neo4j.repository.Neo4jRepository
;
import
org.springframework.data.neo4j.repository.Neo4jRepository
;
...
@@ -12,8 +14,14 @@ import org.springframework.data.repository.query.Param;
...
@@ -12,8 +14,14 @@ import org.springframework.data.repository.query.Param;
*/
*/
public
interface
TempNodeRepository
extends
Neo4jRepository
<
TempNode
,
Long
>
{
public
interface
TempNodeRepository
extends
Neo4jRepository
<
TempNode
,
Long
>
{
Long
deleteTempNodesBySqlId
(
String
sqlId
);
Long
deleteTempNodesByEtlScriptId
(
String
etlScriptId
);
Long
deleteTempNodesByEtlJobId
(
String
etlJobId
);
Long
deleteTempNodesByCatalogName
(
String
catalogName
);
@Query
(
"match (source:BaseNode)-[r]-(target:BaseNode) where source.catalogName=$catalogName or target.catalogName=$catalogName delete r"
)
Long
deleteAllRelation
(
@Param
(
"catalogName"
)
String
catalogName
);
@Query
(
"match (source:BaseNode)-[r]-(target:BaseNode) where source.sqlId=$sqlId or target.sqlId=$sqlId delete r"
)
List
<
TempNode
>
findByCatalogNameAndEtlJobIdAndParentIdAndName
(
String
catalogName
,
String
etlJobId
,
Long
parentId
,
String
name
);
Long
deleteAllRelation
(
@Param
(
"sqlId"
)
String
sqlId
);
}
}
src/main/java/com/keymobile/metadata/metadataRelation/service/IMetadataService.java
View file @
2fd8c237
...
@@ -4,7 +4,6 @@ import com.keymobile.metadata.metadataRelation.pojo.BaseRelationship;
...
@@ -4,7 +4,6 @@ import com.keymobile.metadata.metadataRelation.pojo.BaseRelationship;
import
com.keymobile.metadata.metadataRelation.pojo.MetaData
;
import
com.keymobile.metadata.metadataRelation.pojo.MetaData
;
import
com.keymobile.metadata.metadataRelation.pojo.TempNode
;
import
com.keymobile.metadata.metadataRelation.pojo.TempNode
;
import
com.keymobile.metadata.metadataRelation.pojo.returnBean.ReturnReslult
;
import
com.keymobile.metadata.metadataRelation.pojo.returnBean.ReturnReslult
;
import
org.springframework.data.mongodb.core.query.Meta
;
import
java.util.List
;
import
java.util.List
;
...
@@ -73,7 +72,7 @@ public interface IMetadataService {
...
@@ -73,7 +72,7 @@ public interface IMetadataService {
void
createTempNode
(
String
catalogName
);
void
createTempNode
(
String
catalogName
);
void
deleteTempNode
(
String
sqlId
);
void
deleteTempNode
ByCatalogName
(
String
catalogName
);
List
<
TempNode
>
findAllTempNode
();
List
<
TempNode
>
findAllTempNode
();
}
}
src/main/java/com/keymobile/metadata/metadataRelation/service/impl/MetadataServiceImpl.java
View file @
2fd8c237
...
@@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
...
@@ -22,6 +22,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.CollectionUtils
;
import
java.util.*
;
import
java.util.*
;
...
@@ -404,27 +405,38 @@ public class MetadataServiceImpl implements IMetadataService {
...
@@ -404,27 +405,38 @@ public class MetadataServiceImpl implements IMetadataService {
return
labels
;
return
labels
;
}
}
private
Long
createNode
(
Map
<
String
,
Long
>
nameIdMap
,
String
sqlId
,
String
name
,
boolean
isTable
)
{
private
Long
createNode
(
Map
<
String
,
Long
>
nameIdMap
,
String
catalogName
,
String
etlJobId
,
String
etlScriptId
,
String
name
,
boolean
isTable
,
Long
parentId
)
{
Long
nodeId
=
nameIdMap
.
get
(
name
);
String
identifier
=
String
.
format
(
"%s,%s,%s"
,
etlJobId
,
parentId
,
name
);
Long
nodeId
=
nameIdMap
.
get
(
identifier
);
if
(
nodeId
==
null
)
{
if
(
nodeId
==
null
)
{
String
[]
split
=
StringUtils
.
split
(
name
,
'.'
);
String
[]
split
=
StringUtils
.
split
(
name
,
'.'
);
if
(
split
.
length
==
2
)
{
if
(
split
.
length
==
2
)
{
String
tableName
=
split
[
0
];
String
tableName
=
split
[
0
];
String
columnName
=
split
[
1
];
String
columnName
=
split
[
1
];
Long
tableId
=
createNode
(
nameIdMap
,
sqlId
,
tableName
,
true
);
Long
tableId
=
createNode
(
nameIdMap
,
catalogName
,
etlJobId
,
etlScriptId
,
tableName
,
true
,
null
);
nodeId
=
createNode
(
nameIdMap
,
sqlId
,
columnName
,
false
);
nodeId
=
createNode
(
nameIdMap
,
catalogName
,
etlJobId
,
etlScriptId
,
columnName
,
false
,
tableId
);
if
(
tableId
!=
null
&&
nodeId
!=
null
)
{
if
(
tableId
!=
null
&&
nodeId
!=
null
)
{
compositionRelationRespository
.
mergeConpositionRelation
(
tableId
,
nodeId
);
compositionRelationRespository
.
mergeConpositionRelation
(
tableId
,
nodeId
);
}
}
}
else
{
}
else
{
TempNode
tempNode
=
new
TempNode
();
TempNode
tempNode
;
String
modelName
=
isTable
?
"TempTable"
:
"TempColumn"
;
List
<
TempNode
>
list
=
tempNodeRepository
.
findByCatalogNameAndEtlJobIdAndParentIdAndName
(
catalogName
,
etlJobId
,
parentId
,
name
);
tempNode
.
setMetadataId
(
modelName
+
"="
+
UUID
.
randomUUID
());
if
(!
CollectionUtils
.
isEmpty
(
list
))
{
tempNode
.
setName
(
name
);
tempNode
=
list
.
get
(
0
);
tempNode
.
setSqlId
(
sqlId
);
}
else
{
tempNode
=
new
TempNode
();
String
modelName
=
isTable
?
"TempTable"
:
"TempColumn"
;
tempNode
.
setMetadataId
(
modelName
+
"="
+
UUID
.
randomUUID
());
tempNode
.
setCatalogName
(
catalogName
);
tempNode
.
setEtlJobId
(
etlJobId
);
tempNode
.
setEtlScriptId
(
etlScriptId
);
tempNode
.
setName
(
name
);
}
tempNode
.
setParentId
(
parentId
);
tempNode
=
tempNodeRepository
.
save
(
tempNode
);
tempNode
=
tempNodeRepository
.
save
(
tempNode
);
nodeId
=
tempNode
.
getId
();
nodeId
=
tempNode
.
getId
();
nameIdMap
.
put
(
name
,
nodeId
);
nameIdMap
.
put
(
identifier
,
nodeId
);
}
}
}
}
return
nodeId
;
return
nodeId
;
...
@@ -434,23 +446,21 @@ public class MetadataServiceImpl implements IMetadataService {
...
@@ -434,23 +446,21 @@ public class MetadataServiceImpl implements IMetadataService {
public
void
createTempNode
(
String
catalogName
)
{
public
void
createTempNode
(
String
catalogName
)
{
int
page
=
0
,
pageSize
=
500
;
int
page
=
0
,
pageSize
=
500
;
long
totalElement
=
mongoDbServiceImpl
.
countTempRelation
(
PageRequest
.
of
(
page
,
pageSize
),
catalogName
);
long
totalElement
=
mongoDbServiceImpl
.
countTempRelation
(
PageRequest
.
of
(
page
,
pageSize
),
catalogName
);
Map
<
String
,
Long
>
sqlIdNodeIdMap
=
new
HashMap
<>();
Map
<
String
,
Long
>
nameIdMap
=
new
HashMap
<>();
Map
<
String
,
Long
>
nameIdMap
=
new
HashMap
<>();
for
(;
page
<
totalElement
;
page
+=
pageSize
)
{
for
(;
page
<
totalElement
;
page
+=
pageSize
)
{
List
<
JSONObject
>
list
=
mongoDbServiceImpl
.
findTempRelationByPage
(
PageRequest
.
of
(
page
,
pageSize
,
Sort
.
by
(
"
sql
Id"
)),
catalogName
);
List
<
JSONObject
>
list
=
mongoDbServiceImpl
.
findTempRelationByPage
(
PageRequest
.
of
(
page
,
pageSize
,
Sort
.
by
(
"
etlJob
Id"
)),
catalogName
);
for
(
JSONObject
relation
:
list
)
{
for
(
JSONObject
relation
:
list
)
{
String
sqlId
=
relation
.
getString
(
"sqlId"
);
String
sqlId
=
relation
.
getString
(
"etlSqlId"
);
deleteTempNode
(
sqlId
);
String
etlScriptId
=
relation
.
getString
(
"etlScriptId"
);
String
etlJobId
=
relation
.
getString
(
"etlJobId"
);
deleteTempNodeByCatalogName
(
sqlId
);
MetaData
metadata
=
metadataRepository
.
findMetaDataByMetadataId
(
sqlId
);
MetaData
metadata
=
metadataRepository
.
findMetaDataByMetadataId
(
sqlId
);
if
(
metadata
==
null
)
{
if
(
metadata
==
null
)
{
logger
.
error
(
"id : {} is not found"
,
sqlId
);
logger
.
error
(
"id : {} is not found"
,
sqlId
);
continue
;
continue
;
}
}
Long
id
=
metadata
.
getId
();
Long
id
=
metadata
.
getId
();
if
(!
sqlIdNodeIdMap
.
containsKey
(
sqlId
))
{
sqlIdNodeIdMap
.
put
(
sqlId
,
id
);
nameIdMap
=
new
HashMap
<>();
}
String
source
=
relation
.
getString
(
"source"
);
String
source
=
relation
.
getString
(
"source"
);
String
target
=
relation
.
getString
(
"target"
);
String
target
=
relation
.
getString
(
"target"
);
if
(
StringUtils
.
isBlank
(
source
)
||
StringUtils
.
isBlank
(
target
))
{
if
(
StringUtils
.
isBlank
(
source
)
||
StringUtils
.
isBlank
(
target
))
{
...
@@ -459,13 +469,13 @@ public class MetadataServiceImpl implements IMetadataService {
...
@@ -459,13 +469,13 @@ public class MetadataServiceImpl implements IMetadataService {
String
type
=
relation
.
getString
(
"type"
);
String
type
=
relation
.
getString
(
"type"
);
if
(
"Input"
.
equalsIgnoreCase
(
type
))
{
if
(
"Input"
.
equalsIgnoreCase
(
type
))
{
Long
nodeId
=
createNode
(
nameIdMap
,
sqlId
,
source
,
false
);
Long
nodeId
=
createNode
(
nameIdMap
,
catalogName
,
etlJobId
,
etlScriptId
,
source
,
false
,
null
);
if
(
nodeId
!=
null
)
{
if
(
nodeId
!=
null
)
{
inputRelationReRepository
.
mergeInputRelation
(
nodeId
,
id
);
inputRelationReRepository
.
mergeInputRelation
(
nodeId
,
id
);
}
}
}
}
if
(
"Output"
.
equalsIgnoreCase
(
type
))
{
if
(
"Output"
.
equalsIgnoreCase
(
type
))
{
Long
nodeId
=
createNode
(
nameIdMap
,
sqlId
,
target
,
false
);
Long
nodeId
=
createNode
(
nameIdMap
,
catalogName
,
etlJobId
,
etlScriptId
,
target
,
false
,
null
);
if
(
nodeId
!=
null
)
{
if
(
nodeId
!=
null
)
{
outputRelationRepository
.
mergeOutRelation
(
id
,
nodeId
);
outputRelationRepository
.
mergeOutRelation
(
id
,
nodeId
);
}
}
...
@@ -475,9 +485,9 @@ public class MetadataServiceImpl implements IMetadataService {
...
@@ -475,9 +485,9 @@ public class MetadataServiceImpl implements IMetadataService {
}
}
@Override
@Override
public
void
deleteTempNode
(
String
sqlId
)
{
public
void
deleteTempNode
ByCatalogName
(
String
catalogName
)
{
tempNodeRepository
.
deleteAllRelation
(
sqlId
);
tempNodeRepository
.
deleteAllRelation
(
catalogName
);
tempNodeRepository
.
deleteTempNodesBy
SqlId
(
sqlId
);
tempNodeRepository
.
deleteTempNodesBy
CatalogName
(
catalogName
);
}
}
@Override
@Override
...
...
src/main/java/com/keymobile/metadata/metadataRelation/service/impl/MongoDbServiceImpl.java
View file @
2fd8c237
...
@@ -60,8 +60,8 @@ public class MongoDbServiceImpl {
...
@@ -60,8 +60,8 @@ public class MongoDbServiceImpl {
list
.
forEach
(
o
->
mongoTemplate
.
save
(
o
,
PREFIX_MD_RELATION_TEMP_NODE
+
catalogName
));
list
.
forEach
(
o
->
mongoTemplate
.
save
(
o
,
PREFIX_MD_RELATION_TEMP_NODE
+
catalogName
));
}
}
public
void
removeTempRelation
(
String
sql
Id
,
String
catalogName
)
{
public
void
removeTempRelation
(
String
etlScript
Id
,
String
catalogName
)
{
Query
query
=
Query
.
query
(
Criteria
.
where
(
"
sqlId"
).
is
(
sql
Id
));
Query
query
=
Query
.
query
(
Criteria
.
where
(
"
etlScriptId"
).
is
(
etlScript
Id
));
mongoTemplate
.
remove
(
query
,
PREFIX_MD_RELATION_TEMP_NODE
+
catalogName
);
mongoTemplate
.
remove
(
query
,
PREFIX_MD_RELATION_TEMP_NODE
+
catalogName
);
}
}
...
...
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