core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLDeleteEdge.java
public Object execute(final Map<Object, Object> iArgs) {
    if (fromExpr == null && toExpr == null && rids == null && query == null && compiledFilter == null)
      throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
    ODatabaseDocumentInternal db = getDatabase();
    txAlreadyBegun = db.getTransaction().isActive();

    if (rids != null) {
      // REMOVE PUNCTUAL RID
      db.begin();
      for (ORecordId rid : rids) {
        final OEdge e = toEdge(rid);
        if (e != null) {
          e.delete();
          removed++;
        }
      }
      db.commit();
      return removed;
    } else {
      // MULTIPLE EDGES
      final Set<OEdge> edges = new HashSet<OEdge>();
      if (query == null) {
        db.begin();
        Set<OIdentifiable> fromIds = null;
        if (fromExpr != null)
          fromIds = OSQLEngine.getInstance().parseRIDTarget(db, fromExpr, context, iArgs);
        Set<OIdentifiable> toIds = null;
        if (toExpr != null)
          toIds = OSQLEngine.getInstance().parseRIDTarget(db, toExpr, context, iArgs);
        if (label == null)
          label = "E";

        if (fromIds != null && toIds != null) {
          int fromCount = 0;
          int toCount = 0;
          for (OIdentifiable fromId : fromIds) {
            final OVertex v = toVertex(fromId);
            if (v != null)
              fromCount += count(v.getEdges(ODirection.OUT, label));
          }
          for (OIdentifiable toId : toIds) {
            final OVertex v = toVertex(toId);
            if (v != null)
              toCount += count(v.getEdges(ODirection.IN, label));
          }
          if (fromCount <= toCount) {
            // REMOVE ALL THE EDGES BETWEEN VERTICES
            for (OIdentifiable fromId : fromIds) {
              final OVertex v = toVertex(fromId);
              if (v != null)
                for (OEdge e : v.getEdges(ODirection.OUT, label)) {
                  final OIdentifiable inV = ((OEdge) e).getTo();
                  if (inV != null && toIds.contains(inV.getIdentity()))
                    edges.add(e);
                }
            }
          } else {
            for (OIdentifiable toId : toIds) {
              final OVertex v = toVertex(toId);
              if (v != null)
                for (OEdge e : v.getEdges(ODirection.IN, label)) {
                  final OIdentifiable outV = ((OEdge) e).getFrom();
                  if (outV != null && fromIds.contains(outV.getIdentity()))
                    edges.add(e);
                }
            }
          }
        } else if (fromIds != null) {
          // REMOVE ALL THE EDGES THAT START FROM A VERTEXES
          for (OIdentifiable fromId : fromIds) {

            final OVertex v = toVertex(fromId);
            if (v != null) {
              for (OEdge e : v.getEdges(ODirection.OUT, label)) {
                edges.add(e);
              }
            }
          }
        } else if (toIds != null) {
          // REMOVE ALL THE EDGES THAT ARRIVE TO A VERTEXES
          for (OIdentifiable toId : toIds) {
            final OVertex v = toVertex(toId);
            if (v != null) {
              for (OEdge e : v.getEdges(ODirection.IN, label)) {
                edges.add(e);
              }
            }
          }
        } else
          throw new OCommandExecutionException("Invalid target: " + toIds);

        if (compiledFilter != null) {
          // ADDITIONAL FILTERING
          for (Iterator<OEdge> it = edges.iterator(); it.hasNext(); ) {
            final OEdge edge = it.next();
            if (!(Boolean) compiledFilter.evaluate(edge.getRecord(), null, context))
              it.remove();
          }
        }

        // DELETE THE FOUND EDGES
        removed = edges.size();
        for (OEdge edge : edges)
          edge.delete();

        db.commit();
        return removed;

      } else {
        db.begin();
        // TARGET IS A CLASS + OPTIONAL CONDITION
        query.setContext(getContext());
        query.execute(iArgs);
        db.commit();
        return removed;
      }
    }
  }
