Commit 28223c94 by qiuchaofei

1.修改获取neo4j session的方法

parent 0ab9e74f
......@@ -3,6 +3,7 @@ package com.keymobile.metadata.metadataRelation.config;
import org.neo4j.driver.v1.AuthTokens;
import org.neo4j.driver.v1.Driver;
import org.neo4j.driver.v1.GraphDatabase;
import org.neo4j.driver.v1.Session;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -20,18 +21,10 @@ public class Neo4jConfig {
@Value("${spring.data.neo4j.password}")
private String neo4jPassword;
private static Driver driver;
@Bean
public Driver getNeo4jConnection() {
if (driver != null) {
} else {
driver = GraphDatabase.driver(neo4jUrl, AuthTokens.basic(neo4jUsername, neo4jPassword));
}
return driver;
@Bean(name = "Session")
public Session getNeo4jSession() {
Driver driver = GraphDatabase.driver(neo4jUrl, AuthTokens.basic(neo4jUsername, neo4jPassword));
return driver.session();
}
}
......@@ -36,6 +36,8 @@ public class BaseRelationshipServiceImpl implements IBaseRelationshipService {
@Autowired
private ExecuteRelationRepository executeRelationRepository;
@Autowired
private Session session;
@Override
public List<BaseRelationship> findAllRelation() {
......@@ -79,9 +81,6 @@ public class BaseRelationshipServiceImpl implements IBaseRelationshipService {
List<String> relationTypes = new ArrayList<>();
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
String cypher = " MATCH (n)-[r]->() RETURN id(STARTNODE(r)) as startId,id(endNode(r)) as endId, type(r) as name";
logger.info("cypher:" + cypher);
StatementResult result = session.run(cypher);
......@@ -170,9 +169,9 @@ public class BaseRelationshipServiceImpl implements IBaseRelationshipService {
@Override
public void saveRelation(String startId, String endId, String relationType) {
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
// match (n{metadataId:"Column=1=d9c2d67e56a3428e8e4f22918782437f"}),
// (m{metadataId:"Table=1=d644b631fa8c434e928bcd1f1665b060"})
// create (n)<-[r:Composition]-(m)
......@@ -184,9 +183,9 @@ public class BaseRelationshipServiceImpl implements IBaseRelationshipService {
@Override
public void saveRelation(String startId, String endId, String relationType,String jobId) {
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
// match (n{metadataId:"Column=1=d9c2d67e56a3428e8e4f22918782437f"}),
// (m{metadataId:"Table=1=d644b631fa8c434e928bcd1f1665b060"})
// create (n)<-[r:Composition]-(m)
......@@ -199,9 +198,9 @@ public class BaseRelationshipServiceImpl implements IBaseRelationshipService {
@Override
public void saveRelation(String startId, String endId, String relationType,String jobId,String description) {
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
// match (n { metadataId:"Column=1=0c8a3201eaf349918363471496c19a96"}),
// ( m { metadataId:"SQL=1=b33fc95c948a43d7af504632bf6e7641"} )
// merge (n)-[r:流向]->(m)
......
......@@ -9,6 +9,7 @@ import org.neo4j.driver.v1.*;
import org.neo4j.driver.v1.types.Node;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
......@@ -20,6 +21,8 @@ public class DataRelationAnalyServiceImpl implements DataRelationAnalyService {
private static final Logger logger = LoggerFactory.getLogger(DataRelationAnalyServiceImpl.class);
@Autowired
private Session session;
@Override
public Map<String, ReturnNode> findTableWithoutRelations(String parentId) {
......@@ -27,9 +30,9 @@ public class DataRelationAnalyServiceImpl implements DataRelationAnalyService {
//区分传入的id是系统还是schema,还是为空,为空则找出所有的孤立点
//match (n:Neo4jTable) where not ((n)-[:`流向`]-(:Neo4jTable)) return n
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
String condition = "";
if(parentId !=null && parentId .startsWith("System=")){
......
......@@ -57,6 +57,11 @@ public class MetadataRelationServiceImpl implements IMetadataRelationService {
@Autowired
private IBaseRelationshipService relationshipService;
@Autowired
private Session session;
private String FORWARD = "forward";
private String BACKWARD = "backward";
private String tableModelName = "Table=";
......@@ -74,9 +79,9 @@ public class MetadataRelationServiceImpl implements IMetadataRelationService {
String cypher = getCypher(metadataId, direction, directionNeo4j);
Map<Long, MetaData> longMetaDataMap = new HashMap<>();
Map<String, ReturnEdge> edgeMap = new HashMap<>();
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
StatementResult result = session.run(cypher);
while(result.hasNext()){
Record record = result.next();
......@@ -391,9 +396,9 @@ public class MetadataRelationServiceImpl implements IMetadataRelationService {
@Override
public void deleteRelationByJobId(String catalogName, String jobId) {
try{
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
String cypher = "match (n)-[r:`流向`]-(m) where r.jobId ="+jobId +" delete r";
logger.info("删除数据的语句:"+cypher);
......
......@@ -110,6 +110,9 @@ public class MetadataServiceImpl implements IMetadataService {
}
@Autowired
private Session session;
@Autowired
private ITableService tableService;
private String OutputString = "Output";
......@@ -143,9 +146,9 @@ public class MetadataServiceImpl implements IMetadataService {
// List<MetaData> metaDataList = metadataRepository.findMetaData(metadataId,3);
List<MetaData> metaDataList = new ArrayList<>();
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
String cypher = "match data=(na:MetaData{metadataId:'" + metadataId + "'})<-[*1.." + depth + "]->(nb:MetaData) return data";
logger.info("cypher语句是:" + cypher);
StatementResult result = session.run(cypher);
......@@ -236,9 +239,9 @@ public class MetadataServiceImpl implements IMetadataService {
public ReturnReslult findResultByModelName(String modelName,int size) {
ReturnReslult returnReslult = new ReturnReslult();
// 先获取modelname的元数据,按每两个元数据去查找,查看是否有关系,注意关系方向
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
// match (n:MetaData ) where n.metadataId =~"Table=.*" return n
String cypher = "match (n:MetaData ) where n.metadataId =~\"" + modelName + ".*\" return n limit "+size;
logger.info("查询cypher :" + cypher);
......@@ -416,9 +419,9 @@ public class MetadataServiceImpl implements IMetadataService {
ReturnReslult returnReslult = new ReturnReslult();
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
// match (n:MetaData ) where n.metadataId =~"Table=.*" return n
String cypher = "match data=(na:softplatform)<-[r]->(nb:softplatform) return data " +
" union match data=(na:softplatform) return data " +
......@@ -540,9 +543,9 @@ public class MetadataServiceImpl implements IMetadataService {
logger.info("开始模糊查找:" + name);
Map<String, String> metadataId2Name = new HashMap<>();
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
//match (n:MetaData) where n.name=~'(?i).*APP.*' return n
String cypher ="match (n) where n.name=~'(?i).*"+name+".*' return n skip "+offsetInt+" limit "+countInt;
//"match (n:MetaData ) where n.name =~\"" + name + ".*\" return n";
......@@ -789,9 +792,9 @@ public class MetadataServiceImpl implements IMetadataService {
long start = System.currentTimeMillis();
ReturnReslult returnReslult = new ReturnReslult();
//横向关系,纵向关系
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
String[] strings = metadataId.split("=");
String metadataName = strings[strings.length-1];
Map<Long, ReturnNode> longMetaDataMap =new HashMap<>();
......@@ -832,9 +835,9 @@ public class MetadataServiceImpl implements IMetadataService {
long start = System.currentTimeMillis();
ReturnReslult returnReslult = new ReturnReslult();
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
Map<String, MetaModel> metaModelMap = new HashMap<>();
if(metadataId .startsWith(TableModelEqual)){
......@@ -2221,9 +2224,9 @@ public class MetadataServiceImpl implements IMetadataService {
public List<MetaData> getMetadataByName(String name) {
List<MetaData> metaDataList = metadataRepository.findMetadataByName(name);
if(CollectionUtils.isEmpty(metaDataList)){// metaDataList ==null || metaDataList.size()==0
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
//向上获取路径
String cypher = "match (n{name:\""+name+"\"}) return n ";
logger.info("cypher语句:" + cypher);
......@@ -2447,9 +2450,9 @@ public class MetadataServiceImpl implements IMetadataService {
@Override
public void deleteNodeByCatalogName(String catalogName) {
try{
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
String cypher = "match (n) where n.metadataId =~'.*="+catalogName+"=.*' detach delete n";
logger.info("删除数据的语句:{}",cypher);
......
......@@ -42,6 +42,9 @@ public class MultiModelServiceImpl implements MultiModelService {
@Autowired
private ExecuteRelationRepository executeRelationRepository;
@Autowired
private Session session;
private Long getParentId(Long neo4jId, Map<Long, Long> child2Parent) {
Long parentId = neo4jId;
while (child2Parent.containsKey(neo4jId)) {
......@@ -367,9 +370,9 @@ public class MultiModelServiceImpl implements MultiModelService {
@Override
public List<Map<String, String>> getAllAlgorithm() {
List<Map<String, String>> returnResult = new ArrayList<>() ;
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
String cypher = " call algo.list() ";
StatementResult result = session.run(cypher);
......@@ -389,9 +392,9 @@ public class MultiModelServiceImpl implements MultiModelService {
@Override
public ReturnReslult getImportantTable(String schemaId) {
ReturnReslult returnReslult = new ReturnReslult();
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
String cypher = "MATCH (p:Neo4jTable)<-[:流向]->(c) \n" +
"WITH p,count(c) as rels\n" +
"RETURN p, rels order by rels desc";
......@@ -448,9 +451,9 @@ public class MultiModelServiceImpl implements MultiModelService {
Map<String, MetaModel> metaModelMap = new HashMap<>();
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
String cypher = " MATCH (a:Neo4jTable)<-- (m:Neo4jSchema{metadataId:\""+metadataId+"\"}) WHERE not ((a)-[:"+relationType+"]->()) RETURN a limit 20;";
StatementResult result = session.run(cypher);
......
......@@ -50,6 +50,12 @@ public class TableServiceImpl implements ITableService {
@Autowired
private MetadataRepoRemoteService metadataRepoRemoteService;
@Autowired
private Session session;
private String TableEqual = "Table=";
private String TableModelName = "Table";
......@@ -227,9 +233,9 @@ public class TableServiceImpl implements ITableService {
public List<ReturnNode> autoMatchByInputWord(String name,int countInt,int offsetInt){
logger.info("开始模糊查找:" + name);
List<ReturnNode> returnNodeList = new ArrayList<>();
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
// match(n) where (n:Neo4jTable or n:Neo4jSchema ) and (n.name =~'.*部门1.*' or n.cnName =~'.*部门1.*') return n
//match (n:MetaData) where n.name=~'(?i).*APP.*' return n
String cypher ="match (n) where ( n:Neo4jTable or n:Neo4jSchema ) and (n.name=~'(?i).*"+name+".*' or n.name=~'(?i).*"+name+".*') return n skip "+offsetInt+" limit "+countInt;
......@@ -275,9 +281,9 @@ public class TableServiceImpl implements ITableService {
Map<String,ReturnNode> returnNodeMap = new HashMap<>();
Map<String,ReturnEdge> returnEdgeMap = new HashMap<>();
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
//
String cypher = "match p=(n:Neo4jColumn{metadataId:\""+columnId+"\"})<-[r*0..10]->(m) return p"; // "match (n) where ( n:Neo4jTable or n:Neo4jSchema ) and (n.name=~'(?i).*"+name+".*' or n.name=~'(?i).*"+name+".*') return n skip "+offsetInt+" limit "+countInt;
......@@ -487,9 +493,9 @@ public class TableServiceImpl implements ITableService {
Map<String,ReturnEdge> returnEdgeMap = new HashMap<>();
Map<String,ReturnEdge> childrenEdgeMap = new HashMap<>();
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
int runCypherCount = 0;
long runCypherTime = 0;
......@@ -805,9 +811,9 @@ public class TableServiceImpl implements ITableService {
public Map<String, List<ReturnNode>> autoMatchBySchemaIdAndInputWord(String schemaId, String keyWord) {
logger.info("开始在 "+schemaId+" 下模糊查找:" + keyWord);
List<ReturnNode> returnNodeList = new ArrayList<>();
Neo4jConfig neo4jConfig = new Neo4jConfig();
Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
Session session = neo4jConnection.session();
// Neo4jConfig neo4jConfig = new Neo4jConfig();
// Driver neo4jConnection = neo4jConfig.getNeo4jConnection();
// Session session = neo4jConnection.session();
// match(n) where (n:Neo4jTable or n:Neo4jSchema ) and (n.name =~'.*部门1.*' or n.cnName =~'.*部门1.*') return n
//match (n:MetaData) where n.name=~'(?i).*APP.*' return n
String cypher = ""; // "match (n) where ( n:Neo4jTable or n:Neo4jSchema ) and (n.name=~'(?i).*"+name+".*' or n.name=~'(?i).*"+name+".*') return n skip "+offsetInt+" limit "+countInt;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment