mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
EQL - parsing fetch clause with lazy/query option
This commit is contained in:
@@ -4,9 +4,11 @@ import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebeaninternal.api.SpiQuery;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import com.avaje.tests.model.basic.ResetBasicData;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -203,6 +205,15 @@ public class EqlParserTest {
|
||||
assertThat(query.getGeneratedSql()).contains(", t1.id c9, t1.city");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fetch_withProperty_noWhitespace() throws Exception {
|
||||
|
||||
Query<Customer> query = parse("fetch billingAddress(city)");
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).contains(", t1.id c9, t1.city");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fetch_basic_multiple() throws Exception {
|
||||
|
||||
@@ -222,6 +233,58 @@ public class EqlParserTest {
|
||||
assertThat(query.getGeneratedSql()).contains(", t1.id c8, t1.city c9, t2.id c10, t2.city c11");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fetch_lazy() throws Exception {
|
||||
|
||||
Query<Customer> query = parse("fetch lazy billingAddress");
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).doesNotContain(", t1.city ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fetch_lazy50() throws Exception {
|
||||
|
||||
Query<Customer> query = parse("fetch lazy(50) billingAddress");
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).doesNotContain(", t1.city ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fetch_query50() throws Exception {
|
||||
|
||||
ResetBasicData.reset();
|
||||
Query<Customer> query = parse("fetch query(50) billingAddress");
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).doesNotContain(", t1.city ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fetch_query50_asHint() throws Exception {
|
||||
|
||||
ResetBasicData.reset();
|
||||
Query<Customer> query = parse("fetch billingAddress (+query(50),city)");
|
||||
query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).doesNotContain(", t1.city ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fetch_lazy50_asHint() throws Exception {
|
||||
|
||||
ResetBasicData.reset();
|
||||
Query<Customer> query = parse("fetch billingAddress (+lazy(50),city)");
|
||||
List<Customer> list = query.findList();
|
||||
|
||||
assertThat(query.getGeneratedSql()).doesNotContain(", t1.city ");
|
||||
|
||||
Customer customer = list.get(0);
|
||||
customer.getBillingAddress().getCity();
|
||||
|
||||
}
|
||||
|
||||
private Query<Customer> parse(String raw) {
|
||||
|
||||
Query<Customer> query = Ebean.find(Customer.class);
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.avaje.ebeaninternal.server.grammer;
|
||||
|
||||
import com.avaje.ebean.FetchConfig;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class ParseFetchConfigTest {
|
||||
|
||||
@Test
|
||||
public void parse() throws Exception {
|
||||
|
||||
assertNull(ParseFetchConfig.parse("junk"));
|
||||
assertNull(ParseFetchConfig.parse("lazyFoo"));
|
||||
assertNull(ParseFetchConfig.parse("queryFoo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseLazy() throws Exception {
|
||||
|
||||
FetchConfig lazy = ParseFetchConfig.parse("lazy");
|
||||
assertThat(lazy.getLazyBatchSize()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseLazy100() throws Exception {
|
||||
|
||||
FetchConfig lazy = ParseFetchConfig.parse("lazy(100)");
|
||||
assertThat(lazy.getLazyBatchSize()).isEqualTo(100);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseQuery() throws Exception {
|
||||
|
||||
FetchConfig lazy = ParseFetchConfig.parse("query");
|
||||
assertThat(lazy.getQueryBatchSize()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseQuery100() throws Exception {
|
||||
|
||||
FetchConfig lazy = ParseFetchConfig.parse("query(50)");
|
||||
assertThat(lazy.getQueryBatchSize()).isEqualTo(50);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user