mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-19 23:02:24 +00:00
#570 - ENH: Add ability to configure eBean to use true "ilike" expression
This commit is contained in:
1 parent
2797f6bbcc
commit
2b602f6e51
12 files changed
+199
-19
No files matched your search
+9
-2
@@ -28,10 +28,13 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
|
||||
|
||||
private static final Object[] EMPTY_ARRAY = new Object[] {};
|
||||
|
||||
private final boolean nativeIlike;
|
||||
|
||||
private final boolean equalsWithNullAsNoop;
|
||||
|
||||
public DefaultExpressionFactory(boolean equalsWithNullAsNoop) {
|
||||
public DefaultExpressionFactory(boolean equalsWithNullAsNoop, boolean nativeIlike) {
|
||||
this.equalsWithNullAsNoop = equalsWithNullAsNoop;
|
||||
this.nativeIlike = nativeIlike;
|
||||
}
|
||||
|
||||
public ExpressionFactory createExpressionFactory(){
|
||||
@@ -242,7 +245,11 @@ public class DefaultExpressionFactory implements SpiExpressionFactory {
|
||||
* a lower() function to make the expression case insensitive.
|
||||
*/
|
||||
public Expression ilike(String propertyName, String value) {
|
||||
return new LikeExpression(propertyName, value, true, LikeType.RAW);
|
||||
if (nativeIlike) {
|
||||
return new NativeILikeExpression(propertyName, value);
|
||||
} else {
|
||||
return new LikeExpression(propertyName, value, true, LikeType.RAW);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.avaje.ebeaninternal.server.expression;
|
||||
|
||||
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.server.el.ElPropertyValue;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
class NativeILikeExpression extends AbstractExpression {
|
||||
|
||||
private final String val;
|
||||
|
||||
NativeILikeExpression(String propertyName, String value) {
|
||||
super(propertyName);
|
||||
this.val = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeDocQuery(DocQueryContext context) throws IOException {
|
||||
context.writeLike(propName, val, LikeType.RAW, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBindValues(SpiExpressionRequest request) {
|
||||
|
||||
ElPropertyValue prop = getElProp(request);
|
||||
if (prop != null && prop.isDbEncrypted()) {
|
||||
// bind the key as well as the value
|
||||
String encryptKey = prop.getBeanProperty().getEncryptKey().getStringValue();
|
||||
request.addBindEncryptKey(encryptKey);
|
||||
}
|
||||
request.addBindValue(val);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSql(SpiExpressionRequest request) {
|
||||
|
||||
String pname = propName;
|
||||
ElPropertyValue prop = getElProp(request);
|
||||
if (prop != null && prop.isDbEncrypted()) {
|
||||
pname = prop.getBeanProperty().getDecryptProperty(propName);
|
||||
}
|
||||
|
||||
request.append(pname).append(" ilike ? ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Based on caseInsensitive and the property name.
|
||||
*/
|
||||
@Override
|
||||
public void queryPlanHash(HashQueryPlanBuilder builder) {
|
||||
builder.add(NativeILikeExpression.class).add(propName);
|
||||
builder.bind(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int queryBindHash() {
|
||||
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;
|
||||
return val.equals(that.val);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user