Examples of OrientGraph


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

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

    }
  }

  @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

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

    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

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

    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

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

  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

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

    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

Examples of com.tinkerpop.blueprints.pgm.impls.orientdb.OrientGraph

  public static void main(final String[] args) throws Exception {
    final String inputFile = args.length > 0 ? args[0] : INPUT_FILE;
    final String dbURL = args.length > 1 ? args[1] : DBURL;

    OrientGraph g = new OrientGraph(dbURL);

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

    final long startTime = System.currentTimeMillis();

    g.setTransactionMode(Mode.MANUAL);

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

    System.out.println("Imported in " + (System.currentTimeMillis() - startTime) + "ms. Vertexes: "
        + g.getRawGraph().countVertexes() + " Edges: " + g.getRawGraph().countEdges());

  }
View Full Code Here

Examples of com.tinkerpop.blueprints.pgm.impls.orientdb.OrientGraph

      } catch (Throwable e) {
        throw new OConfigurationException("Error on loading Gremlin engine", e);
      }

      // TODO THIS COULD BE IMPROVED BY CREATING A ORIENT-GRAPH POOL (LIKE WITH OTHER DB TYPES) INSTEAD TO CREATE IT PER QUERY
      graph = new OrientGraph(iCurrentRecord.getDatabase().getURL());
      engine.getBindings(ScriptContext.ENGINE_SCOPE).put("g", graph);
    }

    final OrientElement graphElement;
View Full Code Here

Examples of com.tinkerpop.blueprints.pgm.impls.orientdb.OrientGraph

  public static void main(final String[] args) throws Exception {
    final String inputFile = args.length > 0 ? args[0] : INPUT_FILE;
    final String dbURL = args.length > 1 ? args[1] : DBURL;

    OrientGraph g = new OrientGraph(dbURL);

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

    final long startTime = System.currentTimeMillis();

    g.setTransactionMode(Mode.MANUAL);

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

    System.out.println("Imported in " + (System.currentTimeMillis() - startTime) + "ms. Vertexes: "
        + g.getRawGraph().countVertexes() + " Edges: " + g.getRawGraph().countEdges());

  }
View Full Code Here

Examples of com.tinkerpop.blueprints.pgm.impls.orientdb.OrientGraph

  @SuppressWarnings("unchecked")
  @Override
  public <RET extends OCommandExecutor> RET parse(OCommandRequestText iRequest) {
    engine = new GremlinScriptEngine();
    graph = new OrientGraph(iRequest.getDatabase().getURL());
    text = iRequest.getText();

    engine.getBindings(ScriptContext.ENGINE_SCOPE).put("g", graph);
    return (RET) this;
  }
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.