Skip to content

Commit

Permalink
HHH-16385 Ensure QueryKey is immutable and serializable
Browse files Browse the repository at this point in the history
  • Loading branch information
clementdenis authored and mbladel committed May 29, 2023
1 parent cdfa7a9 commit 5293cdd
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.IOException;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Objects;
import java.util.Set;

Expand Down Expand Up @@ -65,7 +66,7 @@ public static QueryKey from(
private final Integer firstRow;
private final Integer maxRows;
private final String tenantIdentifier;
private final Set<String> enabledFilterNames;
private final String[] enabledFilterNames;

/**
* For performance reasons, the hashCode is cached; however, it is marked transient so that it can be
Expand All @@ -85,7 +86,7 @@ public QueryKey(
this.firstRow = firstRow;
this.maxRows = maxRows;
this.tenantIdentifier = tenantIdentifier;
this.enabledFilterNames = enabledFilterNames;
this.enabledFilterNames = enabledFilterNames.toArray( String[]::new );
this.hashCode = generateHashCode();
}

Expand All @@ -110,7 +111,7 @@ private int generateHashCode() {
// result = 37 * result + ( maxRows==null ? 0 : maxRows );
result = 37 * result + ( tenantIdentifier==null ? 0 : tenantIdentifier.hashCode() );
result = 37 * result + parameterBindingsMemento.hashCode();
result = 37 * result + ( enabledFilterNames == null ? 0 : enabledFilterNames.hashCode() );
result = 37 * result + Arrays.hashCode( enabledFilterNames );
return result;
}

Expand Down Expand Up @@ -146,7 +147,7 @@ public boolean equals(Object other) {
return false;
}

if ( ! Objects.equals( enabledFilterNames, that.enabledFilterNames ) ) {
if ( ! Arrays.equals( enabledFilterNames, that.enabledFilterNames ) ) {
return false;
}

Expand Down

0 comments on commit 5293cdd

Please sign in to comment.