Search in sources :

Example 6 with CalledFromGeneratedCode

use of org.neo4j.util.CalledFromGeneratedCode 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 7 with CalledFromGeneratedCode

use of org.neo4j.util.CalledFromGeneratedCode in project neo4j by neo4j.

the class PathValueBuilder method addMultipleUndirected.

/**
 * Adds multiple undirected relationships to the path
 *
 * @param relationships the undirected relationships to add
 * @param target the final target node of the path
 */
@CalledFromGeneratedCode
public void addMultipleUndirected(ListValue relationships, NodeValue target) {
    if (relationships.isEmpty()) {
        // nothing to add
        return;
    }
    long previous = nodes.get(nodes.size() - 1).id();
    RelationshipValue first = (RelationshipValue) relationships.head();
    boolean correctDirection = startNode(first, dbAccess, cursor).id() == previous || endNode(first, dbAccess, cursor).id() == previous;
    int i;
    if (correctDirection) {
        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
                addUndirectedWhenRelationshipsAreFullyLoaded((RelationshipValue) value);
            }
        }
    } else {
        for (i = relationships.size() - 1; i > 0; 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
                addUndirectedWhenRelationshipsAreFullyLoaded((RelationshipValue) relationships.value(i));
            }
        }
    }
    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 8 with CalledFromGeneratedCode

use of org.neo4j.util.CalledFromGeneratedCode in project neo4j by neo4j.

the class PathValueBuilder method addMultipleUndirected.

/**
 * Adds multiple undirected relationships to the path
 *
 * @param relationships the undirected relationships to add
 */
@CalledFromGeneratedCode
public void addMultipleUndirected(ListValue relationships) {
    if (relationships.isEmpty()) {
        // nothing to add
        return;
    }
    long previous = nodes.get(nodes.size() - 1).id();
    RelationshipValue first = (RelationshipValue) relationships.head();
    boolean correctDirection = startNode(first, dbAccess, cursor).id() == previous || endNode(first, dbAccess, cursor).id() == previous;
    if (correctDirection) {
        for (AnyValue value : relationships) {
            if (notNoValue(value)) {
                addUndirectedWhenRelationshipsAreFullyLoaded((RelationshipValue) value);
            }
        }
    } else {
        ListValue reversed = relationships.reverse();
        for (AnyValue rel : reversed) {
            if (notNoValue(rel)) {
                addUndirectedWhenRelationshipsAreFullyLoaded((RelationshipValue) rel);
            }
        }
    }
}
Also used : ListValue(org.neo4j.values.virtual.ListValue) AnyValue(org.neo4j.values.AnyValue) RelationshipValue(org.neo4j.values.virtual.RelationshipValue) CalledFromGeneratedCode(org.neo4j.util.CalledFromGeneratedCode)

Aggregations

CalledFromGeneratedCode (org.neo4j.util.CalledFromGeneratedCode)8 AnyValue (org.neo4j.values.AnyValue)7 RelationshipValue (org.neo4j.values.virtual.RelationshipValue)6 ListValue (org.neo4j.values.virtual.ListValue)2 CypherTypeException (org.neo4j.exceptions.CypherTypeException)1 SequenceValue (org.neo4j.values.SequenceValue)1