From 32f2f30ac335f1105f65d21fc67315d90ad554d5 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 12 Aug 2015 12:36:04 +0200 Subject: [PATCH] =?utf8?q?Got=20more=20rid=20of=20abortProgramWithExceptio?= =?utf8?q?n()=20as=20this=20will=20end=20the=20application=20server=20Sign?= =?utf8?q?ed-off-by:Roland=20H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../application/PizzaServiceApplication.java | 41 ++++++++++++++----- .../bean/PizzaServiceCustomerBean.java | 2 +- .../product/PizzaProductDatabaseFrontend.java | 16 ++++---- 3 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java index 9161e1ab..c86e9328 100644 --- a/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java +++ b/src/java/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java @@ -16,7 +16,9 @@ */ package org.mxchange.pizzaapplication.application; +import java.io.IOException; import java.lang.reflect.Field; +import java.sql.SQLException; import java.text.MessageFormat; import java.util.Iterator; import java.util.Map; @@ -27,6 +29,7 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.mxchange.jcore.contact.Gender; +import org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException; import org.mxchange.pizzaapplication.BasePizzaServiceSystem; import org.mxchange.pizzaapplication.customer.Customer; import org.mxchange.pizzaapplication.customer.PizzaServiceCustomer; @@ -73,8 +76,12 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Not correct instance throw new ServletException("app is not set correctly"); //NOI18N } else { - // "service" is null, so initialize it - instance = new PizzaServiceApplication(context); + try { + // "service" is null, so initialize it + instance = new PizzaServiceApplication(context); + } catch (final UnsupportedDatabaseBackendException | SQLException ex) { + throw new ServletException(ex); + } // And set it here context.setAttribute("app", instance); //NOI18N @@ -114,7 +121,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * Constructor with servet configuration * @param context Servlet context */ - private PizzaServiceApplication (final ServletContext context) { + private PizzaServiceApplication (final ServletContext context) throws UnsupportedDatabaseBackendException, SQLException { // Call other constructor first this(); @@ -886,7 +893,7 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * Fills products list * @todo Very hard-coded stuff ... */ - private void fillProductsList () { + private void fillProductsList () throws UnsupportedDatabaseBackendException, SQLException { // Trace message this.getLogger().trace("CALLED!"); //NOI18N @@ -1084,11 +1091,16 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Init bundle this.initBundle(); - // Init properties - this.initProperties(); + try { + // Init properties + this.initProperties(); - // Fill products list - this.fillProductsList(); + // Fill products list + this.fillProductsList(); + } catch (final IOException | UnsupportedDatabaseBackendException | SQLException ex) { + // Abort here + this.abortProgramWithException(ex); + } // "Walk" over all products for (final Product product : this.getProducts()) { @@ -1110,11 +1122,18 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Gender is MALE now customer.setGender(Gender.MALE); - // Get iterator on all its fields - Iterator> it = customer.iterator(); + // Init iterator + Iterator> it = null; + + try { + // Get iterator on all its fields + it = customer.iterator(); + } catch (final NoSuchMethodException ex) { + this.abortProgramWithException(ex); + } // Output it - while (it.hasNext()) { + while ((it instanceof Iterator) && (it.hasNext())) { Map.Entry entry = it.next(); this.getLogger().debug(MessageFormat.format("entry {0}={1}", entry.getKey(), entry.getValue())); //NOI18N } diff --git a/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java b/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java index dcb94724..74f53fce 100644 --- a/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java +++ b/src/java/org/mxchange/pizzaapplication/customer/bean/PizzaServiceCustomerBean.java @@ -244,7 +244,7 @@ public class PizzaServiceCustomerBean extends BasePizzaServiceSystem implements } @Override - public Iterator> iterator () { + public Iterator> iterator () throws NoSuchMethodException { // Deligate to "hidden" object return this.getContact().iterator(); } diff --git a/src/java/org/mxchange/pizzaapplication/database/frontend/product/PizzaProductDatabaseFrontend.java b/src/java/org/mxchange/pizzaapplication/database/frontend/product/PizzaProductDatabaseFrontend.java index f0a63a78..4dacd358 100644 --- a/src/java/org/mxchange/pizzaapplication/database/frontend/product/PizzaProductDatabaseFrontend.java +++ b/src/java/org/mxchange/pizzaapplication/database/frontend/product/PizzaProductDatabaseFrontend.java @@ -16,6 +16,7 @@ */ package org.mxchange.pizzaapplication.database.frontend.product; +import java.io.IOException; import java.sql.SQLException; import java.text.MessageFormat; import java.util.Iterator; @@ -38,28 +39,25 @@ public class PizzaProductDatabaseFrontend extends BaseDatabaseFrontend implement /** * Default constrcutor + * @throws org.mxchange.jcore.exceptions.UnsupportedDatabaseBackendException If the configured backend is not supported + * @throws java.sql.SQLException If any SQL error occurs */ - public PizzaProductDatabaseFrontend () { + public PizzaProductDatabaseFrontend () throws UnsupportedDatabaseBackendException, SQLException { // Trace message this.getLogger().trace("CALLED!"); //NOI18N // Set "table" name this.setTableName("products"); //NOI18N - try { - // Initalize backend - this.initBackend(); - } catch (final UnsupportedDatabaseBackendException | SQLException ex) { - // Abort program - this.abortProgramWithException(ex); - } + // Initalize backend + this.initBackend(); } /** * Shuts down the database layer */ @Override - public void doShutdown () { + public void doShutdown () throws SQLException, IOException { // Trace message this.getLogger().trace("CALLED!"); //NOI18N -- 2.39.5