neo4j批量创建关系

更新时间:2024-04-07 01:11:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

package neo4j215; /*neo4j 2.1.5

*neo4j-rest-graphdb-2.0.1.jar * jersey-client-1.9.jar

*根据节点创建关系,同时如果节点不存在,把节点也创建上; * 在对关系的操作上,将call-len这个字段实现叠加 * */

import java.io.BufferedReader; import java.io.File;

import java.io.FileReader;

import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map;

import org.neo4j.rest.graphdb.RestAPI;

import org.neo4j.rest.graphdb.RestAPIFacade;

import org.neo4j.rest.graphdb.batch.BatchCallback;

public class createRelation {

static class Process implements BatchCallback { private static final String QUERY = \merge (n:Person {call:{call_src}}) on create set n.call={call_src} merge(m:Person {call:{call_dest}}) on create set m.call={call_dest} merge (n)-[r:phone]->(m) on match set r.call_len=r.call_len+{call_length} on create set r.call_len={call_length},r.p1={rp1},r.p2={rp2},r.p3={rp3},r.p4={rp4},r.p5={rp5};\ private List> params; Process(final List> params) { this.params = params; } @Override public Object recordBatch(final RestAPI restApi) { for (final Map param : params) { restApi.query(QUERY, param); } return null; } }

public static String getCurDateTime(String ptn) { Date d = new Date();

SimpleDateFormat sdf = new SimpleDateFormat(ptn); return sdf.format(d); }

public static void main(String[] args ){ //System.setProperty(\ final RestAPI restAPI = new RestAPIFacade(\ int counter = 0; List> statements = new ArrayList<>(); File csv = new File(\ BufferedReader br= null; long begintime = System.currentTimeMillis(); System.out.print(\开始时间:\ try{ br = new BufferedReader(new FileReader(csv)); String line = \ //2199660,19713972,WCCGN,65,rdbnhndjjj,VFCQN,YHCRP,QDHIH,QGMOW while ((line = br.readLine()) != null && line.length()!=0) { String mapresult[] = line.split(\ Map properties= new HashMap<>(); properties.put(\ properties.put(\ properties.put(\ properties.put(\ properties.put(\ properties.put(\ properties.put(\ properties.put(\ properties.put(\ statements.add(properties) ; if (++counter % 2000 == 0) { restAPI.executeBatch(new Process(statements)); statements = new ArrayList<>(); } } restAPI.executeBatch(new Process(statements)); System.out.print(\总记录条数:\ System.out.print(\完成时间:\ System.out.println(\用时(秒):\- begintime)/1000+\ } catch (Exception e){e.printStackTrace();} finally {try {

} } }

br.close();

} catch (Exception e) { System.out.println(\}

本文来源:https://www.bwwdw.com/article/wubr.html

Top