From 9876533158ebc08d60b9cf9d3e9f9a04f5c46cb7 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Fri, 4 Sep 2015 19:13:15 +0200 Subject: [PATCH] =?utf8?q?Even=20more=20cleanups=20Signed-off-by:Roland=20?= =?utf8?q?H=C3=A4der=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../application/PizzaServiceApplication.java | 102 ++++-------------- 1 file changed, 22 insertions(+), 80 deletions(-) diff --git a/src/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java b/src/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java index cb72f90..9100538 100644 --- a/src/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java +++ b/src/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java @@ -23,10 +23,6 @@ import java.text.MessageFormat; import java.util.Deque; import java.util.Iterator; import org.mxchange.jshop.category.Category; -import org.mxchange.jshop.database.frontend.category.CategoryDatabaseFrontend; -import org.mxchange.jshop.database.frontend.category.CategoryFrontend; -import org.mxchange.jshop.database.frontend.product.ProductDatabaseFrontend; -import org.mxchange.jshop.database.frontend.product.ProductFrontend; import org.mxchange.jshop.exceptions.CategoryTitleAlreadyUsedException; import org.mxchange.jshop.exceptions.ProductTitleAlreadyUsedException; import org.mxchange.jshop.item.AddableBasketItem; @@ -39,16 +35,6 @@ import org.mxchange.pizzaapplication.BasePizzaServiceSystem; * @author Roland Haeder */ public class PizzaServiceApplication extends BasePizzaServiceSystem implements PizzaApplication { - /** - * Database frontend for products - */ - private ProductFrontend productFrontend; - - /** - * Database frontend for categories - */ - private CategoryFrontend categoryFrontend; - /** * Default constructor */ @@ -81,15 +67,12 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P this.getLogger().trace("CALLED!"); //NOI18N // Is the bundle initialized? - if (!this.isBundledInitialized()) { + if (!isBundledInitialized()) { // Temporary initialize default bundle // TODO The enum Gender uses this this.initBundle(); } - // Init database frontends - this.initDatabaseFrontends(); - // Trace message this.getLogger().trace("EXIT!"); //NOI18N } @@ -134,11 +117,8 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P @Override @SuppressWarnings ("unchecked") public Iterator getAvailableProductsIterator () throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { - // categoryFrontend must be set - if (null == this.productFrontend) { - // Abort here - throw new NullPointerException("productFrontend is null"); //NOI18N - } + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N // Ask frontend for a list of products return (Iterator) this.productFrontend.getAvailableProductsIterator(); @@ -150,12 +130,6 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Trace message this.getLogger().trace("CALLED!"); //NOI18N - // categoryFrontend must be set - if (null == this.productFrontend) { - // Abort here - throw new NullPointerException("productFrontend is null"); //NOI18N - } - // Ask frontend for a list of products return (Iterator) this.productFrontend.getAllProductsIterator(); } @@ -166,33 +140,10 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Trace message this.getLogger().trace("CALLED!"); //NOI18N - // categoryFrontend must be set - if (null == this.categoryFrontend) { - // Abort here - throw new NullPointerException("categoryFrontend is null"); //NOI18N - } - // Ask frontend for a list of categories return (Iterator) this.categoryFrontend.getAllCategoriesIterator(); } - /** - * Initializes database frontends. - */ - private void initDatabaseFrontends () throws SQLException { - // Trace message - this.getLogger().trace("CALLED!"); //NOI18N - - // Product frontend - this.productFrontend = new ProductDatabaseFrontend(); - - // Category frontend - this.categoryFrontend = new CategoryDatabaseFrontend(); - - // Trace message - this.getLogger().trace("EXIT!"); //NOI18N - } - /** * Checks whether given category title is already used * @@ -200,11 +151,8 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @return Whether it has been found */ private boolean isCategoryTitleUsed(final Category category) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - // categoryFrontend must be set - if (null == this.categoryFrontend) { - // Abort here - throw new NullPointerException("categoryFrontend is null"); //NOI18N - } + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N // Delegate to frontend return this.categoryFrontend.isCategoryTitleUsed(category.getTitle()); @@ -216,11 +164,8 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P * @return Whether the product title has already been used */ private boolean isProductTitleUsed (final String title) throws IOException, SQLException, NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { - // categoryFrontend must be set - if (null == this.productFrontend) { - // Abort here - throw new NullPointerException("productFrontend is null"); //NOI18N - } + // Trace message + this.getLogger().trace("CALLED!"); //NOI18N // Delegate to frontend return this.productFrontend.isProductTitleUsed(title); @@ -247,13 +192,13 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Check all fields if (null == title) { // "title" not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", CategoryFrontend.COLUMN_TITLE)); //NOI18N + throw new IllegalArgumentException("category title is not set."); //NOI18N } else if (title.isEmpty()) { // Is left empty - throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", CategoryFrontend.COLUMN_TITLE)); //NOI18N + throw new IllegalArgumentException("category title is empty."); //NOI18N } else if ((parentId == null) || (parentId == 0)) { // "parent" is not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", parentId)); + throw new IllegalArgumentException(MessageFormat.format("category id is not valid: {0}", parentId)); } // Try to check if title is used already @@ -281,9 +226,9 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P } // Get title, price and category id - String title = product.getTitle(); - Float price = product.getPrice(); - Long categoryId = product.getCategoryId(); + String title = product.getTitle(); + Float price = product.getPrice(); + Long categoryId = product.getCategoryId(); Boolean available = product.getAvailable(); // Debug message @@ -292,19 +237,19 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P // Check all fields if (null == title) { // "title" not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_TITLE)); //NOI18N + throw new IllegalArgumentException("product title is not set."); //NOI18N } else if (title.isEmpty()) { // Is left empty - throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", ProductFrontend.COLUMN_TITLE)); //NOI18N + throw new IllegalArgumentException("product title is empty."); //NOI18N } else if (null == price) { // "price" not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_PRICE)); //NOI18N + throw new IllegalArgumentException("product price is not set."); //NOI18N } else if (null == categoryId) { - // "title" not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_CATEGORY)); //NOI18N + // "categoryId" not set + throw new IllegalArgumentException("product category id is not set."); //NOI18N } else if (null == available) { - // "title" not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_AVAILABLE)); //NOI18N + // "available" not set + throw new IllegalArgumentException("product availability is not set."); //NOI18N } // Try to check if title is used already @@ -404,10 +349,10 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P if (null == title) { // title is not set - throw new IllegalArgumentException(MessageFormat.format("{0} is not set.", ProductFrontend.COLUMN_TITLE)); //NOI18N + throw new IllegalArgumentException("product title is not set."); //NOI18N } else if (title.isEmpty()) { // Is left empty - throw new IllegalArgumentException(MessageFormat.format("{0} is empty.", ProductFrontend.COLUMN_TITLE)); //NOI18N + throw new IllegalArgumentException("product title is empty."); //NOI18N } // Default is not used @@ -443,9 +388,6 @@ public class PizzaServiceApplication extends BasePizzaServiceSystem implements P if (null == item) { // Abort here throw new NullPointerException("item is null"); //NOI18N - } else if (null == this.productFrontend) { - // Abort here - throw new NullPointerException("productFrontend is null"); //NOI18N } // Init product instance -- 2.39.5