All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.orientechnologies.orient.core.sql.executor.ODeleteVertexExecutionPlanner Maven / Gradle / Ivy
package com.orientechnologies.orient.core.sql.executor;
import com.orientechnologies.orient.core.command.OCommandContext;
import com.orientechnologies.orient.core.exception.OCommandExecutionException;
import com.orientechnologies.orient.core.sql.parser.ODeleteVertexStatement;
import com.orientechnologies.orient.core.sql.parser.OFromClause;
import com.orientechnologies.orient.core.sql.parser.OIndexIdentifier;
import com.orientechnologies.orient.core.sql.parser.OLimit;
import com.orientechnologies.orient.core.sql.parser.OSelectStatement;
import com.orientechnologies.orient.core.sql.parser.OWhereClause;
/** Created by luigidellaquila on 08/08/16. */
public class ODeleteVertexExecutionPlanner {
private final OFromClause fromClause;
private final OWhereClause whereClause;
private final boolean returnBefore;
private final OLimit limit;
public ODeleteVertexExecutionPlanner(ODeleteVertexStatement stm) {
this.fromClause = stm.getFromClause() == null ? null : stm.getFromClause().copy();
this.whereClause = stm.getWhereClause() == null ? null : stm.getWhereClause().copy();
this.returnBefore = stm.isReturnBefore();
this.limit = stm.getLimit() == null ? null : stm.getLimit();
}
public ODeleteExecutionPlan createExecutionPlan(OCommandContext ctx, boolean enableProfiling) {
ODeleteExecutionPlan result = new ODeleteExecutionPlan(ctx);
if (handleIndexAsTarget(result, fromClause.getItem().getIndex(), whereClause, ctx)) {
if (limit != null) {
throw new OCommandExecutionException("Cannot apply a LIMIT on a delete from index");
}
if (returnBefore) {
throw new OCommandExecutionException("Cannot apply a RETURN BEFORE on a delete from index");
}
} else {
handleTarget(result, ctx, this.fromClause, this.whereClause, enableProfiling);
handleLimit(result, ctx, this.limit, enableProfiling);
}
handleCastToVertex(result, ctx, enableProfiling);
handleDelete(result, ctx, enableProfiling);
handleReturn(result, ctx, this.returnBefore, enableProfiling);
return result;
}
private boolean handleIndexAsTarget(
ODeleteExecutionPlan result,
OIndexIdentifier indexIdentifier,
OWhereClause whereClause,
OCommandContext ctx) {
if (indexIdentifier == null) {
return false;
}
throw new OCommandExecutionException("DELETE VERTEX FROM INDEX is not supported");
}
private void handleDelete(
ODeleteExecutionPlan result, OCommandContext ctx, boolean profilingEnabled) {
result.chain(new DeleteStep(ctx, profilingEnabled));
}
private void handleUnsafe(
ODeleteExecutionPlan result, OCommandContext ctx, boolean unsafe, boolean profilingEnabled) {
if (!unsafe) {
result.chain(new CheckSafeDeleteStep(ctx, profilingEnabled));
}
}
private void handleReturn(
ODeleteExecutionPlan result,
OCommandContext ctx,
boolean returnBefore,
boolean profilingEnabled) {
if (!returnBefore) {
result.chain(new CountStep(ctx, profilingEnabled));
}
}
private void handleLimit(
OUpdateExecutionPlan plan, OCommandContext ctx, OLimit limit, boolean profilingEnabled) {
if (limit != null) {
plan.chain(new LimitExecutionStep(limit, ctx, profilingEnabled));
}
}
private void handleCastToVertex(
ODeleteExecutionPlan plan, OCommandContext ctx, boolean profilingEnabled) {
plan.chain(new CastToVertexStep(ctx, profilingEnabled));
}
private void handleTarget(
OUpdateExecutionPlan result,
OCommandContext ctx,
OFromClause target,
OWhereClause whereClause,
boolean profilingEnabled) {
OSelectStatement sourceStatement = new OSelectStatement(-1);
sourceStatement.setTarget(target);
sourceStatement.setWhereClause(whereClause);
OSelectExecutionPlanner planner = new OSelectExecutionPlanner(sourceStatement);
result.chain(
new SubQueryStep(
planner.createExecutionPlan(ctx, profilingEnabled, false), ctx, ctx, profilingEnabled));
}
}