From: Roland Haeder Date: Fri, 31 Jul 2015 06:37:35 +0000 (+0200) Subject: Handled / throw some exceptions X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2a18cd0b61e88043c3e6c3d4b653462cf1c81915;p=jfinancials-swing.git Handled / throw some exceptions Signed-off-by:Roland Häder --- diff --git a/Addressbook/src/org/mxchange/addressbook/database/backend/mysql/MySqlDatabaseBackend.java b/Addressbook/src/org/mxchange/addressbook/database/backend/mysql/MySqlDatabaseBackend.java index d863cb2..d95afb3 100644 --- a/Addressbook/src/org/mxchange/addressbook/database/backend/mysql/MySqlDatabaseBackend.java +++ b/Addressbook/src/org/mxchange/addressbook/database/backend/mysql/MySqlDatabaseBackend.java @@ -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; } diff --git a/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java index 2f4edd0..dc5cdb0 100644 --- a/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java +++ b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactDatabaseFrontend.java @@ -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); } diff --git a/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactWrapper.java b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactWrapper.java index fdf0cf3..011f1a5 100644 --- a/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactWrapper.java +++ b/Addressbook/src/org/mxchange/addressbook/database/frontend/contact/ContactWrapper.java @@ -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; } diff --git a/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java b/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java index 93ed118..66cd7ee 100644 --- a/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java +++ b/Addressbook/src/org/mxchange/addressbook/manager/contact/ContactManager.java @@ -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; } /**