KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > webapp > WebApp


1 // $Id: WebApp.java,v 1.1 2002/07/18 09:08:03 per_nyfelt Exp $
2

3
4 package webapp;
5
6 import org.apache.log4j.Category;
7 import song.SongServices;
8 import org.ozoneDB.*;
9
10 /**
11  * Aplication singleton for the Web Application
12  *
13  * @version $Revision: 1.1 $ $Date: 2002/07/18 09:08:03 $
14  * @author James Stiefel
15  */

16
17 public class WebApp {
18
19     private static ExternalDatabase db = null;
20
21     /**
22      * log4j logger
23      */

24     private static Category logger = Category.getInstance(WebApp.class.getName());
25
26     /**
27      * Initialize the system - establish database connection, etc.
28      *
29      */

30     public static void init() {
31
32         //config log4j logger : log4j.properties will automatically load
33
//PropertyConfigurator.configure("log4j.properties");
34

35         try {
36             logger.info("init()");
37             //TODO: configuration for the database URL might be nice
38

39             // create and open a new database connection
40
db = ExternalDatabase.openDatabase( "ozonedb:remote://localhost:3333" );
41
42             if (db == null){
43                 logger.warn("init(): db == null -- something went wrong.");
44             }
45
46             logger.info( "Connected ..." );
47             db.reloadClasses();
48
49             SongServices.init(db);
50         } catch (Exception JavaDoc e){
51             logger.error("init() failed", e);
52         }
53     }
54
55     /**
56      * Close down the application -- disconnect from the database, etc.
57      *
58      */

59     public static void term() {
60         //close up the database
61

62         logger.info("term()");
63
64         SongServices.term();
65
66         try {
67             db.close();
68         } catch (Exception JavaDoc e){
69             e.printStackTrace();
70         }
71         db = null;
72     }
73
74     /**
75      * Get the database instance.
76      *
77      */

78     public static OzoneInterface database(){
79         return db;
80     }
81
82
83 }
84
85
86
Popular Tags