Java 类org.neo4j.graphdb.factory.GraphDatabaseBuilder 实例源码

项目:jcypher    文件:InMemoryDBAccess.java   
@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();
    }
项目:jooby    文件:Neo4jTest.java   
@SuppressWarnings("unchecked")
private Block dbFactory(final Path dbdir, final String dbkey) {
  return unit -> {
    GraphDatabaseService dbservice = unit.registerMock(GraphDatabaseService.class);
    // unit.mockStatic(RuntimeRegistry.class);
    // expect(RuntimeRegistry.getStartedRuntime(dbservice)).andReturn(null);

    LinkedBindingBuilder<GraphDatabaseService> lbb = unit.mock(LinkedBindingBuilder.class);
    lbb.toInstance(dbservice);

    Binder binder = unit.get(Binder.class);
    expect(binder.bind(Key.get(GraphDatabaseService.class))).andReturn(lbb);

    ServiceKey keys = unit.get(ServiceKey.class);
    keys.generate(eq(GraphDatabaseService.class), eq(dbkey), unit.capture(Consumer.class));

    GraphDatabaseBuilder dbbuilder = unit.registerMock(GraphDatabaseBuilder.class);
    expect(dbbuilder.newGraphDatabase()).andReturn(dbservice);

    GraphDatabaseFactory factory = unit.constructor(GraphDatabaseFactory.class)
        .build();
    expect(factory.setUserLogProvider(isA(Slf4jLogProvider.class))).andReturn(factory);
    expect(factory.newEmbeddedDatabaseBuilder(dbdir.toFile())).andReturn(dbbuilder);
  };
}
项目:checklistbank    文件:UsageDao.java   
/**
 * @param kvp
 * @param neoDir
 * @param neoFactory
 * @param registry
 */
private UsageDao(DB kvp, File neoDir, @Nullable File kvpStore, GraphDatabaseBuilder neoFactory, @Nullable MetricRegistry registry) {
  try {
    this.neoFactory = neoFactory;
    this.neoDir = neoDir;
    this.kvpStore = kvpStore;
    this.kvp = kvp;
    this.registry = registry;

    names = createKvpMap("names", ParsedName.class, 128);
    facts = createKvpMap("facts", UsageFacts.class, 128);
    verbatim = createKvpMap("verbatim", VerbatimNameUsage.class, 512);
    usages = createKvpMap("usages", NameUsage.class, 256);
    extensions = createKvpMap("extensions", UsageExtensions.class, 512);
    srcUsages = createKvpMap("srcUsages", SrcUsage.class, 256);
    nubUsages = createKvpMap("nubUsages", NubUsage.class, 256);

    openNeo();
  } catch (Exception e) {
    LOG.error("Failed to initialize a new DAO", e);
    close();
    throw e;
  }
}
项目:checklistbank    文件:UsageDao.java   
/**
 * A memory based backend which is erased after the JVM exits.
 * Useful for short lived tests. Neo4j always persists some files which are cleaned up afterwards automatically
 *
 * @param mappedMemory used for the neo4j db
 */
public static UsageDao temporaryDao(int mappedMemory, Integer shellPort) {
  LOG.debug("Create new in memory dao");
  DB kvp = DBMaker.memoryDB()
      .make();

  File storeDir = Files.createTempDir();
  NeoConfiguration cfg = new NeoConfiguration();
  cfg.mappedMemory = mappedMemory;
  if (shellPort != null) {
    cfg.shell = true;
    cfg.port = shellPort;
  }
  GraphDatabaseBuilder builder = cfg.newEmbeddedDb(storeDir, false);
  CleanupUtils.registerCleanupHook(storeDir);

  return new UsageDao(kvp, storeDir, null, builder, new MetricRegistry());
}
项目:checklistbank    文件:NeoConfiguration.java   
/**
 * Creates a new embedded db in the neoRepository folder.
 *
 * @param eraseExisting if true deletes previously existing db
 */
