Java Code Examples for org.apache.tinkerpop.gremlin.structure.Graph#close()

The following examples show how to use org.apache.tinkerpop.gremlin.structure.Graph#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BitsyTestGraphProvider.java    From bitsy with Apache License 2.0 6 votes vote down vote up
@Override
	public void clear(Graph graph, Configuration configuration) throws Exception {
        if (graph != null) {
        	if (graph.tx().isOpen()) graph.tx().close();
        	graph.tx().onReadWrite(READ_WRITE_BEHAVIOR.MANUAL);
        	graph.tx().open();
        	System.out.println("Clearing graph");
        	graph.vertices().forEachRemaining(v -> v.remove());
        	graph.tx().commit();
        	System.out.println("Shutting down graph " + graph);
            graph.close();
        }

//		Thread.sleep(10);
//        File directory = new File(configuration.getString(BitsyGraph.DB_PATH_KEY));
//        wipeOut(directory);
//		Thread.sleep(10);
	}
 
Example 2
Source File: AbstractTitanGraphProvider.java    From titan1withtp3.1 with Apache License 2.0 6 votes vote down vote up
@Override
public void clear(Graph g, final Configuration configuration) throws Exception {
    if (null != g) {
        while (g instanceof WrappedGraph) g = ((WrappedGraph<? extends Graph>) g).getBaseGraph();
        TitanGraph graph = (TitanGraph) g;
        if (graph.isOpen()) {
            if (g.tx().isOpen()) g.tx().rollback();
            g.close();
        }
    }

    WriteConfiguration config = new CommonsConfiguration(configuration);
    BasicConfiguration readConfig = new BasicConfiguration(GraphDatabaseConfiguration.ROOT_NS, config, BasicConfiguration.Restriction.NONE);
    if (readConfig.has(GraphDatabaseConfiguration.STORAGE_BACKEND)) {
        TitanGraphBaseTest.clearGraph(config);
    }
}
 
Example 3
Source File: SqlgAbstractGraphProvider.java    From sqlg with MIT License 6 votes vote down vote up
@Override
public void clear(final Graph g, final Configuration configuration) throws Exception {
    logger.debug("clearing datasource " + configuration.getString("jdbc.url"));
    SqlgDataSource sqlgDataSource = null;
    if (null != g) {
        if (g.features().graph().supportsTransactions() && g.tx().isOpen()) {
            g.tx().rollback();
        }
        g.close();
    }
    SqlgPlugin plugin = getSqlgPlugin();
    SqlDialect sqlDialect = plugin.instantiateDialect();
    try {
        sqlgDataSource = SqlgDataSourceFactory.create(configuration);
        try (Connection conn = sqlgDataSource.getDatasource().getConnection()) {
            SqlgUtil.dropDb(sqlDialect, conn);
        }
    } finally {
        if (sqlgDataSource != null) {
            sqlgDataSource.close();
        }
    }
}
 
Example 4
Source File: TestAllVertices.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void testVertexIteratorWithIncorrectId() throws Exception {
    Graph g = this.sqlgGraph;
    final Vertex v1 = g.addVertex("name", "marko");
    final Object oid = v1.id();
    g.tx().onClose(Transaction.CLOSE_BEHAVIOR.ROLLBACK);
    g.close();
    try (SqlgGraph graph = SqlgGraph.open(configuration)) {
        try {
            graph.vertices(oid).next();
            Assert.fail("Vertex should not be found as close behavior was set to rollback");
        } catch (Exception ex) {
            validateException(new NoSuchElementException(), ex);
        }
    }
}
 
Example 5
Source File: TinkerGraphProvider.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
@Override
public void clear(final Graph graph, final Configuration configuration) throws Exception {
    if (graph != null)
        graph.close();

    // in the even the graph is persisted we need to clean up
    final String graphLocation = null != configuration ? configuration.getString(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, null) : null;
    if (graphLocation != null) {
        final File f = new File(graphLocation);
        f.delete();
    }
}
 
