Search in sources :

Example 71 with OrientBaseGraph

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

the class BlueprintsConcurrentGraphChangesTestNoTx method deleteEdgesConcurrently.

private void deleteEdgesConcurrently() throws Exception {
    ExecutorService executorService = Executors.newCachedThreadPool();
    beginTime = System.currentTimeMillis();
    List<Future<Void>> futures = new ArrayList<Future<Void>>();
    for (int i = 0; i < THREADS; i++) futures.add(executorService.submit(new ConcurrentEdgeRemover()));
    latchEdgeDelete.countDown();
    for (Future<Void> future : futures) future.get();
    final OrientBaseGraph g = getGraph();
    printStats(g);
    g.shutdown();
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)

Example 72 with OrientBaseGraph

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

the class SQLMoveVertexCommandInTxTest method testMoveWithUniqueIndex.

@Test
public void testMoveWithUniqueIndex() {
    graph.executeOutsideTx(new OCallable<Object, OrientBaseGraph>() {

        @Override
        public Object call(OrientBaseGraph iArgument) {
            customer.createProperty("id", OType.LONG).createIndex(OClass.INDEX_TYPE.NOTUNIQUE_HASH_INDEX);
            return null;
        }
    });
    for (int i = 0; i < 100; ++i) new ODocument("Customer").field("id", i).save();
    graph.commit();
    Iterable<OrientVertex> result = graph.command(new OCommandSQL("MOVE VERTEX (select from Customer where id = 0) TO CLUSTER:Customer_genius")).execute();
    Iterable<OrientVertex> result2 = graph.command(new OCommandSQL("MOVE VERTEX (select from Customer where id = 1) TO CLASS:Customer")).execute();
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.junit.Test) GraphTxAbstractTest(com.orientechnologies.orient.graph.GraphTxAbstractTest)

Example 73 with OrientBaseGraph

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

the class GraphDatabaseTest method testEmbeddedDoc.

public void testEmbeddedDoc() {
    database.executeOutsideTx(new OCallable<Object, OrientBaseGraph>() {

        @Override
        public Object call(OrientBaseGraph iArgument) {
            return iArgument.getRawGraph().getMetadata().getSchema().createClass("NonVertex");
        }
    });
    Vertex vertex = database.addVertex(null, "name", "vertexWithEmbedded");
    ODocument doc = new ODocument();
    doc.field("foo", "bar");
    vertex.setProperty("emb1", doc);
    ODocument doc2 = new ODocument("V");
    doc2.field("foo", "bar");
    vertex.setProperty("emb2", doc2);
    ODocument doc3 = new ODocument("NonVertex");
    doc3.field("foo", "bar");
    vertex.setProperty("emb3", doc3);
    Object res1 = vertex.getProperty("emb1");
    Assert.assertNotNull(res1);
    Assert.assertTrue(res1 instanceof ODocument);
    Object res2 = vertex.getProperty("emb2");
    Assert.assertNotNull(res2);
    Assert.assertFalse(res2 instanceof ODocument);
    Object res3 = vertex.getProperty("emb3");
    Assert.assertNotNull(res3);
    Assert.assertTrue(res3 instanceof ODocument);
    database.commit();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 74 with OrientBaseGraph

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

the class DatabaseConflictStrategyAutoMergeTest method dbClient2.

private void dbClient2() {
    synchronized (LOCK) {
        OrientBaseGraph graph = new OrientGraph(CLIENT_ORIENT_URL_MAIN);
        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;
                countPropValue++;
                if (parentV1 == null) {
                    parentV1 = graph.getVertex(parentV1Id);
                }
                parentV1.setProperty("cnt", countPropValue);
                graph.commit();
                if (parentV2 == null) {
                    parentV2 = graph.getVertex(parentV2Id);
                }
                parentV2.setProperty("cnt", countPropValue);
                graph.commit();
            }
        } catch (Throwable e) {
            if (exceptionInThread == null) {
                exceptionInThread = e;
            }
        } finally {
            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 75 with OrientBaseGraph

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

the class GraphTransactionConsistency method testTransactionConsistency.

public void testTransactionConsistency() throws InterruptedException {
    final OrientGraphFactory factory = new OrientGraphFactory("plocal:target/GraphTransactionConsistency", false);
    database = txMode ? factory.getTx() : factory.getNoTx();
    System.out.println("Checking consistency of database...");
    System.out.println("Records found V=" + database.countVertices() + " E=" + database.countEdges());
    final Iterable<OrientVertex> vertices = database.command(new OCommandSQL("select from V")).execute();
    for (OrientVertex v : vertices) {
        final ODocument doc = v.getRecord();
        Assert.assertNotNull(doc);
        final ORidBag out = doc.field("out_");
        if (out != null) {
            for (Iterator<OIdentifiable> it = out.rawIterator(); it.hasNext(); ) {
                final OIdentifiable edge = it.next();
                Assert.assertNotNull(edge);
                final ODocument rec = edge.getRecord();
                Assert.assertNotNull(rec);
                Assert.assertNotNull(rec.field("out"));
                Assert.assertEquals(((ODocument) rec.field("out")).getIdentity(), v.getIdentity());
                Assert.assertNotNull(rec.field("in"));
            }
        }
        final ORidBag in = doc.field("in_");
        if (in != null) {
            for (Iterator<OIdentifiable> it = in.rawIterator(); it.hasNext(); ) {
                final OIdentifiable edge = it.next();
                Assert.assertNotNull(edge);
                final ODocument rec = edge.getRecord();
                Assert.assertNotNull(rec);
                Assert.assertNotNull(rec.field("in"));
                Assert.assertEquals(((ODocument) rec.field("in")).getIdentity(), v.getIdentity());
                Assert.assertNotNull(rec.field("out"));
            }
        }
    }
    System.out.println("Consistency ok.");
    final Thread[] threads = new Thread[THREADS];
    for (int i = 0; i < THREADS; ++i) {
        final int threadNum = i;
        threads[i] = new Thread(new Runnable() {

            @Override
            public void run() {
                OrientBaseGraph graph = txMode ? factory.getTx() : factory.getNoTx();
                try {
                    System.out.println("THREAD " + threadNum + " Start transactions (" + TXNUM + ")");
                    for (int i = 0; i < TXNUM; ++i) {
                        final OrientVertex v1 = graph.addVertex(null, "v", i, "type", "Main", "lastUpdate", new Date());
                        for (int e = 0; e < EDGENUM; ++e) {
                            final OrientVertex v2 = graph.addVertex(null, "v", i, "e", e, "type", "Connected", "lastUpdate", new Date());
                            v1.addEdge("E", v2);
                        }
                        if (i % TXBATCH == 0) {
                            System.out.println("THREAD " + threadNum + " Committing batch of " + TXBATCH + " (i=" + i + ")");
                            System.out.flush();
                            graph.commit();
                            System.out.println("THREAD " + threadNum + " Commit ok - records found V=" + graph.countVertices() + " E=" + graph.countEdges());
                            System.out.flush();
                        }
                    }
                } finally {
                    graph.shutdown();
                }
            }
        });
        Thread.sleep(1000);
        threads[i].start();
    }
    for (int i = 0; i < THREADS; ++i) {
        try {
            threads[i].join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    database.shutdown();
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OrientVertex(com.tinkerpop.blueprints.impls.orient.OrientVertex) OrientBaseGraph(com.tinkerpop.blueprints.impls.orient.OrientBaseGraph) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) Date(java.util.Date) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OrientGraphFactory(com.tinkerpop.blueprints.impls.orient.OrientGraphFactory) 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