use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class RelationshipCountsTest method shouldReportTotalNumberOfRelationships.
@Test
public void shouldReportTotalNumberOfRelationships() throws Exception {
// given
GraphDatabaseService graphDb = db.getGraphDatabaseAPI();
long before = numberOfRelationships();
long during;
try (Transaction tx = graphDb.beginTx()) {
Node node = graphDb.createNode();
node.createRelationshipTo(graphDb.createNode(), withName("KNOWS"));
node.createRelationshipTo(graphDb.createNode(), withName("KNOWS"));
node.createRelationshipTo(graphDb.createNode(), withName("KNOWS"));
during = countsForRelationship(null, null, null);
tx.success();
}
// when
long after = numberOfRelationships();
// then
assertEquals(0, before);
assertEquals(3, during);
assertEquals(3, after);
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class RelationshipCountsTest method shouldAccountForDeletedRelationships.
@Test
public void shouldAccountForDeletedRelationships() throws Exception {
// given
GraphDatabaseService graphDb = db.getGraphDatabaseAPI();
Relationship rel;
try (Transaction tx = graphDb.beginTx()) {
Node node = graphDb.createNode();
node.createRelationshipTo(graphDb.createNode(), withName("KNOWS"));
rel = node.createRelationshipTo(graphDb.createNode(), withName("KNOWS"));
node.createRelationshipTo(graphDb.createNode(), withName("KNOWS"));
tx.success();
}
long before = numberOfRelationships(), during;
try (Transaction tx = graphDb.beginTx()) {
rel.delete();
during = countsForRelationship(null, null, null);
tx.success();
}
// when
long after = numberOfRelationships();
// then
assertEquals(3, before);
assertEquals(2, during);
assertEquals(2, after);
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class StoreLockerTest method mustPreventMultipleInstancesFromStartingOnSameStore.
@Test
public void mustPreventMultipleInstancesFromStartingOnSameStore() {
File storeDir = target.graphDbDir();
GraphDatabaseService db = new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
try (Transaction tx = db.beginTx()) {
db.createNode();
tx.success();
}
try {
new TestGraphDatabaseFactory().newEmbeddedDatabase(storeDir);
fail("Should not be able to start up another db in the same dir");
} catch (Exception e) {
// Good
} finally {
db.shutdown();
}
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class TraversalAStar method findPaths.
private Iterable<WeightedPath> findPaths(Node start, Node end, boolean multiplePaths) {
PathInterest interest;
if (multiplePaths) {
interest = stopAfterLowestWeight ? PathInterestFactory.allShortest() : PathInterestFactory.all();
} else {
interest = PathInterestFactory.single();
}
GraphDatabaseService db = start.getGraphDatabase();
TraversalDescription traversalDescription = db.traversalDescription().uniqueness(Uniqueness.NONE).expand(expander, initialState);
lastTraverser = traversalDescription.order(new SelectorFactory(end, interest)).evaluator(includeWhereEndNodeIs(end)).traverse(start);
return new Iterable<WeightedPath>() {
@Override
public Iterator<WeightedPath> iterator() {
return new WeightedPathIterator(lastTraverser.iterator(), costEvaluator, stopAfterLowestWeight);
}
};
}
use of org.neo4j.graphdb.GraphDatabaseService in project neo4j by neo4j.
the class TraversalShortestPath method instantiateTraverser.
@Override
protected Traverser instantiateTraverser(Node start, Node end) {
GraphDatabaseService db = start.getGraphDatabase();
TraversalDescription sideBase = db.traversalDescription().breadthFirst().uniqueness(NODE_PATH);
return db.bidirectionalTraversalDescription().mirroredSides(sideBase.expand(expander)).sideSelector(LEVEL_STOP_DESCENT_ON_RESULT, maxDepth).collisionEvaluator(toDepth(maxDepth)).traverse(start, end);
}
Aggregations