Search in sources :

Example 41 with OCommandExecutionException

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;
}
Also used : OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 42 with OCommandExecutionException

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();
        }
    });
}
Also used : OSQLFunctionRuntime(com.orientechnologies.orient.core.sql.functions.OSQLFunctionRuntime) OCommandParameters(com.orientechnologies.orient.core.sql.OCommandParameters) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 43 with OCommandExecutionException

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;
}
Also used : OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ORecordId(com.orientechnologies.orient.core.id.ORecordId) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OModifiableBoolean(com.orientechnologies.common.types.OModifiableBoolean) Edge(com.tinkerpop.blueprints.Edge)

Example 44 with OCommandExecutionException

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, "'");
}
Also used : OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException)

Example 45 with OCommandExecutionException

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;
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Aggregations

OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)82 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)20 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)19 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)16 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)15 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)14 OException (com.orientechnologies.common.exception.OException)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)9 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)6 IOException (java.io.IOException)6 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)5 OType (com.orientechnologies.orient.core.metadata.schema.OType)5 OQueryParsingException (com.orientechnologies.orient.core.exception.OQueryParsingException)4 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)4 ORecord (com.orientechnologies.orient.core.record.ORecord)4 OHazelcastPlugin (com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin)4 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)4 ArrayList (java.util.ArrayList)4 ORID (com.orientechnologies.orient.core.id.ORID)3 ORecordId (com.orientechnologies.orient.core.id.ORecordId)3