mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-19 23:02:24 +00:00
EQL Named parameter support for Like and ieq
This commit is contained in:
1 parent
1a1c432c2a
commit
84b37fb014
10 files changed
+123
-88
No files matched your search
@@ -0,0 +1,32 @@
|
||||
package com.avaje.ebeaninternal.server.expression;
|
||||
|
||||
/**
|
||||
* Abstract expression that helps with named parameter use.
|
||||
*/
|
||||
public abstract class AbstractValueExpression extends AbstractExpression {
|
||||
|
||||
protected final Object bindValue;
|
||||
|
||||
/**
|
||||
* Construct with property name and potential named parameter.
|
||||
*/
|
||||
protected AbstractValueExpression(String propName, Object bindValue) {
|
||||
super(propName);
|
||||
this.bindValue = bindValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the bind value taking into account named parameters.
|
||||
*/
|
||||
protected Object value() {
|
||||
return NamedParamHelp.value(bindValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the String bind value taking into account named parameters.
|
||||
*/
|
||||
protected String strValue() {
|
||||
return NamedParamHelp.valueAsString(bindValue);
|
||||
}
|
||||
|
||||
}
|
||||
+13
-9
@@ -7,18 +7,22 @@ import com.avaje.ebeaninternal.server.el.ElPropertyValue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
class CaseInsensitiveEqualExpression extends AbstractExpression {
|
||||
class CaseInsensitiveEqualExpression extends AbstractValueExpression {
|
||||
|
||||
private final String value;
|
||||
CaseInsensitiveEqualExpression(String propertyName, Object value) {
|
||||
super(propertyName, value);
|
||||
}
|
||||
|
||||
CaseInsensitiveEqualExpression(String propertyName, String value) {
|
||||
super(propertyName);
|
||||
this.value = value.toLowerCase();
|
||||
/**
|
||||
* Return the bind value taking into account named parameters.
|
||||
*/
|
||||
private String val() {
|
||||
return strValue().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDocQuery(DocQueryContext context) throws IOException {
|
||||
context.writeIEqualTo(propName, value);
|
||||
context.writeIEqualTo(propName, val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -31,7 +35,7 @@ class CaseInsensitiveEqualExpression extends AbstractExpression {
|
||||
request.addBindEncryptKey(encryptKey);
|
||||
}
|
||||
|
||||
request.addBindValue(value);
|
||||
request.addBindValue(val());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,7 +58,7 @@ class CaseInsensitiveEqualExpression extends AbstractExpression {
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return value.hashCode();
|
||||
return val().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -70,6 +74,6 @@ class CaseInsensitiveEqualExpression extends AbstractExpression {
|
||||
@Override
|
||||
public boolean isSameByBind(SpiExpression other) {
|
||||
CaseInsensitiveEqualExpression that = (CaseInsensitiveEqualExpression) other;
|
||||
return value.equals(that.value);
|
||||
return val().equals(that.val());
|
||||
}
|
||||
}
|
||||
+9
-3
@@ -157,6 +157,13 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
|
||||
return new CaseInsensitiveEqualExpression(propertyName, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create for named parameter use (and without support for equalsWithNullAsNoop).
|
||||
*/
|
||||
public Expression ieqObject(String propertyName, Object value) {
|
||||
return new CaseInsensitiveEqualExpression(propertyName, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Between - property between the two given values.
|
||||
*/
|
||||
@@ -252,9 +259,8 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Expression like(LikeType likeType, String propertyName, Object value) {
|
||||
|
||||
return new LikeExpression(propertyName, value, true, LikeType.RAW);
|
||||
public Expression like(String propertyName, Object value, boolean caseInsensitive, LikeType likeType) {
|
||||
return new LikeExpression(propertyName, value, caseInsensitive, likeType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,43 +4,25 @@ import com.avaje.ebean.LikeType;
|
||||
import com.avaje.ebeaninternal.api.HashQueryPlanBuilder;
|
||||
import com.avaje.ebeaninternal.api.SpiExpression;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.api.SpiNamedParam;
|
||||
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
class LikeExpression extends AbstractExpression {
|
||||
|
||||
private final Object value;
|
||||
class LikeExpression extends AbstractValueExpression {
|
||||
|
||||
private final boolean caseInsensitive;
|
||||
|
||||
private final LikeType type;
|
||||
|
||||
LikeExpression(String propertyName, Object value, boolean caseInsensitive, LikeType type) {
|
||||
super(propertyName);
|
||||
super(propertyName, value);
|
||||
this.caseInsensitive = caseInsensitive;
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the bind value taking into account named parameters.
|
||||
*/
|
||||
private Object value() {
|
||||
if (value instanceof SpiNamedParam) {
|
||||
return ((SpiNamedParam)value).getValue();
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
private String val() {
|
||||
return value().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDocQuery(DocQueryContext context) throws IOException {
|
||||
context.writeLike(propName, val(), type, caseInsensitive);
|
||||
context.writeLike(propName, strValue(), type, caseInsensitive);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,7 +35,7 @@ class LikeExpression extends AbstractExpression {
|
||||
request.addBindEncryptKey(encryptKey);
|
||||
}
|
||||
|
||||
String bindValue = getValue(val(), caseInsensitive, type);
|
||||
String bindValue = getValue(strValue(), caseInsensitive, type);
|
||||
request.addBindValue(bindValue);
|
||||
}
|
||||
|
||||
@@ -89,7 +71,7 @@ class LikeExpression extends AbstractExpression {
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
return val().hashCode();
|
||||
return strValue().hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,7 +89,7 @@ class LikeExpression extends AbstractExpression {
|
||||
@Override
|
||||
public boolean isSameByBind(SpiExpression other) {
|
||||
LikeExpression that = (LikeExpression) other;
|
||||
return val().equals(that.val());
|
||||
return strValue().equals(that.strValue());
|
||||
}
|
||||
|
||||
private static String getValue(String value, boolean caseInsensitive, LikeType type) {
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.avaje.ebeaninternal.server.expression;
|
||||
|
||||
import com.avaje.ebeaninternal.api.SpiNamedParam;
|
||||
|
||||
/**
|
||||
* Helper for evaluating named parameters.
|
||||
*/
|
||||
class NamedParamHelp {
|
||||
|
||||
/**
|
||||
* Return the bind value taking into account named parameters.
|
||||
*/
|
||||
static Object value(Object val) {
|
||||
if (val instanceof SpiNamedParam) {
|
||||
return ((SpiNamedParam) val).getValue();
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value as a string.
|
||||
*/
|
||||
static String valueAsString(Object val) {
|
||||
Object value = value(val);
|
||||
return (value == null) ? null : value.toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,31 +5,17 @@ import com.avaje.ebean.plugin.ExpressionPath;
|
||||
import com.avaje.ebeaninternal.api.HashQueryPlanBuilder;
|
||||
import com.avaje.ebeaninternal.api.SpiExpression;
|
||||
import com.avaje.ebeaninternal.api.SpiExpressionRequest;
|
||||
import com.avaje.ebeaninternal.api.SpiNamedParam;
|
||||
import com.avaje.ebeaninternal.server.el.ElPropertyValue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class SimpleExpression extends AbstractExpression {
|
||||
public class SimpleExpression extends AbstractValueExpression {
|
||||
|
||||
private final Op type;
|
||||
|
||||
private final Object val;
|
||||
|
||||
public SimpleExpression(String propertyName, Op type, Object value) {
|
||||
super(propertyName);
|
||||
super(propertyName, value);
|
||||
this.type = type;
|
||||
this.val = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the bind value taking into account named parameters.
|
||||
*/
|
||||
private Object value() {
|
||||
if (val instanceof SpiNamedParam) {
|
||||
return ((SpiNamedParam)val).getValue();
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user