public GraphDatabaseBuilder newEmbeddedDb(File storeDir, boolean eraseExisting) {
  if (eraseExisting && storeDir.exists()) {
    // erase previous db
    LOG.debug("Removing previous neo4j database from {}", storeDir.getAbsolutePath());
    FileUtils.deleteQuietly(storeDir);
  }
  GraphDatabaseBuilder builder = new GraphDatabaseFactory()
      .setUserLogProvider(new Slf4jLogProvider())
      .newEmbeddedDatabaseBuilder(storeDir)
      .setConfig(GraphDatabaseSettings.keep_logical_logs, "false")
      .setConfig(GraphDatabaseSettings.pagecache_memory, mappedMemory + "m");
  if (shell) {
    LOG.info("Enable neo4j shell on port " + port);
    builder.setConfig(ShellSettings.remote_shell_enabled, "true")
        .setConfig(ShellSettings.remote_shell_port, String.valueOf(port))
        // listen to all IPs, not localhost only
        .setConfig(ShellSettings.remote_shell_host, "0.0.0.0");
  }
  return builder;
}
项目:extended-objects    文件:FileDatastoreFactory.java   
@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());
    }
    GraphDatabaseBuilder databaseBuilder = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(new File(path));
    Properties neo4jProperties = Neo4jPropertyHelper.getNeo4jProperties(properties);
    for (String name : neo4jProperties.stringPropertyNames()) {
        databaseBuilder.setConfig(name, neo4jProperties.getProperty(name));
    }
    GraphDatabaseService graphDatabaseService = databaseBuilder.newGraphDatabase();
    return new EmbeddedNeo4jDatastore(graphDatabaseService);
}
项目:neo4j-lucene5-index    文件:TestLuceneBatchInsert.java   
private void switchToGraphDatabaseService( ConfigurationParameter... config )
{
    shutdownInserter();
    GraphDatabaseBuilder builder = new TestGraphDatabaseFactory().newEmbeddedDatabaseBuilder( storeDir );
    for ( ConfigurationParameter configurationParameter : config )
    {
        builder = builder.setConfig( configurationParameter.key, configurationParameter.value );
    }
    db = builder.newGraphDatabase();
}
项目:neo4j-lucene5-index    文件:AutoIndexerTest.java   
@Override
protected void configure( GraphDatabaseBuilder builder )
{
    super.configure( builder );
    builder.setConfig( GraphDatabaseSettings.relationship_keys_indexable, "Type" );
    builder.setConfig( GraphDatabaseSettings.relationship_auto_indexing, "true" );
}
项目:trainbenchmark    文件:Neo4jHelper.java   
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.");
}
项目:jcypher    文件:EmbeddedDBAccess.java   
@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();
    }
项目:checklistbank    文件:UsageDao.java   
/**
 * A backend that is stored in files inside the configured neo directory.
 *
 * @param eraseExisting if true erases any previous data files
 */
