use of org.neo4j.graphdb.Relationship in project javaee7-samples by javaee-samples.
the class PersonSessionBean method getPersons.
public List<BackingBean> getPersons() {
List<BackingBean> beans = new ArrayList();
try (Transaction tx = graphDb.beginTx()) {
for (String key : firstNode.getPropertyKeys()) {
BackingBean bean = new BackingBean();
Person p = Person.fromString((String) firstNode.getProperty(key));
bean.setName(p.getName());
bean.setAge(p.getAge());
for (Relationship r : firstNode.getRelationships(RelTypes.SPOUSE, RelTypes.SISTER, RelTypes.BROTHER)) {
if (r.isType(RelTypes.SPOUSE)) {
bean.setRelationship("spouse");
break;
} else if (r.isType(RelTypes.SISTER)) {
bean.setRelationship("sister");
break;
} else if (r.isType(RelTypes.BROTHER)) {
bean.setRelationship("brother");
break;
}
}
beans.add(bean);
}
tx.success();
}
return beans;
}
use of org.neo4j.graphdb.Relationship in project qi4j-sdk by Qi4j.
the class NeoNamedAssociationState method remove.
@Override
public boolean remove(String name) {
for (Relationship rel : underlyingNode.getRelationships(RelTypes.NAMED_ASSOCIATION, Direction.OUTGOING)) {
if (getRelationshipName(rel).equals(name)) {
rel.delete();
decrementCount();
entity.setUpdated();
return true;
}
}
return false;
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class TestPropertyBlocks method testYoyoArrayBase.
private void testYoyoArrayBase(boolean withNewTx) {
Relationship rel = getGraphDb().createNode().createRelationshipTo(getGraphDb().createNode(), RelationshipType.withName("LOCKS"));
long recordsInUseAtStart = propertyRecordsInUse();
long valueRecordsInUseAtStart = dynamicArrayRecordsInUse();
List<Long> theYoyoData = new ArrayList<Long>();
for (int i = 0; i < PropertyType.getPayloadSizeLongs() - 1; i++) {
theYoyoData.add(1L << 63);
Long[] value = theYoyoData.toArray(new Long[] {});
rel.setProperty("yoyo", value);
if (withNewTx) {
newTransaction();
assertEquals(recordsInUseAtStart + 1, propertyRecordsInUse());
assertEquals(valueRecordsInUseAtStart, dynamicArrayRecordsInUse());
}
}
theYoyoData.add(1L << 63);
Long[] value = theYoyoData.toArray(new Long[] {});
rel.setProperty("yoyo", value);
newTransaction();
assertEquals(recordsInUseAtStart + 1, propertyRecordsInUse());
assertEquals(valueRecordsInUseAtStart + 1, dynamicArrayRecordsInUse());
rel.setProperty("filler", new long[] { 1 << 63, 1 << 63, 1 << 63 });
newTransaction();
assertEquals(recordsInUseAtStart + 2, propertyRecordsInUse());
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class ParallelBatchImporterTest method verifyData.
protected void verifyData(int nodeCount, int relationshipCount, GraphDatabaseService db, IdGroupDistribution groups, long nodeRandomSeed, long relationshipRandomSeed) {
// Read all nodes, relationships and properties ad verify against the input data.
try (InputIterator<InputNode> nodes = nodes(nodeRandomSeed, nodeCount, inputIdGenerator, groups).iterator();
InputIterator<InputRelationship> relationships = relationships(relationshipRandomSeed, relationshipCount, inputIdGenerator, groups).iterator()) {
// Nodes
Map<String, Node> nodeByInputId = new HashMap<>(nodeCount);
Iterator<Node> dbNodes = db.getAllNodes().iterator();
int verifiedNodes = 0;
while (nodes.hasNext()) {
InputNode input = nodes.next();
Node node = dbNodes.next();
assertNodeEquals(input, node);
String inputId = uniqueId(input.group(), node);
assertNull(nodeByInputId.put(inputId, node));
verifiedNodes++;
assertDegrees(node);
}
assertEquals(nodeCount, verifiedNodes);
// Relationships
Map<String, Relationship> relationshipByName = new HashMap<>();
for (Relationship relationship : db.getAllRelationships()) {
relationshipByName.put((String) relationship.getProperty("id"), relationship);
}
int verifiedRelationships = 0;
while (relationships.hasNext()) {
InputRelationship input = relationships.next();
if (!inputIdGenerator.isMiss(input.startNode()) && !inputIdGenerator.isMiss(input.endNode())) {
// A relationship referring to missing nodes. The InputIdGenerator is expected to generate
// some (very few) of those. Skip it.
String name = (String) propertyOf(input, "id");
Relationship relationship = relationshipByName.get(name);
assertNotNull("Expected there to be a relationship with name '" + name + "'", relationship);
assertEquals(nodeByInputId.get(uniqueId(input.startNodeGroup(), input.startNode())), relationship.getStartNode());
assertEquals(nodeByInputId.get(uniqueId(input.endNodeGroup(), input.endNode())), relationship.getEndNode());
assertRelationshipEquals(input, relationship);
}
verifiedRelationships++;
}
assertEquals(relationshipCount, verifiedRelationships);
}
}
use of org.neo4j.graphdb.Relationship in project neo4j by neo4j.
the class TxStateTransactionDataViewTest method correctlySaysRelIsDeleted.
@Test
public void correctlySaysRelIsDeleted() throws Exception {
// Given
state.relationshipDoDelete(1L, 1, 1L, 2L);
Relationship rel = mock(Relationship.class);
when(rel.getId()).thenReturn(1L);
long noPropertyId = -1L;
when(storeStatement.acquireSingleRelationshipCursor(1L)).thenReturn(asRelationshipCursor(1L, 1, 1L, 2L, noPropertyId));
when(storeStatement.acquirePropertyCursor(noPropertyId, NO_LOCK)).thenReturn(asPropertyCursor());
// When & Then
assertThat(snapshot().isDeleted(rel), equalTo(true));
}
Aggregations