From: Roland Haeder Date: Thu, 24 Sep 2015 13:11:09 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e8f0175feb8e5dd1d5ba09054400f6df6b2f2804;p=jshop-core.git Continued: - auto-reformatted many files - got rid of some superflous classes - updated jar Signed-off-by:Roland Häder --- diff --git a/lib/jcore.jar b/lib/jcore.jar index 57dc0a0..c0bdbee 100644 Binary files a/lib/jcore.jar and b/lib/jcore.jar differ diff --git a/lib/jcoreee.jar b/lib/jcoreee.jar index 884b0d9..d550fe0 100644 Binary files a/lib/jcoreee.jar and b/lib/jcoreee.jar differ diff --git a/src/org/mxchange/jcore/model/contact/CustomerContact.java b/src/org/mxchange/jcore/model/contact/CustomerContact.java deleted file mode 100644 index 8f02c12..0000000 --- a/src/org/mxchange/jcore/model/contact/CustomerContact.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jcore.model.contact; - -/** - * Customer contact class - * - * @author Roland Haeder - */ -public class CustomerContact extends BaseContact { - - /** - * Serial number - */ - private static final long serialVersionUID = 47_895_786_328_781L; -} diff --git a/src/org/mxchange/jshopcore/exceptions/BasketItemAlreadyAddedException.java b/src/org/mxchange/jshopcore/exceptions/BasketItemAlreadyAddedException.java index ca4cbeb..053d7fb 100644 --- a/src/org/mxchange/jshopcore/exceptions/BasketItemAlreadyAddedException.java +++ b/src/org/mxchange/jshopcore/exceptions/BasketItemAlreadyAddedException.java @@ -20,11 +20,13 @@ import java.text.MessageFormat; import org.mxchange.jshopcore.model.basket.AddableBasketItem; /** - * An exception thrown when the given item is already added to the basketController. + * An exception thrown when the given item is already added to the + * basketController. * * @author Roland Haeder */ public class BasketItemAlreadyAddedException extends Exception { + /** * Serial number */ @@ -36,7 +38,7 @@ public class BasketItemAlreadyAddedException extends Exception { * @param Any item that is or extends the interface * @param item An instance of a T item */ - public BasketItemAlreadyAddedException (final T item) { + public BasketItemAlreadyAddedException (final T item) { // Create message and pass it along super(MessageFormat.format("Item {0} has already been added. Did you miss to call isAdded()?", item)); } diff --git a/src/org/mxchange/jshopcore/exceptions/CannotAddCategoryException.java b/src/org/mxchange/jshopcore/exceptions/CannotAddCategoryException.java index 1322005..45247a4 100644 --- a/src/org/mxchange/jshopcore/exceptions/CannotAddCategoryException.java +++ b/src/org/mxchange/jshopcore/exceptions/CannotAddCategoryException.java @@ -23,6 +23,7 @@ package org.mxchange.jshopcore.exceptions; * @author Roland Haeder */ public class CannotAddCategoryException extends Exception { + /** * Serial number */ diff --git a/src/org/mxchange/jshopcore/exceptions/CannotAddProductException.java b/src/org/mxchange/jshopcore/exceptions/CannotAddProductException.java index feef839..7dd1acc 100644 --- a/src/org/mxchange/jshopcore/exceptions/CannotAddProductException.java +++ b/src/org/mxchange/jshopcore/exceptions/CannotAddProductException.java @@ -23,6 +23,7 @@ package org.mxchange.jshopcore.exceptions; * @author Roland Haeder */ public class CannotAddProductException extends Exception { + /** * Serial number */ diff --git a/src/org/mxchange/jshopcore/exceptions/CategoryTitleAlreadyUsedException.java b/src/org/mxchange/jshopcore/exceptions/CategoryTitleAlreadyUsedException.java index 1718f01..e9a1230 100644 --- a/src/org/mxchange/jshopcore/exceptions/CategoryTitleAlreadyUsedException.java +++ b/src/org/mxchange/jshopcore/exceptions/CategoryTitleAlreadyUsedException.java @@ -21,10 +21,11 @@ import org.mxchange.jshopcore.model.category.Category; /** * An exception thrown when the given title is already used - * + * * @author Roland Haeder */ public class CategoryTitleAlreadyUsedException extends Exception { + /** * Serial number */ diff --git a/src/org/mxchange/jshopcore/exceptions/CustomerAlreadyRegisteredException.java b/src/org/mxchange/jshopcore/exceptions/CustomerAlreadyRegisteredException.java index eb93d49..f095b5b 100644 --- a/src/org/mxchange/jshopcore/exceptions/CustomerAlreadyRegisteredException.java +++ b/src/org/mxchange/jshopcore/exceptions/CustomerAlreadyRegisteredException.java @@ -25,6 +25,7 @@ import org.mxchange.jshopcore.model.customer.Customer; * @author Roland Haeder */ public class CustomerAlreadyRegisteredException extends Exception { + /** * Serial number */ diff --git a/src/org/mxchange/jshopcore/exceptions/ProductTitleAlreadyUsedException.java b/src/org/mxchange/jshopcore/exceptions/ProductTitleAlreadyUsedException.java index dffa4b7..278e681 100644 --- a/src/org/mxchange/jshopcore/exceptions/ProductTitleAlreadyUsedException.java +++ b/src/org/mxchange/jshopcore/exceptions/ProductTitleAlreadyUsedException.java @@ -21,10 +21,11 @@ import org.mxchange.jshopcore.model.product.Product; /** * An exception thrown when the given title is already used - * + * * @author Roland Haeder */ public class ProductTitleAlreadyUsedException extends Exception { + /** * Serial number */ diff --git a/src/org/mxchange/jshopcore/exceptions/QueryNotExecutedException.java b/src/org/mxchange/jshopcore/exceptions/QueryNotExecutedException.java deleted file mode 100644 index a92211e..0000000 --- a/src/org/mxchange/jshopcore/exceptions/QueryNotExecutedException.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jshopcore.exceptions; - -import java.sql.SQLWarning; -import java.text.MessageFormat; - -/** - * This exception is thrown when a query could not be executed - * - * @author Roland Haeder - * @deprecated No longer used - */ -@Deprecated -public class QueryNotExecutedException extends Exception { - /** - * Serial number - */ - private static final long serialVersionUID = 97_548_375_847_581L; - - /** - * Prepares exception with given sql warnings - * - * @param warnings SQL warnings - */ - public QueryNotExecutedException (final SQLWarning warnings) { - // Call super contructor - super(MessageFormat.format("SQL statement did not execute: {0} with state: {1}", warnings.getMessage(), warnings.getSQLState()), warnings.getCause()); - } -} diff --git a/src/org/mxchange/jshopcore/model/basket/AddableBasketItem.java b/src/org/mxchange/jshopcore/model/basket/AddableBasketItem.java index 1c29978..4257d17 100644 --- a/src/org/mxchange/jshopcore/model/basket/AddableBasketItem.java +++ b/src/org/mxchange/jshopcore/model/basket/AddableBasketItem.java @@ -26,6 +26,14 @@ import org.mxchange.jshopcore.model.product.Product; */ public interface AddableBasketItem extends Serializable { + /** + * Check equality on item instance + * + * @param object Other object to check + */ + @Override + public boolean equals (final Object object); + /** * Getter for item amount * @@ -45,28 +53,14 @@ public interface AddableBasketItem extends Serializable { * * @return the id */ - public Long getId (); + public Long getItemId (); /** * Setter for entry id (from database backend) * * @param id the id to set */ - public void setId (final Long id); - - /** - * Getter for product id - * - * @return Product id - */ - public Long getProductId (); - - /** - * Setter for product id - * - * @param productId Product id - */ - public void setProductId (final Long productId); + public void setItemId (final Long id); /** * Getter for item type @@ -97,23 +91,15 @@ public interface AddableBasketItem extends Serializable { public void setProduct (final Product product); /** - * Determines whether the item has a Product instance set - * - * @return Whether a Product instance is set - */ - public boolean isProductType (); - - /** - * Check equality on item instance - * - * @param object Other object to check + * Hash-code calculattion */ @Override - public boolean equals (final Object object); + public int hashCode (); /** - * Hash-code calculattion + * Determines whether the item has a Product instance set + * + * @return Whether a Product instance is set */ - @Override - public int hashCode (); + public boolean isProductType (); } diff --git a/src/org/mxchange/jshopcore/model/basket/BaseBasket.java b/src/org/mxchange/jshopcore/model/basket/BaseBasket.java index bf476b9..4d8e7c4 100644 --- a/src/org/mxchange/jshopcore/model/basket/BaseBasket.java +++ b/src/org/mxchange/jshopcore/model/basket/BaseBasket.java @@ -29,6 +29,7 @@ import org.mxchange.jshopcore.exceptions.BasketItemAlreadyAddedException; * @param Any instance that implements AddableBasketItem */ public abstract class BaseBasket implements Basket { + /** * Serial number */ @@ -63,9 +64,9 @@ public abstract class BaseBasket implements Basket< } @Override - public boolean isEmpty () { - // Deligate call to frontend - return this.deque.isEmpty(); + public void clear () { + // Deligate to deque + this.deque.clear(); } @Override @@ -132,8 +133,8 @@ public abstract class BaseBasket implements Basket< } @Override - public void clear () { - // Deligate to deque - this.deque.clear(); + public boolean isEmpty () { + // Deligate call to frontend + return this.deque.isEmpty(); } } diff --git a/src/org/mxchange/jshopcore/model/basket/Basket.java b/src/org/mxchange/jshopcore/model/basket/Basket.java index ea7e899..1a9dabe 100644 --- a/src/org/mxchange/jshopcore/model/basket/Basket.java +++ b/src/org/mxchange/jshopcore/model/basket/Basket.java @@ -30,9 +30,10 @@ public interface Basket extends Serializable { /** * Adds given item instance to this basket - * + * * @param item Item instance to add - * @throws org.mxchange.jshopcore.exceptions.BasketItemAlreadyAddedException If the item instance has already been added + * @throws org.mxchange.jshopcore.exceptions.BasketItemAlreadyAddedException + * If the item instance has already been added */ public void addItem (final T item) throws BasketItemAlreadyAddedException; @@ -41,22 +42,6 @@ public interface Basket extends Serializable { */ public void clear (); - /** - * Checks whether the given item has already been added by checking the - * item's id. - * - * @param item Item instance to check - * @return Whether the given item has been found - */ - public boolean isAdded (final T item); - - /** - * Checks if the basket is empty - * - * @return Whether the basket is empty - */ - public boolean isEmpty (); - /** * Some "getter" for all entries in this basket * @@ -73,8 +58,24 @@ public interface Basket extends Serializable { /** * Getter for last num rows - * + * * @return Last num rows */ public int getLastNumRows (); + + /** + * Checks whether the given item has already been added by checking the + * item's id. + * + * @param item Item instance to check + * @return Whether the given item has been found + */ + public boolean isAdded (final T item); + + /** + * Checks if the basket is empty + * + * @return Whether the basket is empty + */ + public boolean isEmpty (); } diff --git a/src/org/mxchange/jshopcore/model/basket/ShopBasket.java b/src/org/mxchange/jshopcore/model/basket/ShopBasket.java index c24221b..635f55c 100644 --- a/src/org/mxchange/jshopcore/model/basket/ShopBasket.java +++ b/src/org/mxchange/jshopcore/model/basket/ShopBasket.java @@ -22,6 +22,7 @@ package org.mxchange.jshopcore.model.basket; * @author Roland Haeder */ public class ShopBasket extends BaseBasket implements Basket { + /** * Serial number */ diff --git a/src/org/mxchange/jshopcore/model/basket/items/BaseItem.java b/src/org/mxchange/jshopcore/model/basket/items/BaseItem.java index de2f2c0..d0e7901 100644 --- a/src/org/mxchange/jshopcore/model/basket/items/BaseItem.java +++ b/src/org/mxchange/jshopcore/model/basket/items/BaseItem.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2015 Roland Haeder + * Copyright (C) 2015 KLC * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -17,12 +17,6 @@ package org.mxchange.jshopcore.model.basket.items; import java.util.Objects; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Transient; import org.mxchange.jshopcore.model.basket.AddableBasketItem; import org.mxchange.jshopcore.model.product.Product; @@ -32,7 +26,6 @@ import org.mxchange.jshopcore.model.product.Product; * * @author Roland Haeder */ -@Entity(name = "item") public abstract class BaseItem implements AddableBasketItem, Comparable { /** @@ -40,38 +33,6 @@ public abstract class BaseItem implements AddableBasketItem, Comparable item.getProductId()) { + } else if (this.getProduct().getId() > item.getProduct().getId()) { // This id is larger than compared to return -1; } @@ -92,56 +53,6 @@ public abstract class BaseItem implements AddableBasketItem, Comparable */ +@Entity (name = "basket_items") +@Table (name = "basket_items") public class BasketItem extends BaseItem implements AddableBasketItem { + /** * Serial number */ private static final long serialVersionUID = 52_749_158_492_581_578L; + /** + * Item amount + */ + @Basic (optional = false) + @Column (name = "amount", nullable = false, length = 20) + private Long amount; + + /** + * Entry itemId (from database backend) + */ + @Id + @GeneratedValue (strategy = GenerationType.IDENTITY) + @Column (name = "item_id", nullable = false, updatable = false) + private Long itemId; + + /** + * Item type + */ + @Basic (optional = false) + @Column (name = "item_type", nullable = false, length = 20) + private String itemType; + + /** + * Product instance + */ + @JoinColumn (name = "product_id", updatable = false) + @OneToOne (targetEntity = GenericProduct.class) + private Product product; + /** * Default constructor */ @@ -38,7 +80,7 @@ public class BasketItem extends BaseItem implements AddableBasketItem { /** * Constructor for an item from given Product instance - * + * * @param product Product instance */ public BasketItem (final Product product) { @@ -52,16 +94,15 @@ public class BasketItem extends BaseItem implements AddableBasketItem { } // Copy all neccessary values - this.setProductId(product.getId()); - this.setItemType("product"); //NOI18N + this.itemType = "product"; //NOI18N // Copy instance - this.setProduct(product); + this.product = product; } /** * Constructor for an item from given Product instance and amount. - * + * * @param product Product instance * @param amount Ordered amount */ @@ -76,6 +117,46 @@ public class BasketItem extends BaseItem implements AddableBasketItem { } // Set amount - this.setAmount(amount); + this.amount = amount; + } + + @Override + public Long getAmount () { + return this.amount; + } + + @Override + public void setAmount (final Long amount) { + this.amount = amount; + } + + @Override + public Long getItemId () { + return this.itemId; + } + + @Override + public void setItemId (final Long itemId) { + this.itemId = itemId; + } + + @Override + public String getItemType () { + return this.itemType; + } + + @Override + public void setItemType (final String itemType) { + this.itemType = itemType; + } + + @Override + public Product getProduct () { + return this.product; + } + + @Override + public void setProduct (final Product product) { + this.product = product; } } diff --git a/src/org/mxchange/jshopcore/model/category/BaseCategory.java b/src/org/mxchange/jshopcore/model/category/BaseCategory.java deleted file mode 100644 index 6b2e824..0000000 --- a/src/org/mxchange/jshopcore/model/category/BaseCategory.java +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright (C) 2015 Roland Haeder - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.mxchange.jshopcore.model.category; - -import java.util.Objects; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; - -/** - * A general product category class - * - * @author Roland Haeder - */ -@Entity(name = "category") -@Table(name = "category") -public abstract class BaseCategory implements Category, Comparable { - - /** - * Serial number - */ - private static final long serialVersionUID = 38_472_937_685_901L; - - /** - * Id number of category - */ - @Id - @GeneratedValue - @Column - private Long id; - - /** - * Parent category id - */ - @Column(name = "parent_id", length = 20) - private Long parentId; - - /** - * Title of category - */ - @Basic(optional = false) - @Column(length = 100, nullable = false, unique = true) - private String title; - - /** - * Constructor which accepts all database fields - * - * @param id Id number of database record - * @param title Category title - * @param parentId Parent id - */ - protected BaseCategory (final Long id, final String title, final Long parentId) { - // Set all here - this.id = id; - this.title = title; - this.parentId = parentId; - } - - /** - * Default constructor - */ - protected BaseCategory () { - } - - /** - * Compares two categories with each other - * - * @param category Category comparator - * @return Comparison value - */ - @Override - public int compareTo (final Category category) { - // category should not be null - if (null == category) { - throw new NullPointerException("category is null"); //NOI18N - } - - // Is the id the same? - if (Objects.equals(this.getId(), category.getId())) { - // Same id, means same category - return 0; - } else if (this.getId() > category.getId()) { - // This id is larger than compared to - return -1; - } - - // The other id is larger - return 1; - } - - @Override - public void copyAll (final Category category) { - // Copy all data - this.setParentId(category.getParentId()); - this.setTitle(category.getTitle()); - } - - /** - * Id number of category - * - * @return the id - */ - @Override - public Long getId () { - return this.id; - } - - /** - * Id number of category - * - * @param id the id to set - */ - @Override - public void setId (final Long id) { - this.id = id; - } - - /** - * Parent category id - * - * @return the parentId - */ - @Override - public Long getParentId () { - return this.parentId; - } - - /** - * Parent category id - * - * @param parentId the parentId to set - */ - @Override - public void setParentId (final Long parentId) { - this.parentId = parentId; - } - - /** - * Title of category - * - * @return the title - */ - @Override - public String getTitle () { - return this.title; - } - - /** - * Title of category - * - * @param title the title to set - */ - @Override - public void setTitle (final String title) { - this.title = title; - } -} diff --git a/src/org/mxchange/jshopcore/model/category/Category.java b/src/org/mxchange/jshopcore/model/category/Category.java index 5f871c6..c20acbc 100644 --- a/src/org/mxchange/jshopcore/model/category/Category.java +++ b/src/org/mxchange/jshopcore/model/category/Category.java @@ -34,36 +34,42 @@ public interface Category extends Serializable { /** * Id number of category + * * @return the id */ - public Long getId (); + public Long getCategoryId (); /** * Id number of category + * * @param id the id to set */ - public void setId (final Long id); + public void setCategoryId (final Long id); /** - * Parent category id - * @return the parent + * Parent category + * + * @return the parent category */ - public Long getParentId (); + public Category getParentCategory (); /** - * Parent category id - * @param parent the parent to set + * Parent category + * + * @param parentCategory the parent category to set */ - public void setParentId (final Long parent); + public void setParentCategory (final Category parentCategory); /** * Title of category + * * @return the title */ public String getTitle (); /** * Title of category + * * @param title the title to set */ public void setTitle (final String title); diff --git a/src/org/mxchange/jshopcore/model/category/ProductCategory.java b/src/org/mxchange/jshopcore/model/category/ProductCategory.java index d89077f..65a40c8 100644 --- a/src/org/mxchange/jshopcore/model/category/ProductCategory.java +++ b/src/org/mxchange/jshopcore/model/category/ProductCategory.java @@ -16,26 +16,65 @@ */ package org.mxchange.jshopcore.model.category; +import java.util.Objects; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; + /** * A product category + * * @author Roland Haeder */ -public class ProductCategory extends BaseCategory { +@Entity (name = "category") +@Table (name = "category") +public class ProductCategory implements Category, Comparable { + /** * Serial number */ private static final long serialVersionUID = 21_458_945_712_659L; + /** + * Id number of category + */ + @Id + @GeneratedValue (strategy = GenerationType.IDENTITY) + @Column (name = "category_id", length = 20, nullable = false) + private Long categoryId; + + /** + * Parent category categoryId + */ + @JoinColumn (name = "parent_id") + @OneToOne (targetEntity = ProductCategory.class) + private Category parentCategory; + + /** + * Title of category + */ + @Basic (optional = false) + @Column (name = "title", length = 100, nullable = false, unique = true) + private String title; + /** * Constructor which accepts all database fields * - * @param id Id number of database record + * @param categoryId Id number of database record * @param title Category title - * @param parent Parent id + * @param parentCategory Parent category */ - public ProductCategory (final Long id, final String title, final Long parent) { - // Call parent constructor - super(id, title, parent); + public ProductCategory (final Long categoryId, final String title, final Category parentCategory) { + // Set all here + this.categoryId = categoryId; + this.title = title; + this.parentCategory = parentCategory; } /** @@ -43,4 +82,61 @@ public class ProductCategory extends BaseCategory { */ public ProductCategory () { } + + @Override + public int compareTo (final Category category) { + // category should not be null + if (null == category) { + throw new NullPointerException("category is null"); //NOI18N + } + + // Is the categoryId the same? + if (Objects.equals(this.getCategoryId(), category.getCategoryId())) { + // Same categoryId, means same category + return 0; + } else if (this.getCategoryId() > category.getCategoryId()) { + // This categoryId is larger than compared to + return -1; + } + + // The other categoryId is larger + return 1; + } + + @Override + public void copyAll (final Category category) { + // Copy all data + this.setParentCategory(category.getParentCategory()); + this.setTitle(category.getTitle()); + } + + @Override + public Long getCategoryId () { + return this.categoryId; + } + + @Override + public void setCategoryId (final Long categoryId) { + this.categoryId = categoryId; + } + + @Override + public Category getParentCategory () { + return this.parentCategory; + } + + @Override + public void setParentCategory (final Category parentCategory) { + this.parentCategory = parentCategory; + } + + @Override + public String getTitle () { + return this.title; + } + + @Override + public void setTitle (final String title) { + this.title = title; + } } diff --git a/src/org/mxchange/jshopcore/model/customer/Customer.java b/src/org/mxchange/jshopcore/model/customer/Customer.java index 9cee5f7..cbfe426 100644 --- a/src/org/mxchange/jshopcore/model/customer/Customer.java +++ b/src/org/mxchange/jshopcore/model/customer/Customer.java @@ -35,18 +35,18 @@ public interface Customer extends Serializable { public void copyAll (final Customer customer); /** - * Setter for contact instance + * Getter for contact instance * - * @param contact Contact instance + * @return Contact id number */ - public void setContact (final Contact contact); + public Contact getContact (); /** - * Getter for contact instance + * Setter for contact instance * - * @return Contact id number + * @param contact Contact instance */ - public Contact getContact(); + public void setContact (final Contact contact); /** * Getter for confirmation key @@ -76,6 +76,20 @@ public interface Customer extends Serializable { */ public void setCustomerCreated (final Calendar customerCreated); + /** + * Getter for customer id number + * + * @return Customer id number + */ + public Long getCustomerId (); + + /** + * Settte for customer id number + * + * @param customerId Customer id number + */ + public void setCustomerId (final Long customerId); + /** * Getter for "locked" timestamp * @@ -91,18 +105,18 @@ public interface Customer extends Serializable { public void setCustomerLocked (final Calendar customerLocked); /** - * Setter for customer number + * Getter for customer number * - * @param customerNumber Customer number + * @return Customer number */ - public void setCustomerNumber (final String customerNumber); + public String getCustomerNumber (); /** - * Getter for customer number + * Setter for customer number * - * @return Customer number + * @param customerNumber Customer number */ - public String getCustomerNumber (); + public void setCustomerNumber (final String customerNumber); /** * Getter for password hash @@ -131,18 +145,4 @@ public interface Customer extends Serializable { * @param customerStatus Account status */ public void setCustomerStatus (final String customerStatus); - - /** - * Getter for customer id number - * - * @return Customer id number - */ - public Long getCustomerId (); - - /** - * Settte for customer id number - * - * @param customerId Customer id number - */ - public void setCustomerId (final Long customerId); } diff --git a/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java b/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java index 4281137..7544264 100644 --- a/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java +++ b/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java @@ -28,15 +28,15 @@ import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; -import org.mxchange.jcore.model.contact.BaseContact; import org.mxchange.jcore.model.contact.Contact; +import org.mxchange.jcore.model.contact.UserContact; /** * A shop customer class. * * @author Roland Haeder */ -@Entity (name = "Customer") +@Entity (name = "customer") @Table (name = "customer") public class ShopCustomer implements Customer { @@ -45,19 +45,11 @@ public class ShopCustomer implements Customer { */ private static final long serialVersionUID = 4_328_454_581_751L; - /** - * Customer id - */ - @Id - @Column (name = "id", nullable = false, length = 20) - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long customerId; - /** * Id number from "contacts" table */ - @JoinColumn (table = "contacts", referencedColumnName = "customer_contact_id", name = "id", nullable = false, updatable = false, unique = true) - @OneToOne (optional = false, targetEntity = BaseContact.class, orphanRemoval = true) + @JoinColumn (name = "contact_id", nullable = false, updatable = false, unique = true) + @OneToOne (optional = false, targetEntity = UserContact.class) private Contact contact; /** @@ -69,11 +61,19 @@ public class ShopCustomer implements Customer { /** * "created" timestamp */ - @Basic(optional = false) + @Basic (optional = false) @Temporal (TemporalType.TIMESTAMP) @Column (name = "customer_created", nullable = false) private Calendar customerCreated; + /** + * Customer id + */ + @Id + @Column (name = "customer_id", nullable = false, length = 20, updatable = false) + @GeneratedValue (strategy = GenerationType.IDENTITY) + private Long customerId; + /** * "locked" timestamp */ @@ -96,9 +96,16 @@ public class ShopCustomer implements Customer { /** * Account status */ + @Basic (optional = false) @Column (name = "customer_status", nullable = false) private String customerStatus; + /** + * Default constructor + */ + public ShopCustomer () { + } + @Override public void copyAll (final Customer customer) { // Copy also contact data @@ -143,6 +150,16 @@ public class ShopCustomer implements Customer { this.customerCreated = customerCreated; } + @Override + public Long getCustomerId () { + return this.customerId; + } + + @Override + public void setCustomerId (final Long customerId) { + this.customerId = customerId; + } + @Override public Calendar getCustomerLocked () { return this.customerLocked; @@ -182,14 +199,4 @@ public class ShopCustomer implements Customer { public void setCustomerStatus (final String customerStatus) { this.customerStatus = customerStatus; } - - @Override - public Long getCustomerId () { - return this.customerId; - } - - @Override - public void setCustomerId (final Long customerId) { - this.customerId = customerId; - } } diff --git a/src/org/mxchange/jshopcore/model/order/Orderable.java b/src/org/mxchange/jshopcore/model/order/Orderable.java index 47f60ed..4722d45 100644 --- a/src/org/mxchange/jshopcore/model/order/Orderable.java +++ b/src/org/mxchange/jshopcore/model/order/Orderable.java @@ -44,18 +44,18 @@ public interface Orderable extends Serializable { public void setAccessKey (final String accessKey); /** - * Getter for order id + * Getter for created timestamp * - * @return Order id + * @return Created timestamp */ - public Long getId (); + public Calendar getCreated (); /** - * Setter for order id + * Setter for created timestamp * - * @param id Order id + * @param created Created timestamp */ - public void setId (final Long id); + public void setCreated (final Calendar created); /** * Getter for customer instance @@ -72,18 +72,18 @@ public interface Orderable extends Serializable { public void setCustomer (final Customer customer); /** - * Getter for created timestamp + * Getter for order id * - * @return Created timestamp + * @return Order id */ - public Calendar getCreated (); + public Long getOrderId (); /** - * Setter for created timestamp + * Setter for order id * - * @param created Created timestamp + * @param id Order id */ - public void setCreated (final Calendar created); + public void setOrderId (final Long id); /** * Getter for list of ordered basket items diff --git a/src/org/mxchange/jshopcore/model/order/ShopOrder.java b/src/org/mxchange/jshopcore/model/order/ShopOrder.java index 0aaa1a0..addcf8d 100644 --- a/src/org/mxchange/jshopcore/model/order/ShopOrder.java +++ b/src/org/mxchange/jshopcore/model/order/ShopOrder.java @@ -25,20 +25,21 @@ import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; -import javax.persistence.OneToMany; +import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; import org.mxchange.jshopcore.model.basket.AddableBasketItem; import org.mxchange.jshopcore.model.customer.Customer; +import org.mxchange.jshopcore.model.customer.ShopCustomer; /** * An entity class for shop orders * * @author Roland Haeder */ -@Entity (name = "Orders") +@Entity (name = "orders") @Table (name = "orders") public class ShopOrder implements Orderable { @@ -47,21 +48,6 @@ public class ShopOrder implements Orderable { */ private static final long serialVersionUID = 19_728_938_459_834L; - /** - * Order id - */ - @Id - @GeneratedValue (strategy = GenerationType.IDENTITY) - private Long id; - - /** - * Customer instance - */ - @Basic (optional = false) - @OneToMany - @JoinColumn (table = "customer", referencedColumnName = "id", name = "customer_id", nullable = false, updatable = false) - private Customer customer; - /** * Access key */ @@ -74,15 +60,30 @@ public class ShopOrder implements Orderable { */ @Basic (optional = false) @Temporal (TemporalType.TIMESTAMP) - @Column (nullable = false) + @Column (name = "created", nullable = false) private Calendar created; + /** + * Customer instance + */ + @JoinColumn (name = "customer_id", nullable = false, updatable = false) + @OneToOne (targetEntity = ShopCustomer.class, optional = false) + private Customer customer; + /** * Item list, don't save this */ @Transient private List itemList; + /** + * Order orderId + */ + @Id + @GeneratedValue (strategy = GenerationType.IDENTITY) + @Column (name = "order_id", length = 20) + private Long orderId; + @Override public String getAccessKey () { return this.accessKey; @@ -114,13 +115,13 @@ public class ShopOrder implements Orderable { } @Override - public Long getId () { - return this.id; + public Long getOrderId () { + return this.orderId; } @Override - public void setId (final Long id) { - this.id = id; + public void setOrderId (final Long orderId) { + this.orderId = orderId; } @Override diff --git a/src/org/mxchange/jshopcore/model/order/items/OrderItem.java b/src/org/mxchange/jshopcore/model/order/items/OrderItem.java index c12cf50..5defb8f 100644 --- a/src/org/mxchange/jshopcore/model/order/items/OrderItem.java +++ b/src/org/mxchange/jshopcore/model/order/items/OrderItem.java @@ -16,25 +16,106 @@ */ package org.mxchange.jshopcore.model.order.items; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; import javax.persistence.Table; import org.mxchange.jshopcore.model.basket.AddableBasketItem; import org.mxchange.jshopcore.model.basket.items.BaseItem; +import org.mxchange.jshopcore.model.product.GenericProduct; +import org.mxchange.jshopcore.model.product.Product; /** * A general basket item * * @author Roland Haeder */ -@Table(name = "ordered_items") +@Entity (name = "ordered_item") +@Table (name = "ordered_items") public class OrderItem extends BaseItem implements AddableBasketItem { + /** * Serial number */ private static final long serialVersionUID = 44_189_562_738_723_581L; + /** + * Item amount + */ + @Basic (optional = false) + @Column (name = "amount", length = 20, nullable = false) + private Long amount; + + /** + * Entry id (from database backend) + */ + @Id + @GeneratedValue (strategy = GenerationType.IDENTITY) + @Column (name = "id", nullable = false, length = 20) + private Long id; + + /** + * Item type + */ + @Basic (optional = false) + @Column (name = "item_type", length = 20) + private String itemType; + + /** + * Product instance + */ + @JoinColumn (name = "product_id", updatable = false) + @OneToOne (targetEntity = GenericProduct.class) + private Product product; + /** * Default constructor */ public OrderItem () { } + + @Override + public Long getAmount () { + return this.amount; + } + + @Override + public void setAmount (final Long amount) { + this.amount = amount; + } + + @Override + public Long getItemId () { + return this.id; + } + + @Override + public void setItemId (final Long id) { + this.id = id; + } + + @Override + public String getItemType () { + return this.itemType; + } + + @Override + public void setItemType (final String itemType) { + this.itemType = itemType; + } + + @Override + public Product getProduct () { + return this.product; + } + + @Override + public void setProduct (final Product product) { + this.product = product; + } } diff --git a/src/org/mxchange/jshopcore/model/product/BaseProduct.java b/src/org/mxchange/jshopcore/model/product/BaseProduct.java deleted file mode 100644 index 2b3d81c..0000000 --- a/src/org/mxchange/jshopcore/model/product/BaseProduct.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ -package org.mxchange.jshopcore.model.product; - -import java.util.Objects; -import javax.persistence.Basic; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; - -/** - * A general product class - * - * @author Roland Haeder - */ -@Entity(name = "product") -@Table (name = "products") -public abstract class BaseProduct implements Product, Comparable { - - /** - * Serial number - */ - private static final long serialVersionUID = 48_379_575_267_451L; - - /** - * Availability of product - */ - @Column - private Boolean available; - - /** - * Product category - */ - @Basic(optional = false) - @Column(name = "category_id", length = 20, nullable = false) - private Long categoryId; - - /** - * Id number of product - */ - @Id - @GeneratedValue - @Column - private Long id; - - /** - * Price of product - */ - @Basic(optional = false) - @Column(nullable = false) - private Float price; - - /** - * Title of product - */ - @Basic(optional = false) - @Column(length = 100, nullable = false) - private String title; - - @Override - public int compareTo (final Product product) { - // category should not be null - if (null == product) { - throw new NullPointerException("product is null"); //NOI18N - } - - // Is the id the same? - if (Objects.equals(this.getId(), product.getId())) { - // Same id, means same category - return 0; - } else if (this.getId() > product.getId()) { - // This id is larger than compared to - return 1; - } - - // The other id is larger - return -1; - } - - @Override - public void copyAll (final Product product) { - // Copy all - this.setAvailable(product.getAvailable()); - this.setCategoryId(product.getCategoryId()); - this.setPrice(product.getPrice()); - this.setTitle(product.getTitle()); - } - - @Override - public Boolean getAvailable () { - return this.available; - } - - @Override - public void setAvailable (final Boolean available) { - this.available = available; - } - - @Override - public Long getCategoryId () { - return this.categoryId; - } - - @Override - public void setCategoryId (final Long categoryId) { - this.categoryId = categoryId; - } - - @Override - public Long getId () { - return this.id; - } - - @Override - public void setId (final Long id) { - this.id = id; - } - - @Override - public Float getPrice () { - return this.price; - } - - @Override - public void setPrice (final Float price) { - this.price = price; - } - - @Override - public String getTitle () { - return this.title; - } - - @Override - public void setTitle (final String title) { - this.title = title; - } -} diff --git a/src/org/mxchange/jshopcore/model/product/GenericProduct.java b/src/org/mxchange/jshopcore/model/product/GenericProduct.java index a7e8f88..e794f21 100644 --- a/src/org/mxchange/jshopcore/model/product/GenericProduct.java +++ b/src/org/mxchange/jshopcore/model/product/GenericProduct.java @@ -16,18 +16,66 @@ */ package org.mxchange.jshopcore.model.product; +import java.util.Objects; +import javax.persistence.Basic; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; +import org.mxchange.jshopcore.model.category.Category; + /** * Generic product class * * @author Roland Haeder * TODO: Find a better name */ -public class GenericProduct extends BaseProduct implements Product { +@Entity (name = "products") +@Table (name = "products") +public class GenericProduct implements Product, Comparable { + /** * Serial number */ private static final long serialVersionUID = 54_578_571_769_283L; + /** + * Availability of product + */ + @Column (name = "available", nullable = false) + private Boolean available; + + /** + * Product category + */ + @Basic (optional = false) + @Column (name = "category_id", length = 20, nullable = false) + private Category category; + + /** + * Id number of product + */ + @Id + @GeneratedValue (strategy = GenerationType.IDENTITY) + @Column(name = "product_id", length = 20, nullable = false, updatable = false) + private Long id; + + /** + * Price of product + */ + @Basic (optional = false) + @Column (name = "price", nullable = false) + private Float price; + + /** + * Title of product + */ + @Basic (optional = false) + @Column (name = "title", length = 100, nullable = false) + private String title; + /** * Default constructor */ @@ -40,15 +88,94 @@ public class GenericProduct extends BaseProduct implements Product { * @param id Id number of product * @param title Name of product * @param price Price - * @param categoryId Category id + * @param category Category instance * @param available Availability (selectable by customer) */ - public GenericProduct (final Long id, final String title, final Float price, final Long categoryId, final Boolean available) { + public GenericProduct (final Long id, final String title, final Float price, final Category category, final Boolean available) { // Set all here - this.setId(id); - this.setTitle(title); - this.setPrice(price); - this.setCategoryId(categoryId); - this.setAvailable(available); + this.id = id; + this.title = title; + this.price = price; + this.category = category; + this.available = available; + } + + @Override + public int compareTo (final Product product) { + // category should not be null + if (null == product) { + throw new NullPointerException("product is null"); //NOI18N + } + + // Is the id the same? + if (Objects.equals(this.getId(), product.getId())) { + // Same id, means same category + return 0; + } else if (this.getId() > product.getId()) { + // This id is larger than compared to + return 1; + } + + // The other id is larger + return -1; + } + + @Override + public void copyAll (final Product product) { + // Copy all + this.setAvailable(product.getAvailable()); + this.setCategory(product.getCategory()); + this.setPrice(product.getPrice()); + this.setTitle(product.getTitle()); + } + + @Override + public Boolean getAvailable () { + return this.available; + } + + @Override + public void setAvailable (final Boolean available) { + this.available = available; + } + + @Override + public Category getCategory () { + return this.category; + } + + @Override + public void setCategory (final Category category) { + this.category = category; + } + + @Override + public Long getId () { + return this.id; + } + + @Override + public void setId (final Long id) { + this.id = id; + } + + @Override + public Float getPrice () { + return this.price; + } + + @Override + public void setPrice (final Float price) { + this.price = price; + } + + @Override + public String getTitle () { + return this.title; + } + + @Override + public void setTitle (final String title) { + this.title = title; } } diff --git a/src/org/mxchange/jshopcore/model/product/Product.java b/src/org/mxchange/jshopcore/model/product/Product.java index a48499d..5f00876 100644 --- a/src/org/mxchange/jshopcore/model/product/Product.java +++ b/src/org/mxchange/jshopcore/model/product/Product.java @@ -17,6 +17,7 @@ package org.mxchange.jshopcore.model.product; import java.io.Serializable; +import org.mxchange.jshopcore.model.category.Category; /** * An interface for in database storable products @@ -33,69 +34,72 @@ public interface Product extends Serializable { public void copyAll (final Product product); /** - * Getter for id number, suitable for form fields. - * - * @return Id number of product + * Getter for product availability + * + * @return Product availability */ - public Long getId (); + public Boolean getAvailable (); /** - * Id number of product - * @param id the id number to set + * Setter for product availability + * + * @param available Product availability */ - public void setId (final Long id); + public void setAvailable (final Boolean available); /** - * Getter for title. - * - * @return Title of product + * Getter for product category id + * + * @return Product category id */ - public String getTitle (); + public Category getCategory (); /** - * Title of product - * @param title the title to set + * Setter for product category + * + * @param category Product category */ - public void setTitle (final String title); + public void setCategory (final Category category); /** - * Getter for raw price. - * - * @return Single price of product + * Getter for id number, suitable for form fields. + * + * @return Id number of product */ - public Float getPrice (); + public Long getId (); /** - * Price of product - * @param price the price to set + * Id number of product + * + * @param id the id number to set */ - public void setPrice (final Float price); + public void setId (final Long id); /** - * Getter for product category id + * Getter for raw price. * - * @return Product category id + * @return Single price of product */ - public Long getCategoryId (); + public Float getPrice (); /** - * Setter for product category + * Price of product * - * @param categoryId Product category + * @param price the price to set */ - public void setCategoryId (final Long categoryId); + public void setPrice (final Float price); /** - * Getter for product availability + * Getter for title. * - * @return Product availability + * @return Title of product */ - public Boolean getAvailable (); + public String getTitle (); /** - * Setter for product availability + * Title of product * - * @param available Product availability + * @param title the title to set */ - public void setAvailable (final Boolean available); + public void setTitle (final String title); } diff --git a/src/org/mxchange/jshopcore/wrapper/CheckoutWrapper.java b/src/org/mxchange/jshopcore/wrapper/CheckoutWrapper.java index 7a70470..6bfe3c5 100644 --- a/src/org/mxchange/jshopcore/wrapper/CheckoutWrapper.java +++ b/src/org/mxchange/jshopcore/wrapper/CheckoutWrapper.java @@ -26,6 +26,7 @@ import org.mxchange.jshopcore.model.customer.Customer; * @author Roland Haeder */ public class CheckoutWrapper implements WrapableCheckout { + /** * Serial number */ diff --git a/src/org/mxchange/jshopcore/wrapper/WrapableCheckout.java b/src/org/mxchange/jshopcore/wrapper/WrapableCheckout.java index 7d5d9db..1ad5a9f 100644 --- a/src/org/mxchange/jshopcore/wrapper/WrapableCheckout.java +++ b/src/org/mxchange/jshopcore/wrapper/WrapableCheckout.java @@ -37,18 +37,21 @@ public interface WrapableCheckout extends Serializable { /** * Setter for customer instance + * * @param customer Customer instance */ public void setCustomer (final Customer customer); /** * Getter for a List of AddableBasktem instances + * * @return List with AddableBasketItem instances */ public List getList (); /** * Setter for a List of AddableBasktem instances + * * @param list List with AddableBasketItem instances */ public void setList (final List list);