core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLCreateEdge.java
public Object execute(final Map<Object, Object> iArgs) {
    if (clazz == null)
      throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");

    ODatabaseDocumentInternal db = getDatabase();
    final List<Object> edges = new ArrayList<Object>();
    Set<OIdentifiable> fromIds = null;
    Set<OIdentifiable> toIds = null;
    db.begin();
    try {
      fromIds = OSQLEngine.getInstance().parseRIDTarget(db, from, context, iArgs);
      toIds = OSQLEngine.getInstance().parseRIDTarget(db, to, context, iArgs);

      // CREATE EDGES
      for (OIdentifiable from : fromIds) {
        final OVertex fromVertex = toVertex(from);
        if (fromVertex == null)
          throw new OCommandExecutionException("Source vertex '" + from + "' does not exist");

        for (OIdentifiable to : toIds) {
          final OVertex toVertex;
          if (from.equals(to)) {
            toVertex = fromVertex;
          } else {
            toVertex = toVertex(to);
          }
          if (toVertex == null) {
            throw new OCommandExecutionException("Source vertex '" + to + "' does not exist");
          }

          if (fields != null)
            // EVALUATE FIELDS
            for (final OPair<String, Object> f : fields) {
              if (f.getValue() instanceof OSQLFunctionRuntime) {
                f.setValue(((OSQLFunctionRuntime) f.getValue()).getValue(to, null, context));
              } else if (f.getValue() instanceof OSQLFilterItem) {
                f.setValue(((OSQLFilterItem) f.getValue()).getValue(to, null, context));
              }
            }

          OEdge edge = null;

          if (content != null) {
            if (fields != null)
              // MERGE CONTENT WITH FIELDS
              fields.addAll(OPair.convertFromMap(content.toMap()));
            else
              fields = OPair.convertFromMap(content.toMap());
          }

          edge = fromVertex.addEdge(toVertex, edgeLabel);
          if (fields != null && !fields.isEmpty()) {
            OSQLHelper.bindParameters(edge.getRecord(), fields, new OCommandParameters(iArgs), context);
          }

          edge.save(clusterName);
          fromVertex.save();
          toVertex.save();

          edges.add(edge);

          if (batch > 0 && edges.size() % batch == 0) {
            db.commit();
            db.begin();
          }
        }
      }

    } finally {
      db.commit();
    }

    if (edges.isEmpty()) {
      if (fromIds.isEmpty())
        throw new OCommandExecutionException("No edge has been created because no source vertices");
      else if (toIds.isEmpty())
        throw new OCommandExecutionException("No edge has been created because no target vertices");
      throw new OCommandExecutionException("No edge has been created between " + fromIds + " and " + toIds);
    }

    return edges;

  }
public Object execute(final Map<Object, Object> iArgs) {
    if (clazz == null)
      throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");

    ODatabaseDocumentInternal db = getDatabase();
    final List<Object> edges = new ArrayList<Object>();
    Set<OIdentifiable> fromIds = null;
    Set<OIdentifiable> toIds = null;
    db.begin();
    try {
      fromIds = OSQLEngine.getInstance().parseRIDTarget(db, from, context, iArgs);
      toIds = OSQLEngine.getInstance().parseRIDTarget(db, to, context, iArgs);

      // CREATE EDGES
      for (OIdentifiable from : fromIds) {
        final OVertex fromVertex = toVertex(from);
        if (fromVertex == null)
          throw new OCommandExecutionException("Source vertex '" + from + "' does not exist");

        for (OIdentifiable to : toIds) {
          final OVertex toVertex;
          if (from.equals(to)) {
            toVertex = fromVertex;
          } else {
            toVertex = toVertex(to);
          }
          if (toVertex == null) {
            throw new OCommandExecutionException("Source vertex '" + to + "' does not exist");
          }

          if (fields != null)
            // EVALUATE FIELDS
            for (final OPair<String, Object> f : fields) {
              if (f.getValue() instanceof OSQLFunctionRuntime) {
                f.setValue(((OSQLFunctionRuntime) f.getValue()).getValue(to, null, context));
              } else if (f.getValue() instanceof OSQLFilterItem) {
                f.setValue(((OSQLFilterItem) f.getValue()).getValue(to, null, context));
              }
            }

          OEdge edge = null;

          if (content != null) {
            if (fields != null)
              // MERGE CONTENT WITH FIELDS
              fields.addAll(OPair.convertFromMap(content.toMap()));
            else
              fields = OPair.convertFromMap(content.toMap());
          }

          edge = fromVertex.addEdge(toVertex, edgeLabel);
          if (fields != null && !fields.isEmpty()) {
            OSQLHelper.bindParameters(edge.getRecord(), fields, new OCommandParameters(iArgs), context);
          }

          edge.save(clusterName);
          fromVertex.save();
          toVertex.save();

          edges.add(edge);

          if (batch > 0 && edges.size() % batch == 0) {
            db.commit();
            db.begin();
          }
        }
      }

    } finally {
      db.commit();
    }

    if (edges.isEmpty()) {
      if (fromIds.isEmpty())
        throw new OCommandExecutionException("No edge has been created because no source vertices");
      else if (toIds.isEmpty())
        throw new OCommandExecutionException("No edge has been created because no target vertices");
      throw new OCommandExecutionException("No edge has been created between " + fromIds + " and " + toIds);
    }

    return edges;

  }
Execute the command and return the ODocument object created.