Search in sources :

Example 1 with RelationshipValue

use of org.neo4j.values.virtual.RelationshipValue in project neo4j by neo4j.

the class PathValueBuilder method addMultipleIncoming.

/**
 * Adds multiple incoming relationships to the path
 *
 * @param relationships the incoming relationships to add
 * @param target the final target node of the path
 */
@CalledFromGeneratedCode
public void addMultipleIncoming(ListValue relationships, NodeValue target) {
    if (relationships.isEmpty()) {
        // nothing to do here
        return;
    }
    int i;
    for (i = 0; i < relationships.size() - 1; i++) {
        AnyValue value = relationships.value(i);
        if (notNoValue(value)) {
            RelationshipValue relationship = (RelationshipValue) value;
            nodes.add(relationship.startNode());
            rels.add(relationship);
        }
    }
    AnyValue last = relationships.value(i);
    if (notNoValue(last)) {
        rels.add((RelationshipValue) last);
        nodes.add(target);
    }
}
Also used : AnyValue(org.neo4j.values.AnyValue) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) CalledFromGeneratedCode(org.neo4j.util.CalledFromGeneratedCode)

Example 2 with RelationshipValue

use of org.neo4j.values.virtual.RelationshipValue in project neo4j by neo4j.

the class PathValueBuilder method addMultipleOutgoing.

/**
 * Adds multiple outgoing relationships to the path
 *
 * @param relationships the outgoing relationships to add
 */
@CalledFromGeneratedCode
public void addMultipleOutgoing(ListValue relationships) {
    for (AnyValue value : relationships) {
        if (notNoValue(value)) {
            // we know these relationships have already loaded start and end relationship
            // so we should not use CypherFunctions::[start,end]Node to look them up
            RelationshipValue relationship = (RelationshipValue) value;
            nodes.add(relationship.endNode());
            rels.add(relationship);
        }
    }
}
Also used : AnyValue(org.neo4j.values.AnyValue) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) CalledFromGeneratedCode(org.neo4j.util.CalledFromGeneratedCode)

Example 3 with RelationshipValue

use of org.neo4j.values.virtual.RelationshipValue in project neo4j by neo4j.

the class PathValueBuilder method addMultipleIncoming.

/**
 * Adds multiple incoming relationships to the path
 *
 * @param relationships the incoming relationships to add
 */
@CalledFromGeneratedCode
public void addMultipleIncoming(ListValue relationships) {
    for (AnyValue value : relationships) {
        if (notNoValue(value)) {
            // we know these relationships have already loaded start and end relationship
            // so we should not use CypherFunctions::[start,end]Node to look them up
            RelationshipValue relationship = (RelationshipValue) value;
            nodes.add(relationship.startNode());
            rels.add(relationship);
        }
    }
}
Also used : AnyValue(org.neo4j.values.AnyValue) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) CalledFromGeneratedCode(org.neo4j.util.CalledFromGeneratedCode)

Example 4 with RelationshipValue

use of org.neo4j.values.virtual.RelationshipValue in project neo4j by neo4j.

the class PathValueBuilder method addMultipleOutgoing.

/**
 * Adds multiple outgoing relationships to the path
 *
 * @param relationships the outgoing relationships to add
 * @param target the final target node of the path
 */
@CalledFromGeneratedCode
public void addMultipleOutgoing(ListValue relationships, NodeValue target) {
    if (relationships.isEmpty()) {
        // nothing to do here
        return;
    }
    int i;
    for (i = 0; i < relationships.size() - 1; i++) {
        AnyValue value = relationships.value(i);
        if (notNoValue(value)) {
            // we know these relationships have already loaded start and end relationship
            // so we should not use CypherFunctions::[start,end]Node to look them up
            RelationshipValue relationship = (RelationshipValue) value;
            nodes.add(relationship.endNode());
            rels.add(relationship);
        }
    }
    AnyValue last = relationships.value(i);
    if (notNoValue(last)) {
        rels.add((RelationshipValue) last);
        nodes.add(target);
    }
}
Also used : AnyValue(org.neo4j.values.AnyValue) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) CalledFromGeneratedCode(org.neo4j.util.CalledFromGeneratedCode)

Example 5 with RelationshipValue

use of org.neo4j.values.virtual.RelationshipValue in project neo4j by neo4j.

the class SchemaProcedureIT method testRelationShip.

@Test
void testRelationShip() throws Throwable {
    // Given there ar
    KernelTransaction transaction = newTransaction(AnonymousContext.writeToken());
    long nodeIdPerson = transaction.dataWrite().nodeCreate();
    int labelIdPerson = transaction.tokenWrite().labelGetOrCreateForName("Person");
    transaction.dataWrite().nodeAddLabel(nodeIdPerson, labelIdPerson);
    long nodeIdLocation = transaction.dataWrite().nodeCreate();
    int labelIdLocation = transaction.tokenWrite().labelGetOrCreateForName("Location");
    transaction.dataWrite().nodeAddLabel(nodeIdLocation, labelIdLocation);
    int relationshipTypeId = transaction.tokenWrite().relationshipTypeGetOrCreateForName("LIVES_IN");
    transaction.dataWrite().relationshipCreate(nodeIdPerson, relationshipTypeId, nodeIdLocation);
    commit();
    RawIterator<AnyValue[], ProcedureException> stream = procs().procedureCallRead(procs().procedureGet(procedureName("db", "schema", "visualization")).id(), new AnyValue[0], ProcedureCallContext.EMPTY);
    // Then
    while (stream.hasNext()) {
        AnyValue[] next = stream.next();
        assertEquals(2, next.length);
        ListValue relationships = (ListValue) next[1];
        assertEquals(1, relationships.size());
        RelationshipValue relationship = (RelationshipValue) relationships.value(0);
        assertEquals("LIVES_IN", relationship.type().stringValue());
        assertThat(relationship.startNode().labels()).isEqualTo(Values.stringArray("Person"));
        assertThat(relationship.endNode().labels()).isEqualTo(Values.stringArray("Location"));
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ListValue(org.neo4j.values.virtual.ListValue) AnyValue(org.neo4j.values.AnyValue) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) Test(org.junit.jupiter.api.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Aggregations

RelationshipValue (org.neo4j.values.virtual.RelationshipValue)24 Test (org.junit.jupiter.api.Test)15 NodeValue (org.neo4j.values.virtual.NodeValue)13 AnyValue (org.neo4j.values.AnyValue)11 CalledFromGeneratedCode (org.neo4j.util.CalledFromGeneratedCode)6 ListValue (org.neo4j.values.virtual.ListValue)3 PathValue (org.neo4j.values.virtual.PathValue)3 Relationship (org.neo4j.graphdb.Relationship)2 Values.stringValue (org.neo4j.values.storable.Values.stringValue)2 MapValue (org.neo4j.values.virtual.MapValue)2 VirtualNodeValue (org.neo4j.values.virtual.VirtualNodeValue)2 VirtualRelationshipValue (org.neo4j.values.virtual.VirtualRelationshipValue)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)1 Mockito (org.mockito.Mockito)1 Mockito.mock (org.mockito.Mockito.mock)1