package org.mxchange.jproduct.model.category;
import java.io.Serializable;
+import java.util.Date;
/**
* An interface for categories
public interface Category extends Serializable {
/**
- * Copies all properties from other category to this
+ * Getter for created timestamp
* <p>
- * @param category Source category instance
+ * @return Created timestamp
*/
- void copyAll (final Category category);
+ Date getCategoryCreated ();
+
+ /**
+ * Setter for created timestamp
+ * <p>
+ * @param categoryCreated Created timestamp
+ */
+ void setCategoryCreated (final Date categoryCreated);
/**
* Id number of category
*/
package org.mxchange.jproduct.model.category;
+import java.util.Date;
import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
import javax.persistence.Transient;
/**
*/
@Entity (name = "product_category")
@Table (name = "product_category")
+@NamedQueries (
+ {
+ @NamedQuery (name = "AllProductCategories", query = "SELECT pc FROM product_category AS pc ORDER BY pc.categoryId ASC")
+ }
+)
@SuppressWarnings ("PersistenceUnitPresent")
public class ProductCategory implements Category {
@Transient
private static final long serialVersionUID = 21_458_945_712_659L;
+ /**
+ * When this entry has been created
+ */
+ @Basic (optional = false)
+ @Column (name = "category_created", updatable = false, nullable = false)
+ @Temporal (TemporalType.TIMESTAMP)
+ private Date categoryCreated;
+
/**
* Id number of category
*/
* statistics
*/
public ProductCategory (final String categoryTitle, final Category parentCategory, final Boolean categoryShownInStatistics) {
+ // Call other constructor
+ this();
+
// Set all here
this.categoryTitle = categoryTitle;
this.parentCategory = parentCategory;
public ProductCategory () {
}
- @Override
- @Deprecated
- public void copyAll (final Category category) {
- // Copy all data
- this.setParentCategory(category.getParentCategory());
- this.setCategoryTitle(category.getCategoryTitle());
- this.setCategoryShownInStatistics(category.getCategoryShownInStatistics());
- }
-
@Override
public boolean equals (final Object object) {
if (this == object) {
return false;
}
- final Category other = (Category) object;
+ final Category category = (Category) object;
- if (!Objects.equals(this.getCategoryTitle(), other.getCategoryTitle())) {
+ if (!Objects.equals(this.getCategoryTitle(), category.getCategoryTitle())) {
return false;
- } else if (!Objects.equals(this.getCategoryId(), other.getCategoryId())) {
- return false;
- } else if (!Objects.equals(this.getCategoryShownInStatistics(), other.getCategoryShownInStatistics())) {
+ } else if (!Objects.equals(this.getCategoryId(), category.getCategoryId())) {
return false;
}
return true;
}
+ @Override
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getCategoryCreated () {
+ return this.categoryCreated;
+ }
+
+ @Override
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setCategoryCreated (final Date categoryCreated) {
+ this.categoryCreated = categoryCreated;
+ }
+
@Override
public Long getCategoryId () {
return this.categoryId;
@Override
public int hashCode () {
int hash = 7;
+
hash = 13 * hash + Objects.hashCode(this.getCategoryId());
hash = 13 * hash + Objects.hashCode(this.getCategoryTitle());
+
return hash;
}
*/
package org.mxchange.jproduct.model.product;
+import java.util.Date;
import java.util.Objects;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
+import javax.persistence.NamedQueries;
+import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
+import javax.persistence.Temporal;
+import javax.persistence.TemporalType;
import javax.persistence.Transient;
import org.mxchange.jproduct.model.category.Category;
import org.mxchange.jproduct.model.category.ProductCategory;
*/
@Entity (name = "generic_products")
@Table (name = "generic_products")
+@NamedQueries (
+ {
+ @NamedQuery (name = "AllProducts", query = "SELECT p FROM generic_products AS p ORDER BY p.productId ASC"),
+ @NamedQuery (name = "AllAvailableProducts", query = "SELECT p FROM generic_products AS p WHERE p.productAvailability=TRUE ORDER BY p.productId ASC")
+ }
+)
@SuppressWarnings ("PersistenceUnitPresent")
public class GenericProduct implements Product {
@OneToOne (targetEntity = ProductCategory.class, cascade = CascadeType.REFRESH, optional = false)
private Category productCategory;
+ /**
+ * When this product has been created
+ */
+ @Basic(optional = false)
+ @Column(name = "product_created", nullable = false, updatable = false)
+ @Temporal(TemporalType.TIMESTAMP)
+ private Date productCreated;
+
/**
* Id number of product
*/
* Title of product
*/
@Basic (optional = false)
- @Column (name = "product_title", length = 100, nullable = false)
+ @Column (name = "product_title", length = 100, nullable = false, unique = true)
private String productTitle;
/**
this.productAvailability = productAvailability;
}
- @Override
- @Deprecated
- public void copyAll (final Product product) {
- // Copy all
- this.setProductAvailability(product.getProductAvailability());
- this.setProductCategory(product.getProductCategory());
- this.setProductPrice(product.getProductPrice());
- this.setProductTitle(product.getProductTitle());
- }
-
@Override
public boolean equals (final Object object) {
if (this == object) {
if (!Objects.equals(this.getProductId(), product.getProductId())) {
return false;
- } else if (!Objects.equals(this.getProductPrice(), product.getProductPrice())) {
- return false;
} else if (!Objects.equals(this.getProductTitle(), product.getProductTitle())) {
return false;
}
this.productCategory = productCategory;
}
+ @Override
+ @SuppressWarnings ("ReturnOfDateField")
+ public Date getProductCreated () {
+ return this.productCreated;
+ }
+
+ @Override
+ @SuppressWarnings ("AssignmentToDateFieldFromParameter")
+ public void setProductCreated (final Date productCreated) {
+ this.productCreated = productCreated;
+ }
+
@Override
public Long getProductId () {
return this.productId;
int hash = 7;
hash = 23 * hash + Objects.hashCode(this.getProductId());
- hash = 23 * hash + Objects.hashCode(this.getProductPrice());
hash = 23 * hash + Objects.hashCode(this.getProductTitle());
return hash;
package org.mxchange.jproduct.model.product;
import java.io.Serializable;
+import java.util.Date;
import org.mxchange.jproduct.model.category.Category;
/**
public interface Product extends Serializable {
/**
- * Copies all properties from source product to this.
+ * Getter for created timestamp
* <p>
- * @param product Source product
+ * @return Created timestamp
*/
- void copyAll (final Product product);
+ Date getProductCreated ();
+
+ /**
+ * Setter for created timestamp
+ * <p>
+ * @param productCreated Created timestamp
+ */
+ void setProductCreated (final Date productCreated);
/**
* Getter for product availability