01: // $Id: WebApp.java,v 1.1 2002/07/18 09:08:03 per_nyfelt Exp $
02:
03: package webapp;
04:
05: import java.lang.String;
06: import java.lang.Exception;
07: import javax.servlet.http.HttpSession;
08:
09: import org.apache.log4j.Category;
10: import org.apache.log4j.PropertyConfigurator;
11:
12: import SongServices;
13:
14: import org.ozoneDB.*;
15:
16: /**
17: * Aplication singleton for the Web Application
18: *
19: * @version $Revision: 1.1 $ $Date: 2002/07/18 09:08:03 $
20: * @author James Stiefel
21: */
22:
23: public class WebApp {
24:
25: private static ExternalDatabase db = null;
26:
27: /**
28: * log4j logger
29: */
30: private static Category logger = Category.getInstance(WebApp.class
31: .getName());
32:
33: /**
34: * Initialize the system - establish database connection, etc.
35: *
36: */
37: public static void init() {
38:
39: //config log4j logger : log4j.properties will automatically load
40: //PropertyConfigurator.configure("log4j.properties");
41:
42: try {
43: logger.info("init()");
44: //TODO: configuration for the database URL might be nice
45:
46: // create and open a new database connection
47: db = ExternalDatabase
48: .openDatabase("ozonedb:remote://localhost:3333");
49:
50: if (db == null) {
51: logger
52: .warn("init(): db == null -- something went wrong.");
53: }
54:
55: logger.info("Connected ...");
56: db.reloadClasses();
57:
58: SongServices.init(db);
59: } catch (Exception e) {
60: logger.error("init() failed", e);
61: }
62: }
63:
64: /**
65: * Close down the application -- disconnect from the database, etc.
66: *
67: */
68: public static void term() {
69: //close up the database
70:
71: logger.info("term()");
72:
73: SongServices.term();
74:
75: try {
76: db.close();
77: } catch (Exception e) {
78: e.printStackTrace();
79: }
80: db = null;
81: }
82:
83: /**
84: * Get the database instance.
85: *
86: */
87: public static OzoneInterface database() {
88: return db;
89: }
90:
91: }
|