From 19c537623f5d8bc07054027a898c58442e6cb612 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 20 May 2020 01:31:42 +0200 Subject: [PATCH] Product-only: - let's use createManaged() where possible to avoid some duplicate code. It may look a bit to much encapsulation or to fine-granulated, the createManaged() method contains some validation on the entity instance and that is a good reason to have it encapsulated away. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../category/PizzaAdminProductCategorySessionBean.java | 6 +++--- .../product/BasePizzaProductEnterpriseBean.java | 10 ++-------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/src/java/org/mxchange/jproduct/model/category/PizzaAdminProductCategorySessionBean.java b/src/java/org/mxchange/jproduct/model/category/PizzaAdminProductCategorySessionBean.java index 37b92ae..93614cb 100644 --- a/src/java/org/mxchange/jproduct/model/category/PizzaAdminProductCategorySessionBean.java +++ b/src/java/org/mxchange/jproduct/model/category/PizzaAdminProductCategorySessionBean.java @@ -130,13 +130,13 @@ public class PizzaAdminProductCategorySessionBean extends BasePizzaProductEnterp } // Update instance - final Category updatedCategory = this.mergeProductCategoryData(category); + final Category managedCategory = this.mergeProductCategoryData(category); // Trace message - this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateProductCategory: updatedCategory.categoryId={1} - EXIT!", this.getClass().getSimpleName(), updatedCategory.getCategoryId())); //NOI18N + this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateProductCategory: managedCategory.categoryId={1} - EXIT!", this.getClass().getSimpleName(), managedCategory.getCategoryId())); //NOI18N // Return it - return updatedCategory; + return managedCategory; } /** diff --git a/src/java/org/mxchange/pizzaapplication/enterprise/product/BasePizzaProductEnterpriseBean.java b/src/java/org/mxchange/pizzaapplication/enterprise/product/BasePizzaProductEnterpriseBean.java index f44dd4e..59f79d2 100644 --- a/src/java/org/mxchange/pizzaapplication/enterprise/product/BasePizzaProductEnterpriseBean.java +++ b/src/java/org/mxchange/pizzaapplication/enterprise/product/BasePizzaProductEnterpriseBean.java @@ -146,10 +146,7 @@ public abstract class BasePizzaProductEnterpriseBean extends BasePizzaEnterprise detachedProduct.setProductEntryUpdated(new Date()); // Get product from it and find it - final Product foundProduct = this.getEntityManager().find(detachedProduct.getClass(), detachedProduct.getProductId()); - - // Should be found - assert (foundProduct instanceof Product) : MessageFormat.format("Product with id {0} not found, but should be.", detachedProduct.getProductId()); //NOI18N + final Product foundProduct = this.createManaged(detachedProduct); // Debug message this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeProductData: foundProduct.productId={0}", foundProduct.getProductId())); //NOI18N @@ -194,10 +191,7 @@ public abstract class BasePizzaProductEnterpriseBean extends BasePizzaEnterprise detachedCategory.setCategoryEntryUpdated(new Date()); // Get category from it and find it - final Category foundCategory = this.getEntityManager().find(detachedCategory.getClass(), detachedCategory.getCategoryId()); - - // Should be found - assert (foundCategory instanceof Category) : MessageFormat.format("Category with id {0} not found, but should be.", detachedCategory.getCategoryId()); //NOI18N + final Category foundCategory = this.createManaged(detachedCategory); // Debug message this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeCategoryData: foundCategory.categoryId={0}", foundCategory.getCategoryId())); //NOI18N -- 2.39.5