graphdb/src/main/java/com/orientechnologies/orient/graph/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");

    txAlreadyBegun = getDatabase().getTransaction().isActive();

    if (rids != null) {
      // REMOVE PUNCTUAL RID
      OGraphCommandExecutorSQLFactory.runInConfiguredTxMode(new OGraphCommandExecutorSQLFactory.GraphCallBack<Object>() {
        @Override
        public Object call(OrientBaseGraph graph) {
          for (ORecordId rid : rids) {
            final OrientEdge e = graph.getEdge(rid);
            if (e != null) {
              e.remove();
              removed++;
            }
          }
          return null;
        }
      });
      // CLOSE PENDING TX
      end();

    } else {
      // MULTIPLE EDGES
      final Set<OrientEdge> edges = new HashSet<OrientEdge>();
      if (query == null) {
        OGraphCommandExecutorSQLFactory.runInConfiguredTxMode(new OGraphCommandExecutorSQLFactory.GraphCallBack<Object>() {

          @Override
          public Object call(OrientBaseGraph graph) {
            Set<OIdentifiable> fromIds = null;
            if (fromExpr != null)
              fromIds = OSQLEngine.getInstance().parseRIDTarget(graph.getRawGraph(), fromExpr, context, iArgs);
            Set<OIdentifiable> toIds = null;
            if (toExpr != null)
              toIds = OSQLEngine.getInstance().parseRIDTarget(graph.getRawGraph(), toExpr, context, iArgs);
            if(label == null )
              label = OrientEdgeType.CLASS_NAME;
            
            if (fromIds != null && toIds != null) {
              int fromCount = 0;
              int toCount = 0;
              for (OIdentifiable fromId : fromIds) {
                final OrientVertex v = graph.getVertex(fromId);
                if (v != null)
                  fromCount += v.countEdges(Direction.OUT, label);
              }
              for (OIdentifiable toId : toIds) {
                final OrientVertex v = graph.getVertex(toId);
                if (v != null)
                  toCount += v.countEdges(Direction.IN, label);
              }
              if (fromCount <= toCount) {
                // REMOVE ALL THE EDGES BETWEEN VERTICES
                for (OIdentifiable fromId : fromIds) {
                  final OrientVertex v = graph.getVertex(fromId);
                  if (v != null)
                    for (Edge e : v.getEdges(Direction.OUT, label)) {
                      final OIdentifiable inV = ((OrientEdge) e).getInVertex();
                      if (inV != null && toIds.contains(inV.getIdentity()))
                        edges.add((OrientEdge) e);
                    }
                }
              } else {
                for (OIdentifiable toId : toIds) {
                  final OrientVertex v = graph.getVertex(toId);
                  if (v != null)
                    for (Edge e : v.getEdges(Direction.IN, label)) {
                      final OIdentifiable outV = ((OrientEdge) e).getOutVertex();
                      if (outV != null && fromIds.contains(outV.getIdentity()))
                        edges.add((OrientEdge) e);
                    }
                }
              }
            } else if (fromIds != null) {
              // REMOVE ALL THE EDGES THAT START FROM A VERTEXES
              for (OIdentifiable fromId : fromIds) {
                
                final OrientVertex v = graph.getVertex(fromId);
                if (v != null) {
                  for (Edge e : v.getEdges(Direction.OUT, label)) {
                    edges.add((OrientEdge) e);
                  }
                }
              }
            } else if (toIds != null) {
              // REMOVE ALL THE EDGES THAT ARRIVE TO A VERTEXES
              for (OIdentifiable toId : toIds) {
                final OrientVertex v = graph.getVertex(toId);
                if (v != null) {
                  for (Edge e : v.getEdges(Direction.IN, label)) {
                    edges.add((OrientEdge) e);
                  }
                }
              }
            } else
              throw new OCommandExecutionException("Invalid target: " + toIds);

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

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

            return null;
          }
        });

        // CLOSE PENDING TX
        end();

      } else {
        OGraphCommandExecutorSQLFactory.runInConfiguredTxMode(new OGraphCommandExecutorSQLFactory.GraphCallBack<OrientGraph>() {
          @Override
          public OrientGraph call(final OrientBaseGraph iGraph) {
            // TARGET IS A CLASS + OPTIONAL CONDITION
            currentGraph.set(iGraph);
            query.setContext(getContext());
            query.execute(iArgs);
            return null;
          }
        });
      }
    }

    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");

    txAlreadyBegun = getDatabase().getTransaction().isActive();

    if (rids != null) {
      // REMOVE PUNCTUAL RID
      OGraphCommandExecutorSQLFactory.runInConfiguredTxMode(new OGraphCommandExecutorSQLFactory.GraphCallBack<Object>() {
        @Override
        public Object call(OrientBaseGraph graph) {
          for (ORecordId rid : rids) {
            final OrientEdge e = graph.getEdge(rid);
            if (e != null) {
              e.remove();
              removed++;
            }
          }
          return null;
        }
      });
      // CLOSE PENDING TX
      end();

    } else {
      // MULTIPLE EDGES
      final Set<OrientEdge> edges = new HashSet<OrientEdge>();
      if (query == null) {
        OGraphCommandExecutorSQLFactory.runInConfiguredTxMode(new OGraphCommandExecutorSQLFactory.GraphCallBack<Object>() {

          @Override
          public Object call(OrientBaseGraph graph) {
            Set<OIdentifiable> fromIds = null;
            if (fromExpr != null)
              fromIds = OSQLEngine.getInstance().parseRIDTarget(graph.getRawGraph(), fromExpr, context, iArgs);
            Set<OIdentifiable> toIds = null;
            if (toExpr != null)
              toIds = OSQLEngine.getInstance().parseRIDTarget(graph.getRawGraph(), toExpr, context, iArgs);
            if(label == null )
              label = OrientEdgeType.CLASS_NAME;
            
            if (fromIds != null && toIds != null) {
              int fromCount = 0;
              int toCount = 0;
              for (OIdentifiable fromId : fromIds) {
                final OrientVertex v = graph.getVertex(fromId);
                if (v != null)
                  fromCount += v.countEdges(Direction.OUT, label);
              }
              for (OIdentifiable toId : toIds) {
                final OrientVertex v = graph.getVertex(toId);
                if (v != null)
                  toCount += v.countEdges(Direction.IN, label);
              }
              if (fromCount <= toCount) {
                // REMOVE ALL THE EDGES BETWEEN VERTICES
                for (OIdentifiable fromId : fromIds) {
                  final OrientVertex v = graph.getVertex(fromId);
                  if (v != null)
                    for (Edge e : v.getEdges(Direction.OUT, label)) {
                      final OIdentifiable inV = ((OrientEdge) e).getInVertex();
                      if (inV != null && toIds.contains(inV.getIdentity()))
                        edges.add((OrientEdge) e);
                    }
                }
              } else {
                for (OIdentifiable toId : toIds) {
                  final OrientVertex v = graph.getVertex(toId);
                  if (v != null)
                    for (Edge e : v.getEdges(Direction.IN, label)) {
                      final OIdentifiable outV = ((OrientEdge) e).getOutVertex();
                      if (outV != null && fromIds.contains(outV.getIdentity()))
                        edges.add((OrientEdge) e);
                    }
                }
              }
            } else if (fromIds != null) {
              // REMOVE ALL THE EDGES THAT START FROM A VERTEXES
              for (OIdentifiable fromId : fromIds) {
                
                final OrientVertex v = graph.getVertex(fromId);
                if (v != null) {
                  for (Edge e : v.getEdges(Direction.OUT, label)) {
                    edges.add((OrientEdge) e);
                  }
                }
              }
            } else if (toIds != null) {
              // REMOVE ALL THE EDGES THAT ARRIVE TO A VERTEXES
              for (OIdentifiable toId : toIds) {
                final OrientVertex v = graph.getVertex(toId);
                if (v != null) {
                  for (Edge e : v.getEdges(Direction.IN, label)) {
                    edges.add((OrientEdge) e);
                  }
                }
              }
            } else
              throw new OCommandExecutionException("Invalid target: " + toIds);

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

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

            return null;
          }
        });

        // CLOSE PENDING TX
        end();

      } else {
        OGraphCommandExecutorSQLFactory.runInConfiguredTxMode(new OGraphCommandExecutorSQLFactory.GraphCallBack<OrientGraph>() {
          @Override
          public OrientGraph call(final OrientBaseGraph iGraph) {
            // TARGET IS A CLASS + OPTIONAL CONDITION
            currentGraph.set(iGraph);
            query.setContext(getContext());
            query.execute(iArgs);
            return null;
          }
        });
      }
    }

    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" ) ; txAlreadyBegun = getDatabase ( ) . getTransaction ( ) . isActive ( ) ; if ( rids != null ) { // REMOVE PUNCTUAL RID
 OGraphCommandExecutorSQLFactory . runInConfiguredTxMode ( new OGraphCommandExecutorSQLFactory . GraphCallBack < Object > ( ) { @ Override public Object call ( OrientBaseGraph graph ) { for ( ORecordId rid : rids ) { final OrientEdge e = graph . getEdge ( rid ) ; if ( e != null ) { e . remove ( ) ; removed ++ ; } } return null ; } } ) ; // CLOSE PENDING TX
 end ( ) ; } else { // MULTIPLE EDGES
 final Set < OrientEdge > edges = new HashSet < OrientEdge > ( ) ; if ( query == null ) { OGraphCommandExecutorSQLFactory . runInConfiguredTxMode ( new OGraphCommandExecutorSQLFactory . GraphCallBack < Object > ( ) { @ Override public Object call ( OrientBaseGraph graph ) { Set < OIdentifiable > fromIds = null ; if ( fromExpr != null ) fromIds = OSQLEngine . getInstance ( ) . parseRIDTarget ( graph . getRawGraph ( ) , fromExpr , context , iArgs ) ; Set < OIdentifiable > toIds = null ; if ( toExpr != null ) toIds = OSQLEngine . getInstance ( ) . parseRIDTarget ( graph . getRawGraph ( ) , toExpr , context , iArgs ) ; if ( label == null ) label = OrientEdgeType . CLASS_NAME ; if ( fromIds != null && toIds != null ) { int fromCount = 0 ; int toCount = 0 ; for ( OIdentifiable fromId : fromIds ) { final OrientVertex v = graph . getVertex ( fromId ) ; if ( v != null ) fromCount += v . countEdges ( Direction . OUT , label ) ; } for ( OIdentifiable toId : toIds ) { final OrientVertex v = graph . getVertex ( toId ) ; if ( v != null ) toCount += v . countEdges ( Direction . IN , label ) ; } if ( fromCount <= toCount ) { // REMOVE ALL THE EDGES BETWEEN VERTICES
 for ( OIdentifiable fromId : fromIds ) { final OrientVertex v = graph . getVertex ( fromId ) ; if ( v != null ) for ( Edge e : v . getEdges ( Direction . OUT , label ) ) { final OIdentifiable inV = ( ( OrientEdge ) e ) . getInVertex ( ) ; if ( inV != null && toIds . contains ( inV . getIdentity ( ) ) ) edges . add ( ( OrientEdge ) e ) ; } } } else { for ( OIdentifiable toId : toIds ) { final OrientVertex v = graph . getVertex ( toId ) ; if ( v != null ) for ( Edge e : v . getEdges ( Direction . IN , label ) ) { final OIdentifiable outV = ( ( OrientEdge ) e ) . getOutVertex ( ) ; if ( outV != null && fromIds . contains ( outV . getIdentity ( ) ) ) edges . add ( ( OrientEdge ) e ) ; } } } } else if ( fromIds != null ) { // REMOVE ALL THE EDGES THAT START FROM A VERTEXES
 for ( OIdentifiable fromId : fromIds ) { final OrientVertex v = graph . getVertex ( fromId ) ; if ( v != null ) { for ( Edge e : v . getEdges ( Direction . OUT , label ) ) { edges . add ( ( OrientEdge ) e ) ; } } } } else if ( toIds != null ) { // REMOVE ALL THE EDGES THAT ARRIVE TO A VERTEXES
 for ( OIdentifiable toId : toIds ) { final OrientVertex v = graph . getVertex ( toId ) ; if ( v != null ) { for ( Edge e : v . getEdges ( Direction . IN , label ) ) { edges . add ( ( OrientEdge ) e ) ; } } } } else throw new OCommandExecutionException ( "Invalid target: " + toIds ) ; if ( compiledFilter != null ) { // ADDITIONAL FILTERING
 for ( Iterator < OrientEdge > it = edges . iterator ( ) ; it . hasNext ( ) ; ) { final OrientEdge edge = it . next ( ) ; if ( ! ( Boolean ) compiledFilter . evaluate ( edge . getRecord ( ) , null , context ) ) it . remove ( ) ; } } // DELETE THE FOUND EDGES
 removed = edges . size ( ) ; for ( OrientEdge edge : edges ) edge . remove ( ) ; return null ; } } ) ; // CLOSE PENDING TX
 end ( ) ; } else { OGraphCommandExecutorSQLFactory . runInConfiguredTxMode ( new OGraphCommandExecutorSQLFactory . GraphCallBack < OrientGraph > ( ) { @ Override public OrientGraph call ( final OrientBaseGraph iGraph ) { // TARGET IS A CLASS + OPTIONAL CONDITION
 currentGraph . set ( iGraph ) ; query . setContext ( getContext ( ) ) ; query . execute ( iArgs ) ; return null ; } } ) ; } } return removed ; }
Execute the command and return the ODocument object created.
Execute the command and return the ODocument object created .