Examples of OrientBaseGraph


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

      }

      final OrientVertex product;
      final OrientVertex fishing;

      OrientBaseGraph graph = localFactory.getTx();
      try {
        product = graph.addVertex("class:Product");

        fishing = graph.addVertex("class:Hobby");
        fishing.setProperty("name", "Fishing");
      } finally {
        graph.shutdown();
      }

      vertices = new OrientVertex[serverInstance.size()];
      for (int i = 0; i < vertices.length; ++i) {
        final String nodeName = serverInstance.get(i).getServerInstance().getDistributedManager().getLocalNodeName();

        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + i + "/databases/" + getDatabaseName());
        graph = factory.getNoTx();
        try {

          vertices[i] = graph.addVertex("class:Client");

          final int clId = vertices[i].getIdentity().getClusterId();

          if (i == 0)
            Assert.assertEquals("Error on assigning cluster client", clId, graph.getRawGraph().getClusterIdByName("client"));
          else {
            final int clusterId = graph.getRawGraph().getClusterIdByName("client_" + nodeName);
            Assert.assertEquals("Error on assigning cluster client_" + nodeName, clId, clusterId);
          }

          vertices[i].setProperty("name", "shard_" + i);
          vertices[i].setProperty("amount", i * 10000);

          System.out.println("Create vertex, class: " + vertices[i].getLabel() + ", cluster: " + clId + " -> "
              + vertices[i].getRecord());

          if (i > 1)
            // CREATE A LIGHT-WEIGHT EDGE
            vertices[i].addEdge("Knows", vertices[i - 1]);

          // CREATE A REGULAR EDGE
          final Edge edge = vertices[i].addEdge("Buy", product, new Object[] { "price", 1000 * i });

        } finally {
          graph.shutdown();
        }
      }

      for (int i = 0; i < vertices.length; ++i)
        System.out.println("Created vertex " + i + ": " + vertices[i].getRecord());

      for (int i = 0; i < vertices.length; ++i) {
        OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + i + "/databases/" + getDatabaseName());
        graph = factory.getNoTx();
        try {

          // CREATE A REGULAR EDGE
          Iterable<OrientEdge> result = graph.command(
              new OCommandSQL("create edge Loves from " + vertices[i].getIdentity() + " to " + fishing.getIdentity()
                  + " set real = true")).execute();

          Assert.assertTrue(result.iterator().hasNext());
          OrientEdge e = result.iterator().next();
          Assert.assertEquals(e.getProperty("real"), true);

          final OrientVertex explain = graph.command(new OCommandSQL("explain select from " + e.getIdentity())).execute();
          System.out
              .println("explain select from " + e.getIdentity() + " -> " + ((ODocument) explain.getRecord()).field("servers"));

          result = graph.command(new OCommandSQL("select from " + e.getIdentity())).execute();

          Assert.assertTrue(result.iterator().hasNext());
          OrientEdge e2 = result.iterator().next();
          Assert.assertEquals(e2.getProperty("real"), true);

        } finally {
          graph.shutdown();
        }
      }

      // FOR ALL THE DATABASES QUERY THE SINGLE CLUSTER TO TEST ROUTING
      for (int server = 0; server < vertices.length; ++server) {
        OrientGraphFactory f = new OrientGraphFactory("plocal:target/server" + server + "/databases/" + getDatabaseName());
        OrientGraphNoTx g = f.getNoTx();

        System.out.println("Query from server " + server + "...");

        try {
          for (int cluster = 0; cluster < vertices.length; ++cluster) {
            final String query = "select from cluster:client_" + cluster;

            final OrientVertex explain = g.command(new OCommandSQL("explain " + query)).execute();
            System.out.println("explain " + query + " -> " + ((ODocument) explain.getRecord()).field("servers"));

            Iterable<OrientVertex> result = g.command(new OCommandSQL(query)).execute();
            Assert.assertTrue("Error on query against 'cluster_" + cluster + "' on server '" + server + "': " + query, result
                .iterator().hasNext());

            OrientVertex v = result.iterator().next();

            Assert.assertEquals("Returned vertices name property is != shard_" + cluster + " on server " + server, "shard_"
                + cluster, v.getProperty("name"));

            final Iterable<Vertex> knows = v.getVertices(Direction.OUT, "Knows");

            final Iterable<Vertex> boughtV = v.getVertices(Direction.OUT, "Buy");
            Assert.assertTrue(boughtV.iterator().hasNext());
            Assert.assertEquals(boughtV.iterator().next(), product);

            final Iterable<Edge> boughtE = v.getEdges(Direction.OUT, "Buy");
            Assert.assertNotNull(boughtE.iterator().next().getProperty("price"));
          }
        } finally {
          graph.shutdown();
        }
      }

      // TEST DISTRIBUTED QUERY + AGGREGATION + SUB_QUERY AGAINST ALL 3 DATABASES TO TEST MAP/REDUCE
      for (int server = 0; server < vertices.length; ++server) {
View Full Code Here

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

    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.OrientBaseGraph

    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.OrientBaseGraph

    OGlobalConfiguration.STORAGE_KEEP_OPEN.setValue(false);

    ODatabaseDocumentTx db = new ODatabaseDocumentTx(dbURL);
    ODatabaseHelper.deleteDatabase(db, storageType);

    OrientBaseGraph g = new OrientGraphNoTx(dbURL);

    System.out.println("Importing graph from file '" + inputFile + "' into database: " + g + "...");

    final long startTime = System.currentTimeMillis();

    GraphMLReader.inputGraph(g, new FileInputStream(inputFile), 10000, null, null, null);

    System.out.println("Imported in " + (System.currentTimeMillis() - startTime) + "ms. Vertexes: " + g.countVertices());

    g.command(new OCommandSQL("alter database TIMEZONE GMT")).execute();
    g.command(new OCommandSQL("alter database LOCALECOUNTRY UK")).execute();
    g.command(new OCommandSQL("alter database LOCALELANGUAGE EN")).execute();

    OGlobalConfiguration.STORAGE_KEEP_OPEN.setValue(oldKeepOpen);
    // g.drop();
  }
