KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > rentacar > centraloffice > database > CentralOfficeDatabase


1 package org.objectweb.rentacar.centraloffice.database;
2
3 import javax.servlet.http.HttpServlet JavaDoc;
4
5 import org.objectweb.rentacar.persistance.database.DatabaseException;
6 import org.objectweb.rentacar.persistance.database.DatabaseManager;
7 import org.objectweb.rentacar.util.PropertiesLoader;
8 import org.objectweb.rentacar.util.PropertyLoadingException;
9
10 /**
11  * This class is used to start and load data in the database
12  */

13 public class CentralOfficeDatabase extends HttpServlet JavaDoc {
14
15     private static final long serialVersionUID = 1L;
16
17     /**
18      * Database manager
19      */

20     private DatabaseManager databaseManager = new DatabaseManager();
21
22     /**
23      * Start the dabase and build the schema and fill it
24      */

25     public void init() {
26         try {
27             String JavaDoc host = PropertiesLoader.getProperty("database.properties", "database.host");
28             String JavaDoc port = PropertiesLoader.getProperty("database.properties", "database.port");
29             String JavaDoc dbName = PropertiesLoader.getProperty("database.properties", "database.dbname");
30             String JavaDoc dbPath = PropertiesLoader.getProperty("database.properties", "database.pathname");
31             String JavaDoc dataset = PropertiesLoader.getProperty("database.properties", "database.dataset");
32             String JavaDoc url = PropertiesLoader.getProperty("database.properties", "hibernate.connection.url");
33             String JavaDoc driver = PropertiesLoader.getProperty("database.properties", "hibernate.connection.driver_class");
34             String JavaDoc dialect = PropertiesLoader.getProperty("database.properties", "hibernate.dialect");
35             String JavaDoc user = PropertiesLoader.getProperty("database.properties", "hibernate.connection.username");
36             String JavaDoc pass = PropertiesLoader.getProperty("database.properties", "hibernate.connection.password");
37             databaseManager.runServer(host, port, dbName, dbPath);
38             databaseManager.buildDatabaseSchema(url, driver, dialect, user, pass);
39             databaseManager.fillDatabase(host, port, dbName, dataset);
40         }
41         catch (PropertyLoadingException e) {
42             e.printStackTrace();
43         }
44         catch (DatabaseException e) {
45             e.printStackTrace();
46         }
47     }
48
49     /**
50      * Destroy the database
51      */

52     public void destroy() {
53         databaseManager.shutdownServer();
54     }
55 }
56
Popular Tags