01: package auction.persistence;
02:
03: import java.sql.Connection;
04: import java.sql.DriverManager;
05: import java.sql.SQLException;
06: import net.xoetrope.optional.data.sql.DatabaseLifecycleListener;
07: import net.xoetrope.optional.data.sql.NamedConnectionManager;
08: import net.xoetrope.xui.XLifeCycleListener;
09: import net.xoetrope.xui.XProject;
10:
11: public class HsqldbLifeCycleListener implements XLifeCycleListener {
12: private Connection conn;
13:
14: public void initialize(XProject project) {
15: }
16:
17: public void ainitialize(XProject project) {
18: try {
19: Class.forName("org.hsqldb.jdbcDriver");
20: } catch (Exception ex) {
21: System.out
22: .println("ERROR: failed to load HSQLDB JDBC driver.");
23: ex.printStackTrace();
24: System.exit(0);
25: }
26:
27: try {
28: conn = DriverManager
29: .getConnection("jdbc:hsqldb:file:database/db");
30: } catch (SQLException ex) {
31: System.out
32: .println("ERROR: failed to establish a connection.");
33: ex.printStackTrace();
34: System.exit(0);
35: }
36: }
37:
38: public void shutdown() {
39:
40: }
41:
42: public void ashutdown() {
43: try {
44: conn.prepareCall("SHUTDOWN").execute();
45: } catch (Exception ex) {
46: System.out
47: .println("ERROR: failed to save database to a script file");
48: ex.printStackTrace();
49: System.exit(0);
50: }
51: }
52:
53: public boolean canClose(XProject xProject) {
54: return true;
55: }
56:
57: }
|