javac.classpath=\
${file.reference.jcore.jar}:\
${file.reference.jcoreee.jar}:\
- ${libs.javaee-api-7.0.classpath}:\
- ${file.reference.commons-codec-1.10.jar}
+ ${file.reference.commons-codec-1.10.jar}:\
+ ${libs.javaee-api-7.0.classpath}
# Space-separated list of extra javac options
javac.compilerargs=-Xlint:unchecked -Xlint:deprecation
javac.deprecation=true
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+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;
+}
* 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
public void setId (final Long id);
/**
- * Getter for item id (e.g. from product)
+ * Getter for product id
*
- * @return the id
+ * @return Product id
*/
- public Long getItemId ();
+ public Long getProductId ();
/**
- * Setter for item id (e.g. from product)
+ * Setter for product id
*
- * @param id the id to set
+ * @param productId Product id
*/
- public void setItemId (final Long id);
+ public void setProductId (final Long productId);
/**
* Getter for item type
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+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;
+
+/**
+ * An item (addedable to a basket) could respresent a product or a discount
+ * coupon. This depends on the type of the item.
+ *
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Entity(name = "item")
+public abstract class BaseItem implements AddableBasketItem, Comparable<AddableBasketItem> {
+
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 24_348_671_457_829_156L;
+
+ /**
+ * Entry id (from database backend)
+ */
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ /**
+ * Item amount
+ */
+ @Basic(optional = false)
+ private Long amount;
+
+ /**
+ * Product id
+ */
+ @Column(name = "product_id", length = 20)
+ private Long productId;
+
+ /**
+ * Item type
+ */
+ @Basic(optional = false)
+ @Column(name = "item_type", length = 20)
+ private String itemType;
+
+ /**
+ * Product instance
+ */
+ @Transient
+ private Product product;
+
+ @Override
+ public int compareTo (final AddableBasketItem item) {
+ // item should not be null
+ if (null == item) {
+ throw new NullPointerException("item is null"); //NOI18N
+ }
+
+ // Is the id the same?
+ if (Objects.equals(this.getProductId(), item.getProductId())) {
+ // Same id, means same item
+ return 0;
+ } else if (this.getProductId() > item.getProductId()) {
+ // This id is larger than compared to
+ return -1;
+ }
+
+ // The other id is larger
+ return 1;
+ }
+
+ @Override
+ public Long getAmount () {
+ return this.amount;
+ }
+
+ @Override
+ public void setAmount (final Long amount) {
+ this.amount = amount;
+ }
+
+ @Override
+ public Long getId () {
+ return this.id;
+ }
+
+ @Override
+ public void setId (final Long id) {
+ this.id = id;
+ }
+
+ @Override
+ public Long getProductId () {
+ return this.productId;
+ }
+
+ @Override
+ public void setProductId (final Long productId) {
+ this.productId = productId;
+ }
+
+ @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;
+ }
+
+ @Override
+ public boolean equals (final Object object) {
+ // Is it same type?
+ if (!(object instanceof BaseItem)) {
+ // Not equal types
+ return false;
+ } else if (!(object instanceof AddableBasketItem)) {
+ // Not correct interface
+ return false;
+ }
+
+ // Securely cast to wanted interface
+ AddableBasketItem item = (AddableBasketItem) object;
+
+ // Item id and type must be the same
+ return ((Objects.equals(item.getProductId(), this.getProductId()))
+ && (Objects.equals(item.getItemType(), this.getItemType())));
+ }
+
+ @Override
+ public int hashCode () {
+ int hash = 5;
+ hash = 29 * hash + Objects.hashCode(this.getProductId());
+ hash = 29 * hash + Objects.hashCode(this.getItemType());
+ return hash;
+ }
+
+ @Override
+ public boolean isProductType () {
+ // Is the instance set?
+ return (this.getProduct() instanceof Product);
+ }
+}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jshopcore.model.basket.items;
+
+import org.mxchange.jshopcore.model.basket.AddableBasketItem;
+import org.mxchange.jshopcore.model.product.Product;
+
+/**
+ * A general basket item
+ *
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+public class BasketItem extends BaseItem implements AddableBasketItem {
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 52_749_158_492_581_578L;
+
+ /**
+ * Default constructor
+ */
+ public BasketItem () {
+ }
+
+ /**
+ * Constructor for an item from given Product instance
+ *
+ * @param product Product instance
+ */
+ public BasketItem (final Product product) {
+ // Call default constructor
+ this();
+
+ // product must not be null
+ if (null == product) {
+ // Abort here
+ throw new NullPointerException("product is null"); //NOI18N
+ }
+
+ // Copy all neccessary values
+ this.setProductId(product.getId());
+ this.setItemType("product"); //NOI18N
+
+ // Copy instance
+ this.setProduct(product);
+ }
+
+ /**
+ * Constructor for an item from given Product instance and amount.
+ *
+ * @param product Product instance
+ * @param amount Ordered amount
+ */
+ public BasketItem (final Product product, final Long amount) {
+ // Other constructor
+ this(product);
+
+ // amount must not be null
+ if (null == amount) {
+ // Abort here
+ throw new NullPointerException("amount is null"); //NOI18N
+ }
+
+ // Set amount
+ this.setAmount(amount);
+ }
+}
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<roland@mxchange.org>
*/
+@Entity(name = "Category")
+@Table(name = "category")
public abstract class BaseCategory implements Category, Comparable<Category> {
+
/**
* Serial number
*/
/**
* Id number of category
*/
+ @Id
+ @GeneratedValue
+ @Column(length = 20)
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;
/**
return 1;
}
+ @Override
+ public void copyAll (final Category category) {
+ // Copy all data
+ this.setParentId(category.getParentId());
+ this.setTitle(category.getTitle());
+ }
+
/**
* Id number of category
*
*/
public interface Category extends Serializable {
+ /**
+ * Copies all properties from other category to this
+ *
+ * @param category Source category instance
+ */
+ public void copyAll (final Category category);
+
/**
* Id number of category
* @return the id
*/
package org.mxchange.jshopcore.model.customer;
+import java.io.Serializable;
import java.sql.Timestamp;
import org.mxchange.jcore.model.contact.Contact;
*
* @author Roland Haeder<roland@mxchange.org>
*/
-public interface Customer extends Contact {
+public interface Customer extends Serializable {
/**
- * Setter for id number from "contact" table
+ * Copies all attributes from other customer object to this
*
- * @param contactId Contact id number
+ * @param customer Source instance
*/
- public void setContactId (final long contactId);
+ public void copyAll (final Customer customer);
/**
- * Getter for id number from "contact" table
+ * Setter for contact instance
+ *
+ * @param contact Contact instance
+ */
+ public void setContact (final Contact contact);
+
+ /**
+ * Getter for contact instance
*
* @return Contact id number
*/
- public long getContactId();
+ public Contact getContact();
/**
* Getter for confirmation key
*/
package org.mxchange.jshopcore.model.customer;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
import java.sql.SQLException;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityNotFoundException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.Sha2Crypt;
import org.mxchange.jcore.BaseFrameworkSystem;
+import org.mxchange.jshopcore.model.order.Orderable;
+import org.mxchange.jshopcore.model.order.ShopOrder;
/**
* An utilities class for customers
/**
* Generates an unique customer number by checking is existence
*
- * @param connection Connection instance
+ * @param em Entity manager instance
* @return Generated customer number (not used before)
* @throws java.sql.SQLException If any SQL error occured
*/
- public static String generateCustomerNumber (final Connection connection) throws SQLException {
+ public static String generateCustomerNumber (final EntityManager em) throws SQLException {
// Trace message
// TODO: utils.getLogger().logTrace(MessageFormat.format("generateCustomerNumber: connection={0} - CALLED!", connection));
- // connection cannot be null
- if (null == connection) {
+
+ // em cannot be null
+ if (null == em) {
// Abort here
- throw new NullPointerException("connection is null"); //NOI18N
+ throw new NullPointerException("em is null"); //NOI18N
+ } else if (!em.isOpen()) {
+ // Not open
+ throw new IllegalStateException("Entity manager is closed.");
}
- // Prepare statement
- PreparedStatement statement = connection.prepareStatement("SELECT `id` FROM `customer` WHERE `customer_number` = ? LIMIT 1"); //NOI18N
+ // Fake customer instance
+ Customer customer = null;
// Generate number
String customerNumber = null;
// Generate new number
customerNumber = String.format("%s-%s", part1, part2); //NOI18N
- // Debug message
- // TODO: utils.getLogger().logDebug(MessageFormat.format("generateCustomerNumber: customerNumber={0}", customerNumber));
- // Insert customer number
- statement.setString(1, customerNumber);
-
- // Find it
- statement.execute();
-
- // Get result
- ResultSet result = statement.getResultSet();
-
- // Try to get next result
- isFound = result.next();
+ // Try it
+ try {
+ // Get instance
+ customer = em.getReference(ShopCustomer.class, customerNumber);
+ } catch (final EntityNotFoundException ex) {
+ // Not found
+ isFound = false;
+ }
}
// Trace message
// TODO: utils.getLogger().logTrace(MessageFormat.format("generateCustomerNumber: customerNumber={0} - EXIT!", customerNumber));
+
// Found one
return customerNumber;
}
/**
* Generates an unique access key.
*
- * @param connection Connection instance
+ * @param em Entity manager instance
* @param customer Customer instance
* @return An unique access key
- * @throws java.sql.SQLException If any SQL error occured
*/
- public static String generateAccessKey (final Connection connection, final Customer customer) throws SQLException {
+ public static String generateAccessKey (final EntityManager em, final Customer customer) {
// Trace message
// TODO: utils.getLogger().logTrace(MessageFormat.format("generateAccessKey: connection={0} - CALLED!", connection));
- // connection cannot be null
- if (null == connection) {
+
+ // em cannot be null
+ if (null == em) {
// Abort here
- throw new NullPointerException("connection is null"); //NOI18N
+ throw new NullPointerException("em is null"); //NOI18N
+ } else if (!em.isOpen()) {
+ // Not open
+ throw new IllegalStateException("Entity manager is closed.");
}
- // Prepare statement
- PreparedStatement statement = connection.prepareStatement("SELECT `id` FROM `orders` WHERE `access_key` = ? LIMIT 1"); //NOI18N
+ // Generate fake order instance
+ Orderable orderable = null;
// Generate access keyy
String accessKey = null;
// Is the number used?
while (isFound) {
// Both number parts
- String randString = String.format("%s:%s:%s", Long.toHexString(Math.round(Math.random() * 1000000)), connection, customer.getCustomerNumber());
+ String randString = String.format("%s:%s:%s", Long.toHexString(Math.round(Math.random() * 1000000)), em, customer.getCustomerNumber());
- // Generate new number
+ // Generate access key, use SHA512 hashing and BASE64-encoding for strong key generation
accessKey = Base64.encodeBase64String(Sha2Crypt.sha512Crypt(randString.getBytes()).getBytes()).substring(0, 100);
- // Debug message
- // TODO: utils.getLogger().logDebug(MessageFormat.format("generateAccessKey: accessKey={0}", accessKey));
- // Insert customer number
- statement.setString(1, accessKey);
-
- // Find it
- statement.execute();
-
- // Get result
- ResultSet result = statement.getResultSet();
-
- // Try to get next result
- isFound = result.next();
+ // Try this
+ try {
+ // Get reference
+ orderable = em.getReference(ShopOrder.class, accessKey);
+ } catch (final EntityNotFoundException ex) {
+ // Not found, so abort loop here
+ isFound = false;
+ }
}
// Trace message
// TODO: utils.getLogger().logTrace(MessageFormat.format("generateAccessKey: accessKey={0} - EXIT!", accessKey));
+
// Found one
return accessKey;
}
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.mxchange.jcore.model.contact.BaseContact;
+import org.mxchange.jcore.model.contact.Contact;
/**
* A shop customer class.
*/
@Entity (name = "Customer")
@Table (name = "customer")
-public class ShopCustomer extends BaseContact implements Customer {
+public class ShopCustomer implements Customer {
/**
* Serial number
@JoinColumn (table = "contacts", unique = true)
@OneToOne (optional = false, targetEntity = BaseContact.class, orphanRemoval = true)
@Column (name = "customer_contact_id", nullable = false, length = 20)
- private long contactId;
+ private Contact contact;
/**
* Confirmation key
private String customerStatus;
@Override
- public long getContactId () {
- return this.contactId;
+ public void copyAll (final Customer customer) {
+ // Copy other data
+ this.setCustomerConfirmKey(customer.getCustomerConfirmKey());
+ this.setCustomerNumber(customer.getCustomerNumber());
+ this.setCustomerPasswordHash(customer.getCustomerPasswordHash());
+ this.setCustomerStatus(customer.getCustomerStatus());
+ this.setCustomerCreated(customer.getCustomerCreated());
+ this.setCustomerLocked(customer.getCustomerLocked());
}
@Override
- public void setContactId (final long contactId) {
- this.contactId = contactId;
+ public Contact getContact () {
+ return this.contact;
+ }
+
+ @Override
+ public void setContact (final Contact contact) {
+ this.contact = contact;
}
@Override
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jshopcore.model.item;
-
-import java.util.Objects;
-import org.mxchange.jshopcore.model.basket.AddableBasketItem;
-import org.mxchange.jshopcore.model.product.Product;
-
-/**
- * An item (addedable to a basket) could respresent a product or a discount
- * coupon. This depends on the type of the item.
- *
- * @author Roland Haeder<roland@mxchange.org>
- */
-public abstract class BaseItem implements AddableBasketItem, Comparable<AddableBasketItem> {
-
- /**
- * Serial number
- */
- private static final long serialVersionUID = 24_348_671_457_829_156L;
-
- /**
- * Entry id (from database backend)
- */
- private Long id;
-
- /**
- * Item amount
- */
- private Long amount;
-
- /**
- * Item id number
- */
- private Long itemId;
-
- /**
- * Item type
- */
- private String itemType;
-
- /**
- * Item instance
- */
- private Product product;
-
- @Override
- public int compareTo (final AddableBasketItem item) {
- // item should not be null
- if (null == item) {
- throw new NullPointerException("item is null"); //NOI18N
- }
-
- // Is the id the same?
- if (Objects.equals(this.getItemId(), item.getItemId())) {
- // Same id, means same item
- return 0;
- } else if (this.getItemId() > item.getItemId()) {
- // This id is larger than compared to
- return -1;
- }
-
- // The other id is larger
- return 1;
- }
-
- @Override
- public Long getAmount () {
- return this.amount;
- }
-
- @Override
- public void setAmount (final Long amount) {
- this.amount = amount;
- }
-
- @Override
- public Long getId () {
- return this.id;
- }
-
- @Override
- public void setId (final Long id) {
- this.id = id;
- }
-
- @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;
- }
-
- @Override
- public boolean equals (final Object object) {
- // Is it same type?
- if (!(object instanceof BaseItem)) {
- // Not equal types
- return false;
- } else if (!(object instanceof AddableBasketItem)) {
- // Not correct interface
- return false;
- }
-
- // Securely cast to wanted interface
- AddableBasketItem item = (AddableBasketItem) object;
-
- // Item id and type must be the same
- return ((Objects.equals(item.getItemId(), this.getItemId()))
- && (Objects.equals(item.getItemType(), this.getItemType())));
- }
-
- @Override
- public int hashCode () {
- int hash = 5;
- hash = 29 * hash + Objects.hashCode(this.getItemId());
- hash = 29 * hash + Objects.hashCode(this.getItemType());
- return hash;
- }
-
- @Override
- public boolean isProductType () {
- // Is the instance set?
- return (this.getProduct() instanceof Product);
- }
-}
+++ /dev/null
-/*
- * 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 <http://www.gnu.org/licenses/>.
- */
-package org.mxchange.jshopcore.model.item;
-
-import org.mxchange.jshopcore.model.basket.AddableBasketItem;
-import org.mxchange.jshopcore.model.product.Product;
-
-/**
- * A general basket item
- *
- * @author Roland Haeder<roland@mxchange.org>
- */
-public class BasketItem extends BaseItem implements AddableBasketItem {
- /**
- * Serial number
- */
- private static final long serialVersionUID = 52_749_158_492_581_578L;
-
- /**
- * Default constructor
- */
- public BasketItem () {
- }
-
- /**
- * Constructor for an item from given Product instance
- *
- * @param product Product instance
- */
- public BasketItem (final Product product) {
- // Call default constructor
- this();
-
- // product must not be null
- if (null == product) {
- // Abort here
- throw new NullPointerException("product is null"); //NOI18N
- }
-
- // Copy all neccessary values
- this.setItemId(product.getId());
- this.setItemType("product"); //NOI18N
-
- // Copy instance
- this.setProduct(product);
- }
-
- /**
- * Constructor for an item from given Product instance and amount.
- *
- * @param product Product instance
- * @param amount Ordered amount
- */
- public BasketItem (final Product product, final Long amount) {
- // Other constructor
- this(product);
-
- // amount must not be null
- if (null == amount) {
- // Abort here
- throw new NullPointerException("amount is null"); //NOI18N
- }
-
- // Set amount
- this.setAmount(amount);
- }
-}
import java.io.Serializable;
import java.sql.Timestamp;
+import java.util.List;
+import org.mxchange.jshopcore.model.basket.AddableBasketItem;
+import org.mxchange.jshopcore.model.customer.Customer;
/**
* An interface for customer orders
*/
public interface Orderable extends Serializable {
+ /**
+ * Getter for access key
+ *
+ * @return Access key
+ */
+ public String getAccessKey ();
+
+ /**
+ * Setter for access key
+ *
+ * @param accessKey Access key
+ */
+ public void setAccessKey (final String accessKey);
+
/**
* Getter for order id
*
public void setId (final Long id);
/**
- * Getter for customer id
+ * Getter for customer instance
*
- * @return Customer id
+ * @return Customer instance
*/
- public Long getCustomerId ();
+ public Customer getCustomer ();
/**
- * Setter for customer id
+ * Setter for customer instance
*
- * @param customerId Customer id
+ * @param customer Customer instance
*/
- public void setCustomerId (final Long customerId);
+ public void setCustomer (final Customer customer);
/**
* Getter for created timestamp
* @param created Created timestamp
*/
public void setCreated (final Timestamp created);
+
+ /**
+ * Getter for list of ordered basket items
+ *
+ * @return List of items
+ */
+ public List<AddableBasketItem> getOrderedItems ();
+
+ /**
+ * Setter for list of ordered basket items
+ *
+ * @param itemList List of items
+ */
+ public void setOrderedItems (final List<AddableBasketItem> itemList);
}
package org.mxchange.jshopcore.model.order;
import java.sql.Timestamp;
+import java.util.List;
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.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;
/**
* An entity class for shop orders
private Long id;
/**
- * Customer id
+ * Customer instance
*/
@Basic (optional = false)
- @Column (name = "customer_id", length = 20, nullable = false)
- private Long customerId;
+ @JoinColumn (name = "customer_id", nullable = false, updatable = false)
+ private Customer customer;
/**
* Access key
@Column (nullable = false)
private Timestamp created;
+ /**
+ * Item list, don't save this
+ */
+ @Transient
+ private List<AddableBasketItem> itemList;
+
+ @Override
+ public String getAccessKey () {
+ return this.accessKey;
+ }
+
+ @Override
+ public void setAccessKey (final String accessKey) {
+ this.accessKey = accessKey;
+ }
+
@Override
public Timestamp getCreated () {
return this.created;
}
@Override
- public Long getCustomerId () {
- return this.customerId;
+ public Customer getCustomer () {
+ return this.customer;
}
@Override
- public void setCustomerId (final Long customerId) {
- this.customerId = customerId;
+ public void setCustomer (final Customer customer) {
+ this.customer = customer;
}
@Override
public void setId (final Long id) {
this.id = id;
}
+
+ @Override
+ public List<AddableBasketItem> getOrderedItems () {
+ return itemList;
+ }
+
+ @Override
+ public void setOrderedItems (final List<AddableBasketItem> itemList) {
+ this.itemList = itemList;
+ }
}
--- /dev/null
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+package org.mxchange.jshopcore.model.order.items;
+
+import javax.persistence.Table;
+import org.mxchange.jshopcore.model.basket.AddableBasketItem;
+import org.mxchange.jshopcore.model.basket.items.BaseItem;
+
+/**
+ * A general basket item
+ *
+ * @author Roland Haeder<roland@mxchange.org>
+ */
+@Table(name = "ordered_items")
+public class OrderItem extends BaseItem implements AddableBasketItem {
+ /**
+ * Serial number
+ */
+ private static final long serialVersionUID = 44_189_562_738_723_581L;
+
+ /**
+ * Default constructor
+ */
+ public OrderItem () {
+ }
+}