import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
+import java.text.MessageFormat;
import java.util.Properties;
import java.util.ResourceBundle;
import org.apache.logging.log4j.LogManager;
* Prepares all properties, the file is written if it is not found
*/
private void initProperties () {
+ // Trace message
+ this.getLogger().trace("CALLED!"); //NOI18N
+
try {
// Try to read it
this.properties.load(new BufferedReader(new InputStreamReader(new FileInputStream(FrameworkInterface.PROPERTIES_CONFIG_FILE))));
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("{0} properties has been loaded.", this.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.
// 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
- this.properties.put("org.mxchange.addressbook.database.backendType", "base64csv");
+ this.properties.put("org.mxchange.addressbook.database.backendType", "base64csv"); //NOI18N
// For MySQL backend
- this.properties.put("org.mxchange.addressbook.database.mysql.host", "localhost");
- this.properties.put("org.mxchange.addressbook.database.mysql.login", "");
- this.properties.put("org.mxchange.addressbook.database.mysql.password", "");
+ this.properties.put("org.mxchange.addressbook.database.mysql.host", "localhost"); //NOI18N
+ this.properties.put("org.mxchange.addressbook.database.mysql.dbname", "test"); //NOI18N
+ this.properties.put("org.mxchange.addressbook.database.mysql.login", ""); //NOI18N
+ this.properties.put("org.mxchange.addressbook.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
- this.properties.store(new PrintWriter(FrameworkInterface.PROPERTIES_CONFIG_FILE), "This file is automatically generated. You may wish to alter it.");
+ this.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
}
/**
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
+import java.text.MessageFormat;
import java.util.Iterator;
import org.mxchange.addressbook.contact.Contact;
import org.mxchange.addressbook.database.backend.BaseDatabaseBackend;
// Validate driver
this.validateDriver("mysql"); //NOI18N
- // Now that the driver is there ...
+ // Now that the driver is there, set the table name
+ this.setTableName(tableName);
}
@Override
public void connectToDatabase () throws SQLException {
+ // Trace message
+ this.getLogger().trace("CALLED!");
+
// Generate connection string
- String connect = "jdbc:mysql://" + this.getProperty("org.mxchange.database.mysql.host") + "/" + this.getTableName();
+ String connect = String.format("jdbc:mysql://%s/%s", this.getProperty("org.mxchange.addressbook.database.mysql.host"), this.getProperty("org.mxchange.addressbook.database.mysql.dbname"));
+
+ // Debug message
+ this.getLogger().debug(MessageFormat.format("Attempting to connect to {0} ...", connect));
// Now get a connection instance back
- this.connection = DriverManager.getConnection(connect, this.getProperty("org.mxchange.database.mysql.login"), this.getProperty("org.mxchange.database.mysql.password"));
+ this.connection = DriverManager.getConnection(connect, this.getProperty("org.mxchange.addressbook.database.mysql.login"), this.getProperty("org.mxchange.addressbook.database.mysql.password"));
+
+ // Trace message
+ this.getLogger().trace("EXIT!");
}
@Override