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

org.vertexium.cypher.executionPlan.RemoveLabelItemExecutionStep Maven / Gradle / Ivy

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

import org.vertexium.Vertex;
import org.vertexium.cypher.VertexiumCypherQueryContext;
import org.vertexium.cypher.VertexiumCypherResult;
import org.vertexium.cypher.ast.model.CypherLabelName;
import org.vertexium.cypher.exceptions.VertexiumCypherNotImplemented;
import org.vertexium.mutation.ExistingElementMutation;

public class RemoveLabelItemExecutionStep extends ExecutionStepWithChildren {
    private final String leftResultName;
    private final Iterable labelNames;

    public RemoveLabelItemExecutionStep(ExecutionStepWithResultName left, Iterable labelNames) {
        super(left);
        this.leftResultName = left.getResultName();
        this.labelNames = labelNames;
    }

    @Override
    public VertexiumCypherResult execute(VertexiumCypherQueryContext ctx, VertexiumCypherResult source) {
        source = super.execute(ctx, source);
        return source.peek(row -> {
            Object left = row.get(leftResultName);
            if (left instanceof Vertex) {
                executeRemoveLabels(ctx, (Vertex) left);
            } else {
                throw new VertexiumCypherNotImplemented("left is not an vertex: " + left.getClass().getName());
            }
        });
    }

    private void executeRemoveLabels(VertexiumCypherQueryContext ctx, Vertex vertex) {
        ExistingElementMutation m = vertex.prepareMutation();
        for (CypherLabelName labelName : labelNames) {
            ctx.removeLabel(m, labelName.getValue());
        }
        ctx.saveElement(m);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy