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

    final OCommandParameters commandParameters = new OCommandParameters(iArgs);
    if (indexName != null) {
      if (newRecords == null)
        throw new OCommandExecutionException("No key/value found");

      final OIndex<?> index = getDatabase().getMetadata().getIndexManager().getIndex(indexName);
      if (index == null)
        throw new OCommandExecutionException("Target index '" + indexName + "' not found");

      // BIND VALUES
      Map<String, Object> result = new HashMap<String, Object>();

      for (Map<String, Object> candidate : newRecords) {
        Object indexKey = getIndexKeyValue(commandParameters, candidate);
        OIdentifiable indexValue = getIndexValue(commandParameters, candidate);

        if (index instanceof OIndexMultiValues) {
          final Collection<ORID> rids = ((OIndexMultiValues) index).get(indexKey);
          if (!rids.contains(indexValue.getIdentity())) {
            index.put(indexKey, indexValue);
          }
        } else {
          index.put(indexKey, indexValue);
        }

        result.put(KEYWORD_KEY, indexKey);
        result.put(KEYWORD_RID, indexValue);
      }

      // RETURN LAST ENTRY
      return prepareReturnItem(new ODocument(result));
    } else {
      // CREATE NEW DOCUMENTS
      final List<ODocument> docs = new ArrayList<ODocument>();
      if (newRecords != null) {
        for (Map<String, Object> candidate : newRecords) {
          final ODocument doc = className != null ? new ODocument(className) : new ODocument();
          OSQLHelper.bindParameters(doc, candidate, commandParameters, context);

          saveRecord(doc);
          docs.add(doc);
        }

        if (docs.size() == 1)
          return prepareReturnItem(docs.get(0));
        else
          return prepareReturnResult(docs);
      } else if (content != null) {
        final ODocument doc = className != null ? new ODocument(className) : new ODocument();
        doc.merge(content, true, false);
        saveRecord(doc);
        return prepareReturnItem(doc);
      } else if (subQuery != null) {
        subQuery.execute();
        if (queryResult != null)
          return prepareReturnResult(queryResult);

        return saved.longValue();
      }
    }
    return null;
  }
public Object execute(final Map<Object, Object> iArgs) {
    if (newRecords == null && content == null && subQuery == null)
      throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");

    final OCommandParameters commandParameters = new OCommandParameters(iArgs);
    if (indexName != null) {
      if (newRecords == null)
        throw new OCommandExecutionException("No key/value found");

      final OIndex<?> index = getDatabase().getMetadata().getIndexManager().getIndex(indexName);
      if (index == null)
        throw new OCommandExecutionException("Target index '" + indexName + "' not found");

      // BIND VALUES
      Map<String, Object> result = new HashMap<String, Object>();

      for (Map<String, Object> candidate : newRecords) {
        Object indexKey = getIndexKeyValue(commandParameters, candidate);
        OIdentifiable indexValue = getIndexValue(commandParameters, candidate);

        if (index instanceof OIndexMultiValues) {
          final Collection<ORID> rids = ((OIndexMultiValues) index).get(indexKey);
          if (!rids.contains(indexValue.getIdentity())) {
            index.put(indexKey, indexValue);
          }
        } else {
          index.put(indexKey, indexValue);
        }

        result.put(KEYWORD_KEY, indexKey);
        result.put(KEYWORD_RID, indexValue);
      }

      // RETURN LAST ENTRY
      return prepareReturnItem(new ODocument(result));
    } else {
      // CREATE NEW DOCUMENTS
      final List<ODocument> docs = new ArrayList<ODocument>();
      if (newRecords != null) {
        for (Map<String, Object> candidate : newRecords) {
          final ODocument doc = className != null ? new ODocument(className) : new ODocument();
          OSQLHelper.bindParameters(doc, candidate, commandParameters, context);

          saveRecord(doc);
          docs.add(doc);
        }

        if (docs.size() == 1)
          return prepareReturnItem(docs.get(0));
        else
          return prepareReturnResult(docs);
      } else if (content != null) {
        final ODocument doc = className != null ? new ODocument(className) : new ODocument();
        doc.merge(content, true, false);
        saveRecord(doc);
        return prepareReturnItem(doc);
      } else if (subQuery != null) {
        subQuery.execute();
        if (queryResult != null)
          return prepareReturnResult(queryResult);

        return saved.longValue();
      }
    }
    return null;
  }
Execute the INSERT and return the ODocument object created.