Cleanup of expressions after FilterExprPath now only needed on FilterExpressionList

This commit is contained in:
Rob Bygrave
2014-01-31 00:48:59 +13:00
parent 456a1d8608
commit 8bfa331c61
16 changed files with 87 additions and 147 deletions
@@ -36,11 +36,6 @@ import java.util.Map;
*/
public interface ExpressionFactory {
/**
* Return the language for this expression factory.
*/
public String getLang();
/**
* Equal To - property equal to the given value.
*/
@@ -14,51 +14,39 @@ import com.avaje.ebeaninternal.server.el.ElPropertyValue;
*/
public abstract class AbstractExpression implements SpiExpression {
private static final long serialVersionUID = 4072786211853856174L;
protected final String propName;
protected final FilterExprPath pathPrefix;
protected AbstractExpression(FilterExprPath pathPrefix, String propName) {
this.pathPrefix = pathPrefix;
this.propName = propName;
}
private static final long serialVersionUID = 4072786211853856174L;
public String getPropertyName() {
if (pathPrefix == null){
return propName;
} else {
String path = pathPrefix.getPath();
if (path == null || path.length() == 0){
return propName;
} else {
return path+"."+propName;
}
}
}
public void containsMany(BeanDescriptor<?> desc, ManyWhereJoins manyWhereJoin) {
protected final String propName;
String propertyName = getPropertyName();
if (propertyName != null){
ElPropertyDeploy elProp = desc.getElPropertyDeploy(propertyName);
if (elProp != null) {
if (elProp.containsFormulaWithJoin()) {
// for findRowCount query select clause
manyWhereJoin.addFormulaWithJoin(propertyName);
}
if (elProp.containsMany()){
// for findRowCount we join to a many property
protected AbstractExpression(String propName) {
this.propName = propName;
}
public String getPropertyName() {
return propName;
}
public void containsMany(BeanDescriptor<?> desc, ManyWhereJoins manyWhereJoin) {
String propertyName = getPropertyName();
if (propertyName != null) {
ElPropertyDeploy elProp = desc.getElPropertyDeploy(propertyName);
if (elProp != null) {
if (elProp.containsFormulaWithJoin()) {
// for findRowCount query select clause
manyWhereJoin.addFormulaWithJoin(propertyName);
}
if (elProp.containsMany()) {
// for findRowCount we join to a many property
manyWhereJoin.add(elProp);
}
}
}
}
protected ElPropertyValue getElProp(SpiExpressionRequest request) {
String propertyName = getPropertyName();
return request.getBeanDescriptor().getElGetValue(propertyName);
}
}
}
}
protected ElPropertyValue getElProp(SpiExpressionRequest request) {
String propertyName = getPropertyName();
return request.getBeanDescriptor().getElGetValue(propertyName);
}
}
@@ -20,24 +20,12 @@ class AllEqualsExpression implements SpiExpression {
private final Map<String, Object> propMap;
private final FilterExprPath pathPrefix;
AllEqualsExpression(FilterExprPath pathPrefix, Map<String, Object> propMap) {
this.pathPrefix = pathPrefix;
AllEqualsExpression(Map<String, Object> propMap) {
this.propMap = propMap;
}
protected String name(String propName) {
if (pathPrefix == null) {
return propName;
} else {
String path = pathPrefix.getPath();
if (path == null || path.length() == 0) {
return propName;
} else {
return path + "." + propName;
}
}
return propName;
}
public void containsMany(BeanDescriptor<?> desc, ManyWhereJoins manyWhereJoin) {
@@ -15,8 +15,8 @@ class BetweenExpression extends AbstractExpression {
private final Object valueLow;
BetweenExpression(FilterExprPath pathPrefix, String propertyName, Object valLo, Object valHigh) {
super(pathPrefix, propertyName);
BetweenExpression(String propertyName, Object valLo, Object valHigh) {
super(propertyName);
this.valueLow = valLo;
this.valueHigh = valHigh;
}
@@ -10,8 +10,6 @@ import com.avaje.ebeaninternal.server.el.ElPropertyDeploy;
/**
* Between expression where a value is between two properties.
*
* @author rbygrave
*/
class BetweenPropertyExpression implements SpiExpression {
@@ -19,29 +17,18 @@ class BetweenPropertyExpression implements SpiExpression {
private static final String BETWEEN = " between ";
private final FilterExprPath pathPrefix;
private final String lowProperty;
private final String highProperty;
private final Object value;
BetweenPropertyExpression(FilterExprPath pathPrefix, String lowProperty, String highProperty, Object value) {
this.pathPrefix = pathPrefix;
BetweenPropertyExpression(String lowProperty, String highProperty, Object value) {
this.lowProperty = lowProperty;
this.highProperty = highProperty;
this.value = value;
}
protected String name(String propName) {
if (pathPrefix == null) {
return propName;
} else {
String path = pathPrefix.getPath();
if (path == null || path.length() == 0) {
return propName;
} else {
return path + "." + propName;
}
}
return propName;
}
public void containsMany(BeanDescriptor<?> desc, ManyWhereJoins manyWhereJoin) {
@@ -11,8 +11,8 @@ class CaseInsensitiveEqualExpression extends AbstractExpression {
private final String value;
CaseInsensitiveEqualExpression(FilterExprPath pathPrefix, String propertyName, String value) {
super(pathPrefix, propertyName);
CaseInsensitiveEqualExpression(String propertyName, String value) {
super(propertyName);
this.value = value.toLowerCase();
}
@@ -66,8 +66,6 @@ public class DefaultExampleExpression implements SpiExpression, ExampleExpressio
*/
private ArrayList<SpiExpression> list;
private final FilterExprPath pathPrefix;
/**
* Construct the query by example expression.
*
@@ -78,8 +76,7 @@ public class DefaultExampleExpression implements SpiExpression, ExampleExpressio
* @param likeType
* the type of Like wild card used
*/
public DefaultExampleExpression(FilterExprPath pathPrefix, Object entity, boolean caseInsensitive, LikeType likeType) {
this.pathPrefix = pathPrefix;
public DefaultExampleExpression(Object entity, boolean caseInsensitive, LikeType likeType) {
this.entity = entity;
this.caseInsensitive = caseInsensitive;
this.likeType = likeType;
@@ -217,13 +214,13 @@ public class DefaultExampleExpression implements SpiExpression, ExampleExpressio
if (beanProperty.isScalar() && value != null) {
if (value instanceof String) {
list.add(new LikeExpression(pathPrefix, propName, (String) value, caseInsensitive, likeType));
list.add(new LikeExpression(propName, (String) value, caseInsensitive, likeType));
} else {
if (!includeZeros && isZero(value)) {
// exclude the zero values typically to weed out
// primitive int and long that initialise to 0
} else {
list.add(new SimpleExpression(pathPrefix, propName, SimpleExpression.Op.EQ, value));
list.add(new SimpleExpression(propName, SimpleExpression.Op.EQ, value));
}
}
}
@@ -21,19 +21,11 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
private static final Object[] EMPTY_ARRAY = new Object[] {};
private final FilterExprPath prefix = null;
public DefaultExpressionFactory() {
//this();//null);
}
// public DefaultExpressionFactory(FilterExprPath prefix) {
// this.prefix = prefix;
// }
public ExpressionFactory createExpressionFactory(){//FilterExprPath prefix) {
public ExpressionFactory createExpressionFactory(){
return this;
//return new DefaultExpressionFactory(prefix);
}
public String getLang() {
@@ -47,7 +39,7 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
if (value == null) {
return isNull(propertyName);
}
return new SimpleExpression(prefix, propertyName, SimpleExpression.Op.EQ, value);
return new SimpleExpression(propertyName, SimpleExpression.Op.EQ, value);
}
/**
@@ -57,7 +49,7 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
if (value == null) {
return isNotNull(propertyName);
}
return new SimpleExpression(prefix, propertyName, SimpleExpression.Op.NOT_EQ, value);
return new SimpleExpression(propertyName, SimpleExpression.Op.NOT_EQ, value);
}
/**
@@ -68,7 +60,7 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
if (value == null) {
return isNull(propertyName);
}
return new CaseInsensitiveEqualExpression(prefix, propertyName, value);
return new CaseInsensitiveEqualExpression(propertyName, value);
}
/**
@@ -76,7 +68,7 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
*/
public Expression between(String propertyName, Object value1, Object value2) {
return new BetweenExpression(prefix, propertyName, value1, value2);
return new BetweenExpression(propertyName, value1, value2);
}
/**
@@ -84,7 +76,7 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
*/
public Expression betweenProperties(String lowProperty, String highProperty, Object value) {
return new BetweenPropertyExpression(prefix, lowProperty, highProperty, value);
return new BetweenPropertyExpression(lowProperty, highProperty, value);
}
/**
@@ -92,7 +84,7 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
*/
public Expression gt(String propertyName, Object value) {
return new SimpleExpression(prefix, propertyName, SimpleExpression.Op.GT, value);
return new SimpleExpression(propertyName, SimpleExpression.Op.GT, value);
}
/**
@@ -101,7 +93,7 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
*/
public Expression ge(String propertyName, Object value) {
return new SimpleExpression(prefix, propertyName, SimpleExpression.Op.GT_EQ, value);
return new SimpleExpression(propertyName, SimpleExpression.Op.GT_EQ, value);
}
/**
@@ -109,7 +101,7 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
*/
public Expression lt(String propertyName, Object value) {
return new SimpleExpression(prefix, propertyName, SimpleExpression.Op.LT, value);
return new SimpleExpression(propertyName, SimpleExpression.Op.LT, value);
}
/**
@@ -117,7 +109,7 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
*/
public Expression le(String propertyName, Object value) {
return new SimpleExpression(prefix, propertyName, SimpleExpression.Op.LT_EQ, value);
return new SimpleExpression(propertyName, SimpleExpression.Op.LT_EQ, value);
}
/**
@@ -125,7 +117,7 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
*/
public Expression isNull(String propertyName) {
return new NullExpression(prefix, propertyName, false);
return new NullExpression(propertyName, false);
}
/**
@@ -133,14 +125,14 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
*/
public Expression isNotNull(String propertyName) {
return new NullExpression(prefix, propertyName, true);
return new NullExpression(propertyName, true);
}
/**
* Case insensitive {@link #exampleLike(Object)}
*/
public ExampleExpression iexampleLike(Object example) {
return new DefaultExampleExpression(prefix, example, true, LikeType.RAW);
return new DefaultExampleExpression(example, true, LikeType.RAW);
}
/**
@@ -148,14 +140,14 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
* LikeType.RAW (you need to add you own wildcards % and _).
*/
public ExampleExpression exampleLike(Object example) {
return new DefaultExampleExpression(prefix, example, false, LikeType.RAW);
return new DefaultExampleExpression(example, false, LikeType.RAW);
}
/**
* Create the query by Example expression specifying more options.
*/
public ExampleExpression exampleLike(Object example, boolean caseInsensitive, LikeType likeType) {
return new DefaultExampleExpression(prefix, example, caseInsensitive, likeType);
return new DefaultExampleExpression(example, caseInsensitive, likeType);
}
/**
@@ -163,7 +155,7 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
* characters % (percentage) and _ (underscore).
*/
public Expression like(String propertyName, String value) {
return new LikeExpression(prefix, propertyName, value, false, LikeType.RAW);
return new LikeExpression(propertyName, value, false, LikeType.RAW);
}
/**
@@ -172,14 +164,14 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
* a lower() function to make the expression case insensitive.
*/
public Expression ilike(String propertyName, String value) {
return new LikeExpression(prefix, propertyName, value, true, LikeType.RAW);
return new LikeExpression(propertyName, value, true, LikeType.RAW);
}
/**
* Starts With - property like value%.
*/
public Expression startsWith(String propertyName, String value) {
return new LikeExpression(prefix, propertyName, value, false, LikeType.STARTS_WITH);
return new LikeExpression(propertyName, value, false, LikeType.STARTS_WITH);
}
/**
@@ -187,14 +179,14 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
* lower() function to make the expression case insensitive.
*/
public Expression istartsWith(String propertyName, String value) {
return new LikeExpression(prefix, propertyName, value, true, LikeType.STARTS_WITH);
return new LikeExpression(propertyName, value, true, LikeType.STARTS_WITH);
}
/**
* Ends With - property like %value.
*/
public Expression endsWith(String propertyName, String value) {
return new LikeExpression(prefix, propertyName, value, false, LikeType.ENDS_WITH);
return new LikeExpression(propertyName, value, false, LikeType.ENDS_WITH);
}
/**
@@ -202,14 +194,14 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
* function to make the expression case insensitive.
*/
public Expression iendsWith(String propertyName, String value) {
return new LikeExpression(prefix, propertyName, value, true, LikeType.ENDS_WITH);
return new LikeExpression(propertyName, value, true, LikeType.ENDS_WITH);
}
/**
* Contains - property like %value%.
*/
public Expression contains(String propertyName, String value) {
return new LikeExpression(prefix, propertyName, value, false, LikeType.CONTAINS);
return new LikeExpression(propertyName, value, false, LikeType.CONTAINS);
}
/**
@@ -217,28 +209,28 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
* function to make the expression case insensitive.
*/
public Expression icontains(String propertyName, String value) {
return new LikeExpression(prefix, propertyName, value, true, LikeType.CONTAINS);
return new LikeExpression(propertyName, value, true, LikeType.CONTAINS);
}
/**
* In - property has a value in the array of values.
*/
public Expression in(String propertyName, Object[] values) {
return new InExpression(prefix, propertyName, values);
return new InExpression(propertyName, values);
}
/**
* In - using a subQuery.
*/
public Expression in(String propertyName, Query<?> subQuery) {
return new InQueryExpression(prefix, propertyName, (SpiQuery<?>) subQuery);
return new InQueryExpression(propertyName, (SpiQuery<?>) subQuery);
}
/**
* In - property has a value in the collection of values.
*/
public Expression in(String propertyName, Collection<?> values) {
return new InExpression(prefix, propertyName, values);
return new InExpression(propertyName, values);
}
/**
@@ -269,7 +261,7 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
* a map keyed by property names.
*/
public Expression allEq(Map<String, Object> propertyMap) {
return new AllEqualsExpression(prefix, propertyMap);
return new AllEqualsExpression(propertyMap);
}
/**
@@ -13,13 +13,13 @@ class InExpression extends AbstractExpression {
private final Object[] values;
InExpression(FilterExprPath pathPrefix, String propertyName, Collection<?> coll) {
super(pathPrefix, propertyName);
InExpression(String propertyName, Collection<?> coll) {
super(propertyName);
values = coll.toArray(new Object[coll.size()]);
}
InExpression(FilterExprPath pathPrefix, String propertyName, Object[] array) {
super(pathPrefix, propertyName);
InExpression(String propertyName, Object[] array) {
super(propertyName);
this.values = array;
}
@@ -22,8 +22,8 @@ class InQueryExpression extends AbstractExpression {
private transient CQuery<?> compiledSubQuery;
public InQueryExpression(FilterExprPath pathPrefix, String propertyName, SpiQuery<?> subQuery) {
super(pathPrefix, propertyName);
public InQueryExpression(String propertyName, SpiQuery<?> subQuery) {
super(propertyName);
this.subQuery = subQuery;
}
@@ -383,6 +383,7 @@ abstract class JunctionExpression<T> implements Junction<T>, SpiExpression, Expr
return exprList.setFirstRow(firstRow);
}
@Deprecated
public com.avaje.ebean.Query<T> setListener(QueryListener<T> queryListener) {
return exprList.setListener(queryListener);
}
@@ -16,8 +16,8 @@ class LikeExpression extends AbstractExpression {
private final LikeType type;
LikeExpression(FilterExprPath pathPrefix, String propertyName, String value, boolean caseInsensitive, LikeType type) {
super(pathPrefix, propertyName);
LikeExpression(String propertyName, String value, boolean caseInsensitive, LikeType type) {
super(propertyName);
this.caseInsensitive = caseInsensitive;
this.type = type;
this.val = value;
@@ -15,8 +15,8 @@ class NullExpression extends AbstractExpression {
private final boolean notNull;
NullExpression(FilterExprPath pathPrefix, String propertyName, boolean notNull) {
super(pathPrefix, propertyName);
NullExpression(String propertyName, boolean notNull) {
super(propertyName);
this.notNull = notNull;
}
@@ -33,8 +33,8 @@ public class SimpleExpression extends AbstractExpression {
private final Object value;
public SimpleExpression(FilterExprPath pathPrefix, String propertyName, Op type, Object value) {
super(pathPrefix, propertyName);
public SimpleExpression(String propertyName, Op type, Object value) {
super(propertyName);
this.type = type;
this.value = value;
}
@@ -42,7 +42,6 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
protected transient ExpressionFactory expr;
private final String exprLang;
private final String listAndStart;
private final String listAndEnd;
private final String listAndJoin;
@@ -59,20 +58,11 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
this.list = list;
this.query = query;
this.expr = expr;
this.exprLang = expr.getLang();
this.parentExprList = parentExprList;
if ("ldap".equals(exprLang)) {
// Language is LDAP
listAndStart = "(&";
listAndEnd = ")";
listAndJoin = "";
} else {
listAndStart = "";
listAndEnd = "";
listAndJoin = " and ";
}
this.listAndStart = "";
this.listAndEnd = "";
this.listAndJoin = " and ";
}
public SpiExpressionList<?> trimPath(int prefixTrim) {
@@ -231,6 +221,7 @@ public class DefaultExpressionList<T> implements SpiExpressionList<T> {
return query.setMapKey(mapKey);
}
@Deprecated
public Query<T> setListener(QueryListener<T> queryListener) {
return query.setListener(queryListener);
}
@@ -136,6 +136,7 @@ public class FilterExpressionList<T> extends DefaultExpressionList<T> {
return rootQuery.setFirstRow(firstRow);
}
@Deprecated
public Query<T> setListener(QueryListener<T> queryListener) {
return rootQuery.setListener(queryListener);
}