From 6126a768e5387d79605a680f24421a2662b02c24 Mon Sep 17 00:00:00 2001 From: Roland Haeder Date: Wed, 23 Sep 2015 12:39:39 +0200 Subject: [PATCH] Continued with JPA: - moved BaseItem and BasketItem to other package - added more JPA stuff (sorry) - updated jcore.jar MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by:Roland Häder Signed-off-by:Roland Häder --- lib/jcore.jar | Bin 31130 -> 31729 bytes nbproject/project.properties | 4 +- .../jcore/model/contact/CustomerContact.java | 30 ++++++ .../exceptions/QueryNotExecutedException.java | 2 + .../model/basket/AddableBasketItem.java | 12 +-- .../{item => basket/items}/BaseItem.java | 38 +++++--- .../{item => basket/items}/BasketItem.java | 4 +- .../model/category/BaseCategory.java | 22 +++++ .../jshopcore/model/category/Category.java | 7 ++ .../jshopcore/model/customer/Customer.java | 20 ++-- .../model/customer/CustomerUtils.java | 92 +++++++++--------- .../model/customer/ShopCustomer.java | 24 +++-- .../jshopcore/model/order/Orderable.java | 43 ++++++-- .../jshopcore/model/order/ShopOrder.java | 45 +++++++-- .../model/order/items/OrderItem.java | 40 ++++++++ 15 files changed, 290 insertions(+), 93 deletions(-) create mode 100644 src/org/mxchange/jcore/model/contact/CustomerContact.java rename src/org/mxchange/jshopcore/model/{item => basket/items}/BaseItem.java (77%) rename src/org/mxchange/jshopcore/model/{item => basket/items}/BasketItem.java (95%) create mode 100644 src/org/mxchange/jshopcore/model/order/items/OrderItem.java diff --git a/lib/jcore.jar b/lib/jcore.jar index ead5916a21197864b7915b3c83d96c971ff478c8..e17de0c88e23d89b1f0953bcc4c3f8114d699b84 100644 GIT binary patch delta 6202 zcmZ{o30xJ|6~@2&-h;<7C?Jb~3WyK!fuL*xA_5}r8ns4oY2v;F6+{sm>uB3_iP~r; z(TJ(h#;Qp*jUuQ`teT{;+BS``&0>;9tBp;Uq%LV$(gu#QG;Yi2LFx$ortiC2CKuQQ!4pvT9E>=OTf?2s)h3G6pS%$F+XQi=6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xfVx=kqPh)R5 ziGe73@Z^L$1!9gP$v*6NBFV9n%p;Qd5lF0*NN`5ab8%V_`ryg6lPq#1`MEPmuAO8l zku*dgk(n3mKMqjBVr3R#4$iYrwwxwg5n(bbO%s&%I0aq4{i;?4uZpj~D?Ms+4!V3h z$yy>=7lFh|2?d^YBq^|w7~;VoN*GDIGf9D+Dj+wh+nI2qad%D{#af{xCTFi)>C2t&Su|orA8(PO^hYc19qv(rdx*hcf19 z{~xCml9RaVL+I6tRL)*cptu#W&!KmHV&E`JjwR?r6KXT&amsoGeeMVvF&(&}(}j3b7cbCuoJ71hg%t4$dE#{xh&Q@CfWpoUun;Hl zYvSYg4st*|UZMg&o~=vx4UjN`USUpA7x~=2nS8=K=M9w5dq)Qbvhza@bOb_{@pdlb z#c$<1LNs2sUY}@G8O_PR#P0BR;Ko*1FCuN|)fHXVJ3&C=O^AXPTPXynn=N8g|s>D7B3-n0sDg?(rn^JPOpUQHCh|Gu4HrYb9Rb9-I9?9;XuDMR zxl0t87wgN6SimjlOGCWWiLmVM%1%;tva(a?VB`L&^zy_yP1!w^ov!+4sQ#JC&Qf+y zWoIipXR@luRTX*4&R2GUvI~`6gkEytVv1}A2&ncF)!qj;m{+D{=k=GZWf({v6!f8m z{W&I$WT`JUj*_~6(|D=ZG)W7z2m->Tcv!t$BUMKYv z%O^?w@$w~7-?L(Y)TdWi@$86I$VY Q?+P36W=n?W+!Aj7Kkb@Lj{pDw diff --git a/nbproject/project.properties b/nbproject/project.properties index 4776cf1..5655ed7 100644 --- a/nbproject/project.properties +++ b/nbproject/project.properties @@ -40,8 +40,8 @@ jar.index=${jnlp.enabled} 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 diff --git a/src/org/mxchange/jcore/model/contact/CustomerContact.java b/src/org/mxchange/jcore/model/contact/CustomerContact.java new file mode 100644 index 0000000..8f02c12 --- /dev/null +++ b/src/org/mxchange/jcore/model/contact/CustomerContact.java @@ -0,0 +1,30 @@ +/* + * 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/QueryNotExecutedException.java b/src/org/mxchange/jshopcore/exceptions/QueryNotExecutedException.java index afd51fa..a92211e 100644 --- a/src/org/mxchange/jshopcore/exceptions/QueryNotExecutedException.java +++ b/src/org/mxchange/jshopcore/exceptions/QueryNotExecutedException.java @@ -23,7 +23,9 @@ 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 diff --git a/src/org/mxchange/jshopcore/model/basket/AddableBasketItem.java b/src/org/mxchange/jshopcore/model/basket/AddableBasketItem.java index 7ed0335..1c29978 100644 --- a/src/org/mxchange/jshopcore/model/basket/AddableBasketItem.java +++ b/src/org/mxchange/jshopcore/model/basket/AddableBasketItem.java @@ -55,18 +55,18 @@ public interface AddableBasketItem extends Serializable { 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 diff --git a/src/org/mxchange/jshopcore/model/item/BaseItem.java b/src/org/mxchange/jshopcore/model/basket/items/BaseItem.java similarity index 77% rename from src/org/mxchange/jshopcore/model/item/BaseItem.java rename to src/org/mxchange/jshopcore/model/basket/items/BaseItem.java index 8e4591e..de2f2c0 100644 --- a/src/org/mxchange/jshopcore/model/item/BaseItem.java +++ b/src/org/mxchange/jshopcore/model/basket/items/BaseItem.java @@ -14,9 +14,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mxchange.jshopcore.model.item; +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; @@ -26,6 +32,7 @@ import org.mxchange.jshopcore.model.product.Product; * * @author Roland Haeder */ +@Entity(name = "item") public abstract class BaseItem implements AddableBasketItem, Comparable { /** @@ -36,26 +43,33 @@ public abstract class BaseItem implements AddableBasketItem, Comparable item.getItemId()) { + } else if (this.getProductId() > item.getProductId()) { // This id is larger than compared to return -1; } @@ -99,13 +113,13 @@ public abstract class BaseItem implements AddableBasketItem, Comparable. */ -package org.mxchange.jshopcore.model.item; +package org.mxchange.jshopcore.model.basket.items; import org.mxchange.jshopcore.model.basket.AddableBasketItem; import org.mxchange.jshopcore.model.product.Product; @@ -52,7 +52,7 @@ public class BasketItem extends BaseItem implements AddableBasketItem { } // Copy all neccessary values - this.setItemId(product.getId()); + this.setProductId(product.getId()); this.setItemType("product"); //NOI18N // Copy instance diff --git a/src/org/mxchange/jshopcore/model/category/BaseCategory.java b/src/org/mxchange/jshopcore/model/category/BaseCategory.java index bb371cd..aa2757b 100644 --- a/src/org/mxchange/jshopcore/model/category/BaseCategory.java +++ b/src/org/mxchange/jshopcore/model/category/BaseCategory.java @@ -17,13 +17,22 @@ 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 */ @@ -32,16 +41,22 @@ public abstract class BaseCategory implements Category, Comparable { /** * 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; /** @@ -90,6 +105,13 @@ public abstract class BaseCategory implements Category, Comparable { return 1; } + @Override + public void copyAll (final Category category) { + // Copy all data + this.setParentId(category.getParentId()); + this.setTitle(category.getTitle()); + } + /** * Id number of category * diff --git a/src/org/mxchange/jshopcore/model/category/Category.java b/src/org/mxchange/jshopcore/model/category/Category.java index f91422b..5f871c6 100644 --- a/src/org/mxchange/jshopcore/model/category/Category.java +++ b/src/org/mxchange/jshopcore/model/category/Category.java @@ -25,6 +25,13 @@ import java.io.Serializable; */ 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 diff --git a/src/org/mxchange/jshopcore/model/customer/Customer.java b/src/org/mxchange/jshopcore/model/customer/Customer.java index d3a1620..559c112 100644 --- a/src/org/mxchange/jshopcore/model/customer/Customer.java +++ b/src/org/mxchange/jshopcore/model/customer/Customer.java @@ -16,6 +16,7 @@ */ package org.mxchange.jshopcore.model.customer; +import java.io.Serializable; import java.sql.Timestamp; import org.mxchange.jcore.model.contact.Contact; @@ -24,21 +25,28 @@ import org.mxchange.jcore.model.contact.Contact; * * @author Roland Haeder */ -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 diff --git a/src/org/mxchange/jshopcore/model/customer/CustomerUtils.java b/src/org/mxchange/jshopcore/model/customer/CustomerUtils.java index 0a58bd4..ce15d8f 100644 --- a/src/org/mxchange/jshopcore/model/customer/CustomerUtils.java +++ b/src/org/mxchange/jshopcore/model/customer/CustomerUtils.java @@ -16,13 +16,14 @@ */ 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 @@ -40,21 +41,25 @@ public class CustomerUtils extends BaseFrameworkSystem { /** * 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; @@ -73,23 +78,19 @@ public class CustomerUtils extends BaseFrameworkSystem { // 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; } @@ -97,22 +98,25 @@ public class CustomerUtils extends BaseFrameworkSystem { /** * 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; @@ -123,28 +127,24 @@ public class CustomerUtils extends BaseFrameworkSystem { // 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; } diff --git a/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java b/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java index 9b8331b..6695356 100644 --- a/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java +++ b/src/org/mxchange/jshopcore/model/customer/ShopCustomer.java @@ -29,6 +29,7 @@ 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; /** * A shop customer class. @@ -37,7 +38,7 @@ import org.mxchange.jcore.model.contact.BaseContact; */ @Entity (name = "Customer") @Table (name = "customer") -public class ShopCustomer extends BaseContact implements Customer { +public class ShopCustomer implements Customer { /** * Serial number @@ -58,7 +59,7 @@ public class ShopCustomer extends BaseContact implements Customer { @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 @@ -100,13 +101,24 @@ public class ShopCustomer extends BaseContact implements Customer { 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 diff --git a/src/org/mxchange/jshopcore/model/order/Orderable.java b/src/org/mxchange/jshopcore/model/order/Orderable.java index 93f75ff..381c43e 100644 --- a/src/org/mxchange/jshopcore/model/order/Orderable.java +++ b/src/org/mxchange/jshopcore/model/order/Orderable.java @@ -18,6 +18,9 @@ package org.mxchange.jshopcore.model.order; 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 @@ -26,6 +29,20 @@ import java.sql.Timestamp; */ 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 * @@ -41,18 +58,18 @@ public interface Orderable extends Serializable { 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 @@ -67,4 +84,18 @@ public interface Orderable extends Serializable { * @param created Created timestamp */ public void setCreated (final Timestamp created); + + /** + * Getter for list of ordered basket items + * + * @return List of items + */ + public List getOrderedItems (); + + /** + * Setter for list of ordered basket items + * + * @param itemList List of items + */ + public void setOrderedItems (final List itemList); } diff --git a/src/org/mxchange/jshopcore/model/order/ShopOrder.java b/src/org/mxchange/jshopcore/model/order/ShopOrder.java index 65361ee..1af471a 100644 --- a/src/org/mxchange/jshopcore/model/order/ShopOrder.java +++ b/src/org/mxchange/jshopcore/model/order/ShopOrder.java @@ -17,15 +17,20 @@ 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 @@ -49,11 +54,11 @@ public class ShopOrder implements Orderable { 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 @@ -70,6 +75,22 @@ public class ShopOrder implements Orderable { @Column (nullable = false) private Timestamp created; + /** + * Item list, don't save this + */ + @Transient + private List 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; @@ -81,13 +102,13 @@ public class ShopOrder implements Orderable { } @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 @@ -99,4 +120,14 @@ public class ShopOrder implements Orderable { public void setId (final Long id) { this.id = id; } + + @Override + public List getOrderedItems () { + return itemList; + } + + @Override + public void setOrderedItems (final List itemList) { + this.itemList = itemList; + } } diff --git a/src/org/mxchange/jshopcore/model/order/items/OrderItem.java b/src/org/mxchange/jshopcore/model/order/items/OrderItem.java new file mode 100644 index 0000000..c12cf50 --- /dev/null +++ b/src/org/mxchange/jshopcore/model/order/items/OrderItem.java @@ -0,0 +1,40 @@ +/* + * 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.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 + */ +@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 () { + } +} -- 2.39.5