Search in sources :

Example 31 with Relationship

use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.

the class TestNeo4jCacheAndPersistence method testNodeRemoveProperty.

@Test
public void testNodeRemoveProperty() {
    Node node1 = getGraphDb().getNodeById(node1Id);
    Node node2 = getGraphDb().getNodeById(node2Id);
    Relationship rel = node1.getSingleRelationship(MyRelTypes.TEST, Direction.BOTH);
    // test remove property
    assertEquals(1, node1.removeProperty(key1));
    assertEquals(2, node2.removeProperty(key1));
    assertEquals(1, rel.removeProperty(key1));
    assertEquals(string1, node1.removeProperty(key2));
    assertEquals(string2, node2.removeProperty(key2));
    assertEquals(string1, rel.removeProperty(key2));
    assertTrue(node1.removeProperty(arrayKey) != null);
    assertTrue(node2.removeProperty(arrayKey) != null);
    assertTrue(rel.removeProperty(arrayKey) != null);
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 32 with Relationship

use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.

the class TestNeo4jCacheAndPersistence method testNodeChangeProperty.

@Test
public void testNodeChangeProperty() {
    Node node1 = getGraphDb().getNodeById(node1Id);
    Node node2 = getGraphDb().getNodeById(node2Id);
    Relationship rel = node1.getSingleRelationship(MyRelTypes.TEST, Direction.BOTH);
    // test change property
    node1.setProperty(key1, int2);
    node2.setProperty(key1, int1);
    rel.setProperty(key1, int2);
    int[] newIntArray = new int[] { 3, 2, 1 };
    node1.setProperty(arrayKey, newIntArray);
    node2.setProperty(arrayKey, newIntArray);
    rel.setProperty(arrayKey, newIntArray);
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 33 with Relationship

use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.

the class TestNeo4jCacheAndPersistence method testAddCacheCleared.

@Test
public void testAddCacheCleared() {
    Node nodeA = getGraphDb().createNode();
    nodeA.setProperty("1", 1);
    Node nodeB = getGraphDb().createNode();
    Relationship rel = nodeA.createRelationshipTo(nodeB, MyRelTypes.TEST);
    rel.setProperty("1", 1);
    commit();
    newTransaction();
    nodeA.createRelationshipTo(nodeB, MyRelTypes.TEST);
    int count = 0;
    for (Relationship relToB : nodeA.getRelationships(MyRelTypes.TEST)) {
        count++;
    }
    assertEquals(2, count);
    nodeA.setProperty("2", 2);
    assertEquals(1, nodeA.getProperty("1"));
    rel.setProperty("2", 2);
    assertEquals(1, rel.getProperty("1"));
    // trigger empty load
    getGraphDb().getNodeById(nodeA.getId());
    getGraphDb().getRelationshipById(rel.getId());
    // apply COW maps
    commit();
    newTransaction();
    count = 0;
    for (Relationship relToB : nodeA.getRelationships(MyRelTypes.TEST)) {
        count++;
    }
    assertEquals(2, count);
    assertEquals(1, nodeA.getProperty("1"));
    assertEquals(1, rel.getProperty("1"));
    assertEquals(2, nodeA.getProperty("2"));
    assertEquals(2, rel.getProperty("2"));
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 34 with Relationship

use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.

the class TestNeo4jCacheAndPersistence method testSameTxWithArray.

@Test
public void testSameTxWithArray() {
    commit();
    newTransaction();
    Node nodeA = getGraphDb().createNode();
    Node nodeB = getGraphDb().createNode();
    Relationship relA = nodeA.createRelationshipTo(nodeB, MyRelTypes.TEST);
    nodeA.setProperty(arrayKey, array);
    relA.setProperty(arrayKey, array);
    assertTrue(nodeA.getProperty(arrayKey) != null);
    assertTrue(relA.getProperty(arrayKey) != null);
    relA.delete();
    nodeA.delete();
    nodeB.delete();
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Example 35 with Relationship

use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.

the class TestRelationship method testSimple2.

@Test
public void testSimple2() {
    Node node1 = getGraphDb().createNode();
    Node node2 = getGraphDb().createNode();
    for (int i = 0; i < 3; i++) {
        node1.createRelationshipTo(node2, MyRelTypes.TEST);
        node1.createRelationshipTo(node2, MyRelTypes.TEST_TRAVERSAL);
        node1.createRelationshipTo(node2, MyRelTypes.TEST2);
    }
    allGetRelationshipMethods(node1, Direction.OUTGOING);
    allGetRelationshipMethods(node2, Direction.INCOMING);
    newTransaction();
    allGetRelationshipMethods(node1, Direction.OUTGOING);
    allGetRelationshipMethods(node2, Direction.INCOMING);
    node1.getRelationships(MyRelTypes.TEST, Direction.OUTGOING).iterator().next().delete();
    node1.getRelationships(MyRelTypes.TEST_TRAVERSAL, Direction.OUTGOING).iterator().next().delete();
    node1.getRelationships(MyRelTypes.TEST2, Direction.OUTGOING).iterator().next().delete();
    node1.createRelationshipTo(node2, MyRelTypes.TEST);
    node1.createRelationshipTo(node2, MyRelTypes.TEST_TRAVERSAL);
    node1.createRelationshipTo(node2, MyRelTypes.TEST2);
    allGetRelationshipMethods(node1, Direction.OUTGOING);
    allGetRelationshipMethods(node2, Direction.INCOMING);
    newTransaction();
    allGetRelationshipMethods(node1, Direction.OUTGOING);
    allGetRelationshipMethods(node2, Direction.INCOMING);
    for (Relationship rel : node1.getRelationships()) {
        rel.delete();
    }
    node1.delete();
    node2.delete();
}
Also used : Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Aggregations

Relationship (org.neo4j.graphdb.Relationship)490 Node (org.neo4j.graphdb.Node)370 Test (org.junit.Test)250 Transaction (org.neo4j.graphdb.Transaction)138 LinkedList (java.util.LinkedList)48 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)48 RelationshipType (org.neo4j.graphdb.RelationshipType)38 NotFoundException (org.neo4j.graphdb.NotFoundException)35 Path (org.neo4j.graphdb.Path)29 HashMap (java.util.HashMap)27 Direction (org.neo4j.graphdb.Direction)26 HashSet (java.util.HashSet)24 ArrayList (java.util.ArrayList)18 RelationshipIndex (org.neo4j.graphdb.index.RelationshipIndex)18 Map (java.util.Map)14 WeightedPath (org.neo4j.graphalgo.WeightedPath)14 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)14 List (java.util.List)13 PropertyContainer (org.neo4j.graphdb.PropertyContainer)12 Graph (org.neo4j.test.GraphDescription.Graph)11