use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class GraphDbHelper method getIndexedRelationships.
public Collection<Long> getIndexedRelationships(String indexName, String key, Object value) {
try (Transaction tx = database.getGraph().beginTransaction(implicit, AnonymousContext.write())) {
Collection<Long> result = new ArrayList<>();
for (Relationship relationship : database.getGraph().index().forRelationships(indexName).get(key, value)) {
result.add(relationship.getId());
}
tx.success();
return result;
}
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class GraphDbHelper method addRelationshipToIndex.
public void addRelationshipToIndex(String indexName, String key, String value, long relationshipId) {
try (Transaction tx = database.getGraph().beginTransaction(implicit, AUTH_DISABLED)) {
Index<Relationship> index = database.getGraph().index().forRelationships(indexName);
index.add(database.getGraph().getRelationshipById(relationshipId), key, value);
tx.success();
}
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class IncrementalBackupTests method createInitialDataSet.
private DbRepresentation createInitialDataSet(File path) {
db = startGraphDatabase(path);
try (Transaction tx = db.beginTx()) {
db.createNode().setProperty("name", "Goofy");
Node donald = db.createNode();
donald.setProperty("name", "Donald");
Node daisy = db.createNode();
daisy.setProperty("name", "Daisy");
Relationship knows = donald.createRelationshipTo(daisy, RelationshipType.withName("LOVES"));
knows.setProperty("since", 1940);
tx.success();
}
DbRepresentation result = DbRepresentation.of(db);
db.shutdown();
return result;
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class IdReuseTest method shouldReuseRelationshipIdsFromRolledBackTransaction.
@Test
public void shouldReuseRelationshipIdsFromRolledBackTransaction() throws Exception {
// Given
GraphDatabaseService db = dbRule.getGraphDatabaseAPI();
Node node1, node2;
try (Transaction tx = db.beginTx()) {
node1 = db.createNode();
node2 = db.createNode();
tx.success();
}
try (Transaction tx = db.beginTx()) {
node1.createRelationshipTo(node2, RelationshipType.withName("LIKE"));
tx.failure();
}
db = dbRule.restartDatabase();
// When
Relationship relationship;
try (Transaction tx = db.beginTx()) {
node1 = db.getNodeById(node1.getId());
node2 = db.getNodeById(node2.getId());
relationship = node1.createRelationshipTo(node2, RelationshipType.withName("LIKE"));
tx.success();
}
// Then
assertThat(relationship.getId(), equalTo(0L));
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class IdReuseTest method relationshipIdReusableOnlyAfterTransactionFinish.
@Test
public void relationshipIdReusableOnlyAfterTransactionFinish() {
Label testLabel = Label.label("testLabel");
long relationshipId = createRelationship(testLabel);
final IdController idMaintenanceController = getIdMaintenanceController();
try (Transaction transaction = dbRule.beginTx();
ResourceIterator<Node> nodes = dbRule.findNodes(testLabel)) {
List<Node> nodeList = Iterators.asList(nodes);
for (Node node : nodeList) {
Iterable<Relationship> relationships = node.getRelationships(TestRelationshipType.MARKER);
for (Relationship relationship : relationships) {
relationship.delete();
}
}
idMaintenanceController.maintenance();
Node node1 = dbRule.createNode(testLabel);
Node node2 = dbRule.createNode(testLabel);
Relationship relationshipTo = node1.createRelationshipTo(node2, TestRelationshipType.MARKER);
assertNotEquals("Relatioships should have different ids.", relationshipId, relationshipTo.getId());
transaction.success();
}
}
Aggregations