Examples of OrientGraph


Examples of com.tinkerpop.blueprints.impls.orient.OrientGraph

  public SQLCreateVertexTest(@Optional String url) {
    super(url);
  }

  public void testCreateVertexByContent() {
    OrientGraph graph = new OrientGraph(database, false);
    graph.shutdown();
    database.open("admin", "admin");

    OSchema schema = database.getMetadata().getSchema();
    if (!schema.existsClass("CreateVertexByContent")) {
      OClass vClass = schema.createClass("CreateVertexByContent", schema.getClass("V"));
View Full Code Here

Examples of com.tinkerpop.blueprints.impls.orient.OrientGraph

    System.out.println("Started Test PESSIMISTIC Batch Update against SuperNode");

    counter.set(0);
    startedOn = System.currentTimeMillis();

    OrientBaseGraph graphPool = new OrientGraph(url);

    graphPool.setThreadMode(OrientBaseGraph.THREAD_MODE.ALWAYS_AUTOSET);
    OrientVertex superNode = graphPool.addVertex(null, "pessimisticSuperNode", true);
    graphPool.commit();

    PessimisticThread[] ops = new PessimisticThread[THREADS];
    for (int i = 0; i < THREADS; ++i)
      ops[i] = new PessimisticThread(url, superNode, i, "thread" + i);

    Thread[] threads = new Thread[THREADS];
    for (int i = 0; i < THREADS; ++i)
      threads[i] = new Thread(ops[i], "ConcurrentSQLBatchUpdateSuperNodeTest-pessimistic" + i);

    System.out.println("Starting " + THREADS + " threads, " + PESSIMISTIC_CYCLES + " operations each");

    for (int i = 0; i < THREADS; ++i)
      threads[i].start();

    for (int i = 0; i < THREADS; ++i) {
      threads[i].join();
      System.out.println("Thread " + i + " completed");
    }

    System.out.println("ConcurrentSQLBatchUpdateSuperNodeTest Pessimistic Done! Total updates executed in parallel: "
        + counter.get() + " average retries: " + ((float) totalRetries.get() / (float) counter.get()));

    Assert.assertEquals(counter.get(), PESSIMISTIC_CYCLES * THREADS);

    OrientVertex loadedSuperNode = graphPool.getVertex(superNode.getIdentity());

    for (int i = 0; i < THREADS; ++i)
      Assert.assertEquals(loadedSuperNode.countEdges(Direction.IN), PESSIMISTIC_CYCLES * THREADS);

    graphPool.shutdown();

    System.out.println("ConcurrentSQLBatchUpdateSuperNodeTest Pessimistic Test completed in "
        + (System.currentTimeMillis() - startedOn));
  }
View Full Code Here

Examples of com.tinkerpop.blueprints.impls.orient.OrientGraph

    System.out.println("Started Test OPTIMISTIC Batch Update against SuperNode");

    counter.set(0);
    startedOn = System.currentTimeMillis();

    OrientBaseGraph graphPool = new OrientGraph(url);

    OrientVertex superNode = graphPool.addVertex(null, "optimisticSuperNode", true);
    graphPool.commit();

    OptimisticThread[] ops = new OptimisticThread[THREADS];
    for (int i = 0; i < THREADS; ++i)
      ops[i] = new OptimisticThread(url, superNode, i, "thread" + i);

    Thread[] threads = new Thread[THREADS];
    for (int i = 0; i < THREADS; ++i)
      threads[i] = new Thread(ops[i], "ConcurrentSQLBatchUpdateSuperNodeTest-optimistic" + i);

    System.out.println("Starting " + THREADS + " threads, " + OPTIMISTIC_CYCLES + " operations each");

    for (int i = 0; i < THREADS; ++i)
      threads[i].start();

    for (int i = 0; i < THREADS; ++i) {
      threads[i].join();
      System.out.println("Thread " + i + " completed");
    }

    System.out.println("ConcurrentSQLBatchUpdateSuperNodeTest Optimistic Done! Total updates executed in parallel: "
        + counter.get() + " total retries: " + totalRetries.get() + " average retries: "
        + ((float) totalRetries.get() / (float) counter.get()));

    Assert.assertEquals(counter.get(), OPTIMISTIC_CYCLES * THREADS);

    OrientVertex loadedSuperNode = graphPool.getVertex(superNode.getIdentity());

    for (int i = 0; i < THREADS; ++i)
      Assert.assertEquals(loadedSuperNode.countEdges(Direction.IN), OPTIMISTIC_CYCLES * THREADS);

    graphPool.shutdown();

    System.out.println("ConcurrentSQLBatchUpdateSuperNodeTest Optimistic Test completed in "
        + (System.currentTimeMillis() - startedOn));
  }
