summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity
diff options
context:
space:
mode:
Diffstat (limited to 'Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity')
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Customer.java104
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/LineItem.java132
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Order.java183
-rw-r--r--Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Product.java93
4 files changed, 512 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Customer.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Customer.java
new file mode 100644
index 0000000..c986436
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Customer.java
@@ -0,0 +1,104 @@
+package examples.shop.impl.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * This entity represents customer details.
+ */
+@Entity
+public class Customer implements java.io.Serializable {
+
+ private String customerID;
+
+ private String name;
+
+ private String password;
+
+ private String address;
+
+ private double discount;
+
+ /**
+ * Returns the Id of the customer
+ */
+ @Id
+ public String getCustomerID() {
+ return customerID;
+ }
+
+ /**
+ * Sets the id of the customer
+ */
+ public void setCustomerID(String customerId) {
+ this.customerID = customerId;
+ }
+ /**
+ * Returns the name of the customer
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name of the customer
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Returns the password of the customer
+ */
+ public String getPassword() {
+ return password;
+ }
+
+ /**
+ * Sets the password of the customer
+ */
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ /**
+ * Returns the address of the customer
+ */
+ public String getAddress() {
+ return address;
+ }
+
+ /**
+ * Sets the address of the customer
+ */
+ public void setAddress(String address) {
+ this.address = address;
+ }
+
+ public double getDiscount() {
+ return discount;
+ }
+
+ public void setDiscount(double discount) {
+ this.discount = discount;
+ }
+
+ public Customer() {
+ }
+
+ /**
+ * Called when new data is created.
+ *
+ * We need to initialize our Bean's state with the parameters
+ * passed from the client by calling our own abstract set
+ * methods. The Container can then inspect our Bean and
+ * INSERT the corresponding database entries.
+ */
+ public void init(String id, String name, String password, String address) {
+ setCustomerID(id);
+ setName(name);
+ setAddress(address);
+ setPassword(password);
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/LineItem.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/LineItem.java
new file mode 100644
index 0000000..447cc75
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/LineItem.java
@@ -0,0 +1,132 @@
+package examples.shop.impl.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToOne;
+
+
+/**
+ * A line item entity is a quantity of a single product.
+ *
+ * Instances of this class are used for both in-memory represenation
+ * of carts and the persistent representation of orders in
+ * the database
+ */
+@Entity
+public class LineItem implements java.io.Serializable {
+
+ private String id;
+
+ /** the product */
+ private Product product;
+
+ /** Number of items */
+ private int quantity;
+
+ /** Amount of the discount for each item */
+ private double discount;
+
+ /**
+ * Constructor
+ * @param productitem
+ * @param number of items
+ * @Param discount for each item
+ */
+ public LineItem(Product productItem, int quantity, double discount) {
+ System.out.println("LineItem(...) called");
+ this.product = productItem;
+ this.quantity = quantity;
+ this.discount = discount;
+ }
+
+ public LineItem() {
+ System.out.println("New LineItem created.");
+ }
+
+ /**
+ * The id number of this line item. This is our primary key as well.
+ *
+ * @return the id
+ */
+ @Id
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * Sets the id
+ */
+ public void setId(String id) {
+ this.id = id;
+ }
+
+
+ /**
+ * @return the productitem.
+ * productitem has product id, name of the product and description
+ */
+ @OneToOne
+ public Product getProduct() {
+ System.out.println("LineItem.getProduct() called.");
+ return product;
+ }
+
+ /**
+ * @param productItem.
+ */
+ public void setProduct(Product product) {
+ System.out.println("LineItem.setProduct() called.");
+ this.product = product;
+ }
+
+ /**
+ * @return the number of items.
+ */
+ public int getQuantity() {
+ System.out.println("LineItem.getQuantity() called.");
+ return quantity;
+ }
+
+ /**
+ * @param the number of items.
+ */
+ public void setQuantity(int quantity) {
+ System.out.println("LineItem.setQuantity() called.");
+ this.quantity = quantity;
+ }
+
+ /**
+ * @return the base price. The base price is the
+ * product's price times the quantity ordered. This
+ * figure does not take discounts into consideration.
+ */
+ public double basePrice() {
+ System.out.println("LineItem.getBasePrice() called.");
+ return quantity * product.getBasePrice();
+ }
+
+ /**
+ * @return the discount that the customer gets on
+ * this order.
+ *
+ * Note: The discount is a whole number, not
+ * a percentage discount.
+ */
+ public double getDiscount() {
+ System.out.println("LineItem.getDiscount() called.");
+ return discount;
+ }
+
+ /**
+ * @param the discount that the customer gets on
+ * this order.
+ *
+ * Note: The discount is a whole number, not
+ * a percentage discount.
+ */
+ public void setDiscount(double discount) {
+ System.out.println("LineItem.setDiscount(" + discount + ") called.");
+ this.discount = discount;
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Order.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Order.java
new file mode 100644
index 0000000..8986495
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Order.java
@@ -0,0 +1,183 @@
+package examples.shop.impl.entity;
+
+import java.sql.Timestamp;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.persistence.CascadeType;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+import javax.persistence.Table;
+
+/**
+ * This entity represents an order placed for goods.
+ *
+ * Note: This entity could easily be extended to include other things, such as:
+ * <ul>
+ * <li>Shipping charges
+ * <li>Shipping address vs. Billing address
+ * <li>A date which this order is scheduled to be completed/shipped.
+ * </ul>
+ */
+
+@Entity
+@Table(name = "ORDERS")
+public class Order {
+
+ public enum Status {
+ Submitted, Unverified, Approved, Shipping, Delivered, Returned
+ };
+
+ private String orderId;
+
+ private List<LineItem> lineItems;
+
+ private Customer customer;
+
+ private Timestamp orderDate;
+
+ private Status status;
+
+ private double taxes;
+
+ private double subTotal;
+
+ /**
+ * This order's identification number. It's also our Primary Key.
+ *
+ * @return order id
+ */
+ @Id
+ public String getOrderID() {
+ return orderId;
+ }
+
+ /**
+ * Sets the order id of an order
+ */
+ public void setOrderID(String id) {
+ orderId = id;
+ }
+
+ /**
+ * This represents a one-to-many relationship to the
+ * line items in the order. Persisting the order cascades
+ * to the line items.
+ *
+ * @return the set of order line items
+ */
+ @OneToMany(cascade = CascadeType.PERSIST)
+ public List<LineItem> getLineItems() {
+ return lineItems;
+ }
+
+ /**
+ * Sets set of the order line items
+ */
+ public void setLineItems(List<LineItem> lineItems) {
+ this.lineItems = lineItems;
+ }
+
+ /**
+ * @returns the Customer who placed this Order.
+ */
+ public Customer getCustomer() {
+ return customer;
+ }
+
+ /**
+ * set customer who placed this order.
+ */
+ public void setCustomer(Customer customer) {
+ this.customer = customer;
+ }
+
+ /**
+ * Returns the date this order was placed.
+ */
+ public Timestamp getOrderDate() {
+ return orderDate;
+ }
+
+ /**
+ * Sets the date this order
+ */
+ public void setOrderDate(Timestamp orderDate) {
+ this.orderDate = orderDate;
+ }
+
+ /**
+ * @return status information about the order.
+ */
+ public Status getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets status information about the order.
+ */
+ public void setStatus(Status status) {
+ this.status = status;
+ }
+
+ /**
+ * Sets the subtotal of this order
+ */
+
+ public double getSubTotal() {
+ return subTotal;
+ }
+
+ /**
+ * Returns the subtotal of this order
+ */
+ public void setSubTotal(double subTotal) {
+ this.subTotal = subTotal;
+ }
+
+ /**
+ * Returns taxes of this order
+ */
+ public double getTaxes() {
+ return taxes;
+ }
+
+ /**
+ * Sets the taxes of this order
+ */
+ public void setTaxes(double taxes) {
+ this.taxes = taxes;
+ }
+
+ /**
+ * Returns the subtotal rice of the entire order, ie. the sum of
+ * the base prices of all line items in this order.
+ */
+ public double totalPrice() {
+ double totalPrice = 0;
+ for (Iterator<LineItem> iter = getLineItems().iterator(); iter
+ .hasNext();) {
+ LineItem item = iter.next();
+ totalPrice += item.getProduct().basePrice;
+ }
+ return totalPrice;
+ }
+
+ /**
+ * Called to initialize a new order entity
+ *
+ * We need to initialize our entity's state with the parameters passed from
+ * the client.
+ */
+ public void init(String orderID, Customer customer, Status status,
+ double subTotal, double taxes) {
+ System.out.println("Order.init(" + orderID + ") called");
+ setOrderID(orderID);
+ setOrderDate(new java.sql.Timestamp(System.currentTimeMillis()));
+ setStatus(status);
+ setSubTotal(subTotal);
+ setTaxes(taxes);
+ }
+
+}
diff --git a/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Product.java b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Product.java
new file mode 100644
index 0000000..99fb29a
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/EJB 3.0 Code/Gerald Examples/src/examples/shop/impl/entity/Product.java
@@ -0,0 +1,93 @@
+package examples.shop.impl.entity;
+
+import javax.persistence.Entity;
+import javax.persistence.Id;
+
+/**
+ * Entity
+ *
+ * This is a product that's persistent. It has an ID #, a name,
+ * a description, and a base price.
+ */
+@Entity
+public class Product implements java.io.Serializable {
+
+ public String name;
+ public String description;
+ public double basePrice;
+ public String productID;
+
+ public Product() {
+ }
+
+ /**
+ * @return the product id.
+ */
+ @Id
+ public String getProductID() {
+ return productID;
+ }
+
+ /**
+ * Sets the product id.
+ */
+ public void setProductID(String productID) {
+ this.productID = productID;
+ }
+
+ /**
+ * @return the name of the product.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name of the product.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the description of the product.
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Sets the description of the product.
+ */
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ /**
+ * @return the base price of the product.
+ */
+ public double getBasePrice() {
+ return basePrice;
+ }
+
+ /**
+ * Sets the base price of the product.
+ */
+ public void setBasePrice(double price) {
+ this.basePrice = price;
+ }
+
+
+ /**
+ * This is the initialization method
+ */
+ public Product init(String productID, String name, String description,
+ double basePrice) {
+ this.productID = productID;
+ this.name = name;
+ this.description = description;
+ this.basePrice = basePrice;
+ return this;
+ }
+
+}