diff --git a/.gitignore b/.gitignore index 2c88c818..f20fc196 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,8 @@ bin *.ear /target /src/main/java/samples +/blockchain +/state *.db *.xlsx diff --git a/ethereumj-core/src/main/java/org/ethereum/db/Database.java b/ethereumj-core/src/main/java/org/ethereum/db/Database.java index c138c261..ba8c0edf 100644 --- a/ethereumj-core/src/main/java/org/ethereum/db/Database.java +++ b/ethereumj-core/src/main/java/org/ethereum/db/Database.java @@ -30,10 +30,12 @@ public class Database { private static Logger logger = LoggerFactory.getLogger(Database.class); private DB db; + private String name; public Database(String name) { // Initialize Database + this.name = name; Options options = new Options(); options.createIfMissing(true); try { @@ -117,4 +119,13 @@ public class Database { return this.db; } + public void close(){ + try { + logger.info("Release DB: {}", name); + db.close(); + } catch (IOException e) { + logger.error("failed to find the db file on the close: {} ", name); + } + } + } \ No newline at end of file diff --git a/ethereumj-core/src/main/java/org/ethereum/gui/ToolBar.java b/ethereumj-core/src/main/java/org/ethereum/gui/ToolBar.java index c8719ad0..e8050884 100644 --- a/ethereumj-core/src/main/java/org/ethereum/gui/ToolBar.java +++ b/ethereumj-core/src/main/java/org/ethereum/gui/ToolBar.java @@ -1,5 +1,6 @@ package org.ethereum.gui; +import org.ethereum.db.Config; import org.ethereum.manager.MainData; import org.ethereum.util.Utils; import org.slf4j.Logger; @@ -10,6 +11,8 @@ import javax.swing.*; import java.awt.*; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; /** * www.ethereumJ.com @@ -68,6 +71,14 @@ public class ToolBar extends JFrame { setTitle("EthereumJ Studio"); setDefaultCloseOperation(EXIT_ON_CLOSE); + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + Config.CHAIN_DB.close(); + Config.STATE_DB.close(); + } + }); + this.setContentPane(cp); java.net.URL imageURL_1 = ClassLoader.getSystemResource("buttons/feedly.png");