View Full Code Here

Examples of com.tinkerpop.blueprints.impls.orient.OrientGraph

*/
public class EdgeIndexingTest {
  @Test
  public void testOutLinksUniqueness() {
    final String url = "memory:" + this.getClass().getSimpleName();
    OrientGraph graph = new OrientGraph(url);
    graph.drop();

    graph = new OrientGraph(url);
    graph.createEdgeType("link");
    graph.setAutoStartTx(false);

    OClass outVertexType = graph.createVertexType("IndexedOutVertex");
    outVertexType.createProperty("out_link", OType.LINKBAG);
    outVertexType.createIndex("uniqueLinkIndex", "unique", "out_link");

    graph.setAutoStartTx(true);


    Vertex vertexOutOne = graph.addVertex("class:IndexedOutVertex");

    Vertex vertexInOne = graph.addVertex(null);
    Vertex vertexInTwo = graph.addVertex(null);

    vertexOutOne.addEdge("link", vertexInOne);
    vertexOutOne.addEdge("link", vertexInTwo);
    graph.commit();

    Vertex vertexOutTwo = graph.addVertex("class:IndexedOutVertex");
    vertexOutTwo.addEdge("link", vertexInTwo);

    try {
      graph.commit();

      //in vertex can be linked by only one out vertex.
      Assert.fail();
    } catch (ORecordDuplicatedException e) {
    }

    graph.drop();
  }
View Full Code Here

Examples of com.tinkerpop.blueprints.impls.orient.OrientGraph

    initGraph();

    addEdgesConcurrently();
    assertGraph();

    OrientGraph graph = new OrientGraph(URL);
    graph.drop();
  }
View Full Code Here

Examples of com.tinkerpop.blueprints.impls.orient.OrientGraph

      toVertex.inEdges.add(edge);
    }
  }

  private void initGraph() {
    OrientGraph graph = new OrientGraph(URL);
    graph.setAutoStartTx(false);
    graph.commit();

    final OrientVertexType vertexType = graph.createVertexType("TestVertex");
    vertexType.createProperty("uuid", OType.STRING);
    vertexType.createIndex("TestVertexUuidIndex", OClass.INDEX_TYPE.UNIQUE_HASH_INDEX, "uuid");

    final OrientEdgeType edgeType = graph.createEdgeType("TestEdge");
    edgeType.createProperty("uuid", OType.STRING);
    edgeType.createIndex("TestEdgeUuidIndex", OClass.INDEX_TYPE.UNIQUE_HASH_INDEX, "uuid");
    graph.shutdown();
  }
View Full Code Here

