Examples of OrientGraphNoTx


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

    final OrientGraphFactory factory = new OrientGraphFactory(dburl, "admin", "admin");
    if (factory.exists())
      factory.drop();
    factory.close();
    OrientGraphNoTx db = factory.getNoTx();
    db.drop();
    OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.setValue(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD.getValue());
  }
View Full Code Here

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

  @Override
  protected void executeTest() throws Exception {
    try {
      OrientGraphFactory localFactory = new OrientGraphFactory("plocal:target/server0/databases/" + getDatabaseName());
      OrientGraphNoTx graphNoTx = localFactory.getNoTx();

      try {
        final OrientVertexType clientType = graphNoTx.createVertexType("Client");
        for (int i = 1; i < serverInstance.size(); ++i) {
          final String serverName = serverInstance.get(i).getServerInstance().getDistributedManager().getLocalNodeName();
          clientType.addCluster("client_" + serverName);
        }

        graphNoTx.createVertexType("Product");
        graphNoTx.createVertexType("Hobby");

        graphNoTx.createEdgeType("Knows");
        graphNoTx.createEdgeType("Buy");
        graphNoTx.createEdgeType("Loves");
      } finally {
        graphNoTx.shutdown();
      }

      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) {
        OrientGraphFactory f = new OrientGraphFactory("plocal:target/server" + 0 + "/databases/" + getDatabaseName());
        OrientGraphNoTx g = f.getNoTx();
        try {
          // MISC QUERIES
          Iterable<OrientVertex> result = g.command(new OCommandSQL("select sum(amount) from ( select from Client )")).execute();

          int count = 0;
          for (OrientVertex v : result) {
            System.out.println("select sum(amount) from ( select from Client ) -> " + v.getRecord());
            count++;
          }

          Assert.assertEquals("Returned wrong vertices count on server " + server, 1, count);

        } finally {
          g.shutdown();
        }
      }

      // TEST DISTRIBUTED QUERY AGAINST ALL 3 DATABASES TO TEST MAP/REDUCE
      for (int server = 0; server < vertices.length; ++server) {
        OrientGraphFactory f = new OrientGraphFactory("plocal:target/server" + server + "/databases/" + getDatabaseName());
        OrientGraphNoTx g = f.getNoTx();
        try {

          Iterable<OrientVertex> result = g.command(new OCommandSQL("select from Client")).execute();
          int count = 0;
          for (OrientVertex v : result) {
            count++;

            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"));
          }

          Assert.assertEquals("Returned wrong vertices count on server " + server, 3, count);
        } finally {
          g.shutdown();
        }
      }

      // TEST DISTRIBUTED QUERY AGAINST ALL 3 DATABASES TO TEST AGGREGATION
      for (int server = 0; server < vertices.length; ++server) {
        OrientGraphFactory f = new OrientGraphFactory("plocal:target/server" + server + "/databases/" + getDatabaseName());
        OrientGraphNoTx g = f.getNoTx();
        try {

          Iterable<OrientVertex> result = g.command(new OCommandSQL("select max(amount), avg(amount), sum(amount) from Client"))
              .execute();

          int count = 0;
          for (OrientVertex v : result) {
            System.out.println("select max(amount), avg(amount), sum(amount) from Client -> " + v.getRecord());
            count++;
          }

          Assert.assertEquals("Returned wrong vertices count on server " + server, 1, count);
        } finally {
          g.shutdown();
        }
      }
    } catch (Exception e) {
      e.printStackTrace();

View Full Code Here

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

  @Override
  protected void executeTest() throws Exception {
    for (int s = 0; s < SERVERS; ++s) {
      OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
      OrientGraphNoTx g = factory.getNoTx();

      try {
        System.out.println("Creating vertex class Client" + s + " against server " + g + "...");
        OrientVertexType t = g.createVertexType("Client" + s);
        t.createProperty("name", OType.STRING).setMandatory(true);

        System.out.println("Creating vertex class Knows" + s + " against server " + g + "...");
        g.createEdgeType("Knows" + s);
      } finally {
        g.shutdown();
      }
    }

    for (int s = 0; s < SERVERS; ++s) {
      OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
      OrientGraphNoTx g = factory.getNoTx();

      try {
        for (int i = 0; i < SERVERS; ++i) {
          Assert.assertNotNull(g.getVertexType("Client" + i));
          Assert.assertNotNull(g.getEdgeType("Knows" + i));
        }
      } finally {
        g.shutdown();
      }
    }

    for (int s = 0; s < SERVERS; ++s) {
      OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
      OrientGraphNoTx g = factory.getNoTx();

      try {
        for (int i = 0; i < SERVERS; ++i) {
          try {
            final OrientVertex v = g.addVertex("class:" + "Client" + i);
            Assert.assertTrue(false);
          } catch (OValidationException e) {
            // EXPECTED
          }
        }
      } finally {
        g.shutdown();
      }
    }

    for (int s = 0; s < SERVERS; ++s) {
      OrientGraphFactory factory = new OrientGraphFactory("plocal:target/server" + s + "/databases/" + getDatabaseName());
      OrientGraph g = factory.getTx();

      try {
        for (int i = 0; i < SERVERS; ++i) {
          try {
            final OrientVertex v = g.addVertex("class:" + "Client" + i);
            Assert.assertTrue(false);
          } catch (OValidationException e) {
            // EXPECTED
          }
        }
      } finally {
        g.shutdown();
      }
    }
  }
View Full Code Here

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

    final String storageType = getStorageType();
    final String buildDirectory = System.getProperty("buildDirectory", ".");

    OFileUtils.deleteRecursively(new File(buildDirectory + "/" + dbName));

    graph = new OrientGraphNoTx(storageType + ":" + buildDirectory + "/" + dbName);
  }
