/** Execute the INSERT and return the ODocument object created. */ public Object execute(final Map<Object, Object> iArgs) { if (newRecords == null && content == 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 = null; for (Map<String, Object> candidate : newRecords) { index.put( getIndexKeyValue(commandParameters, candidate), getIndexValue(commandParameters, candidate)); result = candidate; } // RETURN LAST ENTRY return 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); if (clusterName != null) { doc.save(clusterName); } else { doc.save(); } docs.add(doc); } if (docs.size() == 1) return docs.get(0); else return docs; } else if (content != null) { final ODocument doc = className != null ? new ODocument(className) : new ODocument(); doc.merge(content, true, false); doc.save(); return doc; } } return null; }