public static UsageDao persistentDao(NeoConfiguration cfg, UUID datasetKey, MetricRegistry registry, boolean eraseExisting) {
  DB kvp = null;
  try {
    final File kvpF = cfg.kvp(datasetKey);
    final File storeDir = cfg.neoDir(datasetKey);
    if (eraseExisting) {
      LOG.debug("Remove existing data store");
      if (kvpF.exists()) {
        kvpF.delete();
      }
    }
    FileUtils.forceMkdir(kvpF.getParentFile());
    LOG.debug("Use KVP store {}", kvpF.getAbsolutePath());
    kvp = DBMaker.fileDB(kvpF)
        .fileMmapEnableIfSupported()
        .make();
    GraphDatabaseBuilder builder = cfg.newEmbeddedDb(storeDir, eraseExisting);
    return new UsageDao(kvp, storeDir, kvpF, builder, registry);

  } catch (Exception e) {
    if (kvp != null && !kvp.isClosed()) {
      kvp.close();
    }
    throw new IllegalStateException("Failed to init persistent DAO for " + datasetKey, e);
  }
}
项目:SciGraph    文件:Neo4jModule.java   
@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);
    }
    if (enableGuard) {
      graphDatabaseBuilder.setConfig(GraphDatabaseSettings.execution_guard_enabled,
          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;
  }
}
项目:mod-neo4j-persistor    文件:Neo4jEmbedded.java   
public Neo4jEmbedded(JsonObject config, Logger logger) {
    GraphDatabaseBuilder gdbb = new GraphDatabaseFactory()
    .newEmbeddedDatabaseBuilder(config.getString("datastore-path"));
    JsonObject neo4jConfig = config.getObject("neo4j");
    if (neo4jConfig != null) {
        gdbb.setConfig(GraphDatabaseSettings.node_keys_indexable,
                neo4jConfig.getString("node_keys_indexable"));
        gdbb.setConfig(GraphDatabaseSettings.node_auto_indexing,
                neo4jConfig.getString("node_auto_indexing", "false"));
        gdbb.setConfig(GraphDatabaseSettings.relationship_keys_indexable,
                neo4jConfig.getString("relationship_keys_indexable"));
        gdbb.setConfig(GraphDatabaseSettings.relationship_auto_indexing,
                neo4jConfig.getString("relationship_auto_indexing", "false"));
        gdbb.setConfig(GraphDatabaseSettings.allow_store_upgrade,
                neo4jConfig.getString("allow_store_upgrade", "true"));
    }
    gdb = gdbb.newGraphDatabase();
    registerShutdownHook(gdb);
    if (neo4jConfig != null) {
        JsonArray legacyIndexes = neo4jConfig.getArray("legacy-indexes");
        if (legacyIndexes != null && legacyIndexes.size() > 0) {
            try (Transaction tx = gdb.beginTx()) {
                for (Object o : legacyIndexes) {
                    if (!(o instanceof JsonObject)) continue;
                    JsonObject j = (JsonObject) o;
                    if ("node".equals(j.getString("for"))) {
                        gdb.index().forNodes(j.getString("name"), MapUtil.stringMap(
                                IndexManager.PROVIDER, "lucene", "type", j.getString("type", "exact")));
                    } else if ("relationship".equals(j.getString("for"))) {
                        gdb.index().forRelationships(j.getString("name"), MapUtil.stringMap(
                                IndexManager.PROVIDER, "lucene", "type", j.getString("type", "exact")));
                    }
                }
                tx.success();
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
    }
    engine = new ExecutionEngine(gdb);
    this.logger = logger;
}
项目:jooby    文件:Neo4jTest.java   
@SuppressWarnings({"unchecked", "deprecation"})
@Test
public void embedded() throws Exception {
  Path dir = Paths.get("target", "des").toAbsolutePath();
  Path dbdir = dir.resolve("neo4jfs").toAbsolutePath();
  new MockUnit(Env.class, Config.class, Binder.class)
      .expect(hasPath("db.url", false))
      .expect(hasPath("db", true))
      .expect(confString("db", dbdir.toString()))
      .expect(hasPath("com.graphaware", false))
      .expect(hasPath("neo4j", true))
      .expect(confConf("neo4j",
          ConfigFactory.empty().withValue("unsupported.dbms.block_size.array_properties",
              ConfigValueFactory.fromAnyRef(120))))
      .expect(hasPath("db", false))
      .expect(hasPath("neo4j.db", false))
      .expect(props())
      .expect(setProp("database_dir", dbdir.toString()))
      .expect(putProp("unsupported.dbms.block_size.array_properties", 120))
      .expect(serviceKey())
      .expect(dbFactory(dbdir, "db"))
      .expect(embeddedAccess("db"))
      .expect(logdb(null, dbdir.toString()))
      .expect(onStop())
      .expect(unit -> {
        GraphDatabaseBuilder builder = unit.get(GraphDatabaseBuilder.class);
        expect(builder.setConfig("unsupported.dbms.block_size.array_properties", "120"))
            .andReturn(builder);
      })
      .run(unit -> {
            Neo4j neo4j = new Neo4j();
            neo4j.configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class));
          }, closeOnStop(),
          bind(GraphDatabaseService.class, 0),
          bind(IDBAccess.class, 1),
          unit -> {
            IDBAccess db = unit.get(IDBAccess.class);
            bind(db.getClass(), 2).run(unit);
          }, unit -> {
            unit.captured(BiConsumer.class).get(0)
                .accept("unsupported.dbms.block_size.array_properties", "120");
          });
}
项目:WiggleIndexer    文件:AfterAnalyze.java   
public AfterAnalyze(JavacTask task, GraphDatabaseBuilder graphDbBuilder, Map<String, String> cuProps) {
    this.graphDbBuilder = graphDbBuilder;
    this.task = task;
    this.cuProps = cuProps;
}
项目:timbuctoo    文件:TinkerPopGraphManager.java   
protected void initGraphDatabaseService() {
  if (databasePath == null) {
    databasePath = new File(configuration.getDatabasePath());
  }
  if (graphDatabase == null) {
    if (configuration.hasHaconfig()) {
      TinkerPopConfig.HaConfig haconfig = configuration.getHaconfig();
      LOG.info(
        "Launching HA mode. Server id is " +
        haconfig.getServerId() +
        " database is at " +
        databasePath.getAbsolutePath() +
        ". allow init cluster is " +
        haconfig.allowInitCluster()
      );
      final GraphDatabaseBuilder graphDatabaseBuilder =
        new HighlyAvailableGraphDatabaseFactory()
          .setUserLogProvider(new Slf4jLogProvider())
          .newEmbeddedDatabaseBuilder(databasePath)
          .setConfig(GraphDatabaseSettings.allow_store_upgrade, "true")

          .setConfig(ClusterSettings.allow_init_cluster, haconfig.allowInitCluster())
          .setConfig(ClusterSettings.server_id, haconfig.getServerId())
          .setConfig(ClusterSettings.initial_hosts, haconfig.getInitialHosts())
          .setConfig(ClusterSettings.cluster_server, haconfig.getIp() + ":5001")
          .setConfig(HaSettings.ha_server, haconfig.getIp() + ":6001")
          /*
           * Neo4j synchronizes the slave databases via pulls of the master data. By default this property is not
           * activated (set to 0s). So this property has to be set. An alternative is to set 'ha.tx_push_factor'.
           * Since a network connection might be temporarily down, a pull is safer then a push. The push_factor is
           * meant for ensuring data duplication so that a master can safely crash
           */
          .setConfig(HaSettings.pull_interval, haconfig.getPullInterval())
          .setConfig(HaSettings.tx_push_factor, haconfig.getPushFactor());
      if (configuration.getPageCacheMemory().length() > 0) {
        graphDatabaseBuilder.setConfig(GraphDatabaseSettings.pagecache_memory, configuration.getPageCacheMemory());
      }
      graphDatabase = graphDatabaseBuilder.newGraphDatabase();
    } else {
      LOG.info("Launching local non-ha mode. Database at " + databasePath.getAbsolutePath());
      graphDatabase = new GraphDatabaseFactory()
        .setUserLogProvider( new Slf4jLogProvider() )
        .newEmbeddedDatabaseBuilder(databasePath)
        .setConfig(GraphDatabaseSettings.allow_store_upgrade, "true")
        .newGraphDatabase();
    }
  }
}