]> git.mxchange.org Git - jaddressbook-share-lib.git/commitdiff
Implemented doShutdown() for MySQL backend
authorRoland Haeder <roland@mxchange.org>
Wed, 29 Jul 2015 13:00:13 +0000 (15:00 +0200)
committerRoland Haeder <roland@mxchange.org>
Wed, 29 Jul 2015 13:00:13 +0000 (15:00 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

Addressbook/src/org/mxchange/addressbook/database/backend/mysql/MySqlDatabaseBackend.java

index 6a7b0094f60a3672f34b3a140ed6b9e767b2161c..900d5a8948d329f00f867e2fd3f6bcee89080242 100644 (file)
@@ -57,19 +57,26 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas
        @Override
        public void connectToDatabase () throws SQLException {
                // Trace message
-               this.getLogger().trace("CALLED!");
+               this.getLogger().trace("CALLED!"); //NOI18N
 
                // Generate connection string
-               String connect = String.format("jdbc:mysql://%s/%s", this.getProperty("org.mxchange.addressbook.database.mysql.host"), this.getProperty("org.mxchange.addressbook.database.mysql.dbname"));
+               String connect = String.format("jdbc:mysql://%s/%s", //NOI18N
+                               this.getProperty("org.mxchange.addressbook.database.mysql.host"), //NOI18N
+                               this.getProperty("org.mxchange.addressbook.database.mysql.dbname") //NOI18N
+               );
 
                // Debug message
-               this.getLogger().debug(MessageFormat.format("Attempting to connect to {0} ...", connect));
+               this.getLogger().debug(MessageFormat.format("Attempting to connect to {0} ...", connect)); //NOI18N
 
                // Now get a connection instance back
-               this.connection = DriverManager.getConnection(connect, this.getProperty("org.mxchange.addressbook.database.mysql.login"), this.getProperty("org.mxchange.addressbook.database.mysql.password"));
+               this.connection = DriverManager.getConnection(
+                               connect,
+                               this.getProperty("org.mxchange.addressbook.database.mysql.login"), //NOI18N
+                               this.getProperty("org.mxchange.addressbook.database.mysql.password") //NOI18N
+               );
 
                // Trace message
-               this.getLogger().trace("EXIT!");
+               this.getLogger().trace("EXIT!"); //NOI18N
        }
 
        @Override
@@ -79,7 +86,15 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas
 
        @Override
        public void doShutdown () {
-               throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
+               // This should not happen:
+               assert(this.connection == null) : "connection is null";
+
+               try {
+                       // Close down database connection
+                       this.connection.close();
+               } catch (final SQLException ex) {
+                       this.abortProgramWithException(ex);
+               }
        }
 
        @Override