All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.vertexium.cypher.ast.model.CypherCreateClause Maven / Gradle / Ivy

There is a newer version: 4.10.0
Show newest version
package org.vertexium.cypher.ast.model;

import com.google.common.collect.ImmutableList;
import org.vertexium.cypher.exceptions.VertexiumCypherSyntaxErrorException;

import java.util.stream.Collectors;
import java.util.stream.Stream;

public class CypherCreateClause extends CypherClause {
    private final ImmutableList patternParts;

    public CypherCreateClause(ImmutableList patternParts) {
        checkRequiresDirectedRelationship(patternParts);
        this.patternParts = patternParts;
    }

    private void checkRequiresDirectedRelationship(ImmutableList patternParts) {
        for (CypherPatternPart patternPart : patternParts) {
            for (CypherElementPattern elementPattern : patternPart.getElementPatterns()) {
                if (elementPattern instanceof CypherRelationshipPattern) {
                    CypherDirection direction = ((CypherRelationshipPattern) elementPattern).getDirection();
                    if (!direction.isDirected()) {
                        throw new VertexiumCypherSyntaxErrorException("RequiresDirectedRelationship: Relationship create statements must have direction: " + elementPattern);
                    }
                }
            }
        }
    }

    public ImmutableList getPatternParts() {
        return patternParts;
    }

    @Override
    public String toString() {
        return String.format(
            "CREATE %s",
            getPatternParts().stream().map(CypherPatternPart::toString).collect(Collectors.joining(", "))
        );
    }

    @Override
    public Stream getChildren() {
        return patternParts.stream();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy