Java Code Examples for org.neo4j.graphdb.GraphDatabaseService#shutdown()

The following examples show how to use org.neo4j.graphdb.GraphDatabaseService#shutdown() . 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: DataImporterNorthwindTest.java    From neo4j-rdbms-import with GNU General Public License v3.0 5 votes vote down vote up
private static String importInfo() {
    GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(STORE_DIR);
    try (Transaction tx = db.beginTx()) {
        int nodes = IteratorUtil.count(db.getAllNodes());
        int rels = IteratorUtil.count(GlobalGraphOperations.at(db).getAllRelationships());
        return "Imported nodes " + nodes + " rels " + rels;
    } finally {
        db.shutdown();
    }
}
 
Example 2
Source File: DataImporterSakilaTest.java    From neo4j-rdbms-import with GNU General Public License v3.0 5 votes vote down vote up
private static String importInfo() {
    GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(STORE_DIR);

    try (Transaction tx = db.beginTx()) {
        int nodes = IteratorUtil.count(db.getAllNodes());
        int rels = IteratorUtil.count(GlobalGraphOperations.at(db).getAllRelationships());
        return "Imported nodes " + nodes + " rels " + rels;
    } finally {
        db.shutdown();
    }
}
 
Example 3
Source File: DataImporterEmployeeTest.java    From neo4j-rdbms-import with GNU General Public License v3.0 5 votes vote down vote up
private static String importInfo() {
    GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(STORE_DIR);

    try (Transaction tx = db.beginTx()) {
        int nodes = IteratorUtil.count(db.getAllNodes());
        int rels = IteratorUtil.count(GlobalGraphOperations.at(db).getAllRelationships());
        return "Imported nodes " + nodes + " rels " + rels;
    } finally {
        db.shutdown();
    }
}
 
Example 4
Source File: DataImporterTest.java    From neo4j-rdbms-import with GNU General Public License v3.0 5 votes vote down vote up
private static String assertImport() {
    GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(STORE_DIR);

    try (Transaction tx = db.beginTx()) {
        int nodes = IteratorUtil.count(db.getAllNodes());
        Assert.assertEquals(USERS, nodes);
        int rels = IteratorUtil.count(GlobalGraphOperations.at(db).getAllRelationships());
        Assert.assertEquals(FRIENDSHIPS, rels);
        return "Imported nodes " + nodes + " rels " + rels;
    } finally {
        db.shutdown();
    }
}
 
Example 5
Source File: LUBM.java    From neo4jena with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	GraphDatabaseService njgraph = new GraphDatabaseFactory().newEmbeddedDatabase(NEO_STORE);
	log.info("Connection created");
	LUBM.write(njgraph);
	LUBM.search(njgraph);
	njgraph.shutdown();
	log.info("Connection closed");
}
 
Example 6
Source File: Wine.java    From neo4jena with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	GraphDatabaseService njgraph = new GraphDatabaseFactory().newEmbeddedDatabase(NEO_STORE);
	
	Wine.write(njgraph);
	Wine.search(njgraph);
	njgraph.shutdown();
}
 
Example 7
Source File: Course.java    From neo4jena with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
	GraphDatabaseService njgraph = new GraphDatabaseFactory().newEmbeddedDatabase(NEO_STORE);
	log.info("Connection created");
	Course.write(njgraph);
	Course.search(njgraph);
	njgraph.shutdown();
	log.info("Connection closed");
}
 
Example 8
Source File: ReachabilityIndexTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Test(expected = IllegalStateException.class)
public void testUncreatedIndex() {
  GraphDatabaseService testDb = new GraphDatabaseFactory().newEmbeddedDatabase(new File(path));
  ReachabilityIndex index = new ReachabilityIndex(testDb);
  index.canReach(a, b);
  testDb.shutdown();
}
 
Example 9
Source File: Neo4jHealthCheckTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Test
public void whenNoNodes_unhealty() throws Exception {
  GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
  Neo4jHealthCheck healthCheck = new Neo4jHealthCheck(graphDb);
  assertThat(healthCheck.check().isHealthy(), is(false));
  graphDb.shutdown();
}
 
