- public final void logException (final Throwable exception) {
- // Log this exception
- this.getLogger().catching(exception);
- }
-
- /**
- * Prepares all properties, the file is written if it is not found
- */
- private void initProperties () {
- // Trace message
- this.getLogger().trace("CALLED!"); //NOI18N
-
- // Debug message
- this.getLogger().debug(MessageFormat.format("{0} properties are loaded already.", BaseFrameworkSystem.properties.size())); //NOI18N
-
- // Are some properties loaded?
- if (!BaseFrameworkSystem.properties.isEmpty()) {
- // Some are already loaded, abort here
- return;
- }
-
- try {
- // Try to read it
- BaseFrameworkSystem.properties.load(new BufferedReader(new InputStreamReader(new FileInputStream(FrameworkInterface.PROPERTIES_CONFIG_FILE))));
-
- // Debug message
- this.getLogger().debug(MessageFormat.format("{0} properties has been loaded.", BaseFrameworkSystem.properties.size())); //NOI18N
- } catch (final FileNotFoundException ex) {
- // Debug message
- this.getLogger().debug(MessageFormat.format("Properties file {0} not found: {1}", FrameworkInterface.PROPERTIES_CONFIG_FILE, ex)); //NOI18N
-
- /*
- * The file is not found which is normal for first run, so
- * initialize default values.
- */
- this.initPropertiesWithDefault();
-
- // Write file
- this.writePropertiesFile();
- } catch (final IOException ex) {
- // Something else didn't work
- this.abortProgramWithException(ex);
- }
-
- // Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
- }
-
- /**
- * Initializes properties with default values
- */
- private void initPropertiesWithDefault () {
- // Trace message
- this.getLogger().trace("CALLED!"); //NOI18N
-
- // Init default values:
- // Default database backend
- BaseFrameworkSystem.properties.put("org.mxchange.database.backendType", "base64csv"); //NOI18N
-
- // For MySQL backend
- BaseFrameworkSystem.properties.put("org.mxchange.database.mysql.host", "localhost"); //NOI18N
- BaseFrameworkSystem.properties.put("org.mxchange.database.mysql.dbname", "test"); //NOI18N
- BaseFrameworkSystem.properties.put("org.mxchange.database.mysql.login", ""); //NOI18N
- BaseFrameworkSystem.properties.put("org.mxchange.database.mysql.password", ""); //NOI18N
-
- // Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
- }
-
- /**
- * Writes the properties file to disk
- */
- private void writePropertiesFile () {
- // Trace message
- this.getLogger().trace("CALLED!"); //NOI18N
-
- try {
- // Write it
- BaseFrameworkSystem.properties.store(new PrintWriter(FrameworkInterface.PROPERTIES_CONFIG_FILE), "This file is automatically generated. You may wish to alter it."); //NOI18N
- } catch (final IOException ex) {
- this.abortProgramWithException(ex);
- }
-
- // Trace message
- this.getLogger().trace("EXIT!"); //NOI18N
- }
-
- /**
- * Converts a column name like "foo_bar" to an attribute name like "fooBar"
- *
- * @param columnName Column name to convert
- * @return Attribute name
- */
- protected String convertColumnNameToAttribute (final String columnName) {
- // Trace message
- this.getLogger().trace(MessageFormat.format("columnName={0} - CALLED!", columnName)); //NOI18N
-
- // First all lower case
- String lower = columnName.toLowerCase();
-
- // Then split on "_"
- StringTokenizer tokenizer = new StringTokenizer(lower, "_"); //NOI18N
-
- // Resulting string
- StringBuilder builder = new StringBuilder(tokenizer.countTokens());
-
- // Init counter
- int count = 0;
-
- // Walk through all
- while (tokenizer.hasMoreTokens()) {
- // Get token
- String token = tokenizer.nextToken();
-
- // Is later than first element?
- if (count > 0) {
- // Make first character upper-case
- char c = token.charAt(0);
- token = String.valueOf(c).toUpperCase() + token.substring(1);
- }
-
- // Add token
- builder.append(token);
-
- // Increment counter
- count++;
- }
-
- // Trace message
- this.getLogger().trace(MessageFormat.format("builder={0} - EXIT!", builder)); //NOI18N
-
- // Return result
- return builder.toString();