Examples of com.tinkerpop.blueprints.impls.orient.OrientGraph

    System.out.println("Graph was created used threads : " + THREADS + " duplication exceptions : " + indexCollisions.get()
        + " version exceptions : " + versionCollisions.get() + " vertexes : " + VERTEXES_COUNT + " edges : " + EDGES_COUNT);
  }

  private void assertGraph() {
    OrientGraph graph = new OrientGraph(URL);
    graph.setUseLightweightEdges(false);

    Assert.assertEquals(VERTEXES_COUNT, graph.countVertices("TestVertex"));
    Assert.assertEquals(EDGES_COUNT, graph.countEdges("TestEdge"));

    for (TestVertex vertex : vertexes) {
      Iterable<Vertex> vertexes = graph.command(
          new OSQLSynchQuery<Vertex>("select from TestVertex where uuid = '" + vertex.uuid + "'")).execute();

      Assert.assertTrue(vertexes.iterator().hasNext());
    }

    for (TestEdge edge : edges) {
      Iterable<Edge> edges = graph.command(new OSQLSynchQuery<Edge>("select from TestEdge where uuid = '" + edge.uuid + "'"))
          .execute();

      Assert.assertTrue(edges.iterator().hasNext());
    }

    for (TestVertex vertex : vertexes) {
      Iterable<Vertex> vertexes = graph.command(
          new OSQLSynchQuery<Vertex>("select from TestVertex where uuid = '" + vertex.uuid + "'")).execute();

      Assert.assertTrue(vertexes.iterator().hasNext());

      Vertex gVertex = vertexes.iterator().next();

      Iterable<Edge> outEdges = gVertex.getEdges(Direction.OUT);
      Iterator<Edge> outGEdgesIterator = outEdges.iterator();

      int counter = 0;
      while (outGEdgesIterator.hasNext()) {
        counter++;

        Edge gEdge = outGEdgesIterator.next();
        TestEdge testEdge = new TestEdge();
        testEdge.uuid = gEdge.getProperty("uuid");

        Assert.assertTrue(vertex.outEdges.contains(testEdge));
      }
      Assert.assertEquals(vertex.outEdges.size(), counter);

      Iterable<Edge> inEdges = gVertex.getEdges(Direction.IN);
      Iterator<Edge> inGEdgesIterator = inEdges.iterator();

      counter = 0;
      while (inGEdgesIterator.hasNext()) {
        counter++;

        Edge gEdge = inGEdgesIterator.next();

        TestEdge testEdge = new TestEdge();
        testEdge.uuid = gEdge.getProperty("uuid");

        Assert.assertTrue(vertex.inEdges.contains(testEdge));
      }
      Assert.assertEquals(vertex.inEdges.size(), counter);

    }

    graph.shutdown();
  }
View Full Code Here

