mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#361 - ENH: Add ServerConfig expressionEqualsWithNullAsNoop - Can eq ne gt ... methods in ExpressionList treat null value as 1=1 ?
This commit is contained in:
+58
@@ -0,0 +1,58 @@
|
||||
package com.avaje.ebeaninternal.server.expression;
|
||||
|
||||
import com.avaje.ebean.Expression;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.StrictAssertions.assertThat;
|
||||
|
||||
|
||||
public class DefaultExpressionFactoryTest {
|
||||
|
||||
@Test
|
||||
public void testEq() throws Exception {
|
||||
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(false);
|
||||
Expression expression = factory.eq("name", null);
|
||||
assertThat(expression).isInstanceOf(NullExpression.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNe() throws Exception {
|
||||
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(false);
|
||||
Expression expression = factory.ne("name", null);
|
||||
assertThat(expression).isInstanceOf(NullExpression.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIeq() throws Exception {
|
||||
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(false);
|
||||
Expression expression = factory.ieq("name", null);
|
||||
assertThat(expression).isInstanceOf(NullExpression.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEq_with_equalsWithNullAsNoop() throws Exception {
|
||||
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(true);
|
||||
Expression expression = factory.eq("name", null);
|
||||
assertThat(expression).isInstanceOf(NoopExpression.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNe_with_equalsWithNullAsNoop() throws Exception {
|
||||
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(true);
|
||||
Expression expression = factory.ne("name", null);
|
||||
assertThat(expression).isInstanceOf(NoopExpression.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIeq_with_equalsWithNullAsNoop() throws Exception {
|
||||
|
||||
DefaultExpressionFactory factory = new DefaultExpressionFactory(true);
|
||||
Expression expression = factory.ieq("name", null);
|
||||
assertThat(expression).isInstanceOf(NoopExpression.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.avaje.ebeaninternal.server.expression;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class NoopExpressionQueryTest extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class)
|
||||
.select("id")
|
||||
.where().add(NoopExpression.INSTANCE)
|
||||
.query();
|
||||
|
||||
query.findList();
|
||||
String generatedSql = query.getGeneratedSql();
|
||||
|
||||
assertThat(generatedSql).contains("select t0.id c0 from o_customer t0 where 1=1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_withPreAndPost() {
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class)
|
||||
.select("id")
|
||||
.where().eq("name", null)
|
||||
.add(NoopExpression.INSTANCE)
|
||||
.ne("status", null)
|
||||
.query();
|
||||
|
||||
query.findList();
|
||||
String generatedSql = query.getGeneratedSql();
|
||||
|
||||
assertThat(generatedSql).contains("select t0.id c0 from o_customer t0 where t0.name is null and 1=1 and t0.status is not null");
|
||||
}
|
||||
}
|
||||
@@ -87,7 +87,7 @@ public class TestQueryLanguage extends BaseTestCase {
|
||||
OrmQueryDetailParser p = new OrmQueryDetailParser(q);
|
||||
p.parse();
|
||||
DefaultOrmQuery<Order> qry = new DefaultOrmQuery<Order>(Order.class, server,
|
||||
new DefaultExpressionFactory(), (String) null);
|
||||
new DefaultExpressionFactory(false), (String) null);
|
||||
p.assign(qry);
|
||||
|
||||
return qry;
|
||||
|
||||
Reference in New Issue
Block a user