I want to create nodes and relatioships based on column values in DB. Node1 values will come from column "App-Name",Node2 -> "Corresponding_App" & relationship->"Interface_Name" Based on column values "Interface_Type_Name"->Incoming/Outgoing arrows will be drawn to particular nodes.
nodes should be unique and if created already then should not create duplicate one.
Transaction tx=graphDb.beginTx();
Connection conn = null;
try{{
conn=ConnectionFactory.getConnection();
Statement stat=conn.createStatement();
String sql="select * from Fade where App_Int_Id < 22";
ResultSet rs=stat.executeQuery(sql);
String n1 = "",n2="",rel="",type="";
while(rs.next()){
n1=rs.getString(1);
n2=rs.getString(7);
rel=rs.getString(3);
type=rs.getString(4);
Node first=graphDb.createNode();
first.setProperty("name", n1);
first.addLabel(DynamicLabel.label(n1));
Node sec=graphDb.createNode();
sec.setProperty("name", n2);
sec.addLabel(DynamicLabel.label(n2));
RelationshipType KNOWS = DynamicRelationshipType.withName(rel);
if(type.equalsIgnoreCase("Incoming")){
sec.createRelationshipTo(first, KNOWS);
}
else if(type.equalsIgnoreCase("Outgoing")){
first.createRelationshipTo(sec, KNOWS);
}
For every single row its creating new nodes.so How to create unique nodes in the above code?