Skip to content

Commit

Permalink
HHH-16049 Setting a property to its current value with bytecode enhan…
Browse files Browse the repository at this point in the history
…cement enabled results in unnecessary SQL Update in some (many) cases
  • Loading branch information
dreab8 committed Jan 24, 2023
1 parent 802fc76 commit 1078caa
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static boolean areEquals(
Object b) {
final PersistentAttributeInterceptor persistentAttributeInterceptor = persistentAttributeInterceptable.$$_hibernate_getInterceptor();
if ( persistentAttributeInterceptor != null
&& !persistentAttributeInterceptor.getInitializedLazyAttributeNames().contains( fieldName ) ) {
&& !persistentAttributeInterceptor.isAttributeLoaded( fieldName ) ) {
return false;
}
return Objects.deepEquals( a, b );
Expand All @@ -33,7 +33,7 @@ public static boolean areEquals(
boolean b) {
final PersistentAttributeInterceptor persistentAttributeInterceptor = persistentAttributeInterceptable.$$_hibernate_getInterceptor();
if ( persistentAttributeInterceptor != null
&& !persistentAttributeInterceptor.getInitializedLazyAttributeNames().contains( fieldName ) ) {
&& !persistentAttributeInterceptor.isAttributeLoaded( fieldName ) ) {
return false;
}
return a == b;
Expand All @@ -46,7 +46,7 @@ public static boolean areEquals(
byte b) {
final PersistentAttributeInterceptor persistentAttributeInterceptor = persistentAttributeInterceptable.$$_hibernate_getInterceptor();
if ( persistentAttributeInterceptor != null
&& !persistentAttributeInterceptor.getInitializedLazyAttributeNames().contains( fieldName ) ) {
&& !persistentAttributeInterceptor.isAttributeLoaded( fieldName ) ) {
return false;
}
return a == b;
Expand All @@ -59,7 +59,7 @@ public static boolean areEquals(
short b) {
final PersistentAttributeInterceptor persistentAttributeInterceptor = persistentAttributeInterceptable.$$_hibernate_getInterceptor();
if ( persistentAttributeInterceptor != null
&& !persistentAttributeInterceptor.getInitializedLazyAttributeNames().contains( fieldName ) ) {
&& !persistentAttributeInterceptor.isAttributeLoaded( fieldName ) ) {
return false;
}
return a == b;
Expand All @@ -72,7 +72,7 @@ public static boolean areEquals(
char b) {
final PersistentAttributeInterceptor persistentAttributeInterceptor = persistentAttributeInterceptable.$$_hibernate_getInterceptor();
if ( persistentAttributeInterceptor != null
&& !persistentAttributeInterceptor.getInitializedLazyAttributeNames().contains( fieldName ) ) {
&& !persistentAttributeInterceptor.isAttributeLoaded( fieldName ) ) {
return false;
}
return a == b;
Expand All @@ -85,7 +85,7 @@ public static boolean areEquals(
int b) {
final PersistentAttributeInterceptor persistentAttributeInterceptor = persistentAttributeInterceptable.$$_hibernate_getInterceptor();
if ( persistentAttributeInterceptor != null
&& !persistentAttributeInterceptor.getInitializedLazyAttributeNames().contains( fieldName ) ) {
&& !persistentAttributeInterceptor.isAttributeLoaded( fieldName ) ) {
return false;
}
return a == b;
Expand All @@ -98,7 +98,7 @@ public static boolean areEquals(
long b) {
final PersistentAttributeInterceptor persistentAttributeInterceptor = persistentAttributeInterceptable.$$_hibernate_getInterceptor();
if ( persistentAttributeInterceptor != null
&& !persistentAttributeInterceptor.getInitializedLazyAttributeNames().contains( fieldName ) ) {
&& !persistentAttributeInterceptor.isAttributeLoaded( fieldName ) ) {
return false;
}
return a == b;
Expand All @@ -111,7 +111,7 @@ public static boolean areEquals(
float b) {
final PersistentAttributeInterceptor persistentAttributeInterceptor = persistentAttributeInterceptable.$$_hibernate_getInterceptor();
if ( persistentAttributeInterceptor != null
&& !persistentAttributeInterceptor.getInitializedLazyAttributeNames().contains( fieldName ) ) {
&& !persistentAttributeInterceptor.isAttributeLoaded( fieldName ) ) {
return false;
}
return a == b;
Expand All @@ -124,7 +124,7 @@ public static boolean areEquals(
double b) {
final PersistentAttributeInterceptor persistentAttributeInterceptor = persistentAttributeInterceptable.$$_hibernate_getInterceptor();
if ( persistentAttributeInterceptor != null
&& !persistentAttributeInterceptor.getInitializedLazyAttributeNames().contains( fieldName ) ) {
&& !persistentAttributeInterceptor.isAttributeLoaded( fieldName ) ) {
return false;
}
return a == b;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public interface BytecodeLazyAttributeInterceptor extends SessionAssociableInter
*/
void attributeInitialized(String name);

@Override
boolean isAttributeLoaded(String fieldName);

boolean hasAnyUninitializedAttributes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,19 @@ default Set<String> getInitializedLazyAttributeNames() {
@Deprecated
default void attributeInitialized(String name) {
}

/**
*
* Callback from the enhanced class that an attribute has been loaded
*
* @deprecated Interceptors that deal with
* * lazy state should implement {@link BytecodeLazyAttributeInterceptor}
*
* @param fieldName
* @return true id the attribute is loaded false otherwise
*/
@Deprecated
default boolean isAttributeLoaded(String fieldName){
return false;
}
}

0 comments on commit 1078caa

Please sign in to comment.