Search in sources :

Example 1 with Relationship

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;
}
Also used : Transaction(org.neo4j.graphdb.Transaction) Relationship(org.neo4j.graphdb.Relationship) ArrayList(java.util.ArrayList)

Example 2 with Relationship

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;
}
Also used : Relationship(org.neo4j.graphdb.Relationship)

Example 3 with Relationship

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());
}
Also used : Relationship(org.neo4j.graphdb.Relationship) ArrayList(java.util.ArrayList)

Example 4 with Relationship

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);
    }
}
Also used : InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) HashMap(java.util.HashMap) InputNode(org.neo4j.unsafe.impl.batchimport.input.InputNode) Node(org.neo4j.graphdb.Node) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship) Relationship(org.neo4j.graphdb.Relationship) InputRelationship(org.neo4j.unsafe.impl.batchimport.input.InputRelationship)

Example 5 with Relationship

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));
}
Also used : Relationship(org.neo4j.graphdb.Relationship) Test(org.junit.Test)

Aggregations

Relationship (org.neo4j.graphdb.Relationship)773 Node (org.neo4j.graphdb.Node)559 Transaction (org.neo4j.graphdb.Transaction)303 Test (org.junit.Test)225 Test (org.junit.jupiter.api.Test)147 GraphDatabaseService (org.neo4j.graphdb.GraphDatabaseService)69 RelationshipType (org.neo4j.graphdb.RelationshipType)64 HashMap (java.util.HashMap)55 LinkedList (java.util.LinkedList)52 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)46 ArrayList (java.util.ArrayList)44 Path (org.neo4j.graphdb.Path)44 HashSet (java.util.HashSet)35 Study (org.eol.globi.domain.Study)33 Map (java.util.Map)31 Direction (org.neo4j.graphdb.Direction)30 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)28 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)28 List (java.util.List)26 NotFoundException (org.neo4j.graphdb.NotFoundException)25