Update HashCodeBindHash to use values for equals()

This commit is contained in:
rbygrave
2021-08-10 21:49:31 +12:00
parent cd6df2be39
commit 3e8f76cd6d
2 changed files with 11 additions and 3 deletions
@@ -1300,7 +1300,8 @@ public class DefaultOrmQuery<T> extends AbstractQuery implements SpiQuery<T> {
public HashQuery queryHash() {
// calculateQueryPlanHash is called just after potential AutoTune tuning
// so queryPlanHash is calculated well before this method is called
BindHash hash = bindHashAlgorithm == null ? new HashCodeBindHash() : new MdBindHash(bindHashAlgorithm);
//BindHash hash = bindHashAlgorithm == null ? new HashCodeBindHash() : new MdBindHash(bindHashAlgorithm);
BindHash hash = new HashCodeBindHash();// : new MdBindHash(bindHashAlgorithm);
queryBindHash(hash);
hash.finish();
return new HashQuery(queryPlanKey, hash);
@@ -1,5 +1,7 @@
package io.ebeaninternal.server.querydefn;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import io.ebeaninternal.api.BindHash;
@@ -12,28 +14,33 @@ import io.ebeaninternal.api.BindHash;
*/
public class HashCodeBindHash implements BindHash {
int hashCode;
private final List<Object> values = new ArrayList<>();
private int hashCode;
@Override
public BindHash update(int intValue) {
values.add(intValue);
hashCode = hashCode * 92821 + intValue;
return this;
}
@Override
public BindHash update(long longValue) {
values.add(longValue);
hashCode = hashCode * 92821 + Long.hashCode(longValue);
return this;
}
@Override
public BindHash update(boolean boolValue) {
values.add(boolValue);
hashCode = hashCode * 92821 + Boolean.hashCode(boolValue);
return this;
}
@Override
public BindHash update(Object value) {
values.add(value);
hashCode = hashCode * 92821 + Objects.hashCode(value);
return this;
}
@@ -45,7 +52,7 @@ public class HashCodeBindHash implements BindHash {
@Override
public boolean equals(Object obj) {
return obj instanceof HashCodeBindHash && ((HashCodeBindHash) obj).hashCode == hashCode;
return obj instanceof HashCodeBindHash && ((HashCodeBindHash) obj).values.equals(values);
}
@Override