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

    return OGraphCommandExecutorSQLFactory.runInConfiguredTxMode(new OGraphCommandExecutorSQLFactory.GraphCallBack<List<Object>>() {
      @Override
      public List<Object> call(OrientBaseGraph graph) {

        final Set<OIdentifiable> fromIds = OSQLEngine.getInstance().parseRIDTarget(graph.getRawGraph(), from, context, iArgs);
        final Set<OIdentifiable> toIds = OSQLEngine.getInstance().parseRIDTarget(graph.getRawGraph(), to, context, iArgs);

        // CREATE EDGES
        final List<Object> edges = new ArrayList<Object>();
        for (OIdentifiable from : fromIds) {
          final OrientVertex fromVertex = graph.getVertex(from);
          if (fromVertex == null)
            throw new OCommandExecutionException("Source vertex '" + from + "' not exists");

          for (OIdentifiable to : toIds) {
            final OrientVertex toVertex;
            if (from.equals(to)) {
              toVertex = fromVertex;
            } else {
              toVertex = graph.getVertex(to);
            }

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

            OrientEdge 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(null, toVertex, edgeLabel, clusterName, fields);

            if (fields != null && !fields.isEmpty()) {
              if (edge.isLightweight())
                edge.convertToDocument();

              OSQLHelper.bindParameters(edge.getRecord(), fields, new OCommandParameters(iArgs), context);
            }

            edge.save(clusterName);

            edges.add(edge);

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

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

    return OGraphCommandExecutorSQLFactory.runInConfiguredTxMode(new OGraphCommandExecutorSQLFactory.GraphCallBack<List<Object>>() {
      @Override
      public List<Object> call(OrientBaseGraph graph) {

        final Set<OIdentifiable> fromIds = OSQLEngine.getInstance().parseRIDTarget(graph.getRawGraph(), from, context, iArgs);
        final Set<OIdentifiable> toIds = OSQLEngine.getInstance().parseRIDTarget(graph.getRawGraph(), to, context, iArgs);

        // CREATE EDGES
        final List<Object> edges = new ArrayList<Object>();
        for (OIdentifiable from : fromIds) {
          final OrientVertex fromVertex = graph.getVertex(from);
          if (fromVertex == null)
            throw new OCommandExecutionException("Source vertex '" + from + "' not exists");

          for (OIdentifiable to : toIds) {
            final OrientVertex toVertex;
            if (from.equals(to)) {
              toVertex = fromVertex;
            } else {
              toVertex = graph.getVertex(to);
            }

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

            OrientEdge 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(null, toVertex, edgeLabel, clusterName, fields);

            if (fields != null && !fields.isEmpty()) {
              if (edge.isLightweight())
                edge.convertToDocument();

              OSQLHelper.bindParameters(edge.getRecord(), fields, new OCommandParameters(iArgs), context);
            }

            edge.save(clusterName);

            edges.add(edge);

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

        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" ) ; return OGraphCommandExecutorSQLFactory . runInConfiguredTxMode ( new OGraphCommandExecutorSQLFactory . GraphCallBack < List < Object > > ( ) { @ Override public List < Object > call ( OrientBaseGraph graph ) { final Set < OIdentifiable > fromIds = OSQLEngine . getInstance ( ) . parseRIDTarget ( graph . getRawGraph ( ) , from , context , iArgs ) ; final Set < OIdentifiable > toIds = OSQLEngine . getInstance ( ) . parseRIDTarget ( graph . getRawGraph ( ) , to , context , iArgs ) ; // CREATE EDGES
 final List < Object > edges = new ArrayList < Object > ( ) ; for ( OIdentifiable from : fromIds ) { final OrientVertex fromVertex = graph . getVertex ( from ) ; if ( fromVertex == null ) throw new OCommandExecutionException ( "Source vertex '" + from + "' not exists" ) ; for ( OIdentifiable to : toIds ) { final OrientVertex toVertex ; if ( from . equals ( to ) ) { toVertex = fromVertex ; } else { toVertex = graph . getVertex ( to ) ; } 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 ) ) ; } } OrientEdge 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 ( null , toVertex , edgeLabel , clusterName , fields ) ; if ( fields != null && ! fields . isEmpty ( ) ) { if ( edge . isLightweight ( ) ) edge . convertToDocument ( ) ; OSQLHelper . bindParameters ( edge . getRecord ( ) , fields , new OCommandParameters ( iArgs ) , context ) ; } edge . save ( clusterName ) ; edges . add ( edge ) ; if ( batch > 0 && edges . size ( ) % batch == 0 ) { graph . commit ( ) ; graph . begin ( ) ; } } } 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.
Execute the command and return the ODocument object created .