#1863 - L2 cache miss on natural key cache when multiple properties that include a ManyToOne

This commit is contained in:
rob bygrave
2019-11-16 17:03:34 +13:00
parent 738f19491a
commit dfefbecf44
16 changed files with 368 additions and 49 deletions
@@ -1,6 +1,7 @@
package io.ebeaninternal.api;
import io.ebean.Pairs;
import io.ebeaninternal.server.deploy.BeanNaturalKey;
import java.util.ArrayList;
import java.util.HashSet;
@@ -12,7 +13,7 @@ import java.util.Set;
*/
public class NaturalKeyQueryData<T> {
private final String[] naturalKey;
private final BeanNaturalKey naturalKey;
/**
* Only one of IN or IN PAIRS is allowed.
@@ -34,18 +35,12 @@ public class NaturalKeyQueryData<T> {
private int hitCount;
public NaturalKeyQueryData(String[] naturalKey) {
public NaturalKeyQueryData(BeanNaturalKey naturalKey) {
this.naturalKey = naturalKey;
}
private boolean matchProperty(String propName) {
for (String key : naturalKey) {
if (key.equals(propName)) {
return true;
}
}
return false;
return naturalKey.matchProperty(propName);
}
/**
@@ -132,13 +127,8 @@ public class NaturalKeyQueryData<T> {
* Return true if the properties match the natural key properties.
*/
private boolean matchProperties() {
if (naturalKey.length == 1) {
// simple single property case
if (inProperty != null) {
return inProperty.equals(naturalKey[0]);
} else {
return eqList.get(0).property.equals(naturalKey[0]);
}
if (naturalKey.isSingleProperty()) {
naturalKey.matchSingleProperty((inProperty != null) ? inProperty : eqList.get(0).property);
}
// multiple properties case
@@ -157,27 +147,17 @@ public class NaturalKeyQueryData<T> {
exprProps.add(eq.property);
}
}
if (exprProps.size() != naturalKey.length) {
return false;
}
for (String key : naturalKey) {
if (!exprProps.remove(key)) {
return false;
}
}
return exprProps.isEmpty();
return naturalKey.matchMultiProperties(exprProps);
}
/**
* Check that all the natural key properties are defined.
*/
private boolean expressionCount() {
int defined = (inValues == null) ? 0 : 1;
defined += (inPairs == null) ? 0 : 2;
defined += (eqList == null) ? 0 : eqList.size();
return defined == naturalKey.length;
return defined == naturalKey.length();
}
/**