public Object execute(final Map<Object, Object> iArgs) {
    if (fromExpr == null && toExpr == null && rids == null && query == null && compiledFilter == null)
      throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
    ODatabaseDocumentInternal db = getDatabase();
    txAlreadyBegun = db.getTransaction().isActive();

    if (rids != null) {
      // REMOVE PUNCTUAL RID
      db.begin();
      for (ORecordId rid : rids) {
        final OEdge e = toEdge(rid);
        if (e != null) {
          e.delete();
          removed++;
        }
      }
      db.commit();
      return removed;
    } else {
      // MULTIPLE EDGES
      final Set<OEdge> edges = new HashSet<OEdge>();
      if (query == null) {
        db.begin();
        Set<OIdentifiable> fromIds = null;
        if (fromExpr != null)
          fromIds = OSQLEngine.getInstance().parseRIDTarget(db, fromExpr, context, iArgs);
        Set<OIdentifiable> toIds = null;
        if (toExpr != null)
          toIds = OSQLEngine.getInstance().parseRIDTarget(db, toExpr, context, iArgs);
        if (label == null)
          label = "E";

        if (fromIds != null && toIds != null) {
          int fromCount = 0;
          int toCount = 0;
          for (OIdentifiable fromId : fromIds) {
            final OVertex v = toVertex(fromId);
            if (v != null)
              fromCount += count(v.getEdges(ODirection.OUT, label));
          }
          for (OIdentifiable toId : toIds) {
            final OVertex v = toVertex(toId);
            if (v != null)
              toCount += count(v.getEdges(ODirection.IN, label));
          }
          if (fromCount <= toCount) {
            // REMOVE ALL THE EDGES BETWEEN VERTICES
            for (OIdentifiable fromId : fromIds) {
              final OVertex v = toVertex(fromId);
              if (v != null)
                for (OEdge e : v.getEdges(ODirection.OUT, label)) {
                  final OIdentifiable inV = ((OEdge) e).getTo();
                  if (inV != null && toIds.contains(inV.getIdentity()))
                    edges.add(e);
                }
            }
          } else {
            for (OIdentifiable toId : toIds) {
              final OVertex v = toVertex(toId);
              if (v != null)
                for (OEdge e : v.getEdges(ODirection.IN, label)) {
                  final OIdentifiable outV = ((OEdge) e).getFrom();
                  if (outV != null && fromIds.contains(outV.getIdentity()))
                    edges.add(e);
                }
            }
          }
        } else if (fromIds != null) {
          // REMOVE ALL THE EDGES THAT START FROM A VERTEXES
          for (OIdentifiable fromId : fromIds) {

            final OVertex v = toVertex(fromId);
            if (v != null) {
              for (OEdge e : v.getEdges(ODirection.OUT, label)) {
                edges.add(e);
              }
            }
          }
        } else if (toIds != null) {
          // REMOVE ALL THE EDGES THAT ARRIVE TO A VERTEXES
          for (OIdentifiable toId : toIds) {
            final OVertex v = toVertex(toId);
            if (v != null) {
              for (OEdge e : v.getEdges(ODirection.IN, label)) {
                edges.add(e);
              }
            }
          }
        } else
          throw new OCommandExecutionException("Invalid target: " + toIds);

        if (compiledFilter != null) {
          // ADDITIONAL FILTERING
          for (Iterator<OEdge> it = edges.iterator(); it.hasNext(); ) {
            final OEdge edge = it.next();
            if (!(Boolean) compiledFilter.evaluate(edge.getRecord(), null, context))
              it.remove();
          }
        }

        // DELETE THE FOUND EDGES
        removed = edges.size();
        for (OEdge edge : edges)
          edge.delete();

        db.commit();
        return removed;

      } else {
        db.begin();
        // TARGET IS A CLASS + OPTIONAL CONDITION
        query.setContext(getContext());
        query.execute(iArgs);
        db.commit();
        return removed;
      }
    }
  }
Execute the command and return the ODocument object created.