org.neo4j.graphdb.factory.GraphDatabaseBuilder Java Examples

The following examples show how to use org.neo4j.graphdb.factory.GraphDatabaseBuilder. 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: InMemoryDBAccess.java    From jcypher with Apache License 2.0 6 votes vote down vote up
@Override
	protected GraphDatabaseService createGraphDB() {
		GraphDatabaseBuilder builder = new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder();
		if (this.properties != null) {
			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 #2
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 #3
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 #4
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 #5
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 #6
Source File: TestUtil.java    From ongdb-lab-apoc with Apache License 2.0 4 votes vote down vote up
public static GraphDatabaseBuilder apocGraphDatabaseBuilder() {
//        return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig(GraphDatabaseSettings.procedure_unrestricted, "apoc.*");
        return null;
    }
 
Example #7
Source File: TestUtil.java    From atlas with GNU General Public License v3.0 4 votes vote down vote up
public static GraphDatabaseBuilder apocGraphDatabaseBuilder() {
    return new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().setConfig(GraphDatabaseSettings.procedure_unrestricted,"apoc.*");
}