@@ -182,52 +182,44 @@ public boolean isSame(Object x, Object y) throws HibernateException {
182
182
}
183
183
184
184
@ Override
185
- public boolean isEqual (Object x , Object y )
186
- throws HibernateException {
185
+ public boolean isEqual (final Object x , final Object y ) throws HibernateException {
187
186
if ( x == y ) {
188
187
return true ;
189
188
}
190
189
if ( x == null || y == null ) {
191
190
return false ;
192
191
}
193
- Object [] xvalues = getPropertyValues ( x , entityMode );
194
- Object [] yvalues = getPropertyValues ( y , entityMode );
195
192
for ( int i = 0 ; i < propertySpan ; i ++ ) {
196
- if ( !propertyTypes [i ].isEqual ( xvalues [ i ], yvalues [ i ] ) ) {
193
+ if ( !propertyTypes [i ].isEqual ( getPropertyValue ( x , i ), getPropertyValue ( y , i ) ) ) {
197
194
return false ;
198
195
}
199
196
}
200
197
return true ;
201
198
}
202
199
203
200
@ Override
204
- public boolean isEqual (Object x , Object y , SessionFactoryImplementor factory )
205
- throws HibernateException {
201
+ public boolean isEqual (final Object x , final Object y , final SessionFactoryImplementor factory ) throws HibernateException {
206
202
if ( x == y ) {
207
203
return true ;
208
204
}
209
205
if ( x == null || y == null ) {
210
206
return false ;
211
207
}
212
- Object [] xvalues = getPropertyValues ( x , entityMode );
213
- Object [] yvalues = getPropertyValues ( y , entityMode );
214
208
for ( int i = 0 ; i < propertySpan ; i ++ ) {
215
- if ( !propertyTypes [i ].isEqual ( xvalues [ i ], yvalues [ i ] , factory ) ) {
209
+ if ( !propertyTypes [i ].isEqual ( getPropertyValue ( x , i ), getPropertyValue ( y , i ) , factory ) ) {
216
210
return false ;
217
211
}
218
212
}
219
213
return true ;
220
214
}
221
215
222
216
@ Override
223
- public int compare (Object x , Object y ) {
217
+ public int compare (final Object x , final Object y ) {
224
218
if ( x == y ) {
225
219
return 0 ;
226
220
}
227
- Object [] xvalues = getPropertyValues ( x , entityMode );
228
- Object [] yvalues = getPropertyValues ( y , entityMode );
229
221
for ( int i = 0 ; i < propertySpan ; i ++ ) {
230
- int propertyCompare = propertyTypes [i ].compare ( xvalues [ i ], yvalues [ i ] );
222
+ int propertyCompare = propertyTypes [i ].compare ( getPropertyValue ( x , i ), getPropertyValue ( y , i ) );
231
223
if ( propertyCompare != 0 ) {
232
224
return propertyCompare ;
233
225
}
@@ -240,11 +232,10 @@ public boolean isMethodOf(Method method) {
240
232
}
241
233
242
234
@ Override
243
- public int getHashCode (Object x ) {
235
+ public int getHashCode (final Object x ) {
244
236
int result = 17 ;
245
- Object [] values = getPropertyValues ( x , entityMode );
246
237
for ( int i = 0 ; i < propertySpan ; i ++ ) {
247
- Object y = values [ i ] ;
238
+ Object y = getPropertyValue ( x , i ) ;
248
239
result *= 37 ;
249
240
if ( y != null ) {
250
241
result += propertyTypes [i ].getHashCode ( y );
@@ -254,11 +245,10 @@ public int getHashCode(Object x) {
254
245
}
255
246
256
247
@ Override
257
- public int getHashCode (Object x , SessionFactoryImplementor factory ) {
248
+ public int getHashCode (final Object x , final SessionFactoryImplementor factory ) {
258
249
int result = 17 ;
259
- Object [] values = getPropertyValues ( x , entityMode );
260
250
for ( int i = 0 ; i < propertySpan ; i ++ ) {
261
- Object y = values [ i ] ;
251
+ Object y = getPropertyValue ( x , i ) ;
262
252
result *= 37 ;
263
253
if ( y != null ) {
264
254
result += propertyTypes [i ].getHashCode ( y , factory );
@@ -268,48 +258,42 @@ public int getHashCode(Object x, SessionFactoryImplementor factory) {
268
258
}
269
259
270
260
@ Override
271
- public boolean isDirty (Object x , Object y , SessionImplementor session )
272
- throws HibernateException {
261
+ public boolean isDirty (final Object x , final Object y , final SessionImplementor session ) throws HibernateException {
273
262
if ( x == y ) {
274
263
return false ;
275
264
}
276
265
if ( x == null || y == null ) {
277
266
return true ;
278
267
}
279
- Object [] xvalues = getPropertyValues ( x , entityMode );
280
- Object [] yvalues = getPropertyValues ( y , entityMode );
281
- for ( int i = 0 ; i < xvalues .length ; i ++ ) {
282
- if ( propertyTypes [i ].isDirty ( xvalues [i ], yvalues [i ], session ) ) {
268
+ for ( int i = 0 ; i < propertySpan ; i ++ ) {
269
+ if ( propertyTypes [i ].isDirty ( getPropertyValue ( x , i ), getPropertyValue ( y , i ), session ) ) {
283
270
return true ;
284
271
}
285
272
}
286
273
return false ;
287
274
}
288
275
289
- public boolean isDirty (Object x , Object y , boolean [] checkable , SessionImplementor session )
290
- throws HibernateException {
276
+ public boolean isDirty (final Object x , final Object y , final boolean [] checkable , final SessionImplementor session ) throws HibernateException {
291
277
if ( x == y ) {
292
278
return false ;
293
279
}
294
280
if ( x == null || y == null ) {
295
281
return true ;
296
282
}
297
- Object [] xvalues = getPropertyValues ( x , entityMode );
298
- Object [] yvalues = getPropertyValues ( y , entityMode );
299
283
int loc = 0 ;
300
- for ( int i = 0 ; i < xvalues . length ; i ++ ) {
284
+ for ( int i = 0 ; i < propertySpan ; i ++ ) {
301
285
int len = propertyTypes [i ].getColumnSpan ( session .getFactory () );
302
286
if ( len <= 1 ) {
303
287
final boolean dirty = ( len == 0 || checkable [loc ] ) &&
304
- propertyTypes [i ].isDirty ( xvalues [ i ], yvalues [ i ] , session );
288
+ propertyTypes [i ].isDirty ( getPropertyValue ( x , i ), getPropertyValue ( y , i ) , session );
305
289
if ( dirty ) {
306
290
return true ;
307
291
}
308
292
}
309
293
else {
310
294
boolean [] subcheckable = new boolean [len ];
311
295
System .arraycopy ( checkable , loc , subcheckable , 0 , len );
312
- final boolean dirty = propertyTypes [i ].isDirty ( xvalues [ i ], yvalues [ i ] , subcheckable , session );
296
+ final boolean dirty = propertyTypes [i ].isDirty ( getPropertyValue ( x , i ), getPropertyValue ( y , i ) , subcheckable , session );
313
297
if ( dirty ) {
314
298
return true ;
315
299
}
@@ -320,23 +304,20 @@ public boolean isDirty(Object x, Object y, boolean[] checkable, SessionImplement
320
304
}
321
305
322
306
@ Override
323
- public boolean isModified (Object old , Object current , boolean [] checkable , SessionImplementor session )
324
- throws HibernateException {
325
-
307
+ public boolean isModified (final Object old , final Object current , final boolean [] checkable , final SessionImplementor session ) throws HibernateException {
326
308
if ( current == null ) {
327
309
return old != null ;
328
310
}
329
311
if ( old == null ) {
330
312
return true ;
331
313
}
332
- Object [] currentValues = getPropertyValues ( current , session );
333
314
Object [] oldValues = ( Object [] ) old ;
334
315
int loc = 0 ;
335
- for ( int i = 0 ; i < currentValues . length ; i ++ ) {
316
+ for ( int i = 0 ; i < propertySpan ; i ++ ) {
336
317
int len = propertyTypes [i ].getColumnSpan ( session .getFactory () );
337
318
boolean [] subcheckable = new boolean [len ];
338
319
System .arraycopy ( checkable , loc , subcheckable , 0 , len );
339
- if ( propertyTypes [i ].isModified ( oldValues [i ], currentValues [ i ] , subcheckable , session ) ) {
320
+ if ( propertyTypes [i ].isModified ( oldValues [i ], getPropertyValue ( current , i ) , subcheckable , session ) ) {
340
321
return true ;
341
322
}
342
323
loc += len ;
@@ -410,13 +391,26 @@ public Object nullSafeGet(ResultSet rs, String name, SessionImplementor session,
410
391
@ Override
411
392
public Object getPropertyValue (Object component , int i , SessionImplementor session )
412
393
throws HibernateException {
413
- return getPropertyValue ( component , i , entityMode );
394
+ return getPropertyValue ( component , i );
414
395
}
415
-
416
396
public Object getPropertyValue (Object component , int i , EntityMode entityMode )
417
397
throws HibernateException {
418
- return componentTuplizer . getPropertyValue ( component , i );
398
+ return getPropertyValue ( component , i );
419
399
}
400
+
401
+ public Object getPropertyValue (Object component , int i )
402
+ throws HibernateException {
403
+ if ( component instanceof Object [] ) {
404
+ // A few calls to hashCode pass the property values already in an
405
+ // Object[] (ex: QueryKey hash codes for cached queries).
406
+ // It's easiest to just check for the condition here prior to
407
+ // trying reflection.
408
+ return (( Object [] ) component )[i ];
409
+ } else {
410
+ return componentTuplizer .getPropertyValue ( component , i );
411
+ }
412
+ }
413
+
420
414
@ Override
421
415
public Object [] getPropertyValues (Object component , SessionImplementor session )
422
416
throws HibernateException {
0 commit comments