org.neo4j.graphdb.factory.GraphDatabaseFactory Java Examples

The following examples show how to use org.neo4j.graphdb.factory.GraphDatabaseFactory. 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: Neo4jGraphDatabase.java    From graphdb-benchmarks with Apache License 2.0 6 votes vote down vote up
@Override
public void createGraphForSingleLoad()
{
    neo4jGraph = new GraphDatabaseFactory().newEmbeddedDatabase(dbStorageDirectory.getAbsolutePath());
    try (final Transaction tx = beginUnforcedTransaction())
    {
        try
        {
            schema = neo4jGraph.schema();
            schema.indexFor(NODE_LABEL).on(NODE_ID).create();
            schema.indexFor(NODE_LABEL).on(COMMUNITY).create();
            schema.indexFor(NODE_LABEL).on(NODE_COMMUNITY).create();
            tx.success();
        }
        catch (Exception e)
        {
            tx.failure();
            throw new BenchmarkingException("unknown error", e);
        }
    }
}
 
Example #2
Source File: GraphOwlVisitorTransactionalGraphTest.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
@Override
protected GraphTransactionalImpl createInstance() throws Exception {
  GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(new File(path));
  Neo4jConfiguration config = new Neo4jConfiguration();
  config.getExactNodeProperties().addAll(newHashSet(
    NodeProperties.LABEL,
    Concept.SYNONYM,
    Concept.ABREVIATION,
    Concept.ACRONYM));
  config.getIndexedNodeProperties().addAll(newHashSet(
      NodeProperties.LABEL,
      Concept.CATEGORY, Concept.SYNONYM,
      Concept.ABREVIATION,
      Concept.ACRONYM));
  Neo4jModule.setupAutoIndexing(graphDb, config);
  IdMap idMap = new IdMap();
  RelationshipMap relationahipMap = new RelationshipMap();
  return new GraphTransactionalImpl(graphDb, idMap, relationahipMap);
}
 
Example #3
Source File: Neo4jGraphDatabase.java    From graphdb-benchmarks with Apache License 2.0 6 votes vote down vote up
@Override
public void open()
{
    neo4jGraph = new GraphDatabaseFactory().newEmbeddedDatabase(dbStorageDirectory.getAbsolutePath());
    try (final Transaction tx = beginUnforcedTransaction())
    {
        try
        {
            neo4jGraph.schema().awaitIndexesOnline(10l, TimeUnit.MINUTES);
            tx.success();
        }
        catch (Exception e)
        {
            tx.failure();
            throw new BenchmarkingException("unknown error", e);
        }
    }
}
 