View Full Code Here

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

    OrientVertex v = getFromCache(id);
    if (v != null) {
      return v;
    }

    final OrientBaseGraph g = acquire();
    try {
      // LOAD FROM DATABASE AND STORE IN CACHE
      v = (OrientVertex) g.getVertexByKey(keyFieldName, id);
      if (v != null) {
        verticesLoaded.incrementAndGet();
      }

      return v;

    } finally {
      g.shutdown();
    }
  }
View Full Code Here

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

    beginAsynchOperation();

    Orient.instance().getWorkers().submit(new Callable<Object>() {
      @Override
      public Object call() throws Exception {
        final OrientBaseGraph g = acquire();
        try {
          if (vertexCache != null) {
            final Object field = vertex.getProperty(keyFieldName);
            if (field != null)
              vertexCache.remove(field);
          }

          g.removeVertex(vertex);

          verticesRemoved.incrementAndGet();
        } finally {
          g.shutdown();
          endAsynchOperation();
        }
        return null;
      }
    });
View Full Code Here

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

    });
  }

  @Override
  public Iterable<Vertex> getVertices() {
    final OrientBaseGraph g = acquire();
    try {
      return g.getVertices();
    } finally {
      g.shutdown();
    }
  }
View Full Code Here

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

    }
  }

  @Override
  public Iterable<Vertex> getVertices(final String key, final Object value) {
    final OrientBaseGraph g = acquire();
    try {
      return g.getVertices(key, value);
    } finally {
      g.shutdown();
    }
  }
View Full Code Here

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

    beginAsynchOperation();

    return new OrientEdgeFuture(Orient.instance().getWorkers().submit(new Callable<OrientEdge>() {
      @Override
      public OrientEdge call() throws Exception {
        final OrientBaseGraph g = acquire();
        try {
          final OrientExtendedVertex vOut = getOrAddVertex(iOutVertex);
          final OrientExtendedVertex vIn = getOrAddVertex(iInVertex);

          boolean reloaded = false;

          for (int retry = 0;; retry++) {
            try {

              final OrientEdge e = g.addEdge(null, vOut, vIn, iEdgeLabel);

              addInCache(vOut.getProperty(keyFieldName), vOut.getVertexInstance());
              addInCache(vIn.getProperty(keyFieldName), vIn.getVertexInstance());

              edgesCreated.incrementAndGet();

              return e;

            } catch (OConcurrentModificationException e) {
              concurrentException.incrementAndGet();
              reloadVertices(vOut, vIn, iEdgeLabel, retry, e);
              reloaded = true;
            } catch (ORecordDuplicatedException e) {
              indexUniqueException.incrementAndGet();
              reloadVertices(vOut, vIn, iEdgeLabel, retry, e);
              reloaded = true;
            } catch (Exception e) {
              unknownException.incrementAndGet();
              OLogManager.instance().warn(
                  this,
                  "Error on addEdge(" + iOutVertex + "," + iInVertex + "," + iEdgeLabel + "), retrying (retry=" + retry + "/"
                      + maxRetries + ") Thread: " + Thread.currentThread().getId());
              e.printStackTrace();
            }
          }
        } finally {
          g.shutdown();
          endAsynchOperation();
        }
      }
    }));
  }
View Full Code Here

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

    beginAsynchOperation();

    return new OrientEdgeFuture(Orient.instance().getWorkers().submit(new Callable<OrientEdge>() {
      @Override
      public OrientEdge call() throws Exception {
        final OrientBaseGraph g = acquire();
        try {
          // ASSURE ARE NOT REUSED FROM CACHE
          OrientVertex vOut = outVertex instanceof OrientVertexFuture ? ((OrientVertexFuture) outVertex).get()
              : (OrientVertex) outVertex;
          OrientVertex vIn = inVertex instanceof OrientVertexFuture ? ((OrientVertexFuture) inVertex).get()
              : (OrientVertex) inVertex;

          vOut.attach(g);
          vIn.attach(g);

          boolean reloaded = false;

          for (int retry = 0;; retry++) {
            try {

              final OrientEdge e = g.addEdge(id, vOut, vIn, label);

              addInCache(vOut.getProperty(keyFieldName), vOut);
              addInCache(vIn.getProperty(keyFieldName), vIn);

              edgesCreated.incrementAndGet();

              return e;

            } catch (OConcurrentModificationException e) {
              concurrentException.incrementAndGet();
              reloadVertices(vOut, vIn, label, retry, e);
              reloaded = true;
            } catch (ORecordDuplicatedException e) {
              indexUniqueException.incrementAndGet();
              reloadVertices(vOut, vIn, label, retry, e);
              reloaded = true;
            } catch (Exception e) {
              unknownException.incrementAndGet();
              OLogManager.instance().warn(
                  this,
                  "Error on addEdge(" + id + "," + outVertex + "," + inVertex + "," + label + "), retrying (retry=" + retry + "/"
                      + maxRetries + ") Thread: " + Thread.currentThread().getId());
              e.printStackTrace();
            }
          }
        } finally {
          g.shutdown();
          endAsynchOperation();
        }
      }
    }));
  }
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.