use of org.neo4j.server.rest.repr.RelationshipRepresentation in project neo4j by neo4j.
the class TransactionWrappedDatabaseActions method getRelationship.
@Override
public RelationshipRepresentation getRelationship(long relationshipId) throws RelationshipNotFoundException {
try (Transaction transaction = graph.beginTx()) {
RelationshipRepresentation relationship = super.getRelationship(relationshipId);
transaction.success();
return relationship;
}
}
use of org.neo4j.server.rest.repr.RelationshipRepresentation in project neo4j by neo4j.
the class TransactionWrappedDatabaseActions method createRelationship.
@Override
public RelationshipRepresentation createRelationship(long startNodeId, long endNodeId, String type, Map<String, Object> properties) throws StartNodeNotFoundException, EndNodeNotFoundException, PropertyValueException {
try (Transaction transaction = graph.beginTx()) {
RelationshipRepresentation relationshipRepresentation = super.createRelationship(startNodeId, endNodeId, type, properties);
transaction.success();
return relationshipRepresentation;
}
}
use of org.neo4j.server.rest.repr.RelationshipRepresentation in project neo4j by neo4j.
the class DatabaseActionsTest method shouldAllowCreateRelationshipWithSameStartAsEndNode.
@Test
public void shouldAllowCreateRelationshipWithSameStartAsEndNode() throws Exception {
long nodeId = graphdbHelper.createNode();
Map<String, Object> properties = Collections.emptyMap();
RelationshipRepresentation rel = actions.createRelationship(nodeId, nodeId, "Loves", properties);
assertNotNull(rel);
}
use of org.neo4j.server.rest.repr.RelationshipRepresentation in project neo4j by neo4j.
the class DatabaseActions method createRelationship.
public RelationshipRepresentation createRelationship(long startNodeId, long endNodeId, String type, Map<String, Object> properties) throws StartNodeNotFoundException, EndNodeNotFoundException, PropertyValueException {
Node start, end;
try {
start = node(startNodeId);
} catch (NodeNotFoundException e) {
throw new StartNodeNotFoundException(e);
}
try {
end = node(endNodeId);
} catch (NodeNotFoundException e) {
throw new EndNodeNotFoundException(e);
}
Relationship rel = start.createRelationshipTo(end, RelationshipType.withName(type));
propertySetter.setProperties(rel, properties);
return new RelationshipRepresentation(rel);
}
use of org.neo4j.server.rest.repr.RelationshipRepresentation in project neo4j by neo4j.
the class RestRepresentationWriter method write.
private void write(JsonGenerator out, RepresentationFormat format, Object value, TransactionStateChecker checker) throws IOException {
if (value instanceof Map<?, ?>) {
out.writeStartObject();
try {
for (Map.Entry<String, ?> entry : ((Map<String, ?>) value).entrySet()) {
out.writeFieldName(entry.getKey());
write(out, format, entry.getValue(), checker);
}
} finally {
out.writeEndObject();
}
} else if (value instanceof Path) {
write(format, new PathRepresentation<>((Path) value));
} else if (value instanceof Iterable<?>) {
out.writeStartArray();
try {
for (Object item : (Iterable<?>) value) {
write(out, format, item, checker);
}
} finally {
out.writeEndArray();
}
} else if (value instanceof Node) {
NodeRepresentation representation = new NodeRepresentation((Node) value);
representation.setTransactionStateChecker(checker);
write(format, representation);
} else if (value instanceof Relationship) {
RelationshipRepresentation representation = new RelationshipRepresentation((Relationship) value);
representation.setTransactionStateChecker(checker);
write(format, representation);
} else {
out.writeObject(value);
}
}
Aggregations