import java.text.MessageFormat;
import java.util.Date;
import org.mxchange.jfinancials.enterprise.BaseFinancialsEnterpriseBean;
+import org.mxchange.jproduct.model.category.Categories;
import org.mxchange.jproduct.model.category.Category;
import org.mxchange.jproduct.model.product.Product;
import org.mxchange.jproduct.model.product.Products;
* <p>
* @return Managed product instance
*/
- protected Product mergeProductData (final Product detachedProduct) {
+ protected Product mergeGenericProductData (final Product detachedProduct) {
// Trace message
this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeProductData: detachedProduct={0} - CALLED!", detachedProduct)); //NOI18N
return managedProduct;
}
+ /**
+ * Merges given category's data
+ * <p>
+ * @param detachedCategory Category instance to merge
+ * <p>
+ * @return Managed category instance
+ */
+ protected Category mergeProductCategoryData (final Category detachedCategory) {
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeCategoryData: detachedCategory={0} - CALLED!", detachedCategory)); //NOI18N
+
+ // The category instance must be valid
+ if (null == detachedCategory) {
+ // Throw NPE again
+ throw new NullPointerException("detachedCategory is null"); //NOI18N
+ } else if (detachedCategory.getCategoryId() == null) {
+ // Throw NPE again
+ throw new NullPointerException("detachedCategory.categoryId is null"); //NOI18N //NOI18N
+ } else if (detachedCategory.getCategoryId() < 1) {
+ // Not valid
+ throw new IllegalStateException(MessageFormat.format("detachedCategory.categoryId={0} is not valid.", detachedCategory.getCategoryId())); //NOI18N
+ }
+
+ // Set updated timestamp
+ 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
+
+ // Debug message
+ this.getLoggerBeanLocal().logDebug(MessageFormat.format("mergeCategoryData: foundCategory.categoryId={0}", foundCategory.getCategoryId())); //NOI18N
+
+ // Copy all
+ Categories.copyCategoryData(detachedCategory, foundCategory);
+
+ // Merge category instance
+ final Category managedCategory = this.getEntityManager().merge(foundCategory);
+
+ // Trace message
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("mergeCategoryData: managedCategory={0} - EXIT!", managedCategory)); //NOI18N
+
+ // Return detached category
+ return managedCategory;
+ }
+
}
}
// Set created instance
- category.setCategoryCreated(new Date());
+ category.setCategoryEntryCreated(new Date());
// Persist it
this.getEntityManager().persist(category);
category.setParentCategory(managedCategory);
}
- // Set updated instance
- category.setCategoryUpdated(new Date());
-
- // Persist it
- this.getEntityManager().persist(category);
+ // Update instance
+ final Category updatedCategory = this.mergeProductCategoryData(category);
// Trace message
- this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateProductCategory: category.categoryId={1} - EXIT!", this.getClass().getSimpleName(), category.getCategoryId())); //NOI18N
+ this.getLoggerBeanLocal().logTrace(MessageFormat.format("{0}.updateProductCategory: updatedCategory.categoryId={1} - EXIT!", this.getClass().getSimpleName(), updatedCategory.getCategoryId())); //NOI18N
// Return it
- return category;
+ return updatedCategory;
}
/**