]> git.mxchange.org Git - addressbook-swing.git/commitdiff
Handled / throw some exceptions
authorRoland Haeder <roland@mxchange.org>
Fri, 31 Jul 2015 06:37:35 +0000 (08:37 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 31 Jul 2015 06:37:35 +0000 (08:37 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

Addressbook/src/org/mxchange/addressbook/database/backend/mysql/MySqlDatabaseBackend.java
Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java
Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactWrapper.java
Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java

index d863cb274230a8cdd72af3ae40271a828082530d..d95afb3e68c007ff837d791d2f2c5c8a643290c5 100644 (file)
@@ -129,6 +129,9 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas
 
        @Override
        public int getTotalCount () throws SQLException {
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("tableName={0} - CALLED!", this.getTableName())); //NOI18N
+
                // Nothing counted by default
                int count = 0;
 
@@ -143,10 +146,19 @@ public class MySqlDatabaseBackend extends BaseDatabaseBackend implements Databas
                        // Get integer from 'cnt' alias (see statement)
                        count = set.getInt("cnt"); //NOI18N
 
+                       // Debug message
+                       this.getLogger().debug(MessageFormat.format("count={0}", count)); //NOI18N
+
                        // Go back to beginning
                        set.beforeFirst();
+               } else {
+                       // Empty result
+                       this.getLogger().warn(MessageFormat.format("COUNT() query didn't return any result on table {0}.", this.getTableName())); //NOI18N
                }
 
+               // Trace message
+               this.getLogger().trace(MessageFormat.format("count={0} - EXIT!", count)); //NOI18N
+
                // Return result
                return count;
        }
index 2f4edd07e09a575c97e8748c48f85c111f96db9c..dc5cdb07c3fbfb3c818b0449799088f016ad18d2 100644 (file)
@@ -139,7 +139,7 @@ public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements Con
         * @return Total contact count
         */
        @Override
-       public int getContactsCount () {
+       public int getContactsCount () throws SQLException {
                // And deligate to backend
                return this.getBackend().getTotalCount(); //NOI18N
        }
@@ -209,7 +209,7 @@ public class ContactDatabaseFrontend extends BaseDatabaseFrontend implements Con
         * @return Whether own contact is found
         */
        @Override
-       public boolean isOwnContactFound () {
+       public boolean isOwnContactFound () throws SQLException {
                // Deligate this call to backend
                return this.getBackend().isRowFound(ContactDatabaseConstants.COLUMN_NAME_OWN_CONTACT, true);
        }
index fdf0cf30f2ec5faa2f9d7c9e4b95d19fb7c0f611..011f1a5d060315c815062292f70990d2445edfb9 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.addressbook.database.frontend.contact;
 
+import java.sql.SQLException;
 import org.mxchange.addressbook.contact.Contact;
 import org.mxchange.addressbook.database.frontend.DatabaseWrapper;
 import org.mxchange.addressbook.exceptions.BadTokenException;
@@ -44,8 +45,9 @@ public interface ContactWrapper extends DatabaseWrapper {
         * Some "getter" for total contacts count
         *
         * @return Total contacts count
+        * @throws java.sql.SQLException If any SQL error occurs
         */
-       public int getContactsCount ();
+       public int getContactsCount () throws SQLException;
 
        /**
         * Checks if given Contact is found
@@ -67,6 +69,7 @@ public interface ContactWrapper extends DatabaseWrapper {
         * Checks whether own contact is found
         * 
         * @return Whether own contact is found
+        * @throws java.sql.SQLException If any SQL error occurs
         */
-       public boolean isOwnContactFound ();
+       public boolean isOwnContactFound () throws SQLException;
 }
index 93ed1189b5f1f94236d659544c06be9913c753bf..66cd7ee6c7d2f139e6b953a559ec8bbe40d1a18a 100644 (file)
@@ -16,6 +16,7 @@
  */
 package org.mxchange.addressbook.manager.contact;
 
+import java.sql.SQLException;
 import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Iterator;
@@ -518,8 +519,16 @@ public class ContactManager extends BaseManager implements ManageableContact {
                // Trace message
                this.getLogger().trace("CALLED!"); //NOI18N
 
-               // Deligate this call to frontend
-               boolean isAdded = this.getContactDatabase().isOwnContactFound();
+               // Init variable
+               boolean isAdded = false;
+
+               try {
+                       // Deligate this call to frontend
+                       isAdded = this.getContactDatabase().isOwnContactFound();
+               } catch (final SQLException ex) {
+                       // Something bad happened
+                       this.abortProgramWithException(ex);
+               }
 
                // Trace message
                this.getLogger().trace(MessageFormat.format("isAdded={0} : EXIT!", isAdded)); //NOI18N
@@ -578,7 +587,18 @@ public class ContactManager extends BaseManager implements ManageableContact {
         */
        @Override
        public final int size () {
-               return this.getContactDatabase().getContactsCount();
+               // Init size
+               int size = -1;
+
+               try {
+                       size = this.getContactDatabase().getContactsCount();
+               } catch (final SQLException ex) {
+                       // Something happened
+                       this.abortProgramWithException(ex);
+               }
+
+               // Return amount
+               return size;
        }
 
        /**