Example 10
Source File: Neo4jHealthCheckTest.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Test
public void whenNodes_healty() throws Exception {
  GraphDatabaseService graphDb = new TestGraphDatabaseFactory().newImpermanentDatabase();
  Neo4jHealthCheck healthCheck = new Neo4jHealthCheck(graphDb);
  try (Transaction tx = graphDb.beginTx()) {
    graphDb.createNode();
    tx.success();
  }
  assertThat(healthCheck.check().isHealthy(), is(true));
  graphDb.shutdown();
}
 
Example 11
Source File: Neo4jSNAMain.java    From Neo4jSNA with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
       String zipFile = "data/cineasts_12k_movies_50k_actors_2.1.6.zip";
       String path = "data/cineasts_12k_movies_50k_actors.db/";

       try {
           FileUtils.deleteRecursively(new File(path));
           extractFolder(zipFile);
       } catch (Exception e) {
           e.printStackTrace();
           System.exit(1);
       }

       long nodeCount, relsCount;
	
	// Open a database instance
       GraphDatabaseService g = new GraphDatabaseFactory()
               .newEmbeddedDatabaseBuilder(path)
               .setConfig(GraphDatabaseSettings.allow_store_upgrade, "true")
               .newGraphDatabase();
       try (Transaction tx = g.beginTx() ) {
		nodeCount = IteratorUtil.count( GlobalGraphOperations.at(g).getAllNodes() );
		relsCount = IteratorUtil.count( GlobalGraphOperations.at(g).getAllRelationships() );
		tx.success();
	}
	
	System.out.println("Node count: "+nodeCount);
       System.out.println("Rel count: " + relsCount);

       // Declare the GraphAlgoEngine on the database instance
	GraphAlgoEngine engine = new GraphAlgoEngine(g);
	if( args.length > 1 && args[1].equals("off") )
		engine.disableLogging();

       Louvain louvain = new Louvain(g);
       louvain.execute();
       LouvainResult result = louvain.getResult();
       for (int layer : result.layers()) {
           System.out.println("Layer " + layer + ": " + result.layer(layer).size() + " nodes");
       }

       LabelPropagation lp = new LabelPropagation();
       // Starts the algorithm on the given graph g
	engine.execute(lp);
	Long2LongMap communityMap = lp.getResult();
	long totCommunities = new LongOpenHashSet( communityMap.values() ).size();
       System.out.println("There are " + totCommunities + " communities according to Label Propagation");

	DirectedModularity modularity = new DirectedModularity(g);
	engine.execute(modularity);
       System.out.println("The directed modularity of this network is " + modularity.getResult());

       UndirectedModularity umodularity = new UndirectedModularity(g);
	engine.execute(umodularity);
       System.out.println("The undirected modularity of this network is " + umodularity.getResult());

       engine.clean(lp); // Now you can clean Label propagation results

       TriangleCount tc = new TriangleCount();
	engine.execute(tc);
	Long2LongMap triangleCount = tc.getResult();
	Optional<Long> totalTriangles = triangleCount.values().stream().reduce( (x, y) -> x + y );
	System.out.println("There are "+totalTriangles.get()+" triangles");

	PageRank pr = new PageRank(g);
	engine.execute(pr);
	Long2DoubleMap ranks = pr.getResult();
	engine.clean(pr);
	Optional<Double> res = ranks.values().parallelStream().reduce( (x, y) -> x + y );
	System.out.println("Check PageRank sum is 1.0: "+ res.get());

	ConnectedComponents cc = new ConnectedComponents();
	engine.execute(cc);
	Long2LongMap components = cc.getResult();
	engine.clean(cc);
	int totalComponents = new LongOpenHashSet( components.values() ).size();
	System.out.println("There are "+ totalComponents+ " different connected components");
	
	StronglyConnectedComponents scc = new StronglyConnectedComponents();
	engine.execute(scc);
	components = scc.getResult();
	engine.clean(scc);
	totalComponents = new LongOpenHashSet( components.values() ).size();
	System.out.println("There are "+ totalComponents+ " different strongly connected components");
	
	// Don't forget to shutdown the database
	g.shutdown();
}
 
Example 12
Source File: ReachabilityIndexTest.java    From SciGraph with Apache License 2.0 4 votes vote down vote up
@Test
public void testEmptyGraph() {
  GraphDatabaseService testDb = new GraphDatabaseFactory().newEmbeddedDatabase(new File(path));
  new ReachabilityIndex(testDb);
  testDb.shutdown();
}