]> git.mxchange.org Git - pizzaservice-lib.git/commitdiff
Even more cleanups
authorRoland Haeder <roland@mxchange.org>
Fri, 4 Sep 2015 17:13:15 +0000 (19:13 +0200)
committerRoland Haeder <roland@mxchange.org>
Fri, 4 Sep 2015 17:13:15 +0000 (19:13 +0200)
Signed-off-by:Roland Häder <roland@mxchange.org>

src/org/mxchange/pizzaapplication/application/PizzaServiceApplication.java

index cb72f90bb14e8a79565d9bd0fc655709f6bae0b9..9100538aa5482a5931ea71cb2faccd3661ec5bb7 100644 (file)
@@ -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<Product> 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<Product>) 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<Product>) 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<Category>) 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