#1100 - Refactor OrmQueryPlanKey to use string expression for where

This commit is contained in:
rob bygrave
2017-08-31 02:11:49 +12:00
parent a695fb59b2
commit f83c7fdac8
54 changed files with 359 additions and 723 deletions
@@ -35,7 +35,7 @@ public class BindParams implements Serializable {
* Bind hash and count used to detect when the bind values have changed such
* that the generated SQL (with named parameters) needs to be recalculated.
*/
private int[] bindHash;
private String bindHash;
public BindParams() {
}
@@ -56,32 +56,29 @@ public class BindParams implements Serializable {
* taken into account when calculating the query hash.
* </p>
*/
public void buildQueryPlanHash(HashQueryPlanBuilder builder) {
int[] vals = calcQueryPlanHash();
builder.add(vals[0]).bind(vals[1]);
public String calcQueryPlanHash() {
StringBuilder builder = new StringBuilder();
buildQueryPlanHash(builder);
return builder.toString();
}
/**
* Calculate and return a query plan bind hash with total bind count.
*/
public int[] calcQueryPlanHash() {
public void buildQueryPlanHash(StringBuilder builder) {
int tempBindCount;
int bc = 0;
int hc = 92821;
for (Param param : positionedParameters) {
tempBindCount = param.queryBindCount();
bc += tempBindCount;
hc = hc * 92821 + tempBindCount;
builder.append("p").append(bc).append(" ?:").append(tempBindCount).append(",");
}
for (Map.Entry<String, Param> entry : namedParameters.entrySet()) {
tempBindCount = entry.getValue().queryBindCount();
bc += tempBindCount;
hc = hc * 92821 + entry.getKey().hashCode();
hc = hc * 92821 + tempBindCount;
builder.append("n").append(bc).append(" k:").append(entry.getKey()).append(" ?:").append(tempBindCount).append(",");
}
return new int[]{hc, bc};
}
/**
@@ -277,9 +274,9 @@ public class BindParams implements Serializable {
bindHash = calcQueryPlanHash();
return false;
}
int[] oldPlan = bindHash;
String oldPlan = bindHash;
bindHash = calcQueryPlanHash();
return bindHash[0] == oldPlan[0] && bindHash[1] == oldPlan[1];
return bindHash.equals(oldPlan);
}
/**
@@ -48,18 +48,13 @@ public interface SpiExpression extends Expression {
* from an AutoTune perspective and get different tuning.
* </p>
*/
void queryPlanHash(HashQueryPlanBuilder builder);
void queryPlanHash(StringBuilder builder);
/**
* Return the hash value for the values that will be bound.
*/
int queryBindHash();
/**
* Return true if the expression is the same without taking into account bind values.
*/
boolean isSameByPlan(SpiExpression other);
/**
* Return true if the expression is the same with respect to bind values.
*/
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.expression;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
@@ -12,7 +11,7 @@ import io.ebeaninternal.api.SpiExpressionRequest;
*/
public abstract class AbstractTextExpression extends AbstractExpression {
protected AbstractTextExpression(String propName) {
AbstractTextExpression(String propName) {
super(propName);
}
@@ -33,7 +32,7 @@ public abstract class AbstractTextExpression extends AbstractExpression {
}
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
public void queryPlanHash(StringBuilder builder) {
// do nothing, only execute against document store
}
@@ -42,12 +41,6 @@ public abstract class AbstractTextExpression extends AbstractExpression {
return 0;
}
@Override
public boolean isSameByPlan(SpiExpression other) {
// do not compare by plan / bind values (this way)
return false;
}
@Override
public boolean isSameByBind(SpiExpression other) {
// do not compare by plan / bind values (this way)
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.expression;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.ManyWhereJoins;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
@@ -105,16 +104,21 @@ class AllEqualsExpression extends NonPrepareExpression {
* </p>
*/
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(AllEqualsExpression.class);
public void queryPlanHash(StringBuilder builder) {
builder.append("AllEquals[");
for (Entry<String, Object> entry : propMap.entrySet()) {
Object value = entry.getValue();
String propName = entry.getKey();
builder.add(propName).add(value == null ? 0 : 1);
builder.bindIfNotNull(value);
builder.append(propName);
if (value == null) {
builder.append(" isNull");
} else {
builder.append(" =?");
}
builder.append(",");
}
builder.append("]");
}
@Override
@@ -128,16 +132,6 @@ class AllEqualsExpression extends NonPrepareExpression {
return hc;
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof AllEqualsExpression)) {
return false;
}
AllEqualsExpression that = (AllEqualsExpression) other;
return isSameByValue(that, false);
}
@Override
public boolean isSameByBind(SpiExpression other) {
if (!(other instanceof AllEqualsExpression)) {
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.expression;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
@@ -15,7 +14,7 @@ public class ArrayContainsExpression extends AbstractExpression {
private final Object[] values;
protected ArrayContainsExpression(String propName, boolean contains, Object... values) {
ArrayContainsExpression(String propName, boolean contains, Object... values) {
super(propName);
this.contains = contains;
this.values = values;
@@ -43,9 +42,10 @@ public class ArrayContainsExpression extends AbstractExpression {
}
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(ArrayContainsExpression.class).add(propName).add(contains);
builder.bind(values.length);
public void queryPlanHash(StringBuilder builder) {
builder.append("ArrayContains[").append(propName)
.append(" b:").append(contains)
.append(" ?:").append(values.length).append("]");
}
@Override
@@ -57,17 +57,6 @@ public class ArrayContainsExpression extends AbstractExpression {
return hc;
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof ArrayContainsExpression)) {
return false;
}
ArrayContainsExpression that = (ArrayContainsExpression) other;
return this.propName.equals(that.propName)
&& this.contains == that.contains
&& this.values.length == that.values.length;
}
@Override
public boolean isSameByBind(SpiExpression other) {
ArrayContainsExpression that = (ArrayContainsExpression) other;
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.expression;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
@@ -13,7 +12,7 @@ public class ArrayIsEmptyExpression extends AbstractExpression {
private final boolean empty;
protected ArrayIsEmptyExpression(String propName, boolean empty) {
ArrayIsEmptyExpression(String propName, boolean empty) {
super(propName);
this.empty = empty;
}
@@ -24,8 +23,13 @@ public class ArrayIsEmptyExpression extends AbstractExpression {
}
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(ArrayIsEmptyExpression.class).add(propName);
public void queryPlanHash(StringBuilder builder) {
if (empty) {
builder.append("ArrayIsEmpty[");
} else {
builder.append("ArrayIsNotEmpty[");
}
builder.append(propName).append("]");
}
@Override
@@ -33,15 +37,6 @@ public class ArrayIsEmptyExpression extends AbstractExpression {
return empty ? 0 : 92821;
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof ArrayIsEmptyExpression)) {
return false;
}
ArrayIsEmptyExpression that = (ArrayIsEmptyExpression) other;
return this.propName.equals(that.propName) && this.empty == that.empty;
}
@Override
public boolean isSameByBind(SpiExpression other) {
return true;
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.expression;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
@@ -41,14 +40,12 @@ class BetweenExpression extends AbstractExpression {
@Override
public void addSql(SpiExpressionRequest request) {
request.append(propName).append(BETWEEN).append(" ? and ? ");
}
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(BetweenExpression.class).add(propName);
builder.bind(2);
public void queryPlanHash(StringBuilder builder) {
builder.append("Between[").append(propName).append("]");
}
@Override
@@ -58,16 +55,6 @@ class BetweenExpression extends AbstractExpression {
return hc;
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof BetweenExpression)) {
return false;
}
BetweenExpression that = (BetweenExpression) other;
return this.propName.equals(that.propName);
}
@Override
public boolean isSameByBind(SpiExpression other) {
BetweenExpression that = (BetweenExpression) other;
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.expression;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.ManyWhereJoins;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
@@ -85,9 +84,8 @@ class BetweenPropertyExpression extends NonPrepareExpression {
}
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(BetweenPropertyExpression.class).add(lowProperty).add(highProperty);
builder.bind(1);
public void queryPlanHash(StringBuilder builder) {
builder.append("BetweenProperties[").append("low:").append(lowProperty).append(" high:").append(highProperty).append("]");
}
@Override
@@ -95,16 +93,6 @@ class BetweenPropertyExpression extends NonPrepareExpression {
return val().hashCode();
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof BetweenPropertyExpression)) {
return false;
}
BetweenPropertyExpression that = (BetweenPropertyExpression) other;
return lowProperty.equals(that.lowProperty) && highProperty.equals(that.highProperty);
}
@Override
public boolean isSameByBind(SpiExpression other) {
BetweenPropertyExpression that = (BetweenPropertyExpression) other;
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.expression;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
import io.ebeaninternal.server.el.ElPropertyValue;
@@ -51,9 +50,8 @@ class CaseInsensitiveEqualExpression extends AbstractValueExpression {
}
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(CaseInsensitiveEqualExpression.class).add(propName);
builder.bind(1);
public void queryPlanHash(StringBuilder builder) {
builder.append("Ieq[").append(propName).append("]");
}
@Override
@@ -61,16 +59,6 @@ class CaseInsensitiveEqualExpression extends AbstractValueExpression {
return val().hashCode();
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof CaseInsensitiveEqualExpression)) {
return false;
}
CaseInsensitiveEqualExpression that = (CaseInsensitiveEqualExpression) other;
return this.propName.equals(that.propName);
}
@Override
public boolean isSameByBind(SpiExpression other) {
CaseInsensitiveEqualExpression that = (CaseInsensitiveEqualExpression) other;
@@ -4,7 +4,6 @@ import io.ebean.ExampleExpression;
import io.ebean.LikeType;
import io.ebean.bean.EntityBean;
import io.ebean.event.BeanQueryRequest;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.ManyWhereJoins;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
@@ -214,12 +213,14 @@ public class DefaultExampleExpression implements SpiExpression, ExampleExpressio
* Return a hash for AutoTune query identification.
*/
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
public void queryPlanHash(StringBuilder builder) {
builder.add(DefaultExampleExpression.class);
builder.append("Example[");
for (SpiExpression aList : list) {
aList.queryPlanHash(builder);
builder.append(",");
}
builder.append("]");
}
/**
@@ -234,24 +235,6 @@ public class DefaultExampleExpression implements SpiExpression, ExampleExpressio
return hc;
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof DefaultExampleExpression)) {
return false;
}
DefaultExampleExpression that = (DefaultExampleExpression) other;
if (this.list.size() != that.list.size()) {
return false;
}
for (int i = 0; i < list.size(); i++) {
if (!list.get(i).isSameByPlan(that.list.get(i))) {
return false;
}
}
return true;
}
@Override
public boolean isSameByBind(SpiExpression other) {
DefaultExampleExpression that = (DefaultExampleExpression) other;
@@ -1,25 +1,12 @@
package io.ebeaninternal.server.expression;
import io.ebean.Expression;
import io.ebean.ExpressionFactory;
import io.ebean.ExpressionList;
import io.ebean.FetchPath;
import io.ebean.FutureIds;
import io.ebean.FutureList;
import io.ebean.FutureRowCount;
import io.ebean.Junction;
import io.ebean.OrderBy;
import io.ebean.PagedList;
import io.ebean.Query;
import io.ebean.QueryIterator;
import io.ebean.Version;
import io.ebean.*;
import io.ebean.event.BeanQueryRequest;
import io.ebean.search.Match;
import io.ebean.search.MultiMatch;
import io.ebean.search.TextCommonTerms;
import io.ebean.search.TextQueryString;
import io.ebean.search.TextSimple;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.ManyWhereJoins;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionList;
@@ -559,11 +546,19 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
* values.
*/
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(DefaultExpressionList.class);
public void queryPlanHash(StringBuilder builder) {
builder.append("List[");
if (textRoot) {
builder.append("textRoot:true ");
}
if (allDocNestedPath != null) {
builder.append("path:").append(allDocNestedPath).append(" ");
}
for (SpiExpression aList : list) {
aList.queryPlanHash(builder);
builder.append(",");
}
builder.append("]");
}
/**
@@ -578,24 +573,6 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
return hash;
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof DefaultExpressionList)) {
return false;
}
DefaultExpressionList<?> that = (DefaultExpressionList<?>) other;
if (list.size() != that.list.size()) {
return false;
}
for (int i = 0, size = list.size(); i < size; i++) {
if (!list.get(i).isSameByPlan(that.list.get(i))) {
return false;
}
}
return true;
}
@Override
public boolean isSameByBind(SpiExpression other) {
DefaultExpressionList<?> that = (DefaultExpressionList<?>) other;
@@ -1,7 +1,6 @@
package io.ebeaninternal.server.expression;
import io.ebean.event.BeanQueryRequest;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.ManyWhereJoins;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.api.SpiExpression;
@@ -24,7 +23,7 @@ class ExistsQueryExpression implements SpiExpression, UnsupportedDocStoreExpress
protected String sql;
public ExistsQueryExpression(SpiQuery<?> subQuery, boolean not) {
ExistsQueryExpression(SpiQuery<?> subQuery, boolean not) {
this.subQuery = subQuery;
this.not = not;
}
@@ -74,9 +73,9 @@ class ExistsQueryExpression implements SpiExpression, UnsupportedDocStoreExpress
}
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(ExistsQueryExpression.class).add(not);
builder.add(sql).add(bindParams.size());
public void queryPlanHash(StringBuilder builder) {
builder.append("ExistsQuery[").append(" not:").append(not);
builder.append(" sql:").append(sql).append(" ?:").append(bindParams.size()).append("]");
}
@Override
@@ -103,18 +102,6 @@ class ExistsQueryExpression implements SpiExpression, UnsupportedDocStoreExpress
}
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof ExistsQueryExpression)) {
return false;
}
ExistsQueryExpression that = (ExistsQueryExpression) other;
return this.sql.equals(that.sql)
&& this.not == that.not
&& this.bindParams.size() == that.bindParams.size();
}
@Override
public boolean isSameByBind(SpiExpression other) {
ExistsQueryExpression that = (ExistsQueryExpression) other;
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.expression;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.ManyWhereJoins;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
@@ -68,9 +67,8 @@ class IdExpression extends NonPrepareExpression implements SpiExpression {
* No properties so this is just a unique static number.
*/
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(IdExpression.class);
builder.bind(1);
public void queryPlanHash(StringBuilder builder) {
builder.append("Id[]");
}
@Override
@@ -78,11 +76,6 @@ class IdExpression extends NonPrepareExpression implements SpiExpression {
return value.hashCode();
}
@Override
public boolean isSameByPlan(SpiExpression other) {
return other instanceof IdExpression;
}
@Override
public boolean isSameByBind(SpiExpression other) {
IdExpression that = (IdExpression) other;
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.expression;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.ManyWhereJoins;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
@@ -13,7 +12,7 @@ import java.util.Collection;
import java.util.Iterator;
/**
* Slightly redundant as Query.setId() ultimately also does the same job.
* In a collection of Id values.
*/
public class IdInExpression extends NonPrepareExpression {
@@ -92,9 +91,8 @@ public class IdInExpression extends NonPrepareExpression {
* Incorporates the number of Id values to bind.
*/
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(IdInExpression.class).add(idCollection.size());
builder.bind(idCollection.size());
public void queryPlanHash(StringBuilder builder) {
builder.append("IdIn[").append("?").append(idCollection.size()).append("]");
}
@Override
@@ -102,16 +100,6 @@ public class IdInExpression extends NonPrepareExpression {
return idCollection.hashCode();
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof IdInExpression)) {
return false;
}
IdInExpression that = (IdInExpression) other;
return this.idCollection.size() == that.idCollection.size();
}
@Override
public boolean isSameByBind(SpiExpression other) {
IdInExpression that = (IdInExpression) other;
@@ -2,7 +2,6 @@ package io.ebeaninternal.server.expression;
import io.ebean.bean.EntityBean;
import io.ebean.event.BeanQueryRequest;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
import io.ebeaninternal.server.el.ElPropertyValue;
@@ -115,9 +114,14 @@ class InExpression extends AbstractExpression {
* Based on the number of values in the in clause.
*/
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(InExpression.class).add(propName).add(bindValues.length).add(not);
builder.bind(bindValues.length);
public void queryPlanHash(StringBuilder builder) {
if (not) {
builder.append("NotIn[");
} else {
builder.append("In[");
}
builder.append(propName);
builder.append(" ?").append(bindValues.length).append("]");
}
@Override
@@ -129,18 +133,6 @@ class InExpression extends AbstractExpression {
return hc;
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof InExpression)) {
return false;
}
InExpression that = (InExpression) other;
return propName.equals(that.propName)
&& not == that.not
&& bindValues.length == that.bindValues.length;
}
@Override
public boolean isSameByBind(SpiExpression other) {
InExpression that = (InExpression) other;
@@ -1,7 +1,6 @@
package io.ebeaninternal.server.expression;
import io.ebean.event.BeanQueryRequest;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
@@ -57,9 +56,10 @@ class InQueryExpression extends AbstractExpression implements UnsupportedDocStor
}
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(InQueryExpression.class).add(propName).add(not);
builder.add(sql).add(bindParams.size());
public void queryPlanHash(StringBuilder builder) {
builder.append("InQuery[").append(propName)
.append(" not:").append(not).append(" sql:").append(sql)
.append(" ?:").append(bindParams.size()).append("]");
}
/**
@@ -96,19 +96,6 @@ class InQueryExpression extends AbstractExpression implements UnsupportedDocStor
}
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof InQueryExpression)) {
return false;
}
InQueryExpression that = (InQueryExpression) other;
return propName.equals(that.propName)
&& sql.equals(that.sql)
&& not == that.not
&& bindParams.size() == that.bindParams.size();
}
@Override
public boolean isSameByBind(SpiExpression other) {
InQueryExpression that = (InQueryExpression) other;
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.expression;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.ManyWhereJoins;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
@@ -94,8 +93,13 @@ class IsEmptyExpression extends AbstractExpression {
* Based on the type and propertyName.
*/
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(IsEmptyExpression.class).add(propName);
public void queryPlanHash(StringBuilder builder) {
if (empty) {
builder.append("IsEmpty[");
} else {
builder.append("IsNotEmpty[");
}
builder.append(propName).append("]");
}
@Override
@@ -103,16 +107,6 @@ class IsEmptyExpression extends AbstractExpression {
return 1;
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof IsEmptyExpression)) {
return false;
}
IsEmptyExpression that = (IsEmptyExpression) other;
return this.propName.equals(that.propName) && this.empty == that.empty;
}
@Override
public boolean isSameByBind(SpiExpression other) {
return (other instanceof IsEmptyExpression);
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.expression;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
@@ -70,10 +69,16 @@ class JsonPathExpression extends AbstractExpression {
}
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(JsonPathExpression.class).add(propName).add(path).add(operator);
builder.bindIfNotNull(value);
builder.bindIfNotNull(upperValue);
public void queryPlanHash(StringBuilder builder) {
builder.append("JsonPath[");
builder.append(propName).append(" path:").append(path).append(" op:").append(operator);
if (value != null) {
builder.append(" ?1");
}
if (upperValue != null) {
builder.append(" ?2");
}
builder.append("]");
}
@Override
@@ -83,20 +88,6 @@ class JsonPathExpression extends AbstractExpression {
return hc;
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof JsonPathExpression)) {
return false;
}
JsonPathExpression that = (JsonPathExpression) other;
return propName.equals(that.propName)
&& operator == that.operator
&& Same.sameByValue(path, that.path)
&& Same.sameByNull(value, that.value)
&& Same.sameByNull(upperValue, that.upperValue);
}
@Override
public boolean isSameByBind(SpiExpression other) {
JsonPathExpression that = (JsonPathExpression) other;
@@ -1,24 +1,12 @@
package io.ebeaninternal.server.expression;
import io.ebean.Expression;
import io.ebean.ExpressionList;
import io.ebean.FetchPath;
import io.ebean.FutureIds;
import io.ebean.FutureList;
import io.ebean.FutureRowCount;
import io.ebean.Junction;
import io.ebean.OrderBy;
import io.ebean.PagedList;
import io.ebean.Query;
import io.ebean.QueryIterator;
import io.ebean.Version;
import io.ebean.*;
import io.ebean.event.BeanQueryRequest;
import io.ebean.search.Match;
import io.ebean.search.MultiMatch;
import io.ebean.search.TextCommonTerms;
import io.ebean.search.TextQueryString;
import io.ebean.search.TextSimple;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.ManyWhereJoins;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
@@ -194,12 +182,14 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
* Based on Junction type and all the expression contained.
*/
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(JunctionExpression.class).add(type);
public void queryPlanHash(StringBuilder builder) {
builder.append(type).append("[");
List<SpiExpression> list = exprList.internalList();
for (SpiExpression aList : list) {
aList.queryPlanHash(builder);
builder.append(",");
}
builder.append("]");
}
@Override
@@ -212,17 +202,6 @@ class JunctionExpression<T> implements SpiJunction<T>, SpiExpression, Expression
return hc;
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof JunctionExpression)) {
return false;
}
JunctionExpression that = (JunctionExpression) other;
return type == that.type && exprList.isSameByPlan(that.exprList);
}
@Override
public boolean isSameByBind(SpiExpression other) {
JunctionExpression that = (JunctionExpression) other;
@@ -1,7 +1,6 @@
package io.ebeaninternal.server.expression;
import io.ebean.LikeType;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
import io.ebeaninternal.server.el.ElPropertyValue;
@@ -63,9 +62,11 @@ class LikeExpression extends AbstractValueExpression {
* Based on caseInsensitive and the property name.
*/
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(LikeExpression.class).add(caseInsensitive).add(propName);
builder.bind(1);
public void queryPlanHash(StringBuilder builder) {
if (caseInsensitive){
builder.append("I");
}
builder.append("Like[").append(type).append(" ").append(propName).append("]");
}
@Override
@@ -73,18 +74,6 @@ class LikeExpression extends AbstractValueExpression {
return strValue().hashCode();
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof LikeExpression)) {
return false;
}
LikeExpression that = (LikeExpression) other;
return this.propName.equals(that.propName)
&& this.caseInsensitive == that.caseInsensitive
&& this.type == that.type;
}
@Override
public boolean isSameByBind(SpiExpression other) {
LikeExpression that = (LikeExpression) other;
@@ -3,7 +3,6 @@ package io.ebeaninternal.server.expression;
import io.ebean.Expression;
import io.ebean.Junction;
import io.ebean.event.BeanQueryRequest;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.ManyWhereJoins;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
@@ -137,10 +136,12 @@ abstract class LogicExpression implements SpiExpression {
* Based on the joinType plus the two expressions.
*/
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(LogicExpression.class).add(joinType);
public void queryPlanHash(StringBuilder builder) {
builder.append("Logic").append(joinType).append("[");
expOne.queryPlanHash(builder);
builder.append(",");
expTwo.queryPlanHash(builder);
builder.append("]");
}
@Override
@@ -150,19 +151,6 @@ abstract class LogicExpression implements SpiExpression {
return hc;
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof LogicExpression)) {
return false;
}
LogicExpression that = (LogicExpression) other;
return this.joinType.equals(that.joinType)
&& this.expOne.isSameByPlan(that.expOne)
&& this.expTwo.isSameByPlan(that.expTwo);
}
@Override
public boolean isSameByBind(SpiExpression other) {
LogicExpression that = (LogicExpression) other;
@@ -1,7 +1,6 @@
package io.ebeaninternal.server.expression;
import io.ebean.LikeType;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
import io.ebeaninternal.server.el.ElPropertyValue;
@@ -50,9 +49,8 @@ class NativeILikeExpression extends AbstractExpression {
* Based on caseInsensitive and the property name.
*/
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(NativeILikeExpression.class).add(propName);
builder.bind(1);
public void queryPlanHash(StringBuilder builder) {
builder.append("NativeILike[").append(propName).append("]");
}
@Override
@@ -60,16 +58,6 @@ class NativeILikeExpression extends AbstractExpression {
return val.hashCode();
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof NativeILikeExpression)) {
return false;
}
NativeILikeExpression that = (NativeILikeExpression) other;
return this.propName.equals(that.propName);
}
@Override
public boolean isSameByBind(SpiExpression other) {
NativeILikeExpression that = (NativeILikeExpression) other;
@@ -1,7 +1,6 @@
package io.ebeaninternal.server.expression;
import io.ebean.event.BeanQueryRequest;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.ManyWhereJoins;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
@@ -58,8 +57,13 @@ class NestedPathWrapperExpression implements SpiExpression {
}
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
public void queryPlanHash(StringBuilder builder) {
builder.append("NestedPath[");
if (nestedPath != null){
builder.append("path:").append(nestedPath).append(" ");
}
delegate.queryPlanHash(builder);
builder.append("]");
}
@Override
@@ -67,16 +71,6 @@ class NestedPathWrapperExpression implements SpiExpression {
return delegate.queryBindHash();
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (other instanceof NestedPathWrapperExpression) {
NestedPathWrapperExpression that = (NestedPathWrapperExpression) other;
return nestedPath.equals(that.nestedPath)
&& delegate.isSameByPlan(that.delegate);
}
return false;
}
@Override
public boolean isSameByBind(SpiExpression other) {
return delegate.isSameByBind(other);
@@ -1,7 +1,6 @@
package io.ebeaninternal.server.expression;
import io.ebean.event.BeanQueryRequest;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.ManyWhereJoins;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
@@ -58,8 +57,8 @@ class NoopExpression implements SpiExpression {
}
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(NoopExpression.class);
public void queryPlanHash(StringBuilder builder) {
builder.append("Noop[]");
}
@Override
@@ -78,11 +77,6 @@ class NoopExpression implements SpiExpression {
// nothing to do
}
@Override
public boolean isSameByPlan(SpiExpression other) {
return other instanceof NoopExpression;
}
@Override
public boolean isSameByBind(SpiExpression other) {
return true;
@@ -2,7 +2,6 @@ package io.ebeaninternal.server.expression;
import io.ebean.Expression;
import io.ebean.event.BeanQueryRequest;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.ManyWhereJoins;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
@@ -81,9 +80,10 @@ final class NotExpression implements SpiExpression {
* Based on the expression.
*/
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(NotExpression.class);
public void queryPlanHash(StringBuilder builder) {
builder.append("Not[");
exp.queryPlanHash(builder);
builder.append("]");
}
@Override
@@ -91,15 +91,6 @@ final class NotExpression implements SpiExpression {
return exp.queryBindHash();
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof NotExpression)) {
return false;
}
NotExpression that = (NotExpression) other;
return exp.isSameByPlan(that.exp);
}
@Override
public boolean isSameByBind(SpiExpression other) {
NotExpression that = (NotExpression) other;
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.expression;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.ManyWhereJoins;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
@@ -72,17 +71,6 @@ class NullExpression extends AbstractExpression {
}
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof NullExpression)) {
return false;
}
NullExpression that = (NullExpression) other;
return this.propName.equals(that.propName)
&& this.notNull == that.notNull;
}
@Override
public boolean isSameByBind(SpiExpression other) {
// no bind values so always true
@@ -93,8 +81,13 @@ class NullExpression extends AbstractExpression {
* Based on notNull flag and the propertyName.
*/
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(NullExpression.class).add(notNull).add(propName);
public void queryPlanHash(StringBuilder builder) {
if (notNull) {
builder.append("NotNull[");
} else {
builder.append("Null[");
}
builder.append(propName).append("]");
}
@Override
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.expression;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.ManyWhereJoins;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
@@ -58,8 +57,12 @@ class RawExpression extends NonPrepareExpression {
* Based on the sql.
*/
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(RawExpression.class).add(sql);
public void queryPlanHash(StringBuilder builder) {
builder.append("Raw[").append(sql);
if (values != null) {
builder.append(" ?").append(values.length);
}
builder.append("]");
}
@Override
@@ -67,15 +70,6 @@ class RawExpression extends NonPrepareExpression {
return sql.hashCode();
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof RawExpression)) {
return false;
}
RawExpression that = (RawExpression) other;
return sql.equals(that.sql);
}
@Override
public boolean isSameByBind(SpiExpression other) {
if (!(other instanceof RawExpression)) {
@@ -2,7 +2,6 @@ package io.ebeaninternal.server.expression;
import io.ebean.bean.EntityBean;
import io.ebean.plugin.ExpressionPath;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionRequest;
import io.ebeaninternal.server.el.ElPropertyValue;
@@ -106,9 +105,8 @@ public class SimpleExpression extends AbstractValueExpression {
* Based on the type and propertyName.
*/
@Override
public void queryPlanHash(HashQueryPlanBuilder builder) {
builder.add(SimpleExpression.class).add(propName).add(type.name());
builder.bind(1);
public void queryPlanHash(StringBuilder builder) {
builder.append(type.name()).append("[").append(propName).append("]");
}
@Override
@@ -116,16 +114,6 @@ public class SimpleExpression extends AbstractValueExpression {
return value().hashCode();
}
@Override
public boolean isSameByPlan(SpiExpression other) {
if (!(other instanceof SimpleExpression)) {
return false;
}
SimpleExpression that = (SimpleExpression) other;
return this.propName.equals(that.propName) && this.type == that.type;
}
@Override
public boolean isSameByBind(SpiExpression other) {
SimpleExpression that = (SimpleExpression) other;
@@ -1,7 +1,6 @@
package io.ebeaninternal.server.querydefn;
import io.ebean.FetchConfig;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.deploy.BeanPropertyAssoc;
import io.ebeaninternal.server.el.ElPropertyDeploy;
@@ -56,16 +55,10 @@ public class OrmQueryDetail implements Serializable {
return copy;
}
public int queryPlanHash() {
HashQueryPlanBuilder builder = new HashQueryPlanBuilder();
queryPlanHash(builder);
return builder.getPlanHash();
}
/**
* Calculate the hash for the query plan.
*/
public void queryPlanHash(HashQueryPlanBuilder builder) {
public void queryPlanHash(StringBuilder builder) {
baseProps.queryPlanHash(builder);
if (fetchPaths != null) {
for (OrmQueryProperties p : fetchPaths.values()) {
@@ -74,36 +67,6 @@ public class OrmQueryDetail implements Serializable {
}
}
/**
* Return true if the details are the same for query plan purposes.
*/
public boolean isSameByPlan(OrmQueryDetail otherDetail) {
if (!isSameByPlan(baseProps, otherDetail.baseProps)) {
return false;
}
if (fetchPaths == null) {
return otherDetail.fetchPaths == null;
}
if (fetchPaths.size() != otherDetail.fetchPaths.size()) {
return false;
}
// check with ordering being important
Iterator<Map.Entry<String, OrmQueryProperties>> thisIt = fetchPaths.entrySet().iterator();
Iterator<Map.Entry<String, OrmQueryProperties>> thatIt = otherDetail.fetchPaths.entrySet().iterator();
while (thisIt.hasNext() && thatIt.hasNext()) {
Map.Entry<String, OrmQueryProperties> thisEntry = thisIt.next();
Map.Entry<String, OrmQueryProperties> thatEntry = thatIt.next();
if (!thisEntry.getKey().equals(thatEntry.getKey())) {
return false;
}
if (!thisEntry.getValue().isSameByPlan(thatEntry.getValue())) {
return false;
}
}
return true;
}
/**
* Return true if equal in terms of autoTune (select and fetch without property ordering).
*/
@@ -133,10 +96,6 @@ public class OrmQueryDetail implements Serializable {
return p1 == null ? p2 == null : p1.isSameByAutoTune(p2);
}
private boolean isSameByPlan(OrmQueryProperties p1, OrmQueryProperties p2) {
return p1 == null ? p2 == null : p1.isSameByPlan(p2);
}
@Override
public String toString() {
return asString();
@@ -312,7 +271,7 @@ public class OrmQueryDetail implements Serializable {
public void sortFetchPaths(BeanDescriptor<?> d) {
sortFetchPaths(d, true);
}
private void sortFetchPaths(BeanDescriptor<?> d, boolean addIds) {
if (!fetchPaths.isEmpty()) {
@@ -5,7 +5,6 @@ import io.ebean.Query;
import io.ebean.RawSql;
import io.ebeaninternal.api.BindParams;
import io.ebeaninternal.api.CQueryPlanKey;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.server.deploy.TableJoin;
@@ -15,16 +14,11 @@ import io.ebeaninternal.server.deploy.TableJoin;
*/
class OrmQueryPlanKey implements CQueryPlanKey {
private final SpiExpression where;
private final SpiExpression having;
private final RawSql.Key rawSqlKey;
private final int maxRows;
private final int firstRow;
private final OrmUpdateProperties updateProperties;
private final int planHash;
private final int bindCount;
private final String options;
private final String description;
OrmQueryPlanKey(String discValue, TableJoin m2mIncludeTable, SpiQuery.Type type, OrmQueryDetail detail, int maxRows, int firstRow, boolean disableLazyLoading,
OrderBy<?> orderBy, boolean distinct, boolean sqlDistinct, String mapKey, Object id, BindParams bindParams,
@@ -68,43 +62,46 @@ class OrmQueryPlanKey implements CQueryPlanKey {
if (mapKey != null) {
sb.append(",mapKey:").append(mapKey);
}
this.options = sb.toString();
this.maxRows = maxRows;
this.firstRow = firstRow;
this.where = (whereExpressions == null) ? null : whereExpressions.copyForPlanKey();
this.having = (havingExpressions == null) ? null : havingExpressions.copyForPlanKey();
this.updateProperties = updateProperties;
this.rawSqlKey = (rawSql == null) ? null : rawSql.getKey();
// exclude bind values and things unrelated to the sql being generated
HashQueryPlanBuilder builder = new HashQueryPlanBuilder();
builder.add(options.hashCode());
builder.add(firstRow).add(maxRows);
builder.add(rawSqlKey == null ? 0 : rawSqlKey.hashCode());
if (detail != null) {
detail.queryPlanHash(builder);
sb.append(" detail[");
detail.queryPlanHash(sb);
sb.append("]");
}
if (bindParams != null) {
bindParams.buildQueryPlanHash(builder);
sb.append(" bindParams[");
bindParams.buildQueryPlanHash(sb);
sb.append("]");
}
if (where != null) {
where.queryPlanHash(builder);
if (whereExpressions != null) {
sb.append(" where[");
whereExpressions.queryPlanHash(sb);
sb.append("]");
}
if (having != null) {
having.queryPlanHash(builder);
if (havingExpressions != null) {
sb.append(" having[");
havingExpressions.queryPlanHash(sb);
sb.append("]");
}
if (updateProperties != null) {
updateProperties.buildQueryPlanHash(builder);
sb.append(" update[");
updateProperties.buildQueryPlanHash(sb);
sb.append("]");
}
this.planHash = builder.getPlanHash();
this.bindCount = builder.getBindCount();
this.description = sb.toString();
int hc = description.hashCode();
hc = hc * 92821 + (maxRows);
hc = hc * 92821 + (firstRow);
this.planHash = hc;
}
@Override
public String getPartialKey() {
return planHash + "_" + bindCount;
return description;
}
@Override
@@ -119,14 +116,9 @@ class OrmQueryPlanKey implements CQueryPlanKey {
OrmQueryPlanKey that = (OrmQueryPlanKey) o;
if (planHash != that.planHash) return false;
if (bindCount != that.bindCount) return false;
if (maxRows != that.maxRows) return false;
if (firstRow != that.firstRow) return false;
if (!options.equals(that.options)) return false;
if (where != null ? !where.isSameByPlan(that.where) : that.where != null) return false;
if (having != null ? !having.isSameByPlan(that.having) : that.having != null) return false;
if (updateProperties != null ? !updateProperties.isSameByPlan(that.updateProperties) : that.updateProperties != null) return false;
if (!description.equals(that.description)) return false;
return rawSqlKey != null ? rawSqlKey.equals(that.rawSqlKey) : that.rawSqlKey == null;
}
}
@@ -4,14 +4,12 @@ import io.ebean.ExpressionFactory;
import io.ebean.FetchConfig;
import io.ebean.OrderBy;
import io.ebean.Query;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.api.SpiExpressionFactory;
import io.ebeaninternal.api.SpiExpressionList;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.server.expression.FilterExprPath;
import io.ebeaninternal.server.expression.FilterExpressionList;
import io.ebeaninternal.server.expression.Same;
import io.ebeaninternal.server.query.SplitName;
import java.io.Serializable;
@@ -476,33 +474,30 @@ public class OrmQueryProperties implements Serializable {
return included.equals(p2.included);
}
/**
* Properties are the same for query plan purposes.
*/
public boolean isSameByPlan(OrmQueryProperties p2) {
if (!Same.sameByValue(secondaryQueryJoins, p2.secondaryQueryJoins)) return false;
if (!Same.sameByValue(included, p2.included)) return false;
if (!Same.sameByNull(filterMany, p2.filterMany)) return false;
if (filterMany != null && !filterMany.isSameByPlan(p2.filterMany)) return false;
return fetchConfig.equals(p2.fetchConfig);
}
/**
* Calculate the query plan hash.
*/
public void queryPlanHash(HashQueryPlanBuilder builder) {
public void queryPlanHash(StringBuilder builder) {
builder.add(path);
builder.addOrdered(included);
builder.add(secondaryQueryJoins);
builder.add(filterMany != null);
if (filterMany != null) {
filterMany.queryPlanHash(builder);
builder.append("qpp[");
builder.append(path);
if (included != null){
builder.append(" included:").append(included);
}
builder.add(fetchConfig.hashCode());
if (secondaryQueryJoins != null) {
builder.append(" secondary:").append(secondaryQueryJoins);
}
if (filterMany != null) {
builder.append(" filterMany[");
filterMany.queryPlanHash(builder);
builder.append("]");
}
if (fetchConfig != null) {
builder.append(" config:").append(fetchConfig.hashCode());
}
builder.append("]");
}
}
@@ -149,23 +149,14 @@ public class OrmUpdateProperties {
}
}
/**
* Return true if this update has the same logical set clause.
*/
public boolean isSameByPlan(OrmUpdateProperties that) {
return that.values.size() == values.size()
&& logicalSetClause().equals(that.logicalSetClause());
}
/**
* Build the hash for the query plan caching.
*/
void buildQueryPlanHash(HashQueryPlanBuilder builder) {
builder.add(OrmUpdateProperties.class);
void buildQueryPlanHash(StringBuilder builder) {
Set<Map.Entry<String, Value>> entries = values.entrySet();
for (Map.Entry<String, Value> entry : entries) {
builder.add(entry.getKey());
builder.bind(entry.getValue().getBindCount());
builder.append("key:").append(entry.getKey());
builder.append(" ?:").append(entry.getValue().getBindCount());
}
}
@@ -7,8 +7,8 @@ import io.ebean.FetchConfig;
import io.ebean.Query;
import io.ebeaninternal.server.querydefn.DefaultOrmQuery;
import io.ebeaninternal.server.querydefn.OrmQueryDetail;
import org.tests.model.basic.Order;
import org.junit.Test;
import org.tests.model.basic.Order;
import static org.assertj.core.api.Assertions.assertThat;
@@ -305,12 +305,16 @@ public class DefaultServer_createOrmQueryRequestTest extends BaseTestCase {
}
private void assertSame(OrmQueryDetail detail1, OrmQueryDetail detail2) {
assertThat(detail1.isSameByPlan(detail2)).isTrue();
assertThat(detail1.queryPlanHash()).isEqualTo(detail2.queryPlanHash());
assertThat(hash(detail1)).isEqualTo(hash(detail2));
}
private void assertDifferent(OrmQueryDetail detail1, OrmQueryDetail detail2) {
assertThat(detail1.isSameByPlan(detail2)).isFalse();
assertThat(detail1.queryPlanHash()).isNotEqualTo(detail2.queryPlanHash());
assertThat(hash(detail1)).isNotEqualTo(hash(detail2));
}
private String hash(OrmQueryDetail detail1) {
StringBuilder sb = new StringBuilder();
detail1.queryPlanHash(sb);
return sb.toString();
}
}
@@ -8,12 +8,12 @@ import java.util.Map;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class AllEqualsExpressionTest {
public class AllEqualsExpressionTest extends BaseExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp("a", 10).isSameByPlan(exp("a", 10))).isTrue();
same(exp("a", 10), exp("a", 10));
}
@Test
@@ -25,55 +25,55 @@ public class AllEqualsExpressionTest {
@Test
public void isSameByPlan_when_diffBindValue() {
assertThat(exp("a", 10).isSameByPlan(exp("a", 20))).isTrue();
same(exp("a", 10), exp("a", 20));
}
@Test
public void isSameByPlan_when_multiple() {
assertThat(exp("a", 10, "b", 20, "c", 30).isSameByPlan(exp("a", 10, "b", 20, "c", 30))).isTrue();
same(exp("a", 10, "b", 20, "c", 30), exp("a", 10, "b", 20, "c", 30));
}
@Test
public void isSameByPlan_when_less() {
assertThat(exp("a", 10, "b", 20, "c", 30).isSameByPlan(exp("a", 10, "b", 20))).isFalse();
different(exp("a", 10, "b", 20, "c", 30), exp("a", 10, "b", 20));
}
@Test
public void isSameByPlan_when_more() {
assertThat(exp("a", 10, "b", 20).isSameByPlan(exp("a", 10, "b", 20, "c", 30))).isFalse();
different(exp("a", 10, "b", 20), exp("a", 10, "b", 20, "c", 30));
}
@Test
public void isSameByPlan_when_diffProperty_diff() {
assertThat(exp("a", 10).isSameByPlan(exp("b", 10))).isFalse();
different(exp("a", 10), exp("b", 10));
}
@Test
public void isSameByPlan_when_diffType_diff() {
assertThat(exp("a", 10).isSameByPlan(new NoopExpression())).isFalse();
different(exp("a", 10), new NoopExpression());
}
@Test
public void isSameByPlan_when_diffBindByNull_last() {
assertThat(exp("a", 10).isSameByPlan(exp("a", null))).isFalse();
different(exp("a", 10), exp("a", null));
}
@Test
public void isSameByPlan_when_diffBindByNull_first() {
assertThat(exp("a", null).isSameByPlan(exp("a", 10))).isFalse();
different(exp("a", null), exp("a", 10));
}
@Test
public void isSameByPlan_when_differentExpressionType() {
assertThat(exp("a", null).isSameByPlan(new NoopExpression())).isFalse();
different(exp("a", null), new NoopExpression());
}
@Test
@@ -1,13 +1,32 @@
package io.ebeaninternal.server.expression;
import io.ebean.BaseTestCase;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import org.tests.model.basic.Order;
import static org.assertj.core.api.StrictAssertions.assertThat;
public abstract class BaseExpressionTest extends BaseTestCase {
protected DefaultExpressionRequest newExpressionRequest() {
BeanDescriptor<Order> desc = getBeanDescriptor(Order.class);
return new DefaultExpressionRequest(desc);
}
protected String hash(SpiExpression expression) {
StringBuilder sb = new StringBuilder();
if (expression != null) {
expression.queryPlanHash(sb);
}
return sb.toString();
}
protected void same(SpiExpression one, SpiExpression two){
assertThat(hash(one)).isEqualTo(hash(two));
}
protected void different(SpiExpression one, SpiExpression two){
assertThat(hash(one)).isNotEqualTo(hash(two));
}
}
@@ -33,8 +33,8 @@ public class BetweenExpressionTest extends BaseExpressionTest {
BetweenExpression exp0 = new BetweenExpression("startDate", 1, 2);
BetweenExpression exp1 = new BetweenExpression("startDate", 3, 4);
assertThat(exp0.isSameByPlan(exp1)).isTrue();
assertThat(exp1.isSameByPlan(exp0)).isTrue();
same(exp0, exp1);
same(exp1, exp0);
}
@Test
@@ -43,8 +43,8 @@ public class BetweenExpressionTest extends BaseExpressionTest {
BetweenExpression exp0 = new BetweenExpression("startDate", 1, 2);
BetweenExpression exp1 = new BetweenExpression("endDate", 1, 2);
assertThat(exp0.isSameByPlan(exp1)).isFalse();
assertThat(exp1.isSameByPlan(exp0)).isFalse();
different(exp0, exp1);
different(exp1, exp0);
}
@Test
@@ -5,7 +5,7 @@ import org.junit.Test;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class BetweenPropertyExpressionTest {
public class BetweenPropertyExpressionTest extends BaseExpressionTest {
@NotNull
private BetweenPropertyExpression exp(String lowProperty, String highProperty, Object value) {
@@ -21,22 +21,22 @@ public class BetweenPropertyExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp("a", "b", 10).isSameByPlan(exp("a", "b", 10))).isTrue();
same(exp("a", "b", 10), exp("a", "b", 10));
}
@Test
public void isSameByPlan_when_diffValue() {
assertThat(exp("a", "b", 10).isSameByPlan(exp("a", "b", 20))).isTrue();
same(exp("a", "b", 10), exp("a", "b", 20));
}
@Test
public void isSameByPlan_when_diffProperty() {
assertThat(exp("a", "b", 10).isSameByPlan(exp("a", "c", 10))).isFalse();
different(exp("a", "b", 10), exp("a", "c", 10));
}
@Test
public void isSameByPlan_when_diffExpressionType() {
assertThat(exp("a", "b", 10).isSameByPlan(new NoopExpression())).isFalse();
different(exp("a", "b", 10), new NoopExpression());
}
@Test
@@ -5,7 +5,7 @@ import org.junit.Test;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class CaseInsensitiveEqualExpressionTest {
public class CaseInsensitiveEqualExpressionTest extends BaseExpressionTest {
CaseInsensitiveEqualExpression exp(String propName, String value) {
return new CaseInsensitiveEqualExpression(propName, value);
@@ -14,25 +14,25 @@ public class CaseInsensitiveEqualExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp("a", "10").isSameByPlan(exp("a", "10"))).isTrue();
same(exp("a", "10"), exp("a", "10"));
}
@Test
public void isSameByPlan_when_diffBind_same() {
assertThat(exp("a", "10").isSameByPlan(exp("a", "20"))).isTrue();
same(exp("a", "10"), exp("a", "20"));
}
@Test
public void isSameByPlan_when_diffProperty_diff() {
assertThat(exp("a", "10").isSameByPlan(exp("b", "10"))).isFalse();
different(exp("a", "10"), exp("b", "10"));
}
@Test
public void isSameByPlan_when_diffType_diff() {
assertThat(exp("a", "10").isSameByPlan(new NoopExpression())).isFalse();
different(exp("a", "10"), new NoopExpression());
}
@Test
@@ -1,24 +1,22 @@
package io.ebeaninternal.server.expression;
import io.ebean.BaseTestCase;
import io.ebean.LikeType;
import io.ebean.Query;
import io.ebean.bean.EntityBean;
import io.ebean.event.BeanQueryRequest;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.ManyWhereJoins;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.server.core.OrmQueryRequest;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import org.junit.Test;
import org.tests.model.basic.Address;
import org.tests.model.basic.Customer;
import org.tests.model.basic.ResetBasicData;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class DefaultExampleExpressionTest extends BaseTestCase {
public class DefaultExampleExpressionTest extends BaseExpressionTest {
Customer customer() {
@@ -68,7 +66,7 @@ public class DefaultExampleExpressionTest extends BaseTestCase {
prepare(expr);
HashQueryPlanBuilder builder = new HashQueryPlanBuilder();
StringBuilder builder = new StringBuilder();
expr.queryPlanHash(builder);
TDSpiExpressionRequest req = new TDSpiExpressionRequest(customerBeanDescriptor());
@@ -100,25 +98,25 @@ public class DefaultExampleExpressionTest extends BaseTestCase {
@Test
public void isSameByPlan_whenSame() {
assertThat(prepare(exp()).isSameByPlan(prepare(exp()))).isTrue();
same(prepare(exp()), prepare(exp()));
}
@Test
public void isSameByPlan_when_diffBindValue_stillSame() {
assertThat(prepare(exp()).isSameByPlan(prepare(expDiffName()))).isTrue();
same(prepare(exp()), prepare(expDiffName()));
}
@Test
public void isSameByPlan_when_extraExpression_then_different() {
assertThat(prepare(exp()).isSameByPlan(prepare(expExtra()))).isFalse();
different(prepare(exp()), prepare(expExtra()));
}
@Test
public void isSameByPlan_when_lessExpression_then_different() {
assertThat(prepare(expExtra()).isSameByPlan(prepare(exp()))).isFalse();
different(prepare(expExtra()), prepare(exp()));
}
}
@@ -5,7 +5,7 @@ import org.junit.Test;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class DefaultExpressionListTest {
public class DefaultExpressionListTest extends BaseExpressionTest {
DefaultExpressionList exp() {
@@ -13,57 +13,57 @@ public class DefaultExpressionListTest {
return new DefaultExpressionList<>(null, new DefaultExpressionFactory(true, true), null);
}
DefaultExpressionList spi(ExpressionList list) {
private DefaultExpressionList spi(ExpressionList list) {
return (DefaultExpressionList) list;
}
@Test
public void isSameByPlan_when_same() {
assertThat(spi(exp().eq("a", 10).eq("b", 20))
.isSameByPlan(spi(exp().eq("a", 10).eq("b", 20)))).isTrue();
same(spi(exp().eq("a", 10).eq("b", 20))
,spi(exp().eq("a", 10).eq("b", 20)));
}
@Test
public void isSameByPlan_when_diffExpressionType() {
assertThat(spi(exp().eq("a", 10).eq("b", 20))
.isSameByPlan(new NoopExpression())).isFalse();
different(spi(exp().eq("a", 10).eq("b", 20))
,new NoopExpression());
}
@Test
public void isSameByPlan_when_less() {
assertThat(spi(exp().eq("a", 10).eq("b", 20))
.isSameByPlan(spi(exp().eq("a", 10)))).isFalse();
different(spi(exp().eq("a", 10).eq("b", 20))
,spi(exp().eq("a", 10)));
}
@Test
public void isSameByPlan_when_lessEmptyLast() {
assertThat(spi(exp().eq("a", 10).eq("b", 20))
.isSameByPlan(spi(exp()))).isFalse();
different(spi(exp().eq("a", 10).eq("b", 20))
,spi(exp()));
}
@Test
public void isSameByPlan_when_lessEmptyFirst() {
assertThat(spi(exp())
.isSameByPlan(spi(exp().eq("a", 10)))).isFalse();
different(spi(exp())
,spi(exp().eq("a", 10)));
}
@Test
public void isSameByPlan_when_more() {
assertThat(spi(exp().eq("a", 10).eq("b", 20))
.isSameByPlan(spi(exp().eq("a", 10).eq("b", 20).eq("c", 30)))).isFalse();
different(spi(exp().eq("a", 10).eq("b", 20))
,spi(exp().eq("a", 10).eq("b", 20).eq("c", 30)));
}
@Test
public void isSameByPlan_when_diffProperties() {
assertThat(spi(exp().eq("a", 10).eq("b", 20))
.isSameByPlan(spi(exp().eq("c", 10).eq("b", 20)))).isFalse();
different(spi(exp().eq("a", 10).eq("b", 20))
,spi(exp().eq("c", 10).eq("b", 20)));
}
@@ -8,7 +8,7 @@ import java.util.Arrays;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class ExistsQueryExpressionTest {
public class ExistsQueryExpressionTest extends BaseExpressionTest {
@NotNull
@@ -19,37 +19,37 @@ public class ExistsQueryExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp(true, "a", 10).isSameByPlan(exp(true, "a", 10))).isTrue();
same(exp(true, "a", 10), exp(true, "a", 10));
}
@Test
public void isSameByPlan_when_diffBind_same() {
assertThat(exp(true, "a", 10).isSameByPlan(exp(true, "a", 20))).isTrue();
same(exp(true, "a", 10), exp(true, "a", 20));
}
@Test
public void isSameByPlan_when_diffNot() {
assertThat(exp(true, "a", 10).isSameByPlan(exp(false, "a", 10))).isFalse();
different(exp(true, "a", 10), exp(false, "a", 10));
}
@Test
public void isSameByPlan_when_diffSql() {
assertThat(exp(true, "a", 10).isSameByPlan(exp(true, "b", 10))).isFalse();
different(exp(true, "a", 10), exp(true, "b", 10));
}
@Test
public void isSameByBind_when_sameBindValues() {
assertThat(exp(true, "a", 10).isSameByBind(exp(true, "a", 10))).isTrue();
same(exp(true, "a", 10), exp(true, "a", 10));
}
@Test
public void isSameByBind_when_sameMultipleBindValues() {
assertThat(exp(true, "a", 10, "ABC", 20).isSameByBind(exp(true, "a", 10, "ABC", 20))).isTrue();
same(exp(true, "a", 10, "ABC", 20), exp(true, "a", 10, "ABC", 20));
}
@Test
@@ -6,7 +6,7 @@ import org.junit.Test;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class IdExpressionTest {
public class IdExpressionTest extends BaseExpressionTest {
@NotNull
@@ -17,13 +17,13 @@ public class IdExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp(10).isSameByPlan(exp(10))).isTrue();
same(exp(10), exp(10));
}
@Test
public void isSameByPlan_when_diffBind_same() {
assertThat(exp(10).isSameByPlan(exp(20))).isTrue();
same(exp(10), exp(20));
}
@Test
@@ -7,7 +7,7 @@ import java.util.Arrays;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class IdInExpressionTest {
public class IdInExpressionTest extends BaseExpressionTest {
@NotNull
@@ -18,19 +18,19 @@ public class IdInExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp(10).isSameByPlan(exp(10))).isTrue();
same(exp(10), exp(10));
}
@Test
public void isSameByPlan_when_diffBind_same() {
assertThat(exp(10).isSameByPlan(exp(20))).isTrue();
same(exp(10), exp(20));
}
@Test
public void isSameByPlan_when_diffBindCount() {
assertThat(exp(10).isSameByPlan(exp(10, 20))).isFalse();
different(exp(10), exp(10, 20));
}
@Test
@@ -1,7 +1,5 @@
package io.ebeaninternal.server.expression;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import java.util.ArrayList;
@@ -9,10 +7,8 @@ import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.StrictAssertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
public class InExpressionTest {
public class InExpressionTest extends BaseExpressionTest {
@Test
@@ -26,13 +22,7 @@ public class InExpressionTest {
ex1.prepareExpression(null);
ex2.prepareExpression(null);
HashQueryPlanBuilder b1 = new HashQueryPlanBuilder();
ex1.queryPlanHash(b1);
HashQueryPlanBuilder b2 = new HashQueryPlanBuilder();
ex2.queryPlanHash(b2);
assertNotEquals(b1.build(), b2.build());
different(ex1, ex2);
}
@Test
@@ -47,13 +37,7 @@ public class InExpressionTest {
ex1.prepareExpression(null);
ex2.prepareExpression(null);
HashQueryPlanBuilder b1 = new HashQueryPlanBuilder();
ex1.queryPlanHash(b1);
HashQueryPlanBuilder b2 = new HashQueryPlanBuilder();
ex2.queryPlanHash(b2);
assertNotEquals(b1.build(), b2.build());
different(ex1, ex2);
}
@Test
@@ -67,13 +51,7 @@ public class InExpressionTest {
ex1.prepareExpression(null);
ex2.prepareExpression(null);
HashQueryPlanBuilder b1 = new HashQueryPlanBuilder();
ex1.queryPlanHash(b1);
HashQueryPlanBuilder b2 = new HashQueryPlanBuilder();
ex2.queryPlanHash(b2);
assertNotEquals(b1.build(), b2.build());
different(ex1, ex2);
}
@Test
@@ -87,16 +65,10 @@ public class InExpressionTest {
ex1.prepareExpression(null);
ex2.prepareExpression(null);
HashQueryPlanBuilder b1 = new HashQueryPlanBuilder();
ex1.queryPlanHash(b1);
HashQueryPlanBuilder b2 = new HashQueryPlanBuilder();
ex2.queryPlanHash(b2);
assertEquals(b1.build(), b2.build());
same(ex1, ex2);
}
List<Integer> values(int... vals) {
private List<Integer> values(int... vals) {
ArrayList list = new ArrayList<Integer>();
for (int val : vals) {
list.add(val);
@@ -104,7 +76,6 @@ public class InExpressionTest {
return list;
}
@NotNull
private InExpression exp(String propName, boolean not, Object... values) {
InExpression ex = new InExpression(propName, Arrays.asList(values), not);
ex.prepareExpression(null);
@@ -114,31 +85,31 @@ public class InExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp("a", false, 10).isSameByPlan(exp("a", false, 10))).isTrue();
same(exp("a", false, 10), exp("a", false, 10));
}
@Test
public void isSameByPlan_when_diffPropertyName() {
assertThat(exp("a", false, 10).isSameByPlan(exp("b", false, 10))).isFalse();
different(exp("a", false, 10), exp("b", false, 10));
}
@Test
public void isSameByPlan_when_diffNot() {
assertThat(exp("a", false, 10).isSameByPlan(exp("a", true, 10))).isFalse();
different(exp("a", false, 10), exp("a", true, 10));
}
@Test
public void isSameByPlan_when_diffBind_same() {
assertThat(exp("a", false, 10).isSameByPlan(exp("a", false, 10, 20))).isFalse();
different(exp("a", false, 10), exp("a", false, 10, 20));
}
@Test
public void isSameByPlan_when_diffBindCount() {
assertThat(exp("a", false, 10).isSameByPlan(exp("a", false, 10, 20))).isFalse();
different(exp("a", false, 10), exp("a", false, 10, 20));
}
@Test
@@ -7,7 +7,7 @@ import java.util.Arrays;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class InQueryExpressionTest {
public class InQueryExpressionTest extends BaseExpressionTest {
@NotNull
@@ -18,31 +18,31 @@ public class InQueryExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp("name", true, "sql", 10).isSameByPlan(exp("name", true, "sql", 10))).isTrue();
same(exp("name", true, "sql", 10), exp("name", true, "sql", 10));
}
@Test
public void isSameByPlan_when_diffBind_same() {
assertThat(exp("name", true, "sql", 10).isSameByPlan(exp("name", true, "sql", 20))).isTrue();
same(exp("name", true, "sql", 10), exp("name", true, "sql", 20));
}
@Test
public void isSameByPlan_when_diffNPropertyName() {
assertThat(exp("name", true, "sql", 10).isSameByPlan(exp("nameDiff", true, "sql", 10))).isFalse();
different(exp("name", true, "sql", 10), exp("nameDiff", true, "sql", 10));
}
@Test
public void isSameByPlan_when_diffNot() {
assertThat(exp("name", true, "sql", 10).isSameByPlan(exp("name", false, "sql", 10))).isFalse();
different(exp("name", true, "sql", 10), exp("name", false, "sql", 10));
}
@Test
public void isSameByPlan_when_diffSql() {
assertThat(exp("name", true, "sql", 10).isSameByPlan(exp("name", true, "sqlDiff", 10))).isFalse();
different(exp("name", true, "sql", 10), exp("name", true, "sqlDiff", 10));
}
@Test
@@ -5,7 +5,7 @@ import org.junit.Test;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class JsonPathExpressionTest {
public class JsonPathExpressionTest extends BaseExpressionTest {
@NotNull
private JsonPathExpression exp(String propertyName, String path, Op operator, Object value) {
@@ -15,37 +15,37 @@ public class JsonPathExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp("a", "path", Op.EQ, 10).isSameByPlan(exp("a", "path", Op.EQ, 10))).isTrue();
same(exp("a", "path", Op.EQ, 10), exp("a", "path", Op.EQ, 10));
}
@Test
public void isSameByPlan_when_diffBind_same() {
assertThat(exp("a", "path", Op.EQ, 10).isSameByPlan(exp("a", "path", Op.EQ, 20))).isTrue();
same(exp("a", "path", Op.EQ, 10), exp("a", "path", Op.EQ, 20));
}
@Test
public void isSameByPlan_when_diffPath() {
assertThat(exp("a", "path", Op.EQ, 10).isSameByPlan(exp("a", "pathDiff", Op.EQ, 10))).isFalse();
different(exp("a", "path", Op.EQ, 10), exp("a", "pathDiff", Op.EQ, 10));
}
@Test
public void isSameByPlan_when_diffProperty_diff() {
assertThat(exp("a", "path", Op.EQ, 10).isSameByPlan(exp("b", "path", Op.EQ, 10))).isFalse();
different(exp("a", "path", Op.EQ, 10), exp("b", "path", Op.EQ, 10));
}
@Test
public void isSameByPlan_when_diffOperator_diff() {
assertThat(exp("a", "path", Op.EQ, 10).isSameByPlan(exp("a", "path", Op.LT, 10))).isFalse();
different(exp("a", "path", Op.EQ, 10), exp("a", "path", Op.LT, 10));
}
@Test
public void isSameByPlan_when_diffType_diff() {
assertThat(exp("a", "path", Op.EQ, 10).isSameByPlan(new NoopExpression())).isFalse();
different(exp("a", "path", Op.EQ, 10), new NoopExpression());
}
@Test
@@ -5,9 +5,7 @@ import io.ebean.Expression;
import io.ebean.Junction;
import org.junit.Test;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class JunctionExpressionTest {
public class JunctionExpressionTest extends BaseExpressionTest {
Expression eq(String propName, int value) {
return Expr.eq(propName, value);
@@ -34,28 +32,28 @@ public class JunctionExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(and(exp(eq("a", 10), eq("b", 10)))
.isSameByPlan(and(exp(eq("a", 10), eq("b", 10))))).isTrue();
same(and(exp(eq("a", 10), eq("b", 10))),
and(exp(eq("a", 10), eq("b", 10))));
}
@Test
public void copyForPlanKey_isSameByPlan_when_same() {
assertThat(and(exp(eq("a", 10), eq("b", 10)).copyForPlanKey())
.isSameByPlan(and(exp(eq("a", 10), eq("b", 10))))).isTrue();
same(and(exp(eq("a", 10), eq("b", 10)).copyForPlanKey()),
and(exp(eq("a", 10), eq("b", 10))));
}
@Test
public void copyForPlanKey_isSameByPlan_when_diff() {
assertThat(and(exp(eq("a", 10), eq("b", 10)).copyForPlanKey())
.isSameByPlan(and(exp(eq("a", 10), eq("c", 10))))).isFalse();
different(and(exp(eq("a", 10), eq("b", 10)).copyForPlanKey()),
and(exp(eq("a", 10), eq("c", 10))));
}
@Test
public void isSameByPlan_when_diffType() {
assertThat(and(exp(eq("a", 10), eq("b", 10)))
.isSameByPlan(or(exp(eq("a", 10), eq("b", 10))))).isFalse();
different(and(exp(eq("a", 10), eq("b", 10))),
or(exp(eq("a", 10), eq("b", 10))));
}
}
@@ -17,36 +17,36 @@ public class LikeExpressionTest extends BaseExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp("a", "rob", true, LikeType.STARTS_WITH)
.isSameByPlan(exp("a", "rob", true, LikeType.STARTS_WITH))).isTrue();
same(exp("a", "rob", true, LikeType.STARTS_WITH)
, exp("a", "rob", true, LikeType.STARTS_WITH));
}
@Test
public void isSameByPlan_when_diffBind_then_stillSame() {
assertThat(exp("a", "rob", true, LikeType.STARTS_WITH)
.isSameByPlan(exp("a", "bor", true, LikeType.STARTS_WITH))).isTrue();
same(exp("a", "rob", true, LikeType.STARTS_WITH)
, exp("a", "bor", true, LikeType.STARTS_WITH));
}
@Test
public void isSameByPlan_when_diffCaseInsensitive() {
assertThat(exp("a", "rob", true, LikeType.STARTS_WITH)
.isSameByPlan(exp("a", "rob", false, LikeType.STARTS_WITH))).isFalse();
different(exp("a", "rob", true, LikeType.STARTS_WITH)
, exp("a", "rob", false, LikeType.STARTS_WITH));
}
@Test
public void isSameByPlan_when_diffLikeType() {
assertThat(exp("a", "rob", true, LikeType.STARTS_WITH)
.isSameByPlan(exp("a", "rob", true, LikeType.ENDS_WITH))).isFalse();
different(exp("a", "rob", true, LikeType.STARTS_WITH)
, exp("a", "rob", true, LikeType.ENDS_WITH));
}
@Test
public void isSameByPlan_when_diffProperty() {
assertThat(exp("a", "rob", true, LikeType.STARTS_WITH)
.isSameByPlan(exp("b", "rob", true, LikeType.STARTS_WITH))).isFalse();
different(exp("a", "rob", true, LikeType.STARTS_WITH)
, exp("b", "rob", true, LikeType.STARTS_WITH));
}
@@ -2,65 +2,65 @@ package io.ebeaninternal.server.expression;
import io.ebean.Expr;
import io.ebean.Expression;
import org.tests.model.basic.Order;
import org.junit.Test;
import org.tests.model.basic.Order;
import static org.assertj.core.api.Assertions.assertThat;
public class LogicExpressionTest extends BaseExpressionTest {
Expression eq(String propName, int value) {
private Expression eq(String propName, int value) {
return Expr.eq(propName, value);
}
LogicExpression and(Expression a, Expression b) {
private LogicExpression and(Expression a, Expression b) {
return new LogicExpression.And(a, b);
}
LogicExpression or(Expression a, Expression b) {
private LogicExpression or(Expression a, Expression b) {
return new LogicExpression.Or(a, b);
}
@Test
public void isSameByPlan_when_same() {
assertThat(and(eq("a", 10), eq("b", 10))
.isSameByPlan(and(eq("a", 10), eq("b", 10)))).isTrue();
same(and(eq("a", 10), eq("b", 10))
, and(eq("a", 10), eq("b", 10)));
}
@Test
public void isSameByPlan_when_diffBind_then_stillSame() {
assertThat(and(eq("a", 10), eq("b", 10))
.isSameByPlan(and(eq("a", 20), eq("b", 20)))).isTrue();
same(and(eq("a", 10), eq("b", 10))
, and(eq("a", 20), eq("b", 20)));
}
@Test
public void isSameByPlan_when_diffExp1_then_diff() {
assertThat(and(eq("a", 10), eq("b", 10))
.isSameByPlan(and(eq("c", 10), eq("b", 10)))).isFalse();
different(and(eq("a", 10), eq("b", 10))
, and(eq("c", 10), eq("b", 10)));
}
@Test
public void isSameByPlan_when_diffExp2_then_diff() {
assertThat(and(eq("a", 10), eq("b", 10))
.isSameByPlan(and(eq("a", 10), eq("c", 10)))).isFalse();
different(and(eq("a", 10), eq("b", 10))
, and(eq("a", 10), eq("c", 10)));
}
@Test
public void isSameByPlan_when_diffType_then_diff() {
assertThat(or(eq("a", 10), eq("b", 10))
.isSameByPlan(and(eq("a", 10), eq("c", 10)))).isFalse();
different(or(eq("a", 10), eq("b", 10))
, and(eq("a", 10), eq("c", 10)));
}
@Test
public void isSameByPlan_when_diffExpressionType() {
assertThat(or(eq("a", 10), eq("b", 10))
.isSameByPlan(new NoopExpression())).isFalse();
different(or(eq("a", 10), eq("b", 10))
, new NoopExpression());
}
@Test
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.expression;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.Query;
import org.junit.Test;
@@ -10,7 +9,7 @@ import org.tests.model.onetoone.album.Cover;
import static org.assertj.core.api.Assertions.assertThat;
public class NoopExpressionTest extends BaseTestCase {
public class NoopExpressionTest extends BaseExpressionTest {
@Test
public void test() {
@@ -55,13 +54,13 @@ public class NoopExpressionTest extends BaseTestCase {
@Test
public void isSameByPlan_when_same() {
assertThat(new NoopExpression().isSameByPlan(new NoopExpression())).isTrue();
same(new NoopExpression(), new NoopExpression());
}
@Test
public void isSameByPlan_when_diffExpressionType() {
assertThat(new NoopExpression().isSameByPlan(null)).isFalse();
different(new NoopExpression(), null);
}
@Test
@@ -7,7 +7,7 @@ import org.junit.Test;
import static io.ebean.Expr.eq;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class NotExpressionTest {
public class NotExpressionTest extends BaseExpressionTest {
NotExpression not(Expression expression) {
@@ -17,29 +17,25 @@ public class NotExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(not(eq("a", 10))
.isSameByPlan(not(eq("a", 10)))).isTrue();
same(not(eq("a", 10)), not(eq("a", 10)));
}
@Test
public void isSameByPlan_when_sameByPlan() {
assertThat(not(eq("a", 10))
.isSameByPlan(not(eq("a", 20)))).isTrue();
same(not(eq("a", 10)), not(eq("a", 20)));
}
@Test
public void isSameByPlan_when_different() {
assertThat(not(eq("a", 10))
.isSameByPlan(not(eq("b", 10)))).isFalse();
different(not(eq("a", 10)), not(eq("b", 10)));
}
@Test
public void isSameByPlan_when_differentExpressionType() {
assertThat(not(eq("a", 10))
.isSameByPlan(new NoopExpression())).isFalse();
different(not(eq("a", 10)), new NoopExpression());
}
@Test
@@ -9,7 +9,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class NullExpressionTest extends BaseExpressionTest {
NullExpression nullExp(String propertyName, boolean notNull) {
private NullExpression nullExp(String propertyName, boolean notNull) {
NullExpression expr = new NullExpression(propertyName, notNull);
expr.containsMany(getBeanDescriptor(Order.class), new ManyWhereJoins());
return expr;
@@ -74,22 +74,22 @@ public class NullExpressionTest extends BaseExpressionTest {
@Test
public void isSameByPlan_true() throws Exception {
assertThat(nullExp("customer.name", false)
.isSameByPlan(nullExp("customer.name", false))).isTrue();
same(nullExp("customer.name", false),
nullExp("customer.name", false));
}
@Test
public void isSameByPlan_false_when_notNullDiff() throws Exception {
assertThat(new NullExpression("customer.name", false)
.isSameByPlan(new NullExpression("customer.name", true))).isFalse();
different(new NullExpression("customer.name", false),
new NullExpression("customer.name", true));
}
@Test
public void isSameByPlan_false_when_propertyNameDiff() throws Exception {
assertThat(new NullExpression("customer.startDate", true)
.isSameByPlan(new NullExpression("customer.name", true))).isFalse();
different(new NullExpression("customer.startDate", true),
new NullExpression("customer.name", true));
}
}
@@ -5,7 +5,7 @@ import org.junit.Test;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class RawExpressionTest {
public class RawExpressionTest extends BaseExpressionTest {
@NotNull
private RawExpression exp(String sql, Object... values) {
@@ -14,17 +14,17 @@ public class RawExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp("a", 10).isSameByPlan(exp("a", 10))).isTrue();
same(exp("a", 10), exp("a", 10));
}
@Test
public void isSameByPlan_when_diffBindValues() {
assertThat(exp("a", 10).isSameByPlan(exp("a", 20))).isTrue();
same(exp("a", 10), exp("a", 20));
}
@Test
public void isSameByPlan_when_diffSql() {
assertThat(exp("a", 10).isSameByPlan(exp("b", 10))).isFalse();
different(exp("a", 10), exp("b", 10));
}
@Test
@@ -1,14 +1,12 @@
package io.ebeaninternal.server.expression;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class SimpleExpressionTest extends BaseExpressionTest {
@NotNull
private SimpleExpression exp(String propertyName, Op operator, Object value) {
return new SimpleExpression(propertyName, operator, value);
}
@@ -16,31 +14,31 @@ public class SimpleExpressionTest extends BaseExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp("a", Op.EQ, 10).isSameByPlan(exp("a", Op.EQ, 10))).isTrue();
same(exp("a", Op.EQ, 10), exp("a", Op.EQ, 10));
}
@Test
public void isSameByPlan_when_diffBind_same() {
assertThat(exp("a", Op.EQ, 10).isSameByPlan(exp("a", Op.EQ, 20))).isTrue();
same(exp("a", Op.EQ, 10), exp("a", Op.EQ, 20));
}
@Test
public void isSameByPlan_when_diffProperty_diff() {
assertThat(exp("a", Op.EQ, 10).isSameByPlan(exp("b", Op.EQ, 10))).isFalse();
different(exp("a", Op.EQ, 10), exp("b", Op.EQ, 10));
}
@Test
public void isSameByPlan_when_diffOperator_diff() {
assertThat(exp("a", Op.EQ, 10).isSameByPlan(exp("a", Op.LT, 10))).isFalse();
different(exp("a", Op.EQ, 10), exp("a", Op.LT, 10));
}
@Test
public void isSameByPlan_when_diffType_diff() {
assertThat(exp("a", Op.EQ, 10).isSameByPlan(new NoopExpression())).isFalse();
different(exp("a", Op.EQ, 10), new NoopExpression());
}
@Test