Example 6
Source File: ComputeWeight.java    From janusgraph_tutorial with Apache License 2.0 5 votes vote down vote up
public static void main(String[] argv) throws InterruptedException, IOException {
  Graph hadoopGraph = null;

  try {
    LOGGER.info("Connect to the hadoop graph");
    hadoopGraph = GraphFactory.open(new PropertiesConfiguration(HADOOP_CONFIG_FILE));
    ComputeWeightVertexProgram.Builder builder = ComputeWeightVertexProgram.build().withRwGraphConfig(Schema.CONFIG_FILE);

    ComputerResult result = hadoopGraph.
        compute().
        program(
            builder.create(hadoopGraph)
        ).
        vertices(hasLabel(Schema.USER)).
        submit().get();
    result.close();
    hadoopGraph.close();
    Spark.close();

    hadoopGraph = null;
  } catch (Exception e) {
    e.printStackTrace();
    try {
      if (hadoopGraph != null) {
        hadoopGraph.close();
        Spark.close();
      }
    } catch (Exception e1) {
      System.err.println("Couldn't close graph or spark...");
    }
  }

  // we need to call this one or else the program will be waiting forever
  LOGGER.info("bye bye");
  System.exit(0);
}
 
Example 7
Source File: Neo4JTestGraphProvider.java    From neo4j-gremlin-bolt with Apache License 2.0 5 votes vote down vote up
@Override
public void clear(Graph graph, Configuration configuration) throws Exception {
    // check graph instance
    if (graph != null) {
        // close graph instance
        graph.close();
    }
    // create driver instance
    Driver driver = Neo4JGraphFactory.createDriverInstance(configuration);
    // session configuration
    SessionConfig.Builder config = SessionConfig.builder();
    // check database is set
    String database = configuration.getString(Neo4JGraphConfigurationBuilder.Neo4JDatabaseConfigurationKey, null);
    if (database != null) {
        // update session config
        config.withDatabase(database);
    }
    // open session
    try (Session session = driver.session(config.build())) {
        // begin transaction
        try (org.neo4j.driver.Transaction transaction = session.beginTransaction()) {
            // delete everything in database
            transaction.run("MATCH (n) DETACH DELETE n");
            // commit
            transaction.commit();
        }
    }
}
 
Example 8
Source File: TinkerGraphProvider.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void clear(final Graph graph, final Configuration configuration) throws Exception {
    if (graph != null)
        graph.close();

    // in the even the graph is persisted we need to clean up
    final String graphLocation = null != configuration ? configuration.getString(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, null) : null;
    if (graphLocation != null) {
        final File f = new File(graphLocation);
        f.delete();
    }
}
 
Example 9
Source File: TinkerGraphProvider.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void clear(final Graph graph, final Configuration configuration) throws Exception {
    if (graph != null)
        graph.close();

    // in the even the graph is persisted we need to clean up
    final String graphLocation = null != configuration ? configuration.getString(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, null) : null;
    if (graphLocation != null) {
        final File f = new File(graphLocation);
        f.delete();
    }
}
 
Example 10
Source File: AbstractNeo4jGraphProvider.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void clear(final Graph graph, final Configuration configuration) throws Exception {
    if (null != graph) {
        if (graph.tx().isOpen()) graph.tx().rollback();
        graph.close();
    }

    if (null != configuration && configuration.containsKey(Neo4jGraph.CONFIG_DIRECTORY)) {
        // this is a non-in-sideEffects configuration so blow away the directory
        final File graphDirectory = new File(configuration.getString(Neo4jGraph.CONFIG_DIRECTORY));
        deleteDirectory(graphDirectory);
    }
}
 
Example 11
Source File: DefaultGraphManager.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public final Graph removeGraph(final String graphName) throws Exception {
    Graph graph = graphs.remove(graphName);
    graph.close();
    return graph;
}
 
Example 12
Source File: AbstractFileGraphProvider.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public void clear(final Graph graph, final Configuration configuration) throws Exception {
    if (graph != null)
        graph.close();
}