Examples of com.tinkerpop.blueprints.impls.orient.OrientGraph

  }

  private class ConcurrentGraphCreator implements Callable<Void> {
    @Override
    public Void call() throws Exception {
      OrientGraph graph = new OrientGraph(URL);
      latch.await();
      final int startIndex = random.nextInt(vertexes.size());

      final String startUUID = vertexes.get(startIndex).uuid;
      String currentUUID = startUUID;
      try {
        do {
          TestVertex fromVertex = vertexesToCreate.get(currentUUID);

          for (TestEdge edge : fromVertex.outEdges) {
            TestVertex toVertex = vertexesToCreate.get(edge.out);

            boolean success = false;
            while (!success)
              try {
                Iterable<Vertex> vertexes = graph.command(
                    new OSQLSynchQuery<Vertex>("select from TestVertex where uuid = '" + fromVertex.uuid + "'")).execute();

                Vertex gFromVertex;

                Iterator<Vertex> gVertexesIterator = vertexes.iterator();

                if (!gVertexesIterator.hasNext()) {
                  graph.command(new OCommandSQL("CREATE VERTEX TestVertex SET uuid = '" + fromVertex.uuid + "'")).execute();

                  vertexes = graph.command(
                      new OSQLSynchQuery<Vertex>("select from TestVertex where uuid = '" + fromVertex.uuid + "'")).execute();
                  gVertexesIterator = vertexes.iterator();
                  gFromVertex = gVertexesIterator.next();
                } else {
                  gFromVertex = gVertexesIterator.next();
                }

                vertexes = graph.command(new OSQLSynchQuery<Vertex>("select from TestVertex where uuid = '" + toVertex.uuid + "'"))
                    .execute();

                Vertex gToVertex;

                gVertexesIterator = vertexes.iterator();
                if (!gVertexesIterator.hasNext()) {
                  graph.command(new OCommandSQL("CREATE VERTEX TestVertex SET uuid = '" + toVertex.uuid + "'")).execute();
                  vertexes = graph.command(
                      new OSQLSynchQuery<Vertex>("select from TestVertex where uuid = '" + toVertex.uuid + "'")).execute();

                  gVertexesIterator = vertexes.iterator();
                  gToVertex = gVertexesIterator.next();
                } else {
                  gToVertex = gVertexesIterator.next();
                }

                Edge gEdge;

                Iterable<Edge> edges = graph.command(
                    new OSQLSynchQuery<Edge>("select from TestEdge where uuid = '" + edge.uuid + "'")).execute();

                if (!edges.iterator().hasNext()) {
                  graph.command(
                      new OCommandSQL("CREATE EDGE TestEdge FROM " + gFromVertex.getId() + " TO " + gToVertex.getId()
                          + " SET uuid = '" + edge.uuid + "'")).execute();
                }

                graph.commit();

                success = true;
              } catch (OConcurrentModificationException e) {
                graph.rollback();

                versionCollisions.incrementAndGet();
                Thread.yield();
              } catch (ORecordDuplicatedException e) {
                graph.rollback();

                indexCollisions.incrementAndGet();
                Thread.yield();
              }
          }

          if (fromVertex.outEdges.isEmpty()) {
            boolean success = false;
            while (!success)
              try {
                Iterable<Vertex> vertexes = graph.command(
                    new OSQLSynchQuery<Vertex>("select from TestVertex where uuid = '" + fromVertex.uuid + "'")).execute();

                Iterator<Vertex> gVertexesIterator = vertexes.iterator();

                if (!gVertexesIterator.hasNext()) {
                  graph.command(new OCommandSQL("CREATE VERTEX TestVertex SET uuid = '" + fromVertex.uuid + "'")).execute();
                }

                success = true;
              } catch (OConcurrentModificationException e) {
                graph.rollback();

                versionCollisions.incrementAndGet();
                Thread.yield();
              } catch (ORecordDuplicatedException e) {
                graph.rollback();

                indexCollisions.incrementAndGet();
                Thread.yield();
              }
          }

          currentUUID = vertexesToCreate.higherKey(currentUUID);
          if (currentUUID == null)
            currentUUID = vertexesToCreate.firstKey();
        } while (!startUUID.equals(currentUUID));
      } catch (Exception e) {
        e.printStackTrace();
        throw e;
      } finally {
        graph.shutdown();
      }

      return null;

    }
View Full Code Here

Examples of com.tinkerpop.blueprints.impls.orient.OrientGraph

  public BlueprintsTest() {
  }

  @BeforeClass
  public static void before() {
    graph = new OrientGraph(DB_URL);
  }
View Full Code Here

Examples of com.tinkerpop.blueprints.impls.orient.OrientGraph

    Assert.assertEquals(result.size(), 1);
  }

  @Test
  public void testTraverse() {
    OrientGraph graph = new OrientGraph(url);
    graph.setAutoStartTx(false);
    graph.commit();

    OClass oc = graph.getVertexType("vertexA");
    if (oc == null)
      oc = graph.createVertexType("vertexA");

    if (!oc.existsProperty("name"))
      oc.createProperty("name", OType.STRING);

    if (oc.getClassIndex("vertexA_name_idx") == null)
      oc.createIndex("vertexA_name_idx", OClass.INDEX_TYPE.UNIQUE, "name");

    OClass ocb = graph.getVertexType("vertexB");
    if (ocb == null)
      ocb = graph.createVertexType("vertexB");

    ocb.createProperty("name", OType.STRING);
    ocb.createProperty("map", OType.EMBEDDEDMAP);
    ocb.createIndex("vertexB_name_idx", OClass.INDEX_TYPE.UNIQUE, "name");
    graph.setAutoStartTx(true);

    // FIRST: create a root vertex
    ODocument docA = graph.addVertex("class:vertexA").getRecord();
    docA.field("name", "valueA");
    docA.save();

    Map<String, String> map = new HashMap<String, String>();
    map.put("key", "value");

    createAndLink(graph, "valueB1", map, docA);
    createAndLink(graph, "valueB2", map, docA);

    StringBuilder sb = new StringBuilder("select from vertexB");
    sb.append(" where any() traverse(0, -1) (@class = '");
    sb.append("vertexA");
    sb.append("' AND name = 'valueA')");

    List<ODocument> recordDocs = executeQuery(sb.toString(), graph.getRawGraph());

    for (ODocument doc : recordDocs) {
      System.out.println(doc);
    }

    graph.shutdown();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.