Search in sources :

Example 81 with Relationship

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

the class RelationshipIT method shouldReturn404WhenPropertyWhichDoesNotExistRemovedFromRelationshipStreaming.

@Test
@Graph(nodes = { @NODE(name = "Romeo", setNameProperty = true), @NODE(name = "Juliet", setNameProperty = true) }, relationships = { @REL(start = "Romeo", end = "Juliet", type = "LOVES", properties = { @PROP(key = "cost", value = "high", type = GraphDescription.PropType.STRING) }) })
public void shouldReturn404WhenPropertyWhichDoesNotExistRemovedFromRelationshipStreaming() {
    data.get();
    Relationship loves = getFirstRelationshipFromRomeoNode();
    gen().withHeader(StreamingFormat.STREAM_HEADER, "true").expectedStatus(Status.NOT_FOUND.getStatusCode()).delete(getPropertiesUri(loves) + "/non-existent").entity();
}
Also used : Relationship(org.neo4j.graphdb.Relationship) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 82 with Relationship

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

the class RelationshipIT method set_all_properties_on_a_relationship.

@Test
@Graph(nodes = { @NODE(name = "Romeo", setNameProperty = true), @NODE(name = "Juliet", setNameProperty = true) }, relationships = { @REL(start = "Romeo", end = "Juliet", type = "LOVES", properties = { @PROP(key = "cost", value = "high", type = GraphDescription.PropType.STRING), @PROP(key = "since", value = "1day", type = GraphDescription.PropType.STRING) }) })
public void set_all_properties_on_a_relationship() throws Exception {
    Relationship loves = getFirstRelationshipFromRomeoNode();
    assertThat(loves, inTx(graphdb(), hasProperty("cost").withValue("high")));
    gen().expectedStatus(ClientResponse.Status.NO_CONTENT).payload(JsonHelper.createJsonFrom(MapUtil.map("happy", false))).put(getRelPropsURI(loves)).entity();
    assertThat(loves, inTx(graphdb(), hasProperty("happy").withValue(false)));
    assertThat(loves, inTx(graphdb(), not(hasProperty("cost"))));
}
Also used : Relationship(org.neo4j.graphdb.Relationship) Graph(org.neo4j.test.GraphDescription.Graph) Test(org.junit.Test)

Example 83 with Relationship

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

the class GraphDbHelper method setRelationshipProperties.

public void setRelationshipProperties(long relationshipId, Map<String, Object> properties) {
    try (Transaction tx = database.getGraph().beginTransaction(implicit, AnonymousContext.writeToken())) {
        Relationship relationship = database.getGraph().getRelationshipById(relationshipId);
        for (Map.Entry<String, Object> propertyEntry : properties.entrySet()) {
            relationship.setProperty(propertyEntry.getKey(), propertyEntry.getValue());
        }
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Relationship(org.neo4j.graphdb.Relationship) Map(java.util.Map)

Example 84 with Relationship

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

the class RelationshipExpanderBuilderTest method shouldInterpretNoSpecifiedRelationshipsAsAll.

@Test
public void shouldInterpretNoSpecifiedRelationshipsAsAll() throws Exception {
    // GIVEN
    Node node = createSomeData();
    PathExpander expander = RelationshipExpanderBuilder.describeRelationships(map());
    // WHEN
    Set<Relationship> expanded;
    try (Transaction tx = db.beginTx()) {
        expanded = asSet(expander.expand(singleNodePath(node), NO_STATE));
        tx.success();
    }
    try (Transaction tx = db.beginTx()) {
        // THEN
        assertEquals(asSet(node.getRelationships()), expanded);
        tx.success();
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) PathExpander(org.neo4j.graphdb.PathExpander) Test(org.junit.Test)

Example 85 with Relationship

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

the class GraphDbHelper method getRelationship.

public Relationship getRelationship(long relationshipId) {
    try (Transaction tx = database.getGraph().beginTransaction(implicit, AnonymousContext.read())) {
        Relationship relationship = database.getGraph().getRelationshipById(relationshipId);
        tx.success();
        return relationship;
    }
}
Also used : Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Relationship(org.neo4j.graphdb.Relationship)

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