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);
}
final String clsName = clazz.getName();
if (fields != null)
// EVALUATE FIELDS
for (Entry<String, Object> f : fields.entrySet()) {
if (f.getValue() instanceof OSQLFunctionRuntime)
fields.put(f.getKey(), ((OSQLFunctionRuntime) f.getValue()).getValue(to, null, context));
}
OrientEdge edge = null;
for (int r = 0; r < retry; ++r) {
try {
edge = fromVertex.addEdge(null, toVertex, clsName, clusterName, fields);
if (fields != null && !fields.isEmpty()) {
if (!edge.getRecord().getIdentity().isValid())
edge.convertToDocument();
OSQLHelper.bindParameters(edge.getRecord(), fields, new OCommandParameters(iArgs), context);
}
if (content != null) {
if (!edge.getRecord().getIdentity().isValid())
// LIGHTWEIGHT EDGE, TRANSFORM IT BEFORE
edge.convertToDocument();
edge.getRecord().merge(content, true, false);
}
edge.save(clusterName);
// OK
break;
} catch (OConcurrentModificationException e) {
if (r + 1 >= retry)
// NO RETRY; PROPAGATE THE EXCEPTION
throw e;
// RETRY?
if (wait > 0)
try {
Thread.sleep(wait);
} catch (InterruptedException e1) {
}
// RELOAD LAST VERSION
fromVertex.getRecord().reload(null, true);
toVertex.getRecord().reload(null, true);
}
}
edges.add(edge);
}