Search in sources :

Example 1 with OrientGraph

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

the class TestAsyncReplMode method dbClient2.

protected void dbClient2() {
    synchronized (LOCK) {
        OrientBaseGraph graph = new OrientGraph(getRemoteURL());
        OrientVertex parentV1 = null;
        OrientVertex parentV2 = null;
        int countPropValue = 0;
        try {
            for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
                pause();
                if (exceptionInThread != null)
                    break;
                // Let's give it some time for asynchronous replication.
                //          sleep(500);
                countPropValue++;
                if (parentV1 == null) {
                    parentV1 = graph.getVertex(parentV1Id);
                }
                for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
                    try {
                        parentV1.setProperty("cnt", countPropValue);
                        graph.commit();
                    } catch (OConcurrentModificationException c) {
                        graph.rollback();
                        parentV1.reload();
                    }
                }
                if (parentV2 == null) {
                    parentV2 = graph.getVertex(parentV2Id);
                }
                for (int attempt = 0; attempt < NUM_OF_RETRIES; attempt++) {
                    try {
                        parentV2.setProperty("cnt", countPropValue);
                        graph.commit();
                    } catch (OConcurrentModificationException c) {
                        graph.rollback();
                        parentV2.reload();
                    }
                }
            }
        } catch (Throwable e) {
            if (exceptionInThread == null) {
                exceptionInThread = e;
            }
        } finally {
            System.out.println("Shutting down");
            graph.shutdown();
            LOCK.notifyAll();
        }
    }
}
Also used : 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)

Example 2 with OrientGraph

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

the class TestAsyncReplMode2Servers method dbClient2.

protected void dbClient2() {
    sleep(1000);
    synchronized (LOCK) {
        OrientBaseGraph graph = new OrientGraph(getLocalURL2());
        try {
            OrientVertex parentV1 = graph.getVertex(parentV1Id);
            assertEquals(1, parentV1.getRecord().getVersion());
            OrientVertex parentV2 = graph.getVertex(parentV2Id);
            assertEquals(1, parentV2.getRecord().getVersion());
            int countPropValue = 0;
            for (int i = 0; i < NUM_OF_LOOP_ITERATIONS; i++) {
                pause();
                if (exceptionInThread != null)
                    break;
                sleep(500);
                parentV1.reload();
                parentV2.reload();
                assertEquals("parentV1 (" + parentV1.getRecord() + ")", ++countPropValue, parentV1.getProperty(CNT_PROP_NAME));
                assertEquals("parentV2 (" + parentV2.getRecord() + ")", countPropValue, parentV2.getProperty(CNT_PROP_NAME));
            }
        } catch (Throwable e) {
            if (exceptionInThread == null) {
                exceptionInThread = e;
            }
        } finally {
            System.out.println("Shutting down");
            graph.shutdown();
            LOCK.notifyAll();
        }
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 3 with OrientGraph

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

the class TestAsyncReplMode2ServersAddEdge method dbClient2.

protected void dbClient2() {
    sleep(500);
    synchronized (LOCK) {
        OrientBaseGraph graph = new OrientGraph(getLocalURL2());
        try {
            sleep(500);
            OrientVertex parentV1 = graph.getVertex(parentV1Id);
            assertEquals(NUM_OF_LOOP_ITERATIONS + 1, parentV1.getRecord().getVersion());
        } catch (Throwable e) {
            if (exceptionInThread == null) {
                exceptionInThread = e;
            }
        } finally {
            System.out.println("Shutting down");
            graph.shutdown();
            LOCK.notifyAll();
        }
    }
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 4 with OrientGraph

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

the class OCommandExecutorSQLMoveVertex method execute.

/**
   * Executes the command and return the ODocument object created.
   */
public Object execute(final Map<Object, Object> iArgs) {
    if (className == null && clusterName == null)
        throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
    OModifiableBoolean shutdownGraph = new OModifiableBoolean();
    final boolean txAlreadyBegun = getDatabase().getTransaction().isActive();
    final OrientGraph graph = OGraphCommandExecutorSQLFactory.getGraph(true, shutdownGraph);
    try {
        final Set<OIdentifiable> sourceRIDs = OSQLEngine.getInstance().parseRIDTarget(graph.getRawGraph(), source, context, iArgs);
        // CREATE EDGES
        final List<ODocument> result = new ArrayList<ODocument>(sourceRIDs.size());
        for (OIdentifiable from : sourceRIDs) {
            final OrientVertex fromVertex = graph.getVertex(from);
            if (fromVertex == null)
                continue;
            final ORID oldVertex = fromVertex.getIdentity().copy();
            final ORID newVertex = fromVertex.moveTo(className, clusterName);
            final ODocument newVertexDoc = newVertex.getRecord();
            if (fields != null) {
                // EVALUATE FIELDS
                for (final OPair<String, Object> f : fields) {
                    if (f.getValue() instanceof OSQLFunctionRuntime)
                        f.setValue(((OSQLFunctionRuntime) f.getValue()).getValue(newVertex.getRecord(), null, context));
                }
                OSQLHelper.bindParameters(newVertexDoc, fields, new OCommandParameters(iArgs), context);
            }
            if (merge != null)
                newVertexDoc.merge(merge, true, false);
            // SAVE CHANGES
            newVertexDoc.save();
            // PUT THE MOVE INTO THE RESULT
            result.add(new ODocument().setTrackingChanges(false).field("old", oldVertex, OType.LINK).field("new", newVertex, OType.LINK));
            if (batch > 0 && result.size() % batch == 0) {
                graph.commit();
                if (!graph.isAutoStartTx())
                    graph.begin();
            }
        }
        graph.commit();
        return result;
    } finally {
        if (!txAlreadyBegun)
            graph.commit();
        if (shutdownGraph.getValue())
            graph.shutdown(false);
    }
}
Also used : OSQLFunctionRuntime(com.orientechnologies.orient.core.sql.functions.OSQLFunctionRuntime) OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) ArrayList(java.util.ArrayList) OCommandParameters(com.orientechnologies.orient.core.sql.OCommandParameters) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ORID(com.orientechnologies.orient.core.id.ORID) OModifiableBoolean(com.orientechnologies.common.types.OModifiableBoolean) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 5 with OrientGraph

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

the class GraphShutdownTest method graphCommitAfterShutdown.

@Test(expected = ODatabaseException.class)
public void graphCommitAfterShutdown() {
    OrientGraphFactory factory = new OrientGraphFactory("memory:graphCommitAfterShutdown");
    OrientGraph graph1 = factory.getTx();
    OrientGraph graph2 = factory.getTx();
    // in 2.2 this will not close the database because graph1 is still active in the pool
    graph2.shutdown(true);
    // this should fail
    graph2.commit();
    factory.drop();
}
Also used : OrientGraph(com.tinkerpop.blueprints.impls.orient.OrientGraph) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) Test(org.junit.Test)

Aggregations

OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)94 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)43 Test (org.junit.Test)33 Vertex (com.tinkerpop.blueprints.Vertex)22 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)19 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)18 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)13 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)13 OrientVertexType (com.tinkerpop.blueprints.impls.orient.OrientVertexType)12 Edge (com.tinkerpop.blueprints.Edge)8 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)7 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)7 OrientGraphFactory (com.tinkerpop.blueprints.impls.orient.OrientGraphFactory)7 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)6 Test (org.testng.annotations.Test)6 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)5 OrientGraphNoTx (com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx)5 Before (org.junit.Before)5 BeforeClass (org.junit.BeforeClass)5 ORecordDuplicatedException (com.orientechnologies.orient.core.storage.ORecordDuplicatedException)4