1 package ejava.examples.ejbwar.inventory.bo;
2
3 import javax.json.bind.annotation.JsonbProperty;
4 import javax.json.bind.annotation.JsonbPropertyOrder;
5 import javax.json.bind.annotation.JsonbTransient;
6 import javax.persistence.Column;
7 import javax.persistence.Entity;
8 import javax.persistence.GeneratedValue;
9 import javax.persistence.GenerationType;
10 import javax.persistence.Id;
11 import javax.persistence.NamedQueries;
12 import javax.persistence.NamedQuery;
13 import javax.persistence.Table;
14 import javax.xml.bind.annotation.XmlAccessType;
15 import javax.xml.bind.annotation.XmlAccessorType;
16 import javax.xml.bind.annotation.XmlAttribute;
17 import javax.xml.bind.annotation.XmlElement;
18 import javax.xml.bind.annotation.XmlRootElement;
19 import javax.xml.bind.annotation.XmlTransient;
20 import javax.xml.bind.annotation.XmlType;
21
22 import com.fasterxml.jackson.annotation.JsonIgnore;
23 import com.fasterxml.jackson.annotation.JsonProperty;
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 @XmlRootElement(name="product", namespace=InventoryRepresentation.NAMESPACE)
49 @XmlType(name="product", namespace=InventoryRepresentation.NAMESPACE, propOrder={
50 "name",
51 "quantity",
52 "price"
53 })
54 @XmlAccessorType(XmlAccessType.PROPERTY)
55 @JsonbPropertyOrder({"id","name", "quantity", "price"})
56
57 @Entity
58 @Table(name="JAXRSINV_PRODUCT")
59 @NamedQueries({
60 @NamedQuery(name=Product.FIND_BY_NAME,
61 query="select p from Product p where p.name like :criteria")
62 })
63 public class Product extends InventoryRepresentation {
64 private static final long serialVersionUID = -4058695470696405277L;
65 public static final String FIND_BY_NAME = "Inventory.findProductByName";
66
67 @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
68 @Column(name="ID")
69 private int id;
70
71 @Column(name="NAME", nullable=false)
72 private String name;
73
74 @Column(name="QTY", nullable=true)
75 private Integer quantity;
76
77 @Column(name="PRICE", nullable=true)
78 private Double price;
79
80 @Column(name="PROTECTED_VALUE", length=36, nullable=false, updatable=false)
81 private String protectedValue;
82
83 public Product() {}
84 public Product(String name, Integer quantity, Double price) {
85 this.name=name;
86 this.quantity=quantity;
87 this.price=price;
88 }
89 public Product(String name) {
90 this(name, null, null);
91 }
92
93 @XmlAttribute(required=true)
94 public int getId() { return id;}
95 public void setId(int id) {
96 this.id = id;
97 }
98
99 @XmlAttribute(required=true, name="xmlName")
100 @JsonbProperty("jsonName")
101 @JsonProperty("jsonName")
102 public String getName() { return name; }
103 @JsonbProperty("jsonName")
104 public void setName(String name) {
105 this.name = name;
106 }
107
108 @XmlElement(required=false)
109 public Integer getQuantity() { return quantity; }
110 public void setQuantity(Integer quantity) {
111 this.quantity = quantity;
112 }
113
114 @XmlElement(required=false)
115 public Double getPrice() { return price; }
116 public void setPrice(Double price) {
117 this.price = price;
118 }
119
120 @XmlTransient
121 @JsonbTransient
122 public String getProtectedValue() { return protectedValue; }
123 @JsonbTransient
124 @JsonIgnore
125 public void setProtectedValue(String protectedValue) {
126 this.protectedValue = protectedValue;
127 }
128 public Product withProtectedValue(String string) {
129 setProtectedValue(string);
130 return this;
131 }
132
133 @Override
134 public String toString() {
135 StringBuilder builder = new StringBuilder();
136 builder.append("Product [id=").append(id)
137 .append(", name=").append(name)
138 .append(", quantity=").append(quantity)
139 .append(", price=").append(price)
140 .append(", protectedValue=")
141 .append(protectedValue).append("]");
142 return builder.toString();
143 }
144
145
146 }