use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class GraphDbHelper method getPropertyUniquenessConstraints.
public Iterable<ConstraintDefinition> getPropertyUniquenessConstraints(String labelName, final String propertyKey) {
try (Transaction tx = database.getGraph().beginTransaction(implicit, AnonymousContext.read())) {
Iterable<ConstraintDefinition> definitions = Iterables.filter(item -> {
if (item.isConstraintType(ConstraintType.UNIQUENESS)) {
Iterable<String> keys = item.getPropertyKeys();
return single(keys).equals(propertyKey);
} else {
return false;
}
}, database.getGraph().schema().getConstraints(label(labelName)));
tx.success();
return definitions;
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class GraphDbHelper method getFirstNode.
public long getFirstNode() {
try (Transaction tx = database.getGraph().beginTransaction(implicit, AnonymousContext.write())) {
try {
Node referenceNode = database.getGraph().getNodeById(0L);
tx.success();
return referenceNode.getId();
} catch (NotFoundException e) {
Node newNode = database.getGraph().createNode();
tx.success();
return newNode.getId();
}
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class RelationshipExpanderBuilderTest method createSomeData.
private Node createSomeData() {
try (Transaction tx = db.beginTx()) {
Node node = db.createNode();
node.createRelationshipTo(db.createNode(), MyRelTypes.TEST);
node.createRelationshipTo(db.createNode(), MyRelTypes.TEST2);
tx.success();
return node;
}
}
use of org.neo4j.graphdb.Transaction 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();
}
}
use of org.neo4j.graphdb.Transaction in project neo4j by neo4j.
the class PagedTraverserIT method createLinkedList.
private Node createLinkedList(final int listLength, final Database db) {
Node startNode = null;
try (Transaction tx = db.getGraph().beginTx()) {
Node previous = null;
for (int i = 0; i < listLength; i++) {
Node current = db.getGraph().createNode();
current.setProperty("name", String.valueOf(i));
if (previous != null) {
previous.createRelationshipTo(current, RelationshipType.withName("NEXT"));
} else {
startNode = current;
}
previous = current;
}
tx.success();
return startNode;
}
}
Aggregations