Package com.tinkerpop.blueprints.impls.orient

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


    OClass clazz = null;
    String where = null;

    String temp = parseOptionalWord(true);

    final OrientGraph graph = OGraphCommandExecutorSQLFactory.getGraph(false);
    while (temp != null) {

      if (temp.equals("FROM")) {
        fromExpr = parserRequiredWord(false, "Syntax error", " =><,\r\n");
        if (rid != null)
          throwSyntaxErrorException("FROM '" + fromExpr + "' is not allowed when specify a RID (" + rid + ")");

      } else if (temp.equals("TO")) {
        toExpr = parserRequiredWord(false, "Syntax error", " =><,\r\n");
        if (rid != null)
          throwSyntaxErrorException("TO '" + toExpr + "' is not allowed when specify a RID (" + rid + ")");

      } else if (temp.startsWith("#")) {
        rid = new ORecordId(temp);
        if (fromExpr != null || toExpr != null)
          throwSyntaxErrorException("Specifying the RID " + rid + " is not allowed with FROM/TO");

      } else if (temp.equals(KEYWORD_WHERE)) {
        if (clazz == null)
          // ASSIGN DEFAULT CLASS
          clazz = graph.getEdgeType(OrientEdgeType.CLASS_NAME);

        where = parserGetCurrentPosition() > -1 ? " " + parserText.substring(parserGetCurrentPosition()) : "";

        compiledFilter = OSQLEngine.getInstance().parseCondition(where, getContext(), KEYWORD_WHERE);
        break;

      } else if (temp.equals(KEYWORD_RETRY)) {
        parseRetry();
      } else if (temp.length() > 0) {
        // GET/CHECK CLASS NAME
        clazz = graph.getEdgeType(temp);
        if (clazz == null)
          throw new OCommandSQLParsingException("Class '" + temp + " was not found");
      }

      temp = parseOptionalWord(true);
      if (parserIsEnded())
        break;
    }

    if (where == null)
      where = "";
    else
      where = " WHERE " + where;

    if (fromExpr == null && toExpr == null && rid == null)
      if (clazz == null)
        // DELETE ALL THE EDGES
        query = graph.getRawGraph().command(new OSQLAsynchQuery<ODocument>("select from E" + where, this));
      else
        // DELETE EDGES OF CLASS X
        query = graph.getRawGraph().command(new OSQLAsynchQuery<ODocument>("select from " + clazz.getName() + where, this));

    return this;
  }
View Full Code Here


    }
  }

  @Test
  public void deletesWithinTransactionArentWorking() throws IOException {
    OrientGraph graph = new OrientGraph(url);
    graph.setUseLightweightEdges(false);
    try {
      if (graph.getVertexType("Foo") == null)
        graph.createVertexType("Foo");
      if (graph.getVertexType("Bar") == null)
        graph.createVertexType("Bar");
      if (graph.getVertexType("Sees") == null)
        graph.createEdgeType("Sees");

      // Commenting out the transaction will result in the test succeeding.
      ODocument foo = graph.addVertex("class:Foo", "prop", "test1").getRecord();

      // Comment out these two lines and the test will succeed. The issue appears to be related to an edge
      // connecting a deleted vertex during a transaction
      ODocument bar = graph.addVertex("class:Bar", "prop", "test1").getRecord();
      ODocument sees = graph.addEdge(null, graph.getVertex(foo), graph.getVertex(bar), "Sees").getRecord();
      graph.commit();

      List<ODocument> foos = graph.getRawGraph().query(new OSQLSynchQuery("select * from Foo"));
      Assert.assertEquals(foos.size(), 1);

      graph.removeVertex(graph.getVertex(foos.get(0)));
    } finally {
      graph.shutdown();
    }
  }
