/** * Starts up the database. This must be called before calling methods to get connection of execute * queries or updates. */ public void startup() { dbbindingLogger.debug("Begin to start up the database."); Properties prop = new Properties(); try { prop.load(new FileInputStream(dbpropfile)); try { dbType = DBType.MEMORY; // default value. dbType = DBType.valueOf(prop.getProperty("type")); } catch (IllegalArgumentException e) { dbbindingLogger.warn("Bad database type in the property file."); exceptionLogger.warn( "Here is an exception : ", new Exception("Bad database type in the property file.")); } catch (NullPointerException e) { dbbindingLogger.warn("Missing database type in the property file."); exceptionLogger.warn( "Here is an exception : ", new Exception("Missing database type in the property file.")); } database = prop.getProperty("database"); if (database == null) { dbbindingLogger.warn("Missing database key in the property file."); exceptionLogger.warn( "Here is an exception : ", new Exception("Missing database key in the property file.")); } jdbcDriver = prop.getProperty("jdbc.driver"); if (jdbcDriver == null) { dbbindingLogger.warn("Missing jdbcDriver key in the property file."); exceptionLogger.warn( "Here is an exception : ", new Exception("Missing jdbcDriver key in the property file.")); } jdbcURL = prop.getProperty("database.url"); if (jdbcURL == null) { dbbindingLogger.warn("Missing database URL key in the property file."); exceptionLogger.warn( "Here is an exception : ", new Exception("Missing database URL key in the property file.")); } dbHost = prop.getProperty("database.host"); if (dbHost == null) { dbbindingLogger.warn("Missing database host key in the property file."); exceptionLogger.warn( "Here is an exception : ", new Exception("Missing database host key in the property file.")); } dbPort = prop.getProperty("database.port"); if (dbPort == null) { dbbindingLogger.warn("Missing database port key in the property file."); exceptionLogger.warn( "Here is an exception : ", new Exception("Missing database port key in the property file.")); } dbName = prop.getProperty("database.name"); if (dbName == null) { dbbindingLogger.warn("Missing database name key in the property file."); exceptionLogger.warn( "Here is an exception : ", new Exception("Missing database name key in the property file.")); } username = prop.getProperty("username"); if (username == null) { dbbindingLogger.warn("Missing database username key in the property file."); exceptionLogger.warn( "Here is an exception : ", new Exception("Missing database username key in the property file.")); } password = prop.getProperty("password"); if (password == null) { dbbindingLogger.warn("Missing database password key in the property file."); exceptionLogger.warn( "Here is an exception : ", new Exception("Missing database password key in the property file.")); } if (dbbindingLogger.isDebugEnabled()) { dbbindingLogger.debug( "Parse: " + database + "," + jdbcDriver + "," + jdbcURL + dbHost + "," + dbPort + "," + dbName + "," + username + "," + password); } // Make connection to database and initialize the database. initDatabase(); // TODO: support prepared statement if needed } catch (IOException ei) { dbbindingLogger.error("Failed to start up the database, IOException: " + ei); exceptionLogger.error("Failed to start up the database, IOException: " + ei); } }