HHH-16385 Ensure QueryKey is immutable and serializable

This commit is contained in:
clement 2023-03-28 14:16:59 +02:00 committed by Marco Belladelli
parent cdfa7a9bdc
commit 5293cdd235
No known key found for this signature in database
GPG Key ID: D1D0C3030AE3AA35
1 changed files with 5 additions and 4 deletions

View File

@ -8,6 +8,7 @@ package org.hibernate.cache.spi;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable; import java.io.Serializable;
import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
@ -65,7 +66,7 @@ public class QueryKey implements Serializable {
private final Integer firstRow; private final Integer firstRow;
private final Integer maxRows; private final Integer maxRows;
private final String tenantIdentifier; 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 * For performance reasons, the hashCode is cached; however, it is marked transient so that it can be
@ -85,7 +86,7 @@ public class QueryKey implements Serializable {
this.firstRow = firstRow; this.firstRow = firstRow;
this.maxRows = maxRows; this.maxRows = maxRows;
this.tenantIdentifier = tenantIdentifier; this.tenantIdentifier = tenantIdentifier;
this.enabledFilterNames = enabledFilterNames; this.enabledFilterNames = enabledFilterNames.toArray( String[]::new );
this.hashCode = generateHashCode(); this.hashCode = generateHashCode();
} }
@ -110,7 +111,7 @@ public class QueryKey implements Serializable {
// result = 37 * result + ( maxRows==null ? 0 : maxRows ); // result = 37 * result + ( maxRows==null ? 0 : maxRows );
result = 37 * result + ( tenantIdentifier==null ? 0 : tenantIdentifier.hashCode() ); result = 37 * result + ( tenantIdentifier==null ? 0 : tenantIdentifier.hashCode() );
result = 37 * result + parameterBindingsMemento.hashCode(); result = 37 * result + parameterBindingsMemento.hashCode();
result = 37 * result + ( enabledFilterNames == null ? 0 : enabledFilterNames.hashCode() ); result = 37 * result + Arrays.hashCode( enabledFilterNames );
return result; return result;
} }
@ -146,7 +147,7 @@ public class QueryKey implements Serializable {
return false; return false;
} }
if ( ! Objects.equals( enabledFilterNames, that.enabledFilterNames ) ) { if ( ! Arrays.equals( enabledFilterNames, that.enabledFilterNames ) ) {
return false; return false;
} }