package name.matco.simcity;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import jakarta.ws.rs.ApplicationPath;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.glassfish.jersey.jackson.JacksonFeature;
import org.glassfish.jersey.server.ResourceConfig;
import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;

@ApplicationPath("api")
public class App extends ResourceConfig {

	private static final Logger LOGGER = LogManager.getLogger(App.class.getName());

	private static Properties PROPERTIES;
	private static GraphDatabaseService DATABASE;

	public App() {
		packages("name.matco.simcity.api");
		register(JacksonFeature.class);
	}

	public static GraphDatabaseService getDatabase() {
		if(DATABASE == null) {
			final String path = getAppProperties().getProperty("db.path");
			LOGGER.info("Open database with path {}", path);
			DATABASE = new GraphDatabaseFactory().newEmbeddedDatabase(new File(path));
			Runtime.getRuntime().addShutdownHook(new Thread() {
				@Override
				public void run() {
					DATABASE.shutdown();
				}
			});
		}
		return DATABASE;
	}

	public static Properties getAppProperties() {
		if(PROPERTIES == null) {
			PROPERTIES = new Properties();
			try(InputStream stream = App.class.getResourceAsStream("/config.properties")) {
				PROPERTIES.load(stream);
			} catch (final IOException e) {
				e.printStackTrace();
			}
		}
		return PROPERTIES;
	}
}

@@ -809,16 +809,147 @@
 lass);%0D%0A
+%09%09Runtime.getRuntime().addShutdownHook(new Thread() %7B%0D%0A%09%09%09@Override%0D%0A%09%09%09public void run() %7B%0D%0A%09%09%09%09shutdownDatabase();%0D%0A%09%09%09%7D%0D%0A%09%09%7D);%0D%0A
 %09%7D%0D%0A%0D%0A%09p
@@ -1230,105 +1230,80 @@
 %0D%0A%09%09
-%09Runtime.getRuntime().addShutdownHook(new Thread() %7B%0D%0A%09%09%09%09@Override%0D%0A%09%09%09%09public void run
+%7D%0D%0A%09%09return DATABASE;%0D%0A%09%7D%0D%0A%09%0D%0A%09public static void shutdownDatabase
 () %7B%0D%0A
-%09%09%09
 %09%09DA
@@ -1326,48 +1326,8 @@
 );%0D%0A
-%09%09%09%09%7D%0D%0A%09%09%09%7D);%0D%0A%09%09%7D%0D%0A%09%09return DATABASE;%0D%0A
 %09%7D%0D%0A

Rewrite database shutdown