1 package ejava.examples.ejbwar.inventory.bo;
2
3 import javax.persistence.Column;
4 import javax.persistence.Entity;
5 import javax.persistence.GeneratedValue;
6 import javax.persistence.GenerationType;
7 import javax.persistence.Id;
8 import javax.persistence.NamedQueries;
9 import javax.persistence.NamedQuery;
10 import javax.persistence.Table;
11 import javax.xml.bind.annotation.XmlAccessType;
12 import javax.xml.bind.annotation.XmlAccessorType;
13 import javax.xml.bind.annotation.XmlAttribute;
14 import javax.xml.bind.annotation.XmlElement;
15 import javax.xml.bind.annotation.XmlRootElement;
16 import javax.xml.bind.annotation.XmlType;
17
18
19
20
21
22 @XmlRootElement(name="product", namespace=InventoryRepresentation.NAMESPACE)
23 @XmlType(name="product", namespace=InventoryRepresentation.NAMESPACE, propOrder={
24 "name",
25 "quantity",
26 "price"
27 })
28 @XmlAccessorType(XmlAccessType.PROPERTY)
29
30 @Entity
31 @Table(name="JAXRSINV_PRODUCT")
32 @NamedQueries({
33 @NamedQuery(name=Product.FIND_BY_NAME,
34 query="select p from Product p where name like :criteria")
35 })
36 public class Product extends InventoryRepresentation {
37 private static final long serialVersionUID = -4058695470696405277L;
38 public static final String FIND_BY_NAME = "Inventory.findProductByName";
39
40 @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
41 @Column(name="ID")
42 private int id;
43
44 @Column(name="NAME", nullable=false)
45 private String name;
46
47 @Column(name="QTY", nullable=true)
48 private Integer quantity;
49
50 @Column(name="PRICE", nullable=true)
51 private Double price;
52
53 public Product() {}
54 public Product(String name, Integer quantity, Double price) {
55 this.name=name;
56 this.quantity=quantity;
57 this.price=price;
58 }
59 public Product(String name) {
60 this(name, null, null);
61 }
62
63 @XmlAttribute(required=true)
64 public int getId() { return id;}
65 public void setId(int id) {
66 this.id = id;
67 }
68
69 @XmlAttribute(required=true)
70 public String getName() { return name; }
71 public void setName(String name) {
72 this.name = name;
73 }
74
75 @XmlElement(required=false)
76 public Integer getQuantity() { return quantity; }
77 public void setQuantity(Integer quantity) {
78 this.quantity = quantity;
79 }
80
81 @XmlElement(required=false)
82 public Double getPrice() { return price; }
83 public void setPrice(Double price) {
84 this.price = price;
85 }
86 }