closing db on exit
This commit is contained in:
parent
e46f504f4c
commit
711e55203a
|
@ -18,6 +18,8 @@ bin
|
|||
*.ear
|
||||
/target
|
||||
/src/main/java/samples
|
||||
/blockchain
|
||||
/state
|
||||
|
||||
*.db
|
||||
*.xlsx
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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");
|
||||
|
|
Loading…
Reference in New Issue