mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#566 - Refactor internals - Initial tidy on OrmQueryDetail and OrmQueryDetailProperties
This commit is contained in:
+126
@@ -0,0 +1,126 @@
|
||||
package com.avaje.ebeaninternal.server.core;
|
||||
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.FetchConfig;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebeaninternal.api.SpiQuery;
|
||||
import com.avaje.ebeaninternal.server.querydefn.DefaultOrmQuery;
|
||||
import com.avaje.ebeaninternal.server.querydefn.OrmQueryDetail;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.StrictAssertions.assertThat;
|
||||
|
||||
public class DefaultServer_createOrmQueryRequestTest extends BaseTestCase {
|
||||
|
||||
static DefaultServer defaultServer = (DefaultServer)Ebean.getDefaultServer();
|
||||
|
||||
Query<Order> query() {
|
||||
return defaultServer.find(Order.class);
|
||||
}
|
||||
|
||||
OrmQueryRequest<Order> queryRequest(Query<Order> query) {
|
||||
return (OrmQueryRequest<Order>)defaultServer.createQueryRequest(SpiQuery.Type.LIST, query, null);
|
||||
}
|
||||
|
||||
OrmQueryDetail detail(Query<Order> query) {
|
||||
return queryRequest(query).getQuery().getDetail();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_empty_then_same() {
|
||||
|
||||
assertSame(detail(query()), detail(query()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void select_all_then_same() {
|
||||
|
||||
assertSame(detail(query().select("*")), detail(query().select("*")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_propertiesInOrder_then_same() {
|
||||
|
||||
assertSame(detail(query().select("id,name")), detail(query().select("id,name")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_propertiesInDifferentOrder_then_different() {
|
||||
|
||||
assertDifferent(detail(query().select("id,name")), detail(query().select("name, id")));
|
||||
|
||||
// but same from autotune perspective
|
||||
assertThat(detail(query().select("id,name")).isAutoTuneEqual(detail(query().select("name, id")))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_additional_fetch_then_different() {
|
||||
|
||||
assertDifferent(detail(query().select("id,name")), detail(query().select("id,name").fetch("details")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_same_fetch_then_same() {
|
||||
|
||||
assertSame(detail(query().select("id,name").fetch("details")), detail(query().select("id,name").fetch("details")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_fetch_order_different_then_different() {
|
||||
|
||||
assertDifferent(detail(query().select("id,name").fetch("details").fetch("customer")),
|
||||
detail(query().select("id,name").fetch("customer").fetch("details")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_extra_queryFetchToMany_then_same() {
|
||||
|
||||
assertDifferent(detail(query().select("id,name").fetch("customer")),
|
||||
detail(query().select("id,name").fetch("customer").fetch("details", new FetchConfig().query())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_extra_queryToOne_fetch_then_different() {
|
||||
|
||||
// with the fetch of customer the foreign key must be added to the root query
|
||||
assertDifferent(detail(query().select("id,name")),
|
||||
detail(query().select("id,name").fetch("customer",new FetchConfig().query())));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_additional_fetch_V2_then_different() {
|
||||
|
||||
assertDifferent(detail(query().select("id,name")), detail(query().select("id,name").fetch("customer","id")));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void when_fetchConfig_then_differentPlan() throws Exception {
|
||||
|
||||
DefaultOrmQuery<Order> query1 = (DefaultOrmQuery<Order>)Ebean.find(Order.class)
|
||||
.select("status, shipDate")
|
||||
.fetch("details", "orderQty, unitPrice", new FetchConfig().query())
|
||||
.fetch("details.product", "sku, name");
|
||||
|
||||
|
||||
DefaultOrmQuery<Order> query2 = (DefaultOrmQuery<Order>)Ebean.find(Order.class)
|
||||
.select("status, shipDate")
|
||||
.fetch("details", "orderQty, unitPrice")
|
||||
.fetch("details.product", "sku, name");
|
||||
|
||||
assertDifferent(detail(query1), detail(query2));
|
||||
}
|
||||
|
||||
private void assertSame(OrmQueryDetail detail1, OrmQueryDetail detail2) {
|
||||
assertThat(detail1.isSameByPlan(detail2)).isTrue();
|
||||
assertThat(detail1.queryPlanHash()).isEqualTo(detail2.queryPlanHash());
|
||||
}
|
||||
|
||||
private void assertDifferent(OrmQueryDetail detail1, OrmQueryDetail detail2) {
|
||||
assertThat(detail1.isSameByPlan(detail2)).isFalse();
|
||||
assertThat(detail1.queryPlanHash()).isNotEqualTo(detail2.queryPlanHash());
|
||||
}
|
||||
}
|
||||
@@ -40,24 +40,6 @@ public class DefaultOrmQueryTest {
|
||||
assertThat(q1.queryBindHash()).isEqualTo(q2.queryBindHash());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void when_FetchConfig_then_differentPlan() throws Exception {
|
||||
|
||||
DefaultOrmQuery<?> query1 = (DefaultOrmQuery<?>)Ebean.find(Order.class)
|
||||
.select("status, shipDate")
|
||||
.fetch("details", "orderQty, unitPrice", new FetchConfig().query())
|
||||
.fetch("details.product", "sku, name");
|
||||
|
||||
|
||||
DefaultOrmQuery<?> query2 = (DefaultOrmQuery<?>)Ebean.find(Order.class)
|
||||
.select("status, shipDate")
|
||||
.fetch("details", "orderQty, unitPrice")
|
||||
.fetch("details.product", "sku, name");
|
||||
|
||||
assertThat(query1.createQueryPlanKey()).isNotEqualTo(query2.createQueryPlanKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_diffFirstMaxRows_then_differentPlan() throws Exception {
|
||||
|
||||
|
||||
+35
-38
@@ -5,114 +5,111 @@ import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
public class OrmQueryDetailParserTest extends BaseTestCase {
|
||||
|
||||
OrmQueryDetail parse(String query) {
|
||||
return new OrmQueryDetailParser(query).parse();
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void parse_when_nullString() throws Exception {
|
||||
parse(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parse_when_emptyString() throws Exception {
|
||||
assertTrue(parse("").isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseBasic() throws Exception {
|
||||
|
||||
OrmQueryDetail detail = parse("select (id,name)");
|
||||
|
||||
OrmQueryDetail other = new OrmQueryDetail();
|
||||
other.select("id,name");
|
||||
|
||||
OrmQueryProperties root = other.getChunk(null, false);
|
||||
OrmQueryProperties root = detail.getChunk(null, false);
|
||||
assertNull(root.getPath());
|
||||
assertThat(root.getAllIncludedProperties()).contains("id", "name");
|
||||
|
||||
OrmQueryDetailParser p = new OrmQueryDetailParser("select (id,name)");
|
||||
OrmQueryDetail detail = p.parse();
|
||||
|
||||
root = detail.getChunk(null, false);
|
||||
assertNull(root.getPath());
|
||||
assertThat(root.getAllIncludedProperties()).contains("id", "name");
|
||||
assertThat(root.getIncluded()).containsExactly("id", "name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseEmptySelect() throws Exception {
|
||||
|
||||
OrmQueryDetailParser p = new OrmQueryDetailParser("select fetch customer (email)");
|
||||
OrmQueryDetail detail = p.parse();
|
||||
OrmQueryDetail detail = parse("select fetch customer (email)");
|
||||
|
||||
OrmQueryProperties root = detail.getChunk(null, false);
|
||||
assertNull(root.getPath());
|
||||
assertThat(root.getAllIncludedProperties()).isNull();
|
||||
assertThat(root.getIncluded()).isNull();
|
||||
|
||||
OrmQueryProperties chunk = detail.getChunk("customer", false);
|
||||
assertThat(chunk.getPath()).isEqualTo("customer");
|
||||
assertThat(chunk.getAllIncludedProperties()).contains("email");
|
||||
assertThat(chunk.getIncluded()).contains("email");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseSelectFetch() throws Exception {
|
||||
|
||||
OrmQueryDetailParser p = new OrmQueryDetailParser("select (id,name) fetch customer (email)");
|
||||
OrmQueryDetail detail = p.parse();
|
||||
OrmQueryDetail detail = parse("select (id,name) fetch customer (email)");
|
||||
|
||||
OrmQueryProperties root = detail.getChunk(null, false);
|
||||
assertNull(root.getPath());
|
||||
assertThat(root.getAllIncludedProperties()).contains("id", "name");
|
||||
assertThat(root.getIncluded()).contains("id", "name");
|
||||
|
||||
OrmQueryProperties chunk = detail.getChunk("customer", false);
|
||||
assertThat(chunk.getPath()).isEqualTo("customer");
|
||||
assertThat(chunk.getAllIncludedProperties()).contains("email");
|
||||
assertThat(chunk.getIncluded()).contains("email");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseSelectFetchMore() throws Exception {
|
||||
|
||||
OrmQueryDetailParser p = new OrmQueryDetailParser("select (id,name) fetch customer (email) fetch details.product (sku,description)");
|
||||
OrmQueryDetail detail = p.parse();
|
||||
OrmQueryDetail detail = parse("select (id,name) fetch customer (email) fetch details.product (sku,description)");
|
||||
|
||||
OrmQueryProperties root = detail.getChunk(null, false);
|
||||
assertNull(root.getPath());
|
||||
assertThat(root.getAllIncludedProperties()).contains("id", "name");
|
||||
assertThat(root.getIncluded()).contains("id", "name");
|
||||
|
||||
OrmQueryProperties chunk = detail.getChunk("customer", false);
|
||||
assertThat(chunk.getPath()).isEqualTo("customer");
|
||||
assertThat(chunk.getAllIncludedProperties()).contains("email");
|
||||
assertThat(chunk.getIncluded()).contains("email");
|
||||
|
||||
chunk = detail.getChunk("details.product", false);
|
||||
assertThat(chunk.getPath()).isEqualTo("details.product");
|
||||
assertThat(chunk.getAllIncludedProperties()).contains("sku","description");
|
||||
assertThat(chunk.getIncluded()).contains("sku","description");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseWithPlusQuery() throws Exception {
|
||||
|
||||
OrmQueryDetailParser p = new OrmQueryDetailParser("select (id,name) fetch customer (+query,id,name,email)");
|
||||
OrmQueryDetail detail = p.parse();
|
||||
OrmQueryDetail detail = parse("select (id,name) fetch customer (+query,id,name,email)");
|
||||
|
||||
OrmQueryProperties root = detail.getChunk(null, false);
|
||||
assertNull(root.getPath());
|
||||
assertThat(root.getAllIncludedProperties()).contains("id", "name");
|
||||
assertThat(root.getIncluded()).contains("id", "name");
|
||||
|
||||
OrmQueryProperties chunk = detail.getChunk("customer", false);
|
||||
assertThat(chunk.getPath()).isEqualTo("customer");
|
||||
assertThat(chunk.getAllIncludedProperties()).contains("id", "name", "email");
|
||||
assertThat(chunk.getIncluded()).contains("id", "name", "email");
|
||||
assertThat(chunk.isQueryFetch()).isTrue();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTuneApply() {
|
||||
|
||||
OrmQueryDetailParser p = new OrmQueryDetailParser("select (status) fetch customer (email)");
|
||||
OrmQueryDetail detail = p.parse();
|
||||
|
||||
OrmQueryDetailParser p2 = new OrmQueryDetailParser("select (id,name) fetch customer (+query,id,name,email)");
|
||||
OrmQueryDetail tune = p2.parse();
|
||||
|
||||
OrmQueryDetail detail = parse("select (status) fetch customer (email)");
|
||||
OrmQueryDetail tune = parse("select (id,name) fetch customer (+query,id,name,email)");
|
||||
|
||||
detail.tuneFetchProperties(tune);
|
||||
|
||||
OrmQueryProperties root = detail.getChunk(null, false);
|
||||
assertNull(root.getPath());
|
||||
assertThat(root.getAllIncludedProperties()).contains("id", "name");
|
||||
assertThat(root.getIncluded()).contains("id", "name");
|
||||
|
||||
OrmQueryProperties chunk = detail.getChunk("customer", false);
|
||||
assertThat(chunk.getPath()).isEqualTo("customer");
|
||||
assertThat(chunk.getAllIncludedProperties()).contains("id", "name", "email");
|
||||
assertThat(chunk.getIncluded()).contains("id", "name", "email");
|
||||
assertThat(chunk.isQueryFetch()).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,20 +2,70 @@ package com.avaje.ebeaninternal.server.querydefn;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class OrmQueryDetailTest {
|
||||
|
||||
OrmQueryDetail parse(String query) {
|
||||
return new OrmQueryDetailParser(query).parse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_isAutoTuneEqual() {
|
||||
public void isAutoTuneEqual_when_fetchOrderIsDifferent_then_stillEqual() {
|
||||
|
||||
OrmQueryDetailParser parser1 = new OrmQueryDetailParser("select (id,name) fetch customer (name) fetch details (code)");
|
||||
OrmQueryDetail detail1 = parser1.parse();
|
||||
|
||||
OrmQueryDetailParser parser2 = new OrmQueryDetailParser("select (id,name) fetch details (code) fetch customer (name)");
|
||||
OrmQueryDetail detail2 = parser2.parse();
|
||||
OrmQueryDetail detail1 = parse("select (id,name) fetch customer (name) fetch details (code)");
|
||||
OrmQueryDetail detail2 = parse("select (id,name) fetch details (code) fetch customer (name)");
|
||||
|
||||
assertTrue(detail1.isAutoTuneEqual(detail2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAutoTuneEqual_when_different_select() {
|
||||
|
||||
OrmQueryDetail detail1 = parse("select (id,name) fetch customer (name) fetch details (code)");
|
||||
OrmQueryDetail detail2 = parse("select (id) fetch details (code) fetch customer (name)");
|
||||
|
||||
assertFalse(detail1.isAutoTuneEqual(detail2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAutoTuneEqual_when_different_selectInFetch() {
|
||||
|
||||
OrmQueryDetail detail1 = parse("select (id,name) fetch customer (name) fetch details (code)");
|
||||
OrmQueryDetail detail2 = parse("select (id,name) fetch customer (id,name) fetch details (code)");
|
||||
|
||||
assertFalse(detail1.isAutoTuneEqual(detail2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAutoTuneEqual_when_different_additionalFetch() {
|
||||
|
||||
OrmQueryDetail detail1 = parse("select (id,name) fetch customer (name) fetch details (code)");
|
||||
OrmQueryDetail detail2 = parse("select (id,name) fetch customer (name) fetch details (code) fetch customer.contacts");
|
||||
|
||||
assertFalse(detail1.isAutoTuneEqual(detail2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void select_whenMultiple() throws Exception {
|
||||
|
||||
OrmQueryDetail other = new OrmQueryDetail();
|
||||
other.select("id,name");
|
||||
|
||||
OrmQueryProperties root = other.getChunk(null, false);
|
||||
assertNull(root.getPath());
|
||||
assertThat(root.getIncluded()).containsExactly("id", "name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void select_whenOne() throws Exception {
|
||||
|
||||
OrmQueryDetail other = new OrmQueryDetail();
|
||||
other.select("name");
|
||||
|
||||
OrmQueryProperties root = other.getChunk(null, false);
|
||||
assertNull(root.getPath());
|
||||
assertThat(root.getIncluded()).containsExactly("name");
|
||||
}
|
||||
}
|
||||
+132
@@ -0,0 +1,132 @@
|
||||
package com.avaje.ebeaninternal.server.querydefn;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class OrmQueryPropertiesParserTest {
|
||||
|
||||
@Test
|
||||
public void when_null() {
|
||||
|
||||
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse(null);
|
||||
assertAllDefaults(res);
|
||||
assertThat(res.properties).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_empty() throws Exception {
|
||||
|
||||
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("");
|
||||
assertAllDefaults(res);
|
||||
assertThat(res.properties).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_hasStar() throws Exception {
|
||||
|
||||
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("*");
|
||||
assertAllDefaults(res);
|
||||
assertThat(res.properties).isEqualTo("*");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_hasCache() throws Exception {
|
||||
|
||||
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+cache");
|
||||
assertThat(res.cache).isTrue();
|
||||
assertThat(res.included).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_hasCache_first() throws Exception {
|
||||
|
||||
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+cache,id");
|
||||
assertThat(res.cache).isTrue();
|
||||
assertThat(res.included).containsExactly("id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_hasCache_last() throws Exception {
|
||||
|
||||
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("name,+cache");
|
||||
assertThat(res.cache).isTrue();
|
||||
assertThat(res.included).containsExactly("name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_hasCache_middle() throws Exception {
|
||||
|
||||
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("name,+cache, id");
|
||||
assertThat(res.cache).isTrue();
|
||||
assertThat(res.included).containsExactly("name", "id");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_hasReadOnly() throws Exception {
|
||||
|
||||
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+readonly");
|
||||
assertThat(res.readOnly).isTrue();
|
||||
assertThat(res.included).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_hasLazy() throws Exception {
|
||||
|
||||
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+lazy");
|
||||
assertThat(res.lazyFetchBatch).isEqualTo(0);
|
||||
assertThat(res.included).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_hasLazyValue() throws Exception {
|
||||
|
||||
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+lazy(20)");
|
||||
assertThat(res.lazyFetchBatch).isEqualTo(20);
|
||||
assertThat(res.included).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_hasLazyValue_last() throws Exception {
|
||||
|
||||
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("name,+lazy(20)");
|
||||
assertThat(res.lazyFetchBatch).isEqualTo(20);
|
||||
assertThat(res.included).containsExactly("name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_hasLazyValue_first() throws Exception {
|
||||
|
||||
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+lazy(20),id,name");
|
||||
assertThat(res.lazyFetchBatch).isEqualTo(20);
|
||||
assertThat(res.included).containsExactly("id", "name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void when_allProperties() throws Exception {
|
||||
|
||||
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+query(4),+lazy(5)");
|
||||
assertThat(res.lazyFetchBatch).isEqualTo(5);
|
||||
assertThat(res.included).isNull();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void when_everything_set() throws Exception {
|
||||
|
||||
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("id, name +readonly +lazy(20) +query(30) +cache");
|
||||
assertThat(res.lazyFetchBatch).isEqualTo(20);
|
||||
assertThat(res.queryFetchBatch).isEqualTo(30);
|
||||
assertThat(res.readOnly).isTrue();
|
||||
assertThat(res.cache).isTrue();
|
||||
assertThat(res.included).containsExactly("id", "name");
|
||||
}
|
||||
|
||||
private void assertAllDefaults(OrmQueryPropertiesParser.Response res) {
|
||||
assertThat(res.cache).isFalse();
|
||||
assertThat(res.readOnly).isFalse();
|
||||
assertThat(res.lazyFetchBatch).isEqualTo(-1);
|
||||
assertThat(res.queryFetchBatch).isEqualTo(-1);
|
||||
assertThat(res.included).isNull();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.avaje.ebeaninternal.server.querydefn;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class OrmQueryPropertiesTest {
|
||||
|
||||
String append(String prefix, OrmQueryProperties p1) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
p1.append(prefix, sb);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void append_when_empty() {
|
||||
|
||||
OrmQueryProperties p1 = new OrmQueryProperties();
|
||||
assertThat(append("select ",p1)).isEqualTo("select ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void append_when_someProperties() {
|
||||
|
||||
OrmQueryProperties p1 = new OrmQueryProperties(null, "id,name");
|
||||
assertThat(append("select ",p1)).isEqualTo("select (id,name) ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void append_when_somePropertiesWithOptions() {
|
||||
|
||||
OrmQueryProperties p1 = new OrmQueryProperties(null, "id,name +cache");
|
||||
assertThat(append("select ",p1)).isEqualTo("select (id,name +cache) ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void append_when_path_and_emptyProperties() {
|
||||
|
||||
OrmQueryProperties p1 = new OrmQueryProperties("customer", "");
|
||||
assertThat(append("fetch ",p1)).isEqualTo("fetch customer ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void append_when_path_and_somePropertiesWithOptions() {
|
||||
|
||||
OrmQueryProperties p1 = new OrmQueryProperties("customer", "id,name +cache");
|
||||
assertThat(append("fetch ",p1)).isEqualTo("fetch customer (id,name +cache) ");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,15 +1,14 @@
|
||||
package com.avaje.ebeaninternal.server.querydefn;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.ebeaninternal.server.expression.DefaultExpressionFactory;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class TestQueryLanguage extends BaseTestCase {
|
||||
|
||||
@@ -19,7 +18,7 @@ public class TestQueryLanguage extends BaseTestCase {
|
||||
DefaultOrmQuery<Order> q = check("find order join customer (id, name)");
|
||||
OrmQueryDetail detail = q.getDetail();
|
||||
OrmQueryProperties chunk = detail.getChunk("customer", false);
|
||||
Set<String> props = chunk.getAllIncludedProperties();
|
||||
Set<String> props = chunk.getIncluded();
|
||||
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("name"));
|
||||
@@ -27,7 +26,7 @@ public class TestQueryLanguage extends BaseTestCase {
|
||||
q = check("find order join customer(id, name)");
|
||||
detail = q.getDetail();
|
||||
chunk = detail.getChunk("customer", false);
|
||||
props = chunk.getAllIncludedProperties();
|
||||
props = chunk.getIncluded();
|
||||
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("name"));
|
||||
@@ -37,7 +36,7 @@ public class TestQueryLanguage extends BaseTestCase {
|
||||
q = check("find order join customer(+cache +readonly, id, name)");
|
||||
detail = q.getDetail();
|
||||
chunk = detail.getChunk("customer", false);
|
||||
props = chunk.getAllIncludedProperties();
|
||||
props = chunk.getIncluded();
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("name"));
|
||||
Assert.assertTrue(chunk.isCache());
|
||||
@@ -46,7 +45,7 @@ public class TestQueryLanguage extends BaseTestCase {
|
||||
q = check("find order join customer(+cache +readonly,id,name)");
|
||||
detail = q.getDetail();
|
||||
chunk = detail.getChunk("customer", false);
|
||||
props = chunk.getAllIncludedProperties();
|
||||
props = chunk.getIncluded();
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("name"));
|
||||
Assert.assertTrue(chunk.isCache());
|
||||
@@ -55,14 +54,14 @@ public class TestQueryLanguage extends BaseTestCase {
|
||||
q = check("find order(id,status) join customer(+cache +readonly,id,name)");
|
||||
detail = q.getDetail();
|
||||
chunk = detail.getChunk("customer", false);
|
||||
props = chunk.getAllIncludedProperties();
|
||||
props = chunk.getIncluded();
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("name"));
|
||||
Assert.assertTrue(chunk.isCache());
|
||||
Assert.assertTrue(chunk.isReadOnly());
|
||||
|
||||
chunk = detail.getChunk(null, false);
|
||||
props = chunk.getAllIncludedProperties();
|
||||
props = chunk.getIncluded();
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("status"));
|
||||
Assert.assertFalse(props.contains("orderDate"));
|
||||
@@ -70,7 +69,7 @@ public class TestQueryLanguage extends BaseTestCase {
|
||||
q = check("find order(id,status) join customer(+cache +readonly,id,name) where id > :minId order by status");
|
||||
detail = q.getDetail();
|
||||
chunk = detail.getChunk("customer", false);
|
||||
props = chunk.getAllIncludedProperties();
|
||||
props = chunk.getIncluded();
|
||||
Assert.assertTrue(props.contains("id"));
|
||||
Assert.assertTrue(props.contains("name"));
|
||||
Assert.assertTrue(chunk.isCache());
|
||||
|
||||
@@ -101,7 +101,7 @@ public class TunedQueryInfoTest extends BaseTestCase {
|
||||
@NotNull
|
||||
private TunedQueryInfo createTunedQueryInfo(OrmQueryDetail tunedDetail) {
|
||||
Origin origin = new Origin();
|
||||
origin.setDetail(tunedDetail.toString());
|
||||
origin.setDetail(tunedDetail.asString());
|
||||
return new TunedQueryInfo(origin);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,37 +1,40 @@
|
||||
package com.avaje.tests.query;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
import com.avaje.ebean.Ebean;
|
||||
import com.avaje.ebean.Query;
|
||||
import com.avaje.ebeaninternal.api.SpiQuery;
|
||||
import com.avaje.ebeaninternal.server.querydefn.OrmQueryDetail;
|
||||
import com.avaje.tests.model.basic.Order;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TestQueryParsing extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
String oq = "find order join customer join customer.contacts join details (+query(4),+lazy(5))";
|
||||
String oq = "find order join customer (id, name) join customer.contacts join details (+query(4),+lazy(5))";
|
||||
Query<Order> q = Ebean.createQuery(Order.class, oq);
|
||||
checkQuery(q);
|
||||
|
||||
String oq1 = "find order join customer join customer.contacts join details ( +query(4), +lazy(5) )";
|
||||
String oq1 = "find order join customer (id, name) join customer.contacts join details ( +query(4), +lazy(5) )";
|
||||
SpiQuery<?> q1 = (SpiQuery<?>) Ebean.createQuery(Order.class, oq1);
|
||||
checkQuery(q1);
|
||||
|
||||
String oq2 = "find order join customer join customer.contacts join details ( +query(4), +lazy(5) , *)";
|
||||
String oq2 = "find order join customer (id, name) join customer.contacts join details ( +query(4), +lazy(5) , *)";
|
||||
SpiQuery<?> q2 = (SpiQuery<?>) Ebean.createQuery(Order.class, oq2);
|
||||
checkQuery(q2);
|
||||
|
||||
String oq3 = "find order join customer join customer.contacts join details (+query(4),+lazy(5),*)";
|
||||
String oq3 = "find order join customer (id, name) join customer.contacts join details (+query(4),+lazy(5),*)";
|
||||
SpiQuery<?> q3 = (SpiQuery<?>) Ebean.createQuery(Order.class, oq3);
|
||||
checkQuery(q3);
|
||||
|
||||
String oq4 = "find order join customer join customer.contacts join details (+query(4) +lazy(5) *)";
|
||||
String oq4 = "find order join customer (id, name) join customer.contacts join details (+query(4) +lazy(5) *)";
|
||||
SpiQuery<?> q4 = (SpiQuery<?>) Ebean.createQuery(Order.class, oq4);
|
||||
checkQuery(q4);
|
||||
|
||||
@@ -41,23 +44,25 @@ public class TestQueryParsing extends BaseTestCase {
|
||||
|
||||
SpiQuery<?> sq = (SpiQuery<?>) q;
|
||||
OrmQueryDetail detail = sq.getDetail();
|
||||
assertTrue(detail.getChunk(null, false).allProperties());
|
||||
|
||||
Assert.assertNotNull(detail.getChunk("customer", false));
|
||||
Assert.assertFalse(detail.getChunk("customer", false).isQueryFetch());
|
||||
Assert.assertFalse(detail.getChunk("customer", false).isLazyFetch());
|
||||
assertNotNull(detail.getChunk("customer", false));
|
||||
assertFalse(detail.getChunk("customer", false).isQueryFetch());
|
||||
assertFalse(detail.getChunk("customer", false).isLazyFetch());
|
||||
assertFalse(detail.getChunk("customer", false).allProperties());
|
||||
assertEquals("id, name",detail.getChunk("customer", false).getProperties());
|
||||
|
||||
Assert.assertNotNull(detail.getChunk("customer.contacts", false));
|
||||
Assert.assertFalse(detail.getChunk("customer.contacts", false).isQueryFetch());
|
||||
Assert.assertFalse(detail.getChunk("customer.contacts", false).isLazyFetch());
|
||||
assertNotNull(detail.getChunk("customer.contacts", false));
|
||||
assertFalse(detail.getChunk("customer.contacts", false).isQueryFetch());
|
||||
assertFalse(detail.getChunk("customer.contacts", false).isLazyFetch());
|
||||
assertTrue(detail.getChunk("customer.contacts", false).allProperties());
|
||||
|
||||
Assert.assertNotNull(detail.getChunk("details", false));
|
||||
Assert.assertTrue(detail.getChunk("details", false).isQueryFetch());
|
||||
Assert.assertTrue(detail.getChunk("details", false).isLazyFetch());
|
||||
|
||||
Assert.assertEquals(4, detail.getChunk("details", false).getQueryFetchBatch());
|
||||
Assert.assertEquals(5, detail.getChunk("details", false).getLazyFetchBatch());
|
||||
|
||||
Assert.assertTrue(detail.getChunk("details", false).allProperties());
|
||||
assertNotNull(detail.getChunk("details", false));
|
||||
assertTrue(detail.getChunk("details", false).isQueryFetch());
|
||||
assertTrue(detail.getChunk("details", false).isLazyFetch());
|
||||
assertEquals(4, detail.getChunk("details", false).getQueryFetchBatch());
|
||||
assertEquals(5, detail.getChunk("details", false).getLazyFetchBatch());
|
||||
assertTrue(detail.getChunk("details", false).allProperties());
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user