Commit 28223c94 by qiuchaofei

1.修改获取neo4j session的方法

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