use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.
the class OTraverse method next.
public OIdentifiable next() {
if (Thread.interrupted())
throw new OCommandExecutionException("The traverse execution has been interrupted");
if (lastTraversed != null) {
// RETURN LATEST AND RESET IT
final OIdentifiable result = lastTraversed;
lastTraversed = null;
return result;
}
if (limit > 0 && resultCount >= limit)
return null;
OIdentifiable result;
OTraverseAbstractProcess<?> toProcess;
// RESUME THE LAST PROCESS
while ((toProcess = nextProcess()) != null) {
result = toProcess.process();
if (result != null) {
resultCount++;
return result;
}
}
return null;
}
use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.
the class OCommandExecutorSQLCreateVertex method execute.
/**
* Execute the command and return the ODocument object created.
*/
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");
// CREATE VERTEX DOES NOT HAVE TO BE IN TX
return OGraphCommandExecutorSQLFactory.runWithAnyGraph(new OGraphCommandExecutorSQLFactory.GraphCallBack<Object>() {
@Override
public Object call(final OrientBaseGraph graph) {
final OrientVertex vertex = graph.addTemporaryVertex(clazz.getName());
if (fields != null)
// EVALUATE FIELDS
for (final OPair<String, Object> f : fields) {
if (f.getValue() instanceof OSQLFunctionRuntime)
f.setValue(((OSQLFunctionRuntime) f.getValue()).getValue(vertex.getRecord(), null, context));
}
OSQLHelper.bindParameters(vertex.getRecord(), fields, new OCommandParameters(iArgs), context);
if (content != null)
vertex.getRecord().merge(content, true, false);
if (clusterName != null)
vertex.save(clusterName);
else
vertex.save();
return vertex.getRecord();
}
});
}
use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.
the class OCommandExecutorSQLDeleteEdge method execute.
/**
* Execute the command and return the ODocument object created.
*/
public Object execute(final Map<Object, Object> iArgs) {
if (fromExpr == null && toExpr == null && rids == null && query == null && compiledFilter == null)
throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
txAlreadyBegun = getDatabase().getTransaction().isActive();
if (rids != null) {
// REMOVE PUNCTUAL RID
OGraphCommandExecutorSQLFactory.runInConfiguredTxMode(new OGraphCommandExecutorSQLFactory.GraphCallBack<Object>() {
@Override
public Object call(OrientBaseGraph graph) {
for (ORecordId rid : rids) {
final OrientEdge e = graph.getEdge(rid);
if (e != null) {
e.remove();
removed++;
}
}
return null;
}
});
// CLOSE PENDING TX
end();
} else {
// MULTIPLE EDGES
final Set<OrientEdge> edges = new HashSet<OrientEdge>();
if (query == null) {
OGraphCommandExecutorSQLFactory.runInConfiguredTxMode(new OGraphCommandExecutorSQLFactory.GraphCallBack<Object>() {
@Override
public Object call(OrientBaseGraph graph) {
Set<OIdentifiable> fromIds = null;
if (fromExpr != null)
fromIds = OSQLEngine.getInstance().parseRIDTarget(graph.getRawGraph(), fromExpr, context, iArgs);
Set<OIdentifiable> toIds = null;
if (toExpr != null)
toIds = OSQLEngine.getInstance().parseRIDTarget(graph.getRawGraph(), toExpr, context, iArgs);
if (label == null)
label = OrientEdgeType.CLASS_NAME;
if (fromIds != null && toIds != null) {
int fromCount = 0;
int toCount = 0;
for (OIdentifiable fromId : fromIds) {
final OrientVertex v = graph.getVertex(fromId);
if (v != null)
fromCount += v.countEdges(Direction.OUT, label);
}
for (OIdentifiable toId : toIds) {
final OrientVertex v = graph.getVertex(toId);
if (v != null)
toCount += v.countEdges(Direction.IN, label);
}
if (fromCount <= toCount) {
// REMOVE ALL THE EDGES BETWEEN VERTICES
for (OIdentifiable fromId : fromIds) {
final OrientVertex v = graph.getVertex(fromId);
if (v != null)
for (Edge e : v.getEdges(Direction.OUT, label)) {
final OIdentifiable inV = ((OrientEdge) e).getInVertex();
if (inV != null && toIds.contains(inV.getIdentity()))
edges.add((OrientEdge) e);
}
}
} else {
for (OIdentifiable toId : toIds) {
final OrientVertex v = graph.getVertex(toId);
if (v != null)
for (Edge e : v.getEdges(Direction.IN, label)) {
final OIdentifiable outV = ((OrientEdge) e).getOutVertex();
if (outV != null && fromIds.contains(outV.getIdentity()))
edges.add((OrientEdge) e);
}
}
}
} else if (fromIds != null) {
// REMOVE ALL THE EDGES THAT START FROM A VERTEXES
for (OIdentifiable fromId : fromIds) {
final OrientVertex v = graph.getVertex(fromId);
if (v != null) {
for (Edge e : v.getEdges(Direction.OUT, label)) {
edges.add((OrientEdge) e);
}
}
}
} else if (toIds != null) {
// REMOVE ALL THE EDGES THAT ARRIVE TO A VERTEXES
for (OIdentifiable toId : toIds) {
final OrientVertex v = graph.getVertex(toId);
if (v != null) {
for (Edge e : v.getEdges(Direction.IN, label)) {
edges.add((OrientEdge) e);
}
}
}
} else
throw new OCommandExecutionException("Invalid target: " + toIds);
if (compiledFilter != null) {
// ADDITIONAL FILTERING
for (Iterator<OrientEdge> it = edges.iterator(); it.hasNext(); ) {
final OrientEdge edge = it.next();
if (!(Boolean) compiledFilter.evaluate(edge.getRecord(), null, context))
it.remove();
}
}
// DELETE THE FOUND EDGES
removed = edges.size();
for (OrientEdge edge : edges) edge.remove();
return null;
}
});
// CLOSE PENDING TX
end();
} else {
OGraphCommandExecutorSQLFactory.runInConfiguredTxMode(new OGraphCommandExecutorSQLFactory.GraphCallBack<OrientGraph>() {
@Override
public OrientGraph call(final OrientBaseGraph iGraph) {
// TARGET IS A CLASS + OPTIONAL CONDITION
currentGraph.set(iGraph);
query.setContext(getContext());
query.execute(iArgs);
return null;
}
});
}
}
return removed;
}
use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.
the class OrientBaseGraph method dropEdgeType.
/**
* Drops an edge class.
*
* @param iTypeName Edge class name
*/
public void dropEdgeType(final String iTypeName) {
makeActive();
if (getDatabase().countClass(iTypeName) > 0)
throw new OCommandExecutionException("cannot drop edge type '" + iTypeName + "' because it contains Edges. Use 'DELETE EDGE' command first to remove data");
executeOutsideTx(new OCallable<OClass, OrientBaseGraph>() {
@Override
public OClass call(final OrientBaseGraph g) {
getRawGraph().getMetadata().getSchema().dropClass(iTypeName);
return null;
}
}, "drop edge type '", iTypeName, "'");
}
use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.
the class OGremlinHelper method getGraphDatabase.
public static ODatabaseDocumentTx getGraphDatabase(final ODatabaseDocumentInternal iCurrentDatabase) {
ODatabaseDocumentInternal currentDb = ODatabaseRecordThreadLocal.INSTANCE.get();
if (currentDb == null && iCurrentDatabase != null)
// GET FROM THE RECORD
currentDb = iCurrentDatabase;
if (currentDb != null)
currentDb = (ODatabaseDocumentInternal) currentDb.getDatabaseOwner();
final ODatabaseDocumentTx db;
if (currentDb instanceof ODatabaseDocumentTx)
db = (ODatabaseDocumentTx) currentDb;
else
throw new OCommandExecutionException("Cannot find a database of type ODatabaseDocumentTx or ODatabaseDocumentTx");
return db;
}
Aggregations