use of org.neo4j.server.rest.repr.NodeRepresentation in project neo4j by neo4j.
the class DatabaseActions method createNode.
// Nodes
public NodeRepresentation createNode(Map<String, Object> properties, Label... labels) throws PropertyValueException {
Node node = graphDb.createNode();
propertySetter.setProperties(node, properties);
if (labels != null) {
for (Label label : labels) {
node.addLabel(label);
}
}
return new NodeRepresentation(node);
}
use of org.neo4j.server.rest.repr.NodeRepresentation in project neo4j by neo4j.
the class TransactionWrappedDatabaseActions method createNode.
@Override
public NodeRepresentation createNode(Map<String, Object> properties, Label... labels) throws PropertyValueException {
try (Transaction transaction = graph.beginTx()) {
NodeRepresentation nodeRepresentation = super.createNode(properties, labels);
transaction.success();
return nodeRepresentation;
}
}
use of org.neo4j.server.rest.repr.NodeRepresentation in project neo4j by neo4j.
the class TransactionWrappedDatabaseActions method getNode.
@Override
public NodeRepresentation getNode(long nodeId) throws NodeNotFoundException {
try (Transaction transaction = graph.beginTx()) {
NodeRepresentation node = super.getNode(nodeId);
transaction.success();
return node;
}
}
use of org.neo4j.server.rest.repr.NodeRepresentation 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);
}
}
use of org.neo4j.server.rest.repr.NodeRepresentation 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