closing db on exit
This commit is contained in:
parent
e46f504f4c
commit
711e55203a
|
@ -18,6 +18,8 @@ bin
|
||||||
*.ear
|
*.ear
|
||||||
/target
|
/target
|
||||||
/src/main/java/samples
|
/src/main/java/samples
|
||||||
|
/blockchain
|
||||||
|
/state
|
||||||
|
|
||||||
*.db
|
*.db
|
||||||
*.xlsx
|
*.xlsx
|
||||||
|
|
|
@ -30,10 +30,12 @@ public class Database {
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(Database.class);
|
private static Logger logger = LoggerFactory.getLogger(Database.class);
|
||||||
private DB db;
|
private DB db;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
|
||||||
public Database(String name) {
|
public Database(String name) {
|
||||||
// Initialize Database
|
// Initialize Database
|
||||||
|
this.name = name;
|
||||||
Options options = new Options();
|
Options options = new Options();
|
||||||
options.createIfMissing(true);
|
options.createIfMissing(true);
|
||||||
try {
|
try {
|
||||||
|
@ -117,4 +119,13 @@ public class Database {
|
||||||
return this.db;
|
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;
|
package org.ethereum.gui;
|
||||||
|
|
||||||
|
import org.ethereum.db.Config;
|
||||||
import org.ethereum.manager.MainData;
|
import org.ethereum.manager.MainData;
|
||||||
import org.ethereum.util.Utils;
|
import org.ethereum.util.Utils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -10,6 +11,8 @@ import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ItemEvent;
|
import java.awt.event.ItemEvent;
|
||||||
import java.awt.event.ItemListener;
|
import java.awt.event.ItemListener;
|
||||||
|
import java.awt.event.WindowAdapter;
|
||||||
|
import java.awt.event.WindowEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* www.ethereumJ.com
|
* www.ethereumJ.com
|
||||||
|
@ -68,6 +71,14 @@ public class ToolBar extends JFrame {
|
||||||
setTitle("EthereumJ Studio");
|
setTitle("EthereumJ Studio");
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
|
|
||||||
|
addWindowListener(new WindowAdapter() {
|
||||||
|
@Override
|
||||||
|
public void windowClosing(WindowEvent e) {
|
||||||
|
Config.CHAIN_DB.close();
|
||||||
|
Config.STATE_DB.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.setContentPane(cp);
|
this.setContentPane(cp);
|
||||||
|
|
||||||
java.net.URL imageURL_1 = ClassLoader.getSystemResource("buttons/feedly.png");
|
java.net.URL imageURL_1 = ClassLoader.getSystemResource("buttons/feedly.png");
|
||||||
|
|
Loading…
Reference in New Issue