From a358e2516bb341a77b8964df6b5ac27acc5e34e7 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Thu, 13 Aug 2015 15:31:05 +0200 Subject: [PATCH] =?utf8?q?Added=20more=20thrown=20exceptions=20+=20catched?= =?utf8?q?=20some=20+=20added=20getting=20of=20SQL=20warnings=20into=20Res?= =?utf8?q?ult=20instance=20Signed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../jcore/application/Application.java | 4 +-- src/org/mxchange/jcore/client/Client.java | 4 +-- .../jcore/client/gui/ClientFrame.java | 6 +++- .../frontend/BaseDatabaseFrontend.java | 23 ++++++++++++++ .../jcore/database/result/DatabaseResult.java | 30 +++++++++++++++++-- .../jcore/database/result/Result.java | 15 ++++++++++ .../mxchange/jcore/manager/Manageable.java | 4 +-- .../manager/database/ManageableDatabase.java | 6 +++- .../swing/contact/ContactTableModel.java | 16 ++++++++-- 9 files changed, 96 insertions(+), 12 deletions(-) diff --git a/src/org/mxchange/jcore/application/Application.java b/src/org/mxchange/jcore/application/Application.java index fdcc4d6..5a28624 100644 --- a/src/org/mxchange/jcore/application/Application.java +++ b/src/org/mxchange/jcore/application/Application.java @@ -38,8 +38,8 @@ public interface Application extends FrameworkInterface { /** * Shutdown the application - * @throws java.sql.SQLException If an SQL error occurs * @throws java.io.IOException If an IO error occurs + * @throws java.sql.SQLException If a SQL error occurs */ - public void doShutdown () throws SQLException, IOException; + public void doShutdown () throws IOException, SQLException; } diff --git a/src/org/mxchange/jcore/client/Client.java b/src/org/mxchange/jcore/client/Client.java index 1d3fd1e..5131773 100644 --- a/src/org/mxchange/jcore/client/Client.java +++ b/src/org/mxchange/jcore/client/Client.java @@ -30,10 +30,10 @@ public interface Client extends FrameworkInterface { /** * Shuts down the client and therefore whole application - * @throws java.sql.SQLException If an SQL error occurs * @throws java.io.IOException If an IO error occurs + * @throws java.sql.SQLException If a SQL error occurs */ - public void doShutdown () throws SQLException, IOException; + public void doShutdown () throws IOException, SQLException; /** * Displays a message to the user diff --git a/src/org/mxchange/jcore/client/gui/ClientFrame.java b/src/org/mxchange/jcore/client/gui/ClientFrame.java index 6f4f22c..d769cc9 100644 --- a/src/org/mxchange/jcore/client/gui/ClientFrame.java +++ b/src/org/mxchange/jcore/client/gui/ClientFrame.java @@ -16,9 +16,11 @@ */ package org.mxchange.jcore.client.gui; +import java.io.IOException; import org.mxchange.jcore.FrameworkInterface; import org.mxchange.jcore.client.Client; import org.mxchange.jcore.contact.Contact; +import org.mxchange.jcore.exceptions.BadTokenException; import org.mxchange.jcore.exceptions.FrameAlreadyInitializedException; /** @@ -50,8 +52,10 @@ public interface ClientFrame extends FrameworkInterface { * call this method. * * @param client Client instance + * @throws java.io.IOException If an IO error was found + * @throws org.mxchange.jcore.exceptions.BadTokenException If a bad token was found */ - public void setupFrame (final Client client); + public void setupFrame (final Client client) throws IOException, BadTokenException; /** * Initializes frame diff --git a/src/org/mxchange/jcore/database/frontend/BaseDatabaseFrontend.java b/src/org/mxchange/jcore/database/frontend/BaseDatabaseFrontend.java index 7e7a6a3..bf7971d 100644 --- a/src/org/mxchange/jcore/database/frontend/BaseDatabaseFrontend.java +++ b/src/org/mxchange/jcore/database/frontend/BaseDatabaseFrontend.java @@ -17,9 +17,13 @@ package org.mxchange.jcore.database.frontend; import java.lang.reflect.InvocationTargetException; +import java.sql.ResultSet; import java.sql.SQLException; import org.mxchange.jcore.BaseFrameworkSystem; import org.mxchange.jcore.database.backend.DatabaseBackend; +import org.mxchange.jcore.database.result.DatabaseResult; +import org.mxchange.jcore.database.result.Result; +import org.mxchange.jcore.database.storage.Storeable; import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; import org.mxchange.jcore.factory.database.backend.BackendFactory; @@ -64,4 +68,23 @@ public abstract class BaseDatabaseFrontend extends BaseFrameworkSystem implement // Trace message this.getLogger().trace("EXIT!"); //NOI18N } + + /** + * Gets a Result back from given ResultSet instance + * + * @param resultSet ResultSet instance from SQL driver + * @return A typorized Result instance + * @throws java.sql.SQLException If an SQL error occurs + */ + @Override + public Result getResultFromSet (final ResultSet resultSet) throws SQLException { + // Init result instance + Result result = new DatabaseResult(); + + // Attach all possible warnings + result.setWarnings(resultSet.getWarnings()); + + // And return it + return result; + } } diff --git a/src/org/mxchange/jcore/database/result/DatabaseResult.java b/src/org/mxchange/jcore/database/result/DatabaseResult.java index c8dca70..efe8748 100644 --- a/src/org/mxchange/jcore/database/result/DatabaseResult.java +++ b/src/org/mxchange/jcore/database/result/DatabaseResult.java @@ -16,6 +16,7 @@ */ package org.mxchange.jcore.database.result; +import java.sql.SQLWarning; import java.util.Iterator; import java.util.SortedSet; import java.util.TreeSet; @@ -32,6 +33,11 @@ public class DatabaseResult extends BaseFrameworkSystem implements Result result; + /** + * SQLWarning instance + */ + private SQLWarning warnings; + /** * Default constructor */ @@ -54,9 +60,24 @@ public class DatabaseResult extends BaseFrameworkSystem implements Result extends FrameworkInterface, Iterato */ public void add (final Storeable storeable); + /** + * Setter for warnings + * + * @param warnings SQLQarning from ResultSet instance + */ + public void setWarnings (final SQLWarning warnings); + + /** + * Getter for warnings + * + * @return SQLQarning from ResultSet instance + */ + public SQLWarning getWarnings (); + /** * Returns size of result * diff --git a/src/org/mxchange/jcore/manager/Manageable.java b/src/org/mxchange/jcore/manager/Manageable.java index f77ef2e..3aed987 100644 --- a/src/org/mxchange/jcore/manager/Manageable.java +++ b/src/org/mxchange/jcore/manager/Manageable.java @@ -29,8 +29,8 @@ public interface Manageable extends FrameworkInterface { /** * Shuts down this contact manager - * @throws java.sql.SQLException If any SQL error occurs - * @throws java.io.IOException If any IO error occurs + * @throws java.sql.SQLException If an SQL error occurs + * @throws java.io.IOException If an IO error occurs */ public void doShutdown () throws SQLException, IOException; } diff --git a/src/org/mxchange/jcore/manager/database/ManageableDatabase.java b/src/org/mxchange/jcore/manager/database/ManageableDatabase.java index 483b917..91fcb7a 100644 --- a/src/org/mxchange/jcore/manager/database/ManageableDatabase.java +++ b/src/org/mxchange/jcore/manager/database/ManageableDatabase.java @@ -16,6 +16,7 @@ */ package org.mxchange.jcore.manager.database; +import java.lang.reflect.InvocationTargetException; import org.mxchange.jcore.manager.Manageable; /** @@ -53,8 +54,11 @@ public interface ManageableDatabase extends Manageable { * @param rowIndex Row index * @param columnIndex Column index * @return Value from given row/column + * @throws java.lang.NoSuchMethodException If a non-existing method should be invoked + * @throws java.lang.IllegalAccessException If the method cannot be accessed + * @throws java.lang.reflect.InvocationTargetException Something other happened? */ - public Object getValueFromRowColumn (final int rowIndex, final int columnIndex); + public Object getValueFromRowColumn (final int rowIndex, final int columnIndex) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException; /** * Getter for column count diff --git a/src/org/mxchange/jcore/model/swing/contact/ContactTableModel.java b/src/org/mxchange/jcore/model/swing/contact/ContactTableModel.java index a24da4a..39ae1de 100644 --- a/src/org/mxchange/jcore/model/swing/contact/ContactTableModel.java +++ b/src/org/mxchange/jcore/model/swing/contact/ContactTableModel.java @@ -16,6 +16,7 @@ */ package org.mxchange.jcore.model.swing.contact; +import java.lang.reflect.InvocationTargetException; import java.text.MessageFormat; import javax.swing.table.TableModel; import org.mxchange.jcore.client.Client; @@ -86,8 +87,19 @@ public class ContactTableModel extends BaseModel implements TableModel { // Get manager ManageableDatabase manager = (ManageableDatabase) this.getClient().getManager(); - // Deligate this call to contact manager - return manager.getValueFromRowColumn(rowIndex, columnIndex); + // Init value + Object value = null; + + try { + // Deligate this call to contact manager + value = manager.getValueFromRowColumn(rowIndex, columnIndex); + } catch (final NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) { + // Abort here + this.abortProgramWithException(ex); + } + + // Return it + return value; } @Override -- 2.39.5