1 package org.objectweb.rentacar.agency.database; 2 3 import javax.servlet.http.HttpServlet ; 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 13 public class AgencyDatabase extends HttpServlet { 14 15 private static final long serialVersionUID = 1L; 16 17 20 private DatabaseManager databaseManager = new DatabaseManager(); 21 22 25 public void init() { 26 try { 27 String host = PropertiesLoader.getProperty("database.properties", "database.host"); 28 String port = PropertiesLoader.getProperty("database.properties", "database.port"); 29 String dbName = PropertiesLoader.getProperty("database.properties", "database.dbname"); 30 String dbPath = PropertiesLoader.getProperty("database.properties", "database.pathname"); 31 String dataset = PropertiesLoader.getProperty("database.properties", "database.dataset"); 32 String url = PropertiesLoader.getProperty("database.properties", "hibernate.connection.url"); 33 String driver = PropertiesLoader.getProperty("database.properties", "hibernate.connection.driver_class"); 34 String dialect = PropertiesLoader.getProperty("database.properties", "hibernate.dialect"); 35 String user = PropertiesLoader.getProperty("database.properties", "hibernate.connection.username"); 36 String 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 52 public void destroy() { 53 databaseManager.shutdownServer(); 54 } 55 } 56 | Popular Tags |