Search in sources :

Example 1 with NeoStore

use of org.neo4j.kernel.impl.nioneo.store.NeoStore in project neo4j-mobile-android by neo4j-contrib.

the class StoreUpgrader method migrateToIsolatedDirectory.

private void migrateToIsolatedDirectory(String storageFileName, File upgradeDirectory) {
    if (upgradeDirectory.exists()) {
        try {
            FileUtils.deleteRecursively(upgradeDirectory);
        } catch (IOException e) {
            throw new UnableToUpgradeException(e);
        }
    }
    upgradeDirectory.mkdir();
    String upgradeFileName = new File(upgradeDirectory, NeoStore.DEFAULT_NAME).getPath();
    Map<Object, Object> upgradeConfig = new HashMap<Object, Object>(originalConfig);
    upgradeConfig.put("neo_store", upgradeFileName);
    NeoStore.createStore(upgradeFileName, upgradeConfig);
    NeoStore neoStore = new NeoStore(upgradeConfig);
    try {
        storeMigrator.migrate(new LegacyStore(storageFileName), neoStore);
    } catch (IOException e) {
        throw new UnableToUpgradeException(e);
    } finally {
        neoStore.close();
    }
}
Also used : HashMap(java.util.HashMap) NeoStore(org.neo4j.kernel.impl.nioneo.store.NeoStore) IOException(java.io.IOException) LegacyStore(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStore) File(java.io.File)

Example 2 with NeoStore

use of org.neo4j.kernel.impl.nioneo.store.NeoStore in project neo4j-mobile-android by neo4j-contrib.

the class StoreMigrationTool method run.

private void run(String legacyStoreDirectory, String targetStoreDirectory) throws IOException {
    LegacyStore legacyStore = new LegacyStore(new File(new File(legacyStoreDirectory), NeoStore.DEFAULT_NAME).getPath());
    HashMap config = new HashMap();
    config.put(IdGeneratorFactory.class, CommonFactories.defaultIdGeneratorFactory());
    config.put(FileSystemAbstraction.class, CommonFactories.defaultFileSystemAbstraction());
    File targetStoreDirectoryFile = new File(targetStoreDirectory);
    if (targetStoreDirectoryFile.exists()) {
        throw new IllegalStateException("Cannot migrate to a directory that already exists, please delete first and re-run");
    }
    boolean success = targetStoreDirectoryFile.mkdirs();
    if (!success) {
        throw new IllegalStateException("Failed to create directory");
    }
    File targetStoreFile = new File(targetStoreDirectory, NeoStore.DEFAULT_NAME);
    config.put("neo_store", targetStoreFile.getPath());
    NeoStore.createStore(targetStoreFile.getPath(), config);
    NeoStore neoStore = new NeoStore(config);
    long startTime = System.currentTimeMillis();
    new StoreMigrator(new VisibleMigrationProgressMonitor(System.out)).migrate(legacyStore, neoStore);
    long duration = System.currentTimeMillis() - startTime;
    System.out.printf("Migration completed in %d s%n", duration / 1000);
    neoStore.close();
    EmbeddedGraphDatabase database = new EmbeddedGraphDatabase(null, targetStoreDirectoryFile.getPath());
    database.shutdown();
}
Also used : EmbeddedGraphDatabase(org.neo4j.kernel.EmbeddedGraphDatabase) VisibleMigrationProgressMonitor(org.neo4j.kernel.impl.storemigration.monitoring.VisibleMigrationProgressMonitor) HashMap(java.util.HashMap) NeoStore(org.neo4j.kernel.impl.nioneo.store.NeoStore) LegacyStore(org.neo4j.kernel.impl.storemigration.legacystore.LegacyStore) File(java.io.File)

Aggregations

File (java.io.File)2 HashMap (java.util.HashMap)2 NeoStore (org.neo4j.kernel.impl.nioneo.store.NeoStore)2 LegacyStore (org.neo4j.kernel.impl.storemigration.legacystore.LegacyStore)2 IOException (java.io.IOException)1 EmbeddedGraphDatabase (org.neo4j.kernel.EmbeddedGraphDatabase)1 VisibleMigrationProgressMonitor (org.neo4j.kernel.impl.storemigration.monitoring.VisibleMigrationProgressMonitor)1