org.vertexium.cypher.ast.model.CypherCreateClause Maven / Gradle / Ivy
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 extends CypherAstBase> getChildren() {
return patternParts.stream();
}
}