View Full Code Here

    System.out.println("**************************TransactionRollbackConstistencyTest***************************************");
  }

  @Test
  public void testQueryIsolation() {
    OrientGraph graph = new OrientGraph(url);
    try {
      graph.addVertex(null, "purpose", "testQueryIsolation");

      if (!url.startsWith("remote")) {
        List<OIdentifiable> result = graph.getRawGraph().query(
            new OSQLSynchQuery<Object>("select from V where purpose = 'testQueryIsolation'"));
        Assert.assertEquals(result.size(), 1);
      }

      graph.commit();

      List<OIdentifiable> result = graph.getRawGraph().query(
          new OSQLSynchQuery<Object>("select from V where purpose = 'testQueryIsolation'"));
      Assert.assertEquals(result.size(), 1);

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

    database.close();
  }

  @Test
  public void testConsistencyOnDelete() {
    final OrientGraph graph = new OrientGraph(url);

    if (graph.getVertexType("Foo") == null)
      graph.createVertexType("Foo");

    try {
      // Step 1
      // Create several foo's
      graph.addVertex("class:Foo", "address", "test1");
      graph.addVertex("class:Foo", "address", "test2");
      graph.addVertex("class:Foo", "address", "test3");
      graph.commit();

      // just show what is there
      List<ODocument> result = graph.getRawGraph().query(new OSQLSynchQuery<ODocument>("select * from Foo"));

      for (ODocument d : result) {
        System.out.println("Vertex: " + d);
      }

      // remove those foos in a transaction
      // Step 3a
      result = graph.getRawGraph().query(new OSQLSynchQuery<ODocument>("select * from Foo where address = 'test1'"));
      Assert.assertEquals(result.size(), 1);
      // Step 4a
      graph.removeVertex(graph.getVertex(result.get(0)));

      // Step 3b
      result = graph.getRawGraph().query(new OSQLSynchQuery<ODocument>("select * from Foo where address = 'test2'"));
      Assert.assertEquals(result.size(), 1);
      // Step 4b
      graph.removeVertex(graph.getVertex(result.get(0)));

      // Step 3c
      result = graph.getRawGraph().query(new OSQLSynchQuery<ODocument>("select * from Foo where address = 'test3'"));
      Assert.assertEquals(result.size(), 1);
      // Step 4c
      graph.removeVertex(graph.getVertex(result.get(0)));

      // Step 6
      graph.commit();

      // just show what is there
      result = graph.getRawGraph().query(new OSQLSynchQuery<ODocument>("select * from Foo"));

      for (ODocument d : result) {
        System.out.println("Vertex: " + d);
      }

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

  public static OrientGraph getGraph(final boolean autoStartTx) {
    ODatabaseRecord database = ODatabaseRecordThreadLocal.INSTANCE.get();
    if (!(database instanceof ODatabaseDocumentTx))
      database = new ODatabaseDocumentTx((ODatabaseRecordTx) database);

    return new OrientGraph((ODatabaseDocumentTx) database, autoStartTx);
  }
View Full Code Here

    iRequest.data.commandInfo = "Gephi";
    iRequest.data.commandDetail = text;

    final ODatabaseDocumentTx db = getProfiledDatabaseInstance(iRequest);

    final OrientGraph graph = OGraphCommandExecutorSQLFactory.getGraph(false);
    try {

      final Iterable<OrientVertex> vertices;
      if (language.equals("sql"))
        vertices = graph.command(new OSQLSynchQuery<OrientVertex>(text, limit).setFetchPlan(fetchPlan)).execute();
      else if (language.equals("gremlin")) {
        List<Object> result = new ArrayList<Object>();
        OGremlinHelper.execute(graph, text, null, null, result, null, null);

        vertices = new ArrayList<OrientVertex>(result.size());

        for (Object o : result) {
          ((ArrayList<OrientVertex>) vertices).add(graph.getVertex((OIdentifiable) o));
        }
      } else
        throw new IllegalArgumentException("Language '" + language + "' is not supported. Use 'sql' or 'gremlin'");

      sendRecordsContent(iRequest, iResponse, vertices, fetchPlan);

    } finally {
      if (graph != null)
        graph.shutdown();

      if (db != null)
        db.close();
    }
View Full Code Here

    return new OScriptGraphWrapper(new OrientGraphNoTx(threadDatabase));
  }

  public OScriptGraphWrapper getGraph() {
    final ODatabaseDocumentTx threadDatabase = (ODatabaseDocumentTx) ODatabaseRecordThreadLocal.INSTANCE.get().getDatabaseOwner();
    return new OScriptGraphWrapper(new OrientGraph(threadDatabase));
  }
View Full Code Here

TOP

Related Classes of com.tinkerpop.blueprints.impls.orient.OrientGraph

Copyright © 2018 www.massapicom. 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.