Search in sources :

Example 51 with OrientBaseGraph

use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.

the class ConcurrentDistributedUpdateTest method createWriter.

protected Callable<Void> createWriter(final int serverId, final int threadId, final String databaseURL) {
    return new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            final String id = serverId + "." + threadId;
            boolean isRunning = true;
            final OrientBaseGraph graph = new OrientGraph(databaseURL);
            try {
                String query = "select from Test where prop2='v2-1'";
                for (int i = 0; i < 100 && isRunning; i++) {
                    if ((i % 25) == 0) {
                        log("[" + id + "] Records Processed: [" + i + "]");
                    }
                    Iterable<Vertex> vtxs = graph.command(new OCommandSQL(query)).execute();
                    boolean update = true;
                    for (Vertex vtx : vtxs) {
                        if (update) {
                            update = true;
                            for (int k = 0; k < 10 && update; k++) {
                                OrientVertex vtx1 = (OrientVertex) vtx;
                                try {
                                    vtx1.setProperty("prop5", "prop55");
                                    graph.commit();
                                    // log("[" + id + "/" + i + "/" + k + "] OK!\n");
                                    break;
                                } catch (OConcurrentModificationException ex) {
                                    vtx1.reload();
                                } catch (ODistributedRecordLockedException ex) {
                                    log("[" + id + "/" + i + "/" + k + "] Distributed lock Exception " + ex + " for vertex " + vtx1 + " \n");
                                    // ex.printStackTrace();
                                    update = false;
                                    // isRunning = false;
                                    break;
                                } catch (Exception ex) {
                                    log("[" + id + "/" + i + "/" + k + "] Exception " + ex + " for vertex " + vtx1 + "\n\n");
                                    ex.printStackTrace();
                                    isRunning = false;
                                    break;
                                }
                            }
                            if (!isRunning)
                                break;
                        }
                    }
                }
            } catch (Exception ex) {
                System.out.println("ID: [" + id + "]********** Exception " + ex + " \n\n");
                ex.printStackTrace();
            } finally {
                log("[" + id + "] Done................>>>>>>>>>>>>>>>>>>");
                graph.shutdown();
                runningWriters.countDown();
            }
            Assert.assertTrue(isRunning);
            return null;
        }
    };
}
Also used : OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) Vertex(com.tinkerpop.blueprints.Vertex) ODistributedRecordLockedException(com.orientechnologies.orient.server.distributed.task.ODistributedRecordLockedException) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) Callable(java.util.concurrent.Callable) ODistributedRecordLockedException(com.orientechnologies.orient.server.distributed.task.ODistributedRecordLockedException) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL)

Example 52 with OrientBaseGraph

use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.

the class MultipleDBAlignmentOnNodesJoining method prepare.

/**
 * Creates the databases as follows:
 * - server1: db A, db B
 * - server2: db B, db C
 *
 * @throws IOException
 */
@Override
protected void prepare(final boolean iCopyDatabaseToNodes, final boolean iCreateDatabase, final OCallable<Object, OrientGraphFactory> iCfgCallback) throws IOException {
    serverInstance.remove(2);
    // creating databases on server1
    ServerRun master = serverInstance.get(0);
    if (iCreateDatabase) {
        final OrientBaseGraph graph1 = master.createDatabase(dbA, iCfgCallback);
        final OrientBaseGraph graph2 = master.createDatabase(dbB, iCfgCallback);
        try {
            onAfterDatabaseCreation(graph1, "plocal:" + serverInstance.get(0).getDatabasePath(dbA));
            onAfterDatabaseCreation(graph2, "plocal:" + serverInstance.get(0).getDatabasePath(dbB));
        } finally {
            if (!graph1.isClosed()) {
                graph1.shutdown();
            }
            if (!graph1.isClosed()) {
                graph2.shutdown();
            }
        }
    }
    // copying db-B on server2
    if (iCopyDatabaseToNodes)
        master.copyDatabase(dbB, serverInstance.get(1).getDatabasePath(dbB));
    // creating db-C on server2
    master = serverInstance.get(1);
    if (iCreateDatabase) {
        final OrientBaseGraph graph1 = master.createDatabase(dbC, iCfgCallback);
        try {
            onAfterDatabaseCreation(graph1, "plocal:" + serverInstance.get(1).getDatabasePath(dbC));
        } finally {
            if (!graph1.isClosed()) {
                graph1.shutdown();
            }
        }
    }
}
Also used : ServerRun(com.orientechnologies.orient.server.distributed.ServerRun) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 53 with OrientBaseGraph

use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.

the class OGremlinEngineThreadLocal method get.

public ScriptEngine get(final OrientBaseGraph iGraph) {
    ScriptEngine engine = super.get();
    if (engine != null) {
        final OrientBaseGraph currGraph = (OrientBaseGraph) engine.getBindings(ScriptContext.ENGINE_SCOPE).get("g");
        if (currGraph == iGraph || (currGraph != null && currGraph.getRawGraph().getURL().equals(iGraph.getRawGraph().getURL()))) {
            // REUSE IT
            engine.getBindings(ScriptContext.ENGINE_SCOPE).put("g", iGraph);
            return engine;
        }
    }
    // CREATE A NEW ONE
    engine = new GremlinGroovyScriptEngine();
    engine.getBindings(ScriptContext.ENGINE_SCOPE).put("g", iGraph);
    set(engine);
    return engine;
}
Also used : GremlinGroovyScriptEngine(com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) ScriptEngine(javax.script.ScriptEngine) GremlinGroovyScriptEngine(com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine)

Example 54 with OrientBaseGraph

use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph 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 55 with OrientBaseGraph

use of com.tinkerpop.blueprints.impls.orient.OrientBaseGraph in project orientdb by orientechnologies.

the class OCommandExecutorSQLDeleteVertex method result.

/**
 * Delete the current vertex.
 */
public boolean result(final Object iRecord) {
    final OIdentifiable id = (OIdentifiable) iRecord;
    if (id.getIdentity().isValid()) {
        final ODocument record = id.getRecord();
        final OrientBaseGraph g = currentGraph.get();
        final OrientVertex v = g.getVertex(record);
        if (v != null) {
            v.remove();
            if (!txAlreadyBegun && batch > 0 && removed % batch == 0) {
                if (g instanceof OrientGraph) {
                    g.commit();
                    ((OrientGraph) g).begin();
                }
            }
            if (returning.equalsIgnoreCase("BEFORE"))
                allDeletedRecords.add(record);
            removed++;
        }
    }
    return true;
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)75 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)40 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)21 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)15 Vertex (com.tinkerpop.blueprints.Vertex)13 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)11 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)8 Edge (com.tinkerpop.blueprints.Edge)8 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)8 Test (org.junit.Test)8 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)6 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)6 OGraphRepair (com.tinkerpop.blueprints.impls.orient.OGraphRepair)5 ArrayList (java.util.ArrayList)5 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)4 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)4 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)4 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)4 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)4