|
| 1 | +/* |
| 2 | + * SPECjEnterprise2010 - a benchmark for enterprise middleware |
| 3 | + * Copyright 1995-2010 Standard Performance Evaluation Corporation |
| 4 | + * All Rights Reserved |
| 5 | + */ |
| 6 | + |
| 7 | +package org.hibernate.test.bytecode.enhancement.pk; |
| 8 | + |
| 9 | +import java.util.Calendar; |
| 10 | +import javax.persistence.Column; |
| 11 | +import javax.persistence.Entity; |
| 12 | +import javax.persistence.GeneratedValue; |
| 13 | +import javax.persistence.GenerationType; |
| 14 | +import javax.persistence.Id; |
| 15 | +import javax.persistence.IdClass; |
| 16 | +import javax.persistence.NamedQueries; |
| 17 | +import javax.persistence.NamedQuery; |
| 18 | +import javax.persistence.Table; |
| 19 | +import javax.persistence.TableGenerator; |
| 20 | +import javax.persistence.Temporal; |
| 21 | +import javax.persistence.TemporalType; |
| 22 | +import javax.persistence.Version; |
| 23 | +import javax.xml.bind.annotation.XmlAccessType; |
| 24 | +import javax.xml.bind.annotation.XmlAccessorType; |
| 25 | +import javax.xml.bind.annotation.XmlSchemaType; |
| 26 | + |
| 27 | +/** |
| 28 | + * Represent a work order that evolves through multiple processing stages. |
| 29 | + * |
| 30 | + */ |
| 31 | +@SuppressWarnings("serial") |
| 32 | + |
| 33 | +@NamedQueries({ |
| 34 | + @NamedQuery(name=WorkOrder.QUERY_ALL, |
| 35 | + query="select w from WorkOrder w"), |
| 36 | +// @NamedQuery(name=WorkOrder.QUERY_BY_STATUS, |
| 37 | +// query="select w from WorkOrder w where w.status = :status"), |
| 38 | + @NamedQuery(name=WorkOrder.QUERY_BY_OID_OLID, |
| 39 | + query="select w from WorkOrder w where w.location = :location and w.salesId = :salesId and w.orderLineId = :orderLineId"), |
| 40 | + @NamedQuery(name=WorkOrder.QUERY_COUNT, |
| 41 | + query="select COUNT(a) from WorkOrder a") |
| 42 | +}) |
| 43 | + |
| 44 | +@Entity |
| 45 | +@Table(name = "M_WORKORDER") |
| 46 | +@XmlAccessorType(XmlAccessType.PROPERTY) |
| 47 | +@IdClass(WorkOrderPK.class) |
| 48 | +public class WorkOrder { |
| 49 | + |
| 50 | + public static final String QUERY_ALL = "WorkOrder.selectAll"; |
| 51 | + //public static final String QUERY_BY_STATUS = "WorkOrder.selectByStatus"; |
| 52 | + public static final String QUERY_BY_OID_OLID = "WorkOrder.selectByOID_OLID"; |
| 53 | + public static final String QUERY_COUNT = "WorkOrder.count"; |
| 54 | + |
| 55 | + @Id |
| 56 | + @TableGenerator(name = "workorder", |
| 57 | + table = "U_SEQUENCES", |
| 58 | + pkColumnName = "S_ID", |
| 59 | + valueColumnName = "S_NEXTNUM", |
| 60 | + pkColumnValue = "workorder", |
| 61 | + allocationSize = 1000) |
| 62 | + @GeneratedValue(strategy = GenerationType.TABLE, generator = "workorder") |
| 63 | + @Column(name = "WO_NUMBER") |
| 64 | + private int id; |
| 65 | + |
| 66 | + @Id |
| 67 | + @Column(name = "WO_LOCATION") |
| 68 | + private int location; |
| 69 | + |
| 70 | + @Column(name = "WO_O_ID") |
| 71 | + private int salesId; |
| 72 | + |
| 73 | + @Column(name = "WO_OL_ID") |
| 74 | + private int orderLineId; |
| 75 | + |
| 76 | + @Column(name = "WO_ORIG_QTY") |
| 77 | + private int originalQuantity; |
| 78 | + |
| 79 | + @Column(name = "WO_COMP_QTY") |
| 80 | + private int completedQuantity; |
| 81 | + |
| 82 | + @Column(name = "WO_DUE_DATE") |
| 83 | + @Temporal(TemporalType.TIMESTAMP) |
| 84 | + private Calendar dueDate; |
| 85 | + |
| 86 | + @Column(name = "WO_START_DATE") |
| 87 | + @Temporal(TemporalType.TIMESTAMP) |
| 88 | + private Calendar startDate; |
| 89 | + |
| 90 | + @Column(name = "WO_ASSEMBLY_ID") |
| 91 | + private String assemblyId; |
| 92 | + |
| 93 | + @Version |
| 94 | + @Column(name = "WO_VERSION") |
| 95 | + private int version; |
| 96 | + |
| 97 | + /** |
| 98 | + * Public no-arg constructor required by JAXB specification. |
| 99 | + */ |
| 100 | + public WorkOrder() { |
| 101 | + this("", 1, 0, Calendar.getInstance()); |
| 102 | + } |
| 103 | + |
| 104 | + /** |
| 105 | + * Construct with proper state. The status at construction is OPEN. |
| 106 | + * @param location |
| 107 | + */ |
| 108 | + public WorkOrder(String assemblyId, int origQty, int location, Calendar dueDate) { |
| 109 | + if (origQty < 1) |
| 110 | + throw new IllegalArgumentException("WorkOrder can not be created " + |
| 111 | + " with original quantity " + origQty + ". Must be > 0"); |
| 112 | + if (dueDate == null) |
| 113 | + throw new IllegalArgumentException("WorkOrder can not be created " + |
| 114 | + " with null due Date"); |
| 115 | + this.assemblyId = assemblyId; |
| 116 | + originalQuantity = origQty; |
| 117 | + this.dueDate = dueDate; |
| 118 | + this.location=location; |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * Construct with proper state. The status at construction is OPEN. |
| 123 | + * @param location |
| 124 | + */ |
| 125 | + public WorkOrder(String assemblyId, int salesId, int oLineId, int origQty, |
| 126 | + int location, Calendar dueDate) { |
| 127 | + this(assemblyId, origQty, location, dueDate); |
| 128 | + this.salesId = salesId; |
| 129 | + orderLineId = oLineId; |
| 130 | + } |
| 131 | + |
| 132 | + public int getId() { |
| 133 | + return id; |
| 134 | + } |
| 135 | + |
| 136 | + public void setId(int id) { |
| 137 | + this.id = id; |
| 138 | + } |
| 139 | + |
| 140 | + public String getAssemblyId() { |
| 141 | + return assemblyId; |
| 142 | + } |
| 143 | + |
| 144 | + public int getCompletedQuantity() { |
| 145 | + return completedQuantity; |
| 146 | + } |
| 147 | + |
| 148 | + public void setCompletedQuantity(int compQty) { |
| 149 | + this.completedQuantity = compQty; |
| 150 | + } |
| 151 | + |
| 152 | + public Calendar getDueDate() { |
| 153 | + return dueDate; |
| 154 | + } |
| 155 | + |
| 156 | + public int getOrderLineId() { |
| 157 | + return orderLineId; |
| 158 | + } |
| 159 | + |
| 160 | + public int getOriginalQuantity() { |
| 161 | + return originalQuantity; |
| 162 | + } |
| 163 | + |
| 164 | + public int getSalesId() { |
| 165 | + return salesId; |
| 166 | + } |
| 167 | + |
| 168 | + public int getLocation() { |
| 169 | + return location; |
| 170 | + } |
| 171 | + |
| 172 | + @XmlSchemaType(name = "dateTime") |
| 173 | + public Calendar getStartDate() { |
| 174 | + return startDate; |
| 175 | + } |
| 176 | + |
| 177 | + public int getVersion() { |
| 178 | + return version; |
| 179 | + } |
| 180 | + |
| 181 | + // ====================================================================== |
| 182 | + // Processing methods |
| 183 | + // ====================================================================== |
| 184 | + /** |
| 185 | + * Moves to the next state of processing. |
| 186 | + * Return true if the new status can be updated again. |
| 187 | + */ |
| 188 | + public boolean update() { |
| 189 | + return true; |
| 190 | + } |
| 191 | + |
| 192 | + /** |
| 193 | + * When workOrder is finished, it will add the new object to inventory and |
| 194 | + * modify the state of workOrder to finished. |
| 195 | + */ |
| 196 | + public boolean setStatusCompleted() { |
| 197 | + return true; |
| 198 | + } |
| 199 | + |
| 200 | + public void advanceStatus() { |
| 201 | + } |
| 202 | + |
| 203 | + public void setStatusCancelled() { |
| 204 | + } |
| 205 | + |
| 206 | + public boolean equals(Object other) { |
| 207 | + if (this == other) |
| 208 | + return true; |
| 209 | + if (other == null || !(other instanceof WorkOrder)) |
| 210 | + return false; |
| 211 | + return id == ((WorkOrder)other).id; |
| 212 | + } |
| 213 | + |
| 214 | + public int hashCode() { |
| 215 | + final int PRIME = 31; |
| 216 | + return PRIME * new Integer(id).hashCode(); |
| 217 | + } |
| 218 | + |
| 219 | + |
| 220 | + public String toString() { |
| 221 | + return "WorkOrder:["+ getId() + "]" ; |
| 222 | + } |
| 223 | + |
| 224 | + public void setStartDate(Calendar instance) { |
| 225 | + startDate = instance; |
| 226 | + } |
| 227 | + |
| 228 | + public void setLocation(int location) { |
| 229 | + this.location = location; |
| 230 | + } |
| 231 | + |
| 232 | + public void setDueDate(Calendar dueDate) { |
| 233 | + this.dueDate = dueDate; |
| 234 | + } |
| 235 | + |
| 236 | + public void setAssemblyId(String assemblyId) { |
| 237 | + this.assemblyId = assemblyId; |
| 238 | + } |
| 239 | + |
| 240 | + public void setOriginalQuantity(int originalQuantity) { |
| 241 | + this.originalQuantity = originalQuantity; |
| 242 | + } |
| 243 | + |
| 244 | + public void setSalesId(int salesId) { |
| 245 | + this.salesId = salesId; |
| 246 | + } |
| 247 | + |
| 248 | + public void setOrderLineId(int orderLineId) { |
| 249 | + this.orderLineId = orderLineId; |
| 250 | + } |
| 251 | + |
| 252 | +} |
0 commit comments