コード例 #1
0
 protected List<Node> getRelatedNodes(Node startNode, String type, Direction direction) {
   List<Node> result = new ArrayList<Node>();
   for (Relationship relationship :
       startNode.getRelationships(DynamicRelationshipType.withName(type), direction)) {
     result.add(relationship.getOtherNode(startNode));
   }
   return result;
 }
コード例 #2
0
 @Test
 @Transactional
 public void shouldGetDirectRelationshipForTypeAndDirection() throws Exception {
   assertSingleResult(
       "rel1",
       neo4jTemplate
           .convert(referenceNode.getRelationships(KNOWS, Direction.OUTGOING))
           .to(String.class, new RelationshipNameConverter()));
 }
コード例 #3
0
 @Test
 @Transactional
 public void shouldGetDirectRelationship() throws Exception {
   assertSingleResult(
       "rel1",
       neo4jTemplate
           .convert(referenceNode.getRelationships(DynamicRelationshipType.withName("knows")))
           .to(String.class, new RelationshipNameConverter()));
 }
コード例 #4
0
  @Test
  public void testCreateRelationship() {
    Node n1 = restAPI.createNode(map("name", "newnode1"));
    final Transaction tx = restAPI.beginTx();

    Node n2 = restAPI.createNode(map("name", "newnode2"));
    RestRelationship rel = restAPI.createRelationship(n1, n2, Type.TEST, map("name", "rel"));
    Iterable<Relationship> allRelationships = n1.getRelationships();

    tx.success();
    tx.finish();
    Relationship foundRelationship =
        TestHelper.firstRelationshipBetween(
            n1.getRelationships(Type.TEST, Direction.OUTGOING), n1, n2);
    Assert.assertNotNull("found relationship", foundRelationship);
    assertEquals("same relationship", rel, foundRelationship);
    assertEquals("rel", rel.getProperty("name"));

    assertThat(
        n1.getRelationships(Type.TEST, Direction.OUTGOING),
        new IsRelationshipToNodeMatcher(n1, n2));
    assertThat(n1.getRelationships(Direction.OUTGOING), new IsRelationshipToNodeMatcher(n1, n2));
    assertThat(n1.getRelationships(Direction.BOTH), new IsRelationshipToNodeMatcher(n1, n2));
    assertThat(n1.getRelationships(Type.TEST), new IsRelationshipToNodeMatcher(n1, n2));
    assertThat(allRelationships, new IsRelationshipToNodeMatcher(n1, n2));
  }
コード例 #5
0
 @Test
 public void testDeleteRelationship() {
   Transaction tx = restAPI.beginTx();
   Node n1 = restAPI.createNode(map("name", "newnode1"));
   Node n2 = restAPI.createNode(map("name", "newnode2"));
   Relationship rel = restAPI.createRelationship(n1, n2, Type.TEST, map("name", "rel"));
   rel.delete();
   tx.success();
   tx.finish();
   Relationship foundRelationship =
       TestHelper.firstRelationshipBetween(
           n1.getRelationships(Type.TEST, Direction.OUTGOING), n1, n2);
   Assert.assertNull("found relationship", foundRelationship);
 }
コード例 #6
0
ファイル: BulkImport.java プロジェクト: Mamun/pworkshop
  public static void exportFromDB(GraphDatabaseService graphDatabaseService) {

    GlobalGraphOperations graphOperations = GlobalGraphOperations.at(graphDatabaseService);
    Node refNode = graphDatabaseService.getReferenceNode();
    for (Node node : graphOperations.getAllNodes()) {

      StringBuffer stringBuffer = new StringBuffer();
      stringBuffer.append("{");
      for (String key : node.getPropertyKeys()) {
        String value = (String) node.getProperty(key);
        stringBuffer.append(String.format("%s : %s", key, value));
      }
      for (Relationship rel : node.getRelationships(Direction.OUTGOING)) {}

      stringBuffer.append("}");
    }
  }