#1681 - Support hitting L2 bean cache via ... findList() with idsIn() expression

This commit is contained in:
rob bygrave committed 2019-04-26 12:01:16 +12:00
1 parent 242945aa18
commit 65fa1c056b
17 files changed
+304 -79

No files matched your search

@@ -9,20 +9,38 @@ import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.deploy.id.IdBinder;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
* In a collection of Id values.
*/
public class IdInExpression extends NonPrepareExpression {
private final Collection<?> idCollection;
private final List<Object> idCollection;
private boolean multiValueIdSupported;
public IdInExpression(Collection<?> idCollection) {
this.idCollection = idCollection;
this.idCollection = new ArrayList<>(idCollection);
}
/**
* Return the ids this expression is looking to fetch.
*/
public Collection<Object> idValues() {
return idCollection;
}
/**
* Remove Ids that where obtained from l2 cache. Don't fetch these from DB.
*/
public int removeIds(Set<Object> hitIds) {
idCollection.removeAll(hitIds);
return idCollection.size();
}
@Override
@@ -63,23 +63,25 @@ class InExpression extends AbstractExpression {
return vals;
}
private List<Object> initBindValues() {
if (bindValues == null) {
bindValues = values();
}
return bindValues;
}
@Override
public boolean naturalKey(NaturalKeyQueryData<?> data) {
// can't use naturalKey cache for NOT IN or when "empty"
if (not || empty) {
return false;
}
List<Object> copy = data.matchIn(propName, bindValues);
if (copy == null) {
return false;
}
bindValues = copy;
return true;
return data.matchIn(propName, initBindValues());
}
@Override
public void prepareExpression(BeanQueryRequest<?> request) {
bindValues = values();
initBindValues();
if (bindValues.size() > 0) {
multiValueSupported = request.isMultiValueSupported((bindValues.get(0)).getClass());
}
@@ -146,9 +148,7 @@ class InExpression extends AbstractExpression {
if (prop != null) {
request.append(prop.getAssocIdInExpr(propName));
String inClause = prop.getAssocIdInValueExpr(not, bindValues.size());
request.append(inClause);
request.append(prop.getAssocIdInValueExpr(not, bindValues.size()));
} else {
request.append(propName);
request.appendInExpression(not, bindValues);
@@ -54,7 +54,6 @@ class InPairsExpression extends AbstractExpression {
@Override
public void prepareExpression(BeanQueryRequest<?> request) {
// at this stage translating pairs into varchar via DB concat
multiValueSupported = request.isMultiValueSupported(String.class);
}