mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-19 23:02:24 +00:00
EQL - parsing BETWEEN property expressions
This commit is contained in:
1 parent
b4b6a13e75
commit
3f8b389999
5 files changed
+68
-16
No files matched your search
@@ -14,21 +14,29 @@ class BetweenExpression extends AbstractExpression {
|
||||
|
||||
private final Object valueLow;
|
||||
|
||||
BetweenExpression(String propertyName, Object valLo, Object valHigh) {
|
||||
BetweenExpression(String propertyName, Object valueLow, Object valueHigh) {
|
||||
super(propertyName);
|
||||
this.valueLow = valLo;
|
||||
this.valueHigh = valHigh;
|
||||
this.valueLow = valueLow;
|
||||
this.valueHigh = valueHigh;
|
||||
}
|
||||
|
||||
private Object low() {
|
||||
return NamedParamHelp.value(valueLow);
|
||||
}
|
||||
|
||||
private Object high() {
|
||||
return NamedParamHelp.value(valueHigh);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDocQuery(DocQueryContext context) throws IOException {
|
||||
context.writeRange(propName, Op.GT_EQ, valueLow, Op.LT_EQ, valueHigh);
|
||||
context.writeRange(propName, Op.GT_EQ, low(), Op.LT_EQ, high());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBindValues(SpiExpressionRequest request) {
|
||||
request.addBindValue(valueLow);
|
||||
request.addBindValue(valueHigh);
|
||||
request.addBindValue(low());
|
||||
request.addBindValue(high());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -45,8 +53,8 @@ class BetweenExpression extends AbstractExpression {
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
int hc = valueLow.hashCode();
|
||||
hc = hc * 31 + valueHigh.hashCode();
|
||||
int hc = low().hashCode();
|
||||
hc = hc * 31 + high().hashCode();
|
||||
return hc;
|
||||
}
|
||||
|
||||
@@ -63,7 +71,7 @@ class BetweenExpression extends AbstractExpression {
|
||||
@Override
|
||||
public boolean isSameByBind(SpiExpression other) {
|
||||
BetweenExpression that = (BetweenExpression) other;
|
||||
return valueLow.equals(that.valueLow)
|
||||
&& valueHigh.equals(that.valueHigh);
|
||||
return low().equals(that.low())
|
||||
&& high().equals(that.high());
|
||||
}
|
||||
}
|
||||
+9
-5
@@ -32,11 +32,15 @@ class BetweenPropertyExpression extends NonPrepareExpression {
|
||||
return propName;
|
||||
}
|
||||
|
||||
private Object val() {
|
||||
return NamedParamHelp.value(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDocQuery(DocQueryContext context) throws IOException {
|
||||
context.startBoolMust();
|
||||
context.writeSimple(Op.LT_EQ, lowProperty, value);
|
||||
context.writeSimple(Op.GT_EQ, highProperty, value);
|
||||
context.writeSimple(Op.LT_EQ, lowProperty, val());
|
||||
context.writeSimple(Op.GT_EQ, highProperty, val());
|
||||
context.endBool();
|
||||
}
|
||||
|
||||
@@ -72,7 +76,7 @@ class BetweenPropertyExpression extends NonPrepareExpression {
|
||||
|
||||
@Override
|
||||
public void addBindValues(SpiExpressionRequest request) {
|
||||
request.addBindValue(value);
|
||||
request.addBindValue(val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,7 +93,7 @@ class BetweenPropertyExpression extends NonPrepareExpression {
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return value.hashCode();
|
||||
return val().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -106,6 +110,6 @@ class BetweenPropertyExpression extends NonPrepareExpression {
|
||||
@Override
|
||||
public boolean isSameByBind(SpiExpression other) {
|
||||
BetweenPropertyExpression that = (BetweenPropertyExpression) other;
|
||||
return value.equals(that.value);
|
||||
return val().equals(that.val());
|
||||
}
|
||||
}
|
||||
@@ -108,7 +108,13 @@ class EqlAdapter<T> extends EQLBaseListener {
|
||||
|
||||
@Override
|
||||
public void enterPropertyBetween_expression(EQLParser.PropertyBetween_expressionContext ctx) {
|
||||
|
||||
checkChildren(ctx, 5);
|
||||
String rawValue = ctx.getChild(0).getText();
|
||||
EqlOperator op = getOperator(ctx);
|
||||
if (op != EqlOperator.BETWEEN) {
|
||||
throw new IllegalStateException("Expecting BETWEEN operator but got "+op);
|
||||
}
|
||||
helper.addBetweenProperty(rawValue, ctx.getChild(2).getText(), ctx.getChild(4).getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -41,6 +41,10 @@ class EqlAdapterHelper {
|
||||
}
|
||||
}
|
||||
|
||||
protected void addBetweenProperty(String rawValue, String lowProperty, String highProperty) {
|
||||
peekExprList().betweenProperties(lowProperty, highProperty, bind(rawValue));
|
||||
}
|
||||
|
||||
protected void addBetween(String path, String value1, String value2) {
|
||||
peekExprList().between(path, bind(value1), bind(value2));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user