public static void main(String[] args) throws Exception {
    File output = null;
    String bundleName = null;
    if (args.length > 0) {
      bundleName = args[0];

      if (args.length > 1) {
        output = new File(args[1]);
      }

    } else {
      System.out.println("Usage: GenerateConfigDocumentation CONFIG_BUNDLE_CLASS [output file]");
      System.exit(0);
    }

    ConfigAsciiDocGenerator generator = new ConfigAsciiDocGenerator();
    String doc = generator.generateDocsFor(bundleName);

    if (output != null) {
      System.out.println(
          "Saving docs for '" + bundleName + "' in '" + output.getAbsolutePath() + "'.");
      FileUtils.writeToFile(output, doc, false);
    } else {
      System.out.println(doc);
    }
  }
예제 #2
0
 public static void removeDb(String path) {
   try {
     org.neo4j.kernel.impl.util.FileUtils.deleteRecursively(new File(path));
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
예제 #3
0
 @Test
 public void testLocateFileDb() throws Exception {
   FileUtils.deleteRecursively(new File("target/test-db"));
   final GraphDatabaseService db = databases.createDatabase(":file:target/test-db", null);
   assertTrue(db instanceof EmbeddedGraphDatabase);
   final GraphDatabaseService db2 = databases.createDatabase(":file:target/test-db", null);
   assertSame(db2, db);
 }
 @Override
 public void beforeTest() {
   try {
     FileUtils.deleteRecursively(new File(dir));
   } catch (IOException e) {
     throw new RuntimeException(e.getCause());
   }
   db = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(dir).newGraphDatabase();
 }
 @Override
 public void afterTest() {
   db.shutdown();
   try {
     FileUtils.deleteRecursively(new File(dir));
   } catch (IOException e) {
     throw new RuntimeException(e.getCause());
   }
 }
예제 #6
0
 @Test
 @Ignore("readonly mode in parallel is no longer supported")
 public void testLocateFileDbReadonly() throws Exception {
   FileUtils.deleteRecursively(new File("target/test-db-ro"));
   new EmbeddedGraphDatabase("target/test-db-ro");
   final Properties props = new Properties();
   props.setProperty("readonly", "true");
   final GraphDatabaseService db = databases.createDatabase(":file:target/test-db-ro", props);
   assertTrue(db instanceof EmbeddedReadOnlyGraphDatabase);
 }
예제 #7
0
 @Bean(destroyMethod = "shutdown")
 @Scope(SCOPE_PROTOTYPE)
 public GraphDatabaseService graphDatabaseService() {
   try {
     FileUtils.deleteRecursively(new File("target/test-db"));
     return new EmbeddedGraphDatabase("target/test-db");
   } catch (IOException e) {
     throw new RuntimeException(e);
   }
 }
 private String fixPath(String dir) {
   String store = FileUtils.fixSeparatorsInPath(dir);
   File directories = new File(dir);
   if (!directories.exists()) {
     if (!directories.mkdirs()) {
       throw new RuntimeException(
           "Unable to create directory path[" + storeDir + "] for Lucene index store.");
     }
   }
   return store;
 }
  private Configuration buildProperties() throws IOException {
    FileUtils.deleteRecursively(new File(HOME_DIRECTORY));
    new File(HOME_DIRECTORY + "/conf").mkdirs();

    Properties databaseProperties = new Properties();

    String databasePropertiesFileName = HOME_DIRECTORY + "/conf/neo4j.properties";
    databaseProperties.store(new FileWriter(databasePropertiesFileName), null);

    Configuration serverProperties = new MapBasedConfiguration();
    serverProperties.setProperty(Configurator.DATABASE_LOCATION_PROPERTY_KEY, STORE_DIRECTORY);
    serverProperties.setProperty(
        Configurator.DB_TUNING_PROPERTY_FILE_KEY, databasePropertiesFileName);

    return serverProperties;
  }
예제 #10
0
  /*
   * Clean up index and delete the whole data directory
   *
   * */
  @After
  public void afterEachTest() throws IOException {

    ExecutionResult result = executeQuery("start n=node:__types__(type='user') return n");
    final Set<Node> nodes = nodeSetFromResult(result, "n");

    doInTransaction(
        new TransactionCallback() {

          public void execute(GraphDatabaseAPI api) {
            for (Node node : nodes) api.index().forNodes("__types__").remove(node, "type");
          }
        });

    FileUtils.deleteRecursively(new File(NEO4J_SERVER.getServer().getDatabase().getLocation()));
  }
예제 #11
0
  BatchInserterImpl(
      String storeDir, FileSystemAbstraction fileSystem, Map<String, String> stringParams) {
    this.fileSystem = fileSystem;
    this.storeDir = new File(FileUtils.fixSeparatorsInPath(storeDir));

    rejectAutoUpgrade(stringParams);
    msgLog = StringLogger.loggerDirectory(fileSystem, this.storeDir);
    Map<String, String> params = getDefaultParams();
    params.put(GraphDatabaseSettings.use_memory_mapped_buffers.name(), Settings.FALSE);
    params.put(InternalAbstractGraphDatabase.Configuration.store_dir.name(), storeDir);
    params.putAll(stringParams);

    Config config = new Config(params, GraphDatabaseSettings.class);
    boolean dump = config.get(GraphDatabaseSettings.dump_configuration);
    this.idGeneratorFactory = new DefaultIdGeneratorFactory();

    StoreFactory sf =
        new StoreFactory(
            config,
            idGeneratorFactory,
            new DefaultWindowPoolFactory(),
            fileSystem,
            StringLogger.DEV_NULL,
            null);

    File store = fixPath(this.storeDir, sf);

    if (dump) {
      dumpConfiguration(params);
    }
    msgLog.logMessage(Thread.currentThread() + " Starting BatchInserter(" + this + ")");
    neoStore = sf.newNeoStore(store);
    if (!neoStore.isStoreOk()) {
      throw new IllegalStateException(storeDir + " store is not cleanly shutdown.");
    }
    neoStore.makeStoreOk();
    NameData[] indexes = getPropertyIndexStore().getNames(10000);
    indexHolder = new PropertyIndexHolder(indexes);
    NameData[] types = getRelationshipTypeStore().getNames(Integer.MAX_VALUE);
    typeHolder = new RelationshipTypeHolder(types);
    indexStore = new IndexStore(this.storeDir, fileSystem);
    indexStore.start();
  }
  private Properties buildProperties(boolean allowStoreUpgrade) throws IOException {
    FileUtils.deleteRecursively(new File(HOME_DIRECTORY));
    new File(HOME_DIRECTORY + "/conf").mkdirs();

    Properties databaseProperties = new Properties();
    if (allowStoreUpgrade) {
      databaseProperties.setProperty(GraphDatabaseSettings.allow_store_upgrade.name(), "true");
    }
    String databasePropertiesFileName = HOME_DIRECTORY + "/conf/neo4j.properties";
    databaseProperties.store(new FileWriter(databasePropertiesFileName), null);

    Properties serverProperties = new Properties();
    serverProperties.setProperty(Configurator.DATABASE_LOCATION_PROPERTY_KEY, STORE_DIRECTORY);
    serverProperties.setProperty(
        Configurator.DB_TUNING_PROPERTY_FILE_KEY, databasePropertiesFileName);
    String serverPropertiesFileName = HOME_DIRECTORY + "/conf/neo4j-server.properties";
    serverProperties.store(new FileWriter(serverPropertiesFileName), null);

    Properties systemProperties = new Properties();
    systemProperties.put(Configurator.NEO_SERVER_CONFIG_FILE_KEY, serverPropertiesFileName);
    return systemProperties;
  }
예제 #13
0
  /*
   * 1) Do a 2PC transaction, crash when both resource have been prepared and txlog
   *    says "mark as committing" for that tx.
   * 2) Do recovery and then crash again.
   * 3) Do recovery and see so that all data is in there.
   * Also do an incremental backup just to make sure that the logs have gotten the
   * right records injected.
   */
  @Test
  public void crashAfter2PCMarkAsCommittingThenCrashAgainAndRecover() throws Exception {
    String backupDirectory = "target/var/backup-db";
    FileUtils.deleteRecursively(new File(backupDirectory));
    OnlineBackup.from(InetAddress.getLocalHost().getHostAddress()).full(backupDirectory);
    for (BreakPoint bp : breakpoints(0)) bp.enable();
    runInThread(new WriteTransaction());
    afterWrite.await();
    startSubprocesses();
    runInThread(new Crash());
    afterCrash.await();
    startSubprocesses();
    OnlineBackup.from(InetAddress.getLocalHost().getHostAddress()).incremental(backupDirectory);
    run(new Verification());

    GraphDatabaseAPI db =
        (GraphDatabaseAPI) new GraphDatabaseFactory().newEmbeddedDatabase(backupDirectory);
    try {
      new Verification().run(db);
    } finally {
      db.shutdown();
    }
  }
예제 #14
0
 protected void deleteDatabase(boolean synchronous) {
   if (synchronous) {
     try {
       FileUtils.deleteRecursively(getNeoPath());
     } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   } else {
     new Thread(
             new Runnable() {
               @Override
               public void run() {
                 try {
                   FileUtils.deleteRecursively(getNeoPath());
                 } catch (IOException e) {
                   e.printStackTrace();
                 }
               }
             })
         .start();
   }
 }
예제 #15
0
 @Before
 public void cleanDirectory() throws Exception {
   FileUtils.deleteRecursively(new File(PATH));
 }
예제 #16
0
  BatchInserterImpl(
      String storeDir,
      FileSystemAbstraction fileSystem,
      Map<String, String> stringParams,
      Iterable<KernelExtensionFactory<?>> kernelExtensions) {
    life = new LifeSupport();
    this.fileSystem = fileSystem;
    this.storeDir = new File(FileUtils.fixSeparatorsInPath(storeDir));

    rejectAutoUpgrade(stringParams);
    msgLog = StringLogger.loggerDirectory(fileSystem, this.storeDir);
    logging = new SingleLoggingService(msgLog);
    Map<String, String> params = getDefaultParams();
    params.put(GraphDatabaseSettings.use_memory_mapped_buffers.name(), Settings.FALSE);
    params.put(InternalAbstractGraphDatabase.Configuration.store_dir.name(), storeDir);
    params.putAll(stringParams);

    storeLocker = new StoreLocker(fileSystem);
    storeLocker.checkLock(this.storeDir);

    config = new Config(params, GraphDatabaseSettings.class);
    boolean dump = config.get(GraphDatabaseSettings.dump_configuration);
    this.idGeneratorFactory = new DefaultIdGeneratorFactory();

    StoreFactory sf =
        new StoreFactory(
            config, idGeneratorFactory, new DefaultWindowPoolFactory(), fileSystem, msgLog, null);

    File store = fixPath(this.storeDir, sf);

    if (dump) {
      dumpConfiguration(params);
    }
    msgLog.logMessage(Thread.currentThread() + " Starting BatchInserter(" + this + ")");
    neoStore = sf.newNeoStore(store);
    if (!neoStore.isStoreOk()) {
      throw new IllegalStateException(storeDir + " store is not cleanly shutdown.");
    }
    neoStore.makeStoreOk();
    Token[] indexes = getPropertyKeyTokenStore().getTokens(10000);
    propertyKeyTokens = new BatchTokenHolder(indexes);
    labelTokens = new BatchTokenHolder(neoStore.getLabelTokenStore().getTokens(Integer.MAX_VALUE));
    Token[] types = getRelationshipTypeStore().getTokens(Integer.MAX_VALUE);
    relationshipTypeTokens = new BatchTokenHolder(types);
    indexStore = life.add(new IndexStore(this.storeDir, fileSystem));
    schemaCache = new SchemaCache(neoStore.getSchemaStore());

    KernelExtensions extensions =
        life.add(
            new KernelExtensions(
                kernelExtensions,
                config,
                new DependencyResolverImpl(),
                UnsatisfiedDependencyStrategies.ignore()));

    life.start();

    SchemaIndexProvider provider =
        extensions.resolveDependency(
            SchemaIndexProvider.class, SchemaIndexProvider.HIGHEST_PRIORITIZED_OR_NONE);
    schemaIndexProviders = new DefaultSchemaIndexProviderMap(provider);
    labelScanStore =
        life.add(
            extensions
                .resolveDependency(
                    LabelScanStoreProvider.class, LabelScanStoreProvider.HIGHEST_PRIORITIZED)
                .getLabelScanStore());
    actions = new BatchSchemaActions();
  }
예제 #17
0
  public static void main(String[] args) {
    String DB_PATH = "nanocora.db";

    System.out.print("Deleting old database ... ");
    try {
      FileUtils.deleteRecursively(new File(DB_PATH));
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
    System.out.println("done.");

    System.out.print("Creating new database ... ");
    GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
    registerShutdownHook(db);
    System.out.println("done.");

    try (Transaction tx = db.beginTx()) {
      System.out.print("Creating indexes ... ");
      Index<Node> classificationIndex = db.index().forNodes("classificationIndex");
      Index<Node> paperIndex = db.index().forNodes("paperIndex");
      Index<Node> authorIndex = db.index().forNodes("authorIndex");
      System.out.println("done.");

      System.out.print("Populating db ... ");
      Node[] classifications = new Node[2];
      classifications[0] = db.createNode();
      classifications[0].setProperty("name", "Databases");
      classificationIndex.add(classifications[0], "name", "Databases");
      classifications[1] = db.createNode();
      classifications[1].setProperty("name", "Relational");
      classificationIndex.add(classifications[1], "name", "Relational");
      classifications[1].createRelationshipTo(classifications[0], RelTypes.SUPER_CLASSIFICATION);

      Node[] papers = new Node[5];
      for (int i = 0; i < papers.length; i++) {
        Node p = db.createNode();
        p.setProperty("title", "p" + i);
        p.setProperty("year", 2001 + 2 * i);
        p.setProperty("url", "http://p" + i);
        paperIndex.add(p, "title", "p" + i);
        papers[i] = p;
      }

      Node[] authors = new Node[6];
      for (int i = 0; i < authors.length; i++) {
        Node a = db.createNode();
        a.setProperty("lastName", "a" + i);
        a.setProperty("initial", (char) ('d' + 2 * i));
        authorIndex.add(a, "lastName", "a" + i);
        authors[i] = a;
      }

      papers[0].createRelationshipTo(classifications[0], RelTypes.CLASSIFIED_AS);
      papers[1].createRelationshipTo(classifications[1], RelTypes.CLASSIFIED_AS);
      papers[2].createRelationshipTo(classifications[0], RelTypes.CLASSIFIED_AS);
      papers[3].createRelationshipTo(classifications[1], RelTypes.CLASSIFIED_AS);
      // paper 4 is unclassified

      papers[0].createRelationshipTo(authors[0], RelTypes.AUTHORED_BY);
      papers[0].createRelationshipTo(authors[1], RelTypes.AUTHORED_BY);
      papers[1].createRelationshipTo(authors[1], RelTypes.AUTHORED_BY);
      papers[1].createRelationshipTo(authors[2], RelTypes.AUTHORED_BY);
      papers[1].createRelationshipTo(authors[4], RelTypes.AUTHORED_BY);
      papers[2].createRelationshipTo(authors[3], RelTypes.AUTHORED_BY);
      // paper 3 has no author
      papers[4].createRelationshipTo(authors[5], RelTypes.AUTHORED_BY);

      papers[0].createRelationshipTo(papers[1], RelTypes.CITES);
      papers[0].createRelationshipTo(papers[2], RelTypes.CITES);
      papers[1].createRelationshipTo(papers[4], RelTypes.CITES);
      tx.success();
    } catch (Exception e) {
      e.printStackTrace();
    }
    System.out.println("done.");

    System.out.print("Shutting down ... ");
    db.shutdown();
    System.out.println("done.");
  }