Skip to content

Commit e7bd4ea

Browse files
barreirosebersole
authored andcommitted
HHH-10079 - Use enhanced property access for field/property attributes only
(cherry picked from commit 643c0b5)
1 parent 60c4c98 commit e7bd4ea

File tree

5 files changed

+364
-1
lines changed

5 files changed

+364
-1
lines changed

hibernate-core/src/main/java/org/hibernate/property/access/internal/PropertyAccessStrategyResolverStandardImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ public PropertyAccessStrategy resolvePropertyAccessStrategy(
3434
String explicitAccessStrategyName,
3535
EntityMode entityMode) {
3636

37-
if ( Managed.class.isAssignableFrom( containerClass ) ) {
37+
if ( ( BuiltInPropertyAccessStrategies.BASIC.getExternalName().equals( explicitAccessStrategyName ) ||
38+
BuiltInPropertyAccessStrategies.FIELD.getExternalName().equals( explicitAccessStrategyName ) ||
39+
BuiltInPropertyAccessStrategies.MIXED.getExternalName().equals( explicitAccessStrategyName ) ) &&
40+
Managed.class.isAssignableFrom( containerClass ) ) {
3841
return PropertyAccessStrategyEnhancedImpl.INSTANCE;
3942
}
4043

hibernate-core/src/test/java/org/hibernate/test/bytecode/enhancement/EnhancerTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.hibernate.test.bytecode.enhancement.lazy.basic.LazyBasicFieldAccessTestTask;
2727
import org.hibernate.test.bytecode.enhancement.lazy.basic.LazyBasicPropertyAccessTestTask;
2828
import org.hibernate.test.bytecode.enhancement.merge.CompositeMergeTestTask;
29+
import org.hibernate.test.bytecode.enhancement.pk.EmbeddedPKTestTask;
2930
import org.junit.Test;
3031

3132
/**
@@ -64,6 +65,10 @@ public void testMerge() {
6465
EnhancerTestUtils.runEnhancerTestTask( CompositeMergeTestTask.class );
6566
}
6667

68+
@Test
69+
public void testEmbeddedPK() {
70+
EnhancerTestUtils.runEnhancerTestTask( EmbeddedPKTestTask.class );
71+
}
6772

6873
@Test
6974
public void testFieldAccess() {
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.test.bytecode.enhancement.pk;
8+
9+
10+
import org.hibernate.Session;
11+
import org.hibernate.cfg.Configuration;
12+
import org.hibernate.cfg.Environment;
13+
14+
import org.hibernate.test.bytecode.enhancement.AbstractEnhancerTestTask;
15+
16+
/**
17+
* @author Gail Badner
18+
*/
19+
public class EmbeddedPKTestTask extends AbstractEnhancerTestTask {
20+
21+
private Long entityId;
22+
23+
public Class<?>[] getAnnotatedClasses() {
24+
return new Class<?>[] {WorkOrder.class, WorkOrderPK.class};
25+
}
26+
27+
public void prepare() {
28+
Configuration cfg = new Configuration();
29+
cfg.setProperty( Environment.ENABLE_LAZY_LOAD_NO_TRANS, "true" );
30+
cfg.setProperty( Environment.USE_SECOND_LEVEL_CACHE, "false" );
31+
super.prepare( cfg );
32+
33+
Session s = getFactory().openSession();
34+
s.beginTransaction();
35+
36+
WorkOrder wo = new WorkOrder( );
37+
s.persist( wo );
38+
39+
s.getTransaction().commit();
40+
s.clear();
41+
s.close();
42+
}
43+
44+
public void execute() {
45+
46+
}
47+
48+
protected void cleanup() {
49+
}
50+
51+
}
Lines changed: 252 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,252 @@
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+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* SPECjEnterprise2010 - a benchmark for enterprise middleware
3+
* Copyright 1995-2010 Standard Performance Evaluation Corporation
4+
* All Rights Reserved
5+
*
6+
* History:
7+
* Date ID, Company Description
8+
* ---------- ---------------- ----------------------------------------------
9+
* 2009/05/31 Anoop Gupta, Oracle Created for SPECjEnterprise2010
10+
*/
11+
12+
package org.hibernate.test.bytecode.enhancement.pk;
13+
14+
import java.io.Serializable;
15+
16+
@SuppressWarnings("serial")
17+
public class WorkOrderPK implements Serializable {
18+
private int id;
19+
private int location;
20+
21+
public WorkOrderPK() {
22+
}
23+
24+
public WorkOrderPK(int location, int id) {
25+
this.location = location;
26+
this.id = id;
27+
}
28+
29+
public boolean equals(Object other) {
30+
if (other == this) {
31+
return true;
32+
}
33+
if (!(other instanceof WorkOrderPK)) {
34+
return false;
35+
}
36+
WorkOrderPK wop = (WorkOrderPK) other;
37+
return (location == wop.location && id == wop.id);
38+
}
39+
40+
public int hashCode() {
41+
return id ^ location;
42+
}
43+
44+
public int getId() {
45+
return id;
46+
}
47+
48+
public int getLocation() {
49+
return location;
50+
}
51+
52+
}

0 commit comments

Comments
 (0)