-
Notifications
You must be signed in to change notification settings - Fork 103
/
Order1.java
149 lines (128 loc) · 5.25 KB
/
Order1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* Copyright (c) 2007, 2020 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.ts.tests.jpa.core.annotations.nativequery;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.ColumnResult;
import jakarta.persistence.ConstructorResult;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityResult;
import jakarta.persistence.FieldResult;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import jakarta.persistence.SqlResultSetMapping;
import jakarta.persistence.SqlResultSetMappings;
import jakarta.persistence.Table;
/*
* Order1
*/
@SqlResultSetMappings({
@SqlResultSetMapping(name = "Order1ItemResults", entities = {
@EntityResult(entityClass = com.sun.ts.tests.jpa.core.annotations.nativequery.Order1.class),
@EntityResult(entityClass = com.sun.ts.tests.jpa.core.annotations.nativequery.Item.class) }),
@SqlResultSetMapping(name = "Order2ItemResults", entities = {
@EntityResult(entityClass = com.sun.ts.tests.jpa.core.annotations.nativequery.Order1.class, fields = {
@FieldResult(name = "id", column = "OID"),
@FieldResult(name = "totalPrice", column = "OPRICE"),
@FieldResult(name = "item", column = "OITEM") }) }, columns = {
@ColumnResult(name = "INAME") }),
@SqlResultSetMapping(name = "Order3ItemResults", entities = {
@EntityResult(entityClass = com.sun.ts.tests.jpa.core.annotations.nativequery.Order1.class, fields = {
@FieldResult(name = "id", column = "THISID"),
@FieldResult(name = "totalPrice", column = "THISPRICE"),
@FieldResult(name = "item", column = "THISITEM") }),
@EntityResult(entityClass = com.sun.ts.tests.jpa.core.annotations.nativequery.Item.class) }),
@SqlResultSetMapping(name = "Order4ItemResults", entities = {
@EntityResult(entityClass = com.sun.ts.tests.jpa.core.annotations.nativequery.Order1.class, fields = {
@FieldResult(name = "id", column = "OID"),
@FieldResult(name = "totalPrice", column = "OPRICE"),
@FieldResult(name = "item", column = "OITEM") }) }, columns = {
@ColumnResult(name = "INAME", type = String.class) }),
@SqlResultSetMapping(name = "Order5ItemResults", classes = {
@ConstructorResult(targetClass = com.sun.ts.tests.jpa.core.annotations.nativequery.Order2.class, columns = {
@ColumnResult(name = "OID"), @ColumnResult(name = "OPRICE"),
@ColumnResult(name = "OITEMNAME") }) }),
@SqlResultSetMapping(name = "PurchaseOrder1Results", classes = {
@ConstructorResult(targetClass = com.sun.ts.tests.jpa.core.annotations.nativequery.PurchaseOrder.class, columns = {
@ColumnResult(name = "OID"), @ColumnResult(name = "PTOTAL") }) }),
@SqlResultSetMapping(name = "PurchaseOrder2Results", classes = {
@ConstructorResult(targetClass = com.sun.ts.tests.jpa.core.annotations.nativequery.PurchaseOrder.class, columns = {
@ColumnResult(name = "PTOTAL") }) }) })
@Entity
@Table(name = "ORDER1")
public class Order1 implements java.io.Serializable {
// Instance variables
private int id;
private double totalPrice;
private Item item;
public Order1() {
}
public Order1(int id, double totalPrice) {
this.id = id;
this.totalPrice = totalPrice;
}
public Order1(int id) {
this.id = id;
}
// ====================================================================
// getters and setters for State fields
@Id
@Column(name = "ID")
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Column(name = "TOTALPRICE")
public double getTotalPrice() {
return totalPrice;
}
public void setTotalPrice(double price) {
this.totalPrice = price;
}
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "FK1_FOR_ITEM")
public Item getItem() {
return item;
}
public void setItem(Item v) {
item = v;
}
@Override
public int hashCode() {
return this.getItem().getId();
}
public boolean equals(Object obj) {
boolean result = false;
if ((obj != null) && (obj instanceof Order1)) {
Order1 o = (Order1) obj;
result = (o.id == this.id && o.getTotalPrice() == this.totalPrice
&& o.item.equals(this.item));
}
return result;
}
@Override
public String toString() {
StringBuilder result = new StringBuilder();
result.append(this.getClass().getSimpleName() + "[");
result.append("id: " + getId());
result.append(", total price: " + getTotalPrice());
result.append("]");
return result.toString();
}
}