Example #4
Source File: FileDatastoreFactory.java    From extended-objects with Apache License 2.0 6 votes vote down vote up
@Override
public EmbeddedNeo4jDatastore createGraphDatabaseService(URI uri, Properties properties) throws MalformedURLException {
    String path;
    try {
        path = URLDecoder.decode(uri.toURL().getPath(), "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new MalformedURLException(e.getMessage());
    }
    File storeDir = new File(path);
    storeDir.mkdirs();
    LOGGER.debug("Creating graph database service datastore for directory '{}'.", storeDir.getAbsolutePath());
    GraphDatabaseBuilder databaseBuilder = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(storeDir);
    Properties neo4jProperties = Neo4jPropertyHelper.getNeo4jProperties(properties);
    for (String name : neo4jProperties.stringPropertyNames()) {
        databaseBuilder.setConfig(name, neo4jProperties.getProperty(name));
    }
    GraphDatabaseService graphDatabaseService = databaseBuilder.newGraphDatabase();
    LOGGER.debug("Graph database service for directory '{}' created.", storeDir.getAbsolutePath());
    return new EmbeddedNeo4jDatastore(graphDatabaseService);
}
 
Example #5
Source File: BatchOwlLoaderIT.java    From SciGraph with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {
  OwlLoadConfiguration config = new OwlLoadConfiguration();
  Neo4jConfiguration neo4jConfig = new Neo4jConfiguration();
  neo4jConfig.setLocation(folder.getRoot().getAbsolutePath());
  config.setGraphConfiguration(neo4jConfig);
  OntologySetup ontSetup = new OntologySetup();
  ontSetup.setUrl("http://127.0.0.1:10000/main.owl");
  config.getOntologies().add(ontSetup);
  BatchOwlLoader.load(config);

  GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(folder.getRoot());
  graphDb.beginTx();
  GraphvizWriter writer = new GraphvizWriter();
  Walker walker = Walker.fullGraph(graphDb);
  writer.emit(new File("/tmp/test.dot"), walker);
}
 
Example #6
Source File: Neo4jHelper.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
public static GraphDatabaseBuilder getBuilder(final Neo4jDeployment deployment, final File graphDatabaseDirectory) {
	switch (deployment) {
		case EMBEDDED:
			return new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(graphDatabaseDirectory);
		case IN_MEMORY:
			return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder();
	}
	throw new IllegalStateException("Deployment mode '" + deployment + "' not supported.");
}
 
Example #7
Source File: GraphBatchImplIT.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
GraphDatabaseService getGraphDB() {
  graph.shutdown();
  graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(new File(path));
  graphDb.beginTx();
  nodeIndex = graphDb.index().getNodeAutoIndexer().getAutoIndex();
  return graphDb;
}
 
Example #8
Source File: Neo4jModule.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
GraphDatabaseService getGraphDatabaseService() throws IOException {
  try {
    GraphDatabaseBuilder graphDatabaseBuilder = new GraphDatabaseFactory()
        .newEmbeddedDatabaseBuilder(new File(configuration.getLocation()))
        .setConfig(configuration.getNeo4jConfig());
    if (readOnly) {
      graphDatabaseBuilder.setConfig(GraphDatabaseSettings.read_only, Settings.TRUE);
    }

    // #198 - do not keep transaction logs
    graphDatabaseBuilder.setConfig(GraphDatabaseSettings.keep_logical_logs, Settings.FALSE);

    final GraphDatabaseService graphDb = graphDatabaseBuilder.newGraphDatabase();
    Runtime.getRuntime().addShutdownHook(new Thread() {
      @Override
      public void run() {
        graphDb.shutdown();
      }
    });

    if (!readOnly) { // No need of auto-indexing in read-only mode
      setupAutoIndexing(graphDb, configuration);
    }

    setupSchemaIndexes(graphDb, configuration);

    return graphDb;
  } catch (Exception e) {
    if (Throwables.getRootCause(e).getMessage().contains("lock file")) {
      throw new IOException(format("The graph at \"%s\" is locked by another process",
          configuration.getLocation()));
    }
    throw e;
  }
}
 
Example #9
Source File: DatabaseManager.java    From paprika with GNU Affero General Public License v3.0 5 votes vote down vote up
public void start(){
    //graphDatabaseService = new GraphDatabaseFactory().newEmbeddedDatabase( DB_PATH );
    graphDatabaseService = new GraphDatabaseFactory().
            newEmbeddedDatabaseBuilder( DB_PATH ).
            newGraphDatabase();
    registerShutdownHook(graphDatabaseService);
}
 
Example #10
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 #11
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 #12
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 #13
Source File: Neo4jConfig.java    From Project with Apache License 2.0 5 votes vote down vote up
@Bean(destroyMethod="shutdown")
public GraphDatabaseService graphDatabaseService() {	
	/*
	 * 配置嵌入式数据库
	 * 在Neo4j中,嵌入式数据库不要与内存数据库相混淆。
	 * 在这里,“嵌入式”指的是数据库引擎与应用运行在同一个JVM中,作为应用的一部分,
	 * 而不是独立的服务器。数据依然会持久化到文件系统中(在本例中,也就是“/tmp/graphdb”中)。
	 */
	return new GraphDatabaseFactory()
			.newEmbeddedDatabase("/tmp/graphdb");
}
 
Example #14
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 #15
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 #16
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 #17
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 #18
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 #19
Source File: SnowGraphBuilder.java    From SnowGraph with Apache License 2.0 5 votes vote down vote up
private void run(){
    GraphDatabaseService graph=new GraphDatabaseFactory().newEmbeddedDatabase( new File(config.getGraphPath()) );
    for (int i=0;i<extractors.size();i++) {
        System.out.println(extractors.get(i).getClass().getName()+" started.");
        extractors.get(i).run(graph);
        extractors.set(i, new DefaultExtractor());
        System.gc();
    }
}
 
Example #20
Source File: EmbeddedDBAccess.java    From jcypher with Apache License 2.0 5 votes vote down vote up
@Override
	protected GraphDatabaseService createGraphDB() {
		// TODO the following applies to version 2.3.0 and above
//		File dbDir = new File(this.properties
//						.getProperty(DBProperties.DATABASE_DIR));
//		GraphDatabaseBuilder builder = new GraphDatabaseFactory()
//				.newEmbeddedDatabaseBuilder(dbDir);
		
		GraphDatabaseBuilder builder = new GraphDatabaseFactory()
				.newEmbeddedDatabaseBuilder(new File(this.properties
						.getProperty(DBProperties.DATABASE_DIR)));
		if (this.properties
				.getProperty(DBProperties.PAGECACHE_MEMORY) != null)
			builder.setConfig(
					GraphDatabaseSettings.pagecache_memory,
					DBProperties.PAGECACHE_MEMORY);
		if (this.properties.getProperty(DBProperties.STRING_BLOCK_SIZE) != null)
			builder.setConfig(GraphDatabaseSettings.string_block_size,
					DBProperties.ARRAY_BLOCK_SIZE);
		if (this.properties.getProperty(DBProperties.STRING_BLOCK_SIZE) != null)
			builder.setConfig(GraphDatabaseSettings.array_block_size,
					DBProperties.ARRAY_BLOCK_SIZE);
		
//		builder.setConfig(GraphDatabaseSettings.cypher_planner, "RULE");
		
		return builder.newGraphDatabase();
	}
 
Example #21
Source File: Neo4jLiveTest.java    From tutorials with MIT License 5 votes vote down vote up
@Before
public void setUp() {
    GraphDatabaseFactory graphDbFactory = new GraphDatabaseFactory();
    graphDb = graphDbFactory.newEmbeddedDatabase(new File("data/cars"));
}
 
Example #22
Source File: Neo4jAccessorConfigurer.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Bean(name = "factory", destroyMethod = "close")
public SessionFactory getFactory() throws Exception {
    File file = new File("neo4j");
    FileUtils.deleteQuietly(file);
    GraphDatabaseService database = new GraphDatabaseFactory().newEmbeddedDatabase(file);
    org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration.Builder().build();
    EmbeddedDriver driver = new EmbeddedDriver(database, configuration);
    SessionFactory factory = new SessionFactory(driver, "com.jstarcraft.core.storage.neo4j");
    return factory;
}
 
Example #23
Source File: ScanTypechefTest.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private static void initializeDatabase() {
    String directory = "./test/databases/ScanTypechefTest.db";
    BoltConnector bolt = new BoltConnector("0");
    graphDb = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(new File(directory))
            .setConfig(bolt.type, "BOLT").setConfig(bolt.enabled, "true")
            .setConfig(bolt.listen_address, "localhost:7689").newGraphDatabase();
    registerShutdownHook(graphDb);
    connector = DatabaseConnector.getInstance("bolt://localhost:7689");
}
 
Example #24
Source File: ScanJarTest.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
private static void initializeDatabase() {
    String directory = "./test/databases/ScanJarTest.db";
    BoltConnector bolt = new BoltConnector("0");
    graphDb = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(new File(directory))
            .setConfig(bolt.type, "BOLT").setConfig(bolt.enabled, "true")
            .setConfig(bolt.listen_address, "localhost:7689").newGraphDatabase();
    registerShutdownHook(graphDb);
    connector = DatabaseConnector.getInstance("bolt://localhost:7689");
}
 
Example #25
Source File: Bank.java    From Getaviz with Apache License 2.0 5 votes vote down vote up
public void setupDatabase(String directory) {
	graphDb = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(new File(directory))
			.setConfig(bolt.type, "BOLT").setConfig(bolt.enabled, "true")
			.setConfig(bolt.listen_address, "localhost:7689").newGraphDatabase();
	registerShutdownHook(graphDb);
	connector = DatabaseConnector.getInstance("bolt://localhost:7689");
	resetDatabase();
	runCypherScript("Bank.cypher");
}
 
Example #26
Source File: Neo4JDb.java    From knowledge-extraction with Apache License 2.0 4 votes vote down vote up
public Neo4JDb(String dbUrl) {
	graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbUrl);
	registerShutdownHook(graphDb);
}
 
Example #27
Source File: ReachabilityIndexPerfIT.java    From SciGraph with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
  graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(new File(graph.getAbsolutePath()));
  index = new ReachabilityIndex(graphDb);
}
 
Example #28
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();
}
 
Example #29
Source File: GraphBatchImplMultipleLoadTest.java    From SciGraph with Apache License 2.0 4 votes vote down vote up
GraphDatabaseService getGraphDB() {
  graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(new File(path));
  return graphDb;
}
 
Example #30
Source File: Neo4jIndexingTest.java    From SciGraph with Apache License 2.0 4 votes vote down vote up
GraphDatabaseService getGraphDb() {
  return new GraphDatabaseFactory().newEmbeddedDatabase(new File(path));
}