View Full Code Here

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

public class TestOutInChain {

  @BeforeClass
  public static void before() {
    // generate schema
    OrientGraphNoTx graph = new OrientGraphNoTx("memory:" + TestOutInChain.class.getSimpleName(), "admin", "admin");
    graph.command(new OCommandSQL("create class User extends V")).execute();
    graph.command(new OCommandSQL("create class Car extends V")).execute();
    graph.command(new OCommandSQL("create class Owns extends E")).execute();
    graph.shutdown();
  }
View Full Code Here

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

      threadName = iThreadName;
    }

    @Override
    public void run() {
      final OrientGraphNoTx graph = new OrientGraphNoTx(url);
      try {
        String cmd = "";
        for (int i = 0; i < OPTIMISTIC_CYCLES; ++i) {
          cmd = "begin;";
          cmd += "let a = create vertex set type = 'Citizen', id = '" + threadId + "-" + i + "';";
          cmd += "create edge from $a to " + superNode.getIdentity() + ";";
          cmd += "commit retry " + MAX_RETRIES + ";";
          cmd += "return $transactionRetries;";

          final OCommandRequest command = graph.command(new OCommandScript("sql", cmd));
          final Object res = command.execute();
          if (res instanceof Integer) {
            int retries = (Integer) res;

            counter.incrementAndGet();

            totalRetries.addAndGet(retries);
          } else if (res instanceof OrientDynaElementIterable) {
            System.out.println("RETURNED ITER");
            OrientDynaElementIterable it = (OrientDynaElementIterable) res;
            for (Object o : it)
              System.out.println("RETURNED: " + o);
          }
        }

        System.out.println("Thread " + threadId + " completed");

        graph.shutdown();
      } catch (Throwable e) {
        e.printStackTrace();
        Assert.assertTrue(false);
      }
    }
View Full Code Here

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

      threadName = iThreadName;
    }

    @Override
    public void run() {
      final OrientGraphNoTx graph = new OrientGraphNoTx(url);
      try {
        String cmd = "";
        for (int i = 0; i < PESSIMISTIC_CYCLES; ++i) {
          cmd = "begin;";
          cmd += "select from " + superNode.getIdentity() + " lock record;";
          cmd += "let a = create vertex set type = 'Citizen', id = '" + threadId + "-" + i + "';";
          cmd += "create edge from $a to " + superNode.getIdentity() + ";";
          cmd += "commit;";

          Object result = graph.command(new OCommandScript("sql", cmd)).execute();

          counter.incrementAndGet();
        }
        graph.shutdown();

      } catch (Throwable e) {
        e.printStackTrace();
        Assert.assertTrue(false);
      }
View Full Code Here

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

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


  public static void populateDB() throws IOException{
    ODatabaseRecordTx db = getConnection();
    //DO NOT DELETE THE FOLLOWING LINE!
    OrientGraphNoTx dbg =  new OrientGraphNoTx(getODatabaseDocumentTxConnection());
    Logger.info("Populating the db...");
    InputStream is;
    if (Play.application().isProd()) is  =Play.application().resourceAsStream(SCRIPT_FILE_NAME);
    else is = new FileInputStream(Play.application().getFile("conf/"+SCRIPT_FILE_NAME));
    List<String> script=IOUtils.readLines(is, "UTF-8");
View Full Code Here

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

    test.data.go(test);
  }

  @Override
  public void init() {
    final OrientGraphNoTx graph = factory.getNoTx();
    try {
      if (graph.getVertexType("Client") == null) {
        final OrientVertexType clientType = graph.createVertexType("Client");

        final OrientVertexType.OrientVertexProperty property = clientType.createProperty("uid", OType.STRING);
        property.createIndex(OClass.INDEX_TYPE.UNIQUE_HASH_INDEX);

        // CREATE ONE CLUSTER PER THREAD
        for (int i = 0; i < getThreads(); ++i) {
          System.out.println("Creating cluster: client_" + i + "...");
          clientType.addCluster("client_" + i);
        }

        foundObjects = 0;
      } else
        foundObjects = graph.countVertices("Client");

    } finally {
      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.