mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#570 - ENH: Add ability to configure eBean to use true "ilike" expression
This commit is contained in:
+22
-6
@@ -8,10 +8,26 @@ import static org.assertj.core.api.StrictAssertions.assertThat;
|
||||
|
||||
public class DefaultExpressionFactoryTest {
|
||||
|
||||
@Test
|
||||
public void testLowerILike() throws Exception {
|
||||
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(false, false);
|
||||
Expression expression = factory.ilike("name", "foo");
|
||||
assertThat(expression).isInstanceOf(LikeExpression.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNativeILike() throws Exception {
|
||||
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(false, true);
|
||||
Expression expression = factory.ilike("name", "foo");
|
||||
assertThat(expression).isInstanceOf(NativeILikeExpression.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEq() throws Exception {
|
||||
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(false);
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(false, false);
|
||||
Expression expression = factory.eq("name", null);
|
||||
assertThat(expression).isInstanceOf(NullExpression.class);
|
||||
}
|
||||
@@ -19,7 +35,7 @@ public class DefaultExpressionFactoryTest {
|
||||
@Test
|
||||
public void testNe() throws Exception {
|
||||
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(false);
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(false, false);
|
||||
Expression expression = factory.ne("name", null);
|
||||
assertThat(expression).isInstanceOf(NullExpression.class);
|
||||
}
|
||||
@@ -27,7 +43,7 @@ public class DefaultExpressionFactoryTest {
|
||||
@Test
|
||||
public void testIeq() throws Exception {
|
||||
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(false);
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(false, false);
|
||||
Expression expression = factory.ieq("name", null);
|
||||
assertThat(expression).isInstanceOf(NullExpression.class);
|
||||
}
|
||||
@@ -35,7 +51,7 @@ public class DefaultExpressionFactoryTest {
|
||||
@Test
|
||||
public void testEq_with_equalsWithNullAsNoop() throws Exception {
|
||||
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(true);
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(true, false);
|
||||
Expression expression = factory.eq("name", null);
|
||||
assertThat(expression).isInstanceOf(NoopExpression.class);
|
||||
}
|
||||
@@ -43,7 +59,7 @@ public class DefaultExpressionFactoryTest {
|
||||
@Test
|
||||
public void testNe_with_equalsWithNullAsNoop() throws Exception {
|
||||
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(true);
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(true, false);
|
||||
Expression expression = factory.ne("name", null);
|
||||
assertThat(expression).isInstanceOf(NoopExpression.class);
|
||||
}
|
||||
@@ -51,7 +67,7 @@ public class DefaultExpressionFactoryTest {
|
||||
@Test
|
||||
public void testIeq_with_equalsWithNullAsNoop() throws Exception {
|
||||
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(true);
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(true, false);
|
||||
Expression expression = factory.ieq("name", null);
|
||||
assertThat(expression).isInstanceOf(NoopExpression.class);
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ public class DefaultExpressionListTest {
|
||||
|
||||
DefaultExpressionList exp() {
|
||||
|
||||
return new DefaultExpressionList<Object>(null, new DefaultExpressionFactory(true), null);
|
||||
return new DefaultExpressionList<Object>(null, new DefaultExpressionFactory(true, true), null);
|
||||
}
|
||||
|
||||
DefaultExpressionList spi(ExpressionList list) {
|
||||
|
||||
@@ -16,7 +16,7 @@ public class JunctionExpressionTest {
|
||||
|
||||
DefaultExpressionList<?> exp(Expression... expressions) {
|
||||
|
||||
DefaultExpressionList<Object> list = new DefaultExpressionList<Object>(null, new DefaultExpressionFactory(true), null);
|
||||
DefaultExpressionList<Object> list = new DefaultExpressionList<Object>(null, new DefaultExpressionFactory(true, false), null);
|
||||
for (Expression ex : expressions) {
|
||||
list.add(ex);
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ public class TestQueryLanguage extends BaseTestCase {
|
||||
|
||||
BeanDescriptor<Order> desc = server.getBeanDescriptor(Order.class);
|
||||
DefaultOrmQuery<Order> qry = new DefaultOrmQuery<Order>(desc, server,
|
||||
new DefaultExpressionFactory(false), (String) null);
|
||||
new DefaultExpressionFactory(false, false), (String) null);
|
||||
p.assign(qry);
|
||||
|
||||
return qry;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.avaje.tests.query.sqlquery;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebean.plugin.SpiServer;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestNativeILikeExpression extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
boolean expectNative = isExpectNative();
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class)
|
||||
.where().ilike("name", "rob")
|
||||
.query();
|
||||
|
||||
List<Customer> list = query.findList();
|
||||
|
||||
if (expectNative) {
|
||||
assertThat(query.getGeneratedSql()).contains(" from o_customer t0 where t0.name ilike ?");
|
||||
assertThat(list).isNotEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isExpectNative() {
|
||||
|
||||
SpiServer pluginApi = server().getPluginApi();
|
||||
boolean expressionNativeIlike = pluginApi.getServerConfig().isExpressionNativeIlike();
|
||||
String platformName = pluginApi.getDatabasePlatform().getName();
|
||||
|
||||
return expressionNativeIlike && platformName.equalsIgnoreCase("postgres");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user