closing db on exit

This commit is contained in:
romanman 2014-05-31 00:42:23 +03:00
parent e46f504f4c
commit 711e55203a
3 changed files with 24 additions and 0 deletions

2
.gitignore vendored
View File

@ -18,6 +18,8 @@ bin
*.ear
/target
/src/main/java/samples
/blockchain
/state
*.db
*.xlsx

View File

@ -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);
}
}
}

View File

@ -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");