Esempio n. 1
0
  public void rn() throws IOException {
    List<RoadLink> links = loadToDatabase("/Users/duduba/gj.mif", "/Users/duduba/gj.mid", false);

    GraphDatabaseService graphDb = neo.getDb();
    Index<Node> nodeIndex = neo.getNodeIndex();

    for (RoadLink link : links) {
      Transaction tx = graphDb.beginTx();
      try {

        Node fromNode = nodeIndex.get("id", link.fromNode).getSingle();
        if (fromNode == null) {
          fromNode = graphDb.createNode();
          fromNode.setProperty("id", link.fromNode);
          nodeIndex.add(fromNode, "id", link.fromNode);
        }
        Node toNode = nodeIndex.get("id", link.toNode).getSingle();
        if (toNode == null) {
          toNode = graphDb.createNode();
          toNode.setProperty("id", link.toNode);
          nodeIndex.add(toNode, "id", link.toNode);
        }

        Relationship r = fromNode.createRelationshipTo(toNode, Neo.RelTypes.TO);
        r.setProperty("no", link.no);
        r.setProperty("name", link.name);

        tx.success();
      } finally {
        tx.finish();
      }
    }
    logger.debug("haha, it's ok!");
  }
  @Test
  public void testCreateRelationshipToNodeOutsideofBatch() throws Exception {
    final Node node1 = restAPI.createNode(map());
    final Transaction tx = restAPI.beginTx();

    Node node2 = restAPI.createNode(map());
    final Relationship relationship =
        node1.createRelationshipTo(node2, DynamicRelationshipType.withName("foo"));

    tx.success();
    tx.finish();
    assertEquals("foo", relationship.getType().name());
    assertEquals(
        "foo", getGraphDatabase().getRelationshipById(relationship.getId()).getType().name());
  }
  @Test
  public void deletedRelationshipWithNewTypeShouldNotInfluenceEquality() { // bug test
    try (Transaction tx = database.beginTx()) {
      Node node1 = database.createNode();
      Node node2 = database.createNode();
      node1.createRelationshipTo(node2, DynamicRelationshipType.withName("ACCIDENT"));
      tx.success();
    }

    try (Transaction tx = database.beginTx()) {
      GlobalGraphOperations.at(database).getAllRelationships().iterator().next().delete();
      tx.success();
    }

    String cypher = "CREATE (n), (m)";

    assertSameGraph(database, cypher);
  }
 protected Relationship makeFriends(Node from, Node to, int years) {
   Relationship friendship = from.createRelationshipTo(to, KNOWS);
   friendship.setProperty("Friendship.years", years);
   return friendship;
 }
 @Override
 public Relationship createRelationship(Node startNode, Node endNode, RelationshipType type, Map<String, Object> properties) {
     return setProperties(startNode.createRelationshipTo(endNode,type), properties);
 }