@Override public void run() { close(); } });
private String createTemporaryFileStore() { try { Path path = Files.createTempDirectory("neo4jTmpEmbedded.db"); Path databasePath = Paths.get(path.toFile().getAbsolutePath() + "/database"); Files.createDirectories(databasePath); final File f = databasePath.toFile(); URI uri = f.toURI(); final String databaseUriValue = uri.toString(); logger.warn("Creating temporary file store: " + databaseUriValue); Runtime.getRuntime().addShutdownHook(new Thread(() -> { close(); try { logger.warn("Deleting temporary file store: " + databaseUriValue); deleteDirectory(path); } catch (IOException e) { throw new RuntimeException("Failed to delete temporary files in " + databaseUriValue, e); } })); return databaseUriValue; } catch (Exception e) { throw new RuntimeException(e); } }
private String createTemporaryFileStore() { try { Path path = Files.createTempDirectory("neo4jTmpEmbedded.db"); Path databasePath = Paths.get(path.toFile().getAbsolutePath() + "/database"); Files.createDirectories(databasePath); final File f = databasePath.toFile(); URI uri = f.toURI(); final String databaseUriValue = uri.toString(); logger.warn("Creating temporary file store: " + databaseUriValue); Runtime.getRuntime().addShutdownHook(new Thread(() -> { close(); try { logger.warn("Deleting temporary file store: " + databaseUriValue); deleteDirectory(path); } catch (IOException e) { throw new RuntimeException("Failed to delete temporary files in " + databaseUriValue, e); } })); return databaseUriValue; } catch (Exception e) { throw new RuntimeException(e); } }
@Override public synchronized void configure(DriverConfiguration config) { super.configure(config); close(); // force any existing graph database to shutdown try { String fileStoreUri = config.getURI(); // if no URI is set, create a temporary folder for the graph db // that will persist only for the duration of the JVM // This is effectively what the ImpermanentDatabase does. if (fileStoreUri == null) { fileStoreUri = createTemporaryEphemeralFileStore(); } File file = new File(new URI(fileStoreUri)); graphDatabaseService = new GraphDatabaseFactory().newEmbeddedDatabase(file); registerShutdownHook(); } catch (Exception e) { throw new RuntimeException(e); } }