Remove support for "query hints" like +query(50) (#2163)

* Remove support for "query hints" like +query(50)

* Remove unused readOnly from OrmQueryProperties

* OrmQueryProperties cache as final field
This commit is contained in:
Rob Bygrave authored and GitHub committed 2021-02-14 11:21:10 +13:00
1 parent 4c16b85e85
commit a6fdc42934
6 files changed
+23 -169

No files matched your search

@@ -33,16 +33,13 @@ public class OrmQueryProperties implements Serializable {
private final String properties; private final String properties;
private final Set<String> included; private final Set<String> included;
private final FetchConfig fetchConfig; private final FetchConfig fetchConfig;
private final boolean cache;
/** /**
* Flag set when this fetch path needs to be a query join. * Flag set when this fetch path needs to be a query join.
*/ */
private boolean markForQueryJoin; private boolean markForQueryJoin;
private boolean cache;
private boolean readOnly;
/** /**
* Included bean joins. * Included bean joins.
*/ */
@@ -82,6 +79,7 @@ public class OrmQueryProperties implements Serializable {
this.parentPath = SplitName.parent(path); this.parentPath = SplitName.parent(path);
this.properties = null; this.properties = null;
this.included = null; this.included = null;
this.cache = false;
this.fetchConfig = DEFAULT_FETCH; this.fetchConfig = DEFAULT_FETCH;
} }
@@ -96,26 +94,16 @@ public class OrmQueryProperties implements Serializable {
OrmQueryPropertiesParser.Response response = OrmQueryPropertiesParser.parse(rawProperties); OrmQueryPropertiesParser.Response response = OrmQueryPropertiesParser.parse(rawProperties);
this.properties = response.properties; this.properties = response.properties;
this.included = response.included; this.included = response.included;
this.cache = response.cache; this.fetchConfig = fetchConfig != null ? fetchConfig : DEFAULT_FETCH;
this.readOnly = response.readOnly; this.cache = fetchConfig.isCache();
if (fetchConfig != null) {
this.fetchConfig = fetchConfig;
if (fetchConfig.isCache()) {
this.cache = true;
}
} else {
this.fetchConfig = response.fetchConfig;
}
} }
public OrmQueryProperties(String path, Set<String> included) { public OrmQueryProperties(String path, Set<String> included) {
this.path = path; this.path = path;
this.parentPath = SplitName.parent(path); this.parentPath = SplitName.parent(path);
// for rawSql parsedProperties can be empty (when only fetching Id property)
this.included = included; this.included = included;
this.properties = String.join(",", included); this.properties = String.join(",", included);
this.cache = false; this.cache = false;
this.readOnly = false;
this.fetchConfig = DEFAULT_FETCH; this.fetchConfig = DEFAULT_FETCH;
} }
@@ -128,7 +116,6 @@ public class OrmQueryProperties implements Serializable {
this.path = source.path; this.path = source.path;
this.properties = source.properties; this.properties = source.properties;
this.cache = source.cache; this.cache = source.cache;
this.readOnly = source.readOnly;
this.filterMany = source.filterMany; this.filterMany = source.filterMany;
this.markForQueryJoin = source.markForQueryJoin; this.markForQueryJoin = source.markForQueryJoin;
this.included = (source.included == null) ? null : new LinkedHashSet<>(source.included); this.included = (source.included == null) ? null : new LinkedHashSet<>(source.included);
@@ -151,6 +138,7 @@ public class OrmQueryProperties implements Serializable {
/** /**
* Move a OrderBy.Property from the main query to this query join. * Move a OrderBy.Property from the main query to this query join.
*/ */
@SuppressWarnings("rawtypes")
void addSecJoinOrderProperty(OrderBy.Property orderProp) { void addSecJoinOrderProperty(OrderBy.Property orderProp) {
if (orderBy == null) { if (orderBy == null) {
orderBy = new OrderBy(); orderBy = new OrderBy();
@@ -166,7 +154,7 @@ public class OrmQueryProperties implements Serializable {
* Return the expressions used to filter on this path. This should be a many path to use this * Return the expressions used to filter on this path. This should be a many path to use this
* method. * method.
*/ */
@SuppressWarnings({"unchecked"}) @SuppressWarnings({"rawtypes","unchecked"})
public <T> SpiExpressionList<T> filterMany(Query<T> rootQuery) { public <T> SpiExpressionList<T> filterMany(Query<T> rootQuery) {
if (filterMany == null) { if (filterMany == null) {
FilterExprPath exprPath = new FilterExprPath(path); FilterExprPath exprPath = new FilterExprPath(path);
@@ -371,14 +359,7 @@ public class OrmQueryProperties implements Serializable {
} }
/** /**
* Return true if this path has the +readonly option. * Return true if this path should hit the L2 cache.
*/
public boolean isReadOnly() {
return readOnly;
}
/**
* Return true if this path has the +cache option to hit the cache.
*/ */
public boolean isCache() { public boolean isCache() {
return cache; return cache;
@@ -1,9 +1,7 @@
package io.ebeaninternal.server.querydefn; package io.ebeaninternal.server.querydefn;
import io.ebean.FetchConfig;
import io.ebeaninternal.server.util.DSelectColumnsParser; import io.ebeaninternal.server.util.DSelectColumnsParser;
import java.util.Iterator;
import java.util.Set; import java.util.Set;
/** /**
@@ -18,30 +16,15 @@ class OrmQueryPropertiesParser {
*/ */
static class Response { static class Response {
final boolean readOnly;
final boolean cache;
final FetchConfig fetchConfig;
final String properties; final String properties;
final Set<String> included; final Set<String> included;
Response(boolean readOnly, boolean cache, int queryFetchBatch, int lazyFetchBatch, String properties, Set<String> included) { private Response(String properties, Set<String> included) {
this.readOnly = readOnly;
this.cache = cache;
this.properties = properties; this.properties = properties;
this.included = included; this.included = included;
if (queryFetchBatch > 0) {
this.fetchConfig = FetchConfig.ofQuery(queryFetchBatch);
} else if (lazyFetchBatch > 0) {
this.fetchConfig = FetchConfig.ofLazy(lazyFetchBatch);
} else {
this.fetchConfig = OrmQueryProperties.DEFAULT_FETCH;
}
} }
Response() { private Response() {
this.readOnly = false;
this.cache = false;
this.fetchConfig = OrmQueryProperties.DEFAULT_FETCH;
this.properties = ""; this.properties = "";
this.included = null; this.included = null;
} }
@@ -57,10 +40,6 @@ class OrmQueryPropertiesParser {
private final String inputProperties; private final String inputProperties;
private boolean allProperties; private boolean allProperties;
private boolean readOnly;
private boolean cache;
private int queryFetchBatch;
private int lazyFetchBatch;
private OrmQueryPropertiesParser(String inputProperties) { private OrmQueryPropertiesParser(String inputProperties) {
this.inputProperties = inputProperties; this.inputProperties = inputProperties;
@@ -74,50 +53,20 @@ class OrmQueryPropertiesParser {
return EMPTY; return EMPTY;
} }
if (inputProperties.equals("*")) { if (inputProperties.equals("*")) {
// explicit all properties return new Response("*", null);
allProperties = true;
return new Response(readOnly, cache, queryFetchBatch, lazyFetchBatch, "*", null);
} }
boolean hints = false;
Set<String> fields = splitRawSelect(inputProperties); Set<String> fields = splitRawSelect(inputProperties);
final Iterator<String> iterator = fields.iterator(); for (String val : fields) {
while (iterator.hasNext()) { if (val.equals("*")) {
String val = iterator.next();
if (val.startsWith("+")) {
hints = true;
iterator.remove();
parseHint(val);
} else if (val.equals("*")) {
allProperties = true; allProperties = true;
break;
} }
} }
String properties = allProperties ? "*" : hints ? String.join(",", fields) : inputProperties; String properties = allProperties ? "*" : inputProperties;
if (fields.isEmpty()) { if (fields.isEmpty()) {
fields = null; fields = null;
} }
return new Response(readOnly, cache, queryFetchBatch, lazyFetchBatch, properties, fields); return new Response(properties, fields);
}
private void parseHint(String val) {
if (val.equals("+readonly")) {
readOnly = true;
} else if (val.equals("+cache")) {
cache = true;
} else if (val.startsWith("+query")) {
queryFetchBatch = parseBatch(val);
} else if (val.startsWith("+lazy")) {
lazyFetchBatch = parseBatch(val);
}
}
private int parseBatch(String val) {
if (val.endsWith(")")) {
int start = val.lastIndexOf('(');
if (start > 0) {
return Integer.parseInt(val.substring(start + 1, val.length() - 1));
}
}
return 0;
} }
/** /**
@@ -624,7 +624,7 @@ public class EqlParserTest extends BaseTestCase {
public void fetch_query50_asHint() { public void fetch_query50_asHint() {
ResetBasicData.reset(); ResetBasicData.reset();
Query<Customer> query = parse("fetch billingAddress (+query(50),city)"); Query<Customer> query = parse("fetch query(50) billingAddress (city)");
query.findList(); query.findList();
assertSql(query).doesNotContain(", t1.city"); assertSql(query).doesNotContain(", t1.city");
@@ -634,7 +634,7 @@ public class EqlParserTest extends BaseTestCase {
public void fetch_lazy50_asHint() { public void fetch_lazy50_asHint() {
ResetBasicData.reset(); ResetBasicData.reset();
Query<Customer> query = parse("fetch billingAddress (+lazy(50),city) order by id"); Query<Customer> query = parse("fetch lazy(50) billingAddress (city) order by id");
List<Customer> list = query.findList(); List<Customer> list = query.findList();
assertSql(query).doesNotContain(", t1.city"); assertSql(query).doesNotContain(", t1.city");
@@ -31,91 +31,17 @@ public class OrmQueryPropertiesParserTest {
} }
@Test @Test
public void when_hasCache() { public void when_no_spaces() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+cache"); OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("id,name");
assertThat(res.cache).isTrue();
assertThat(res.included).isNull();
}
@Test
public void when_hasCache_first() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+cache,id");
assertThat(res.cache).isTrue();
assertThat(res.included).containsExactly("id");
}
@Test
public void when_hasCache_last() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("name,+cache");
assertThat(res.cache).isTrue();
assertThat(res.included).containsExactly("name");
}
@Test
public void when_hasCache_middle() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("name,+cache, id");
assertThat(res.cache).isTrue();
assertThat(res.included).containsExactly("name", "id");
}
@Test
public void when_hasReadOnly() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+readonly");
assertThat(res.readOnly).isTrue();
assertThat(res.included).isNull();
}
@Test
public void when_hasLazy() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+lazy");
//FIXME: assertThat(res.fetchConfig.getBatchSize()).isEqualTo(0);
assertThat(res.included).isNull();
}
@Test
public void when_hasLazyValue() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+lazy(20)");
assertThat(res.fetchConfig.getBatchSize()).isEqualTo(20);
assertThat(res.included).isNull();
}
@Test
public void when_hasLazyValue_last() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("name,+lazy(20)");
assertThat(res.fetchConfig.getBatchSize()).isEqualTo(20);
assertThat(res.included).containsExactly("name");
}
@Test
public void when_hasLazyValue_first() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+lazy(20),id,name");
assertThat(res.fetchConfig.getBatchSize()).isEqualTo(20);
assertThat(res.included).containsExactly("id", "name"); assertThat(res.included).containsExactly("id", "name");
} }
@Test @Test
public void when_allProperties() { public void when_spaced() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+query(4),+lazy(5)");
assertThat(res.fetchConfig.getBatchSize()).isEqualTo(4);
assertThat(res.included).isNull();
}
@Test OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("id, name");
public void when_everything_set() {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("id, name, +readonly ,+lazy(20), +query(30) ,+cache");
assertThat(res.included).containsExactly("id", "name"); assertThat(res.included).containsExactly("id", "name");
assertThat(res.fetchConfig.getBatchSize()).isEqualTo(30);
assertThat(res.readOnly).isTrue();
assertThat(res.cache).isTrue();
} }
@Test @Test
@@ -126,8 +52,6 @@ public class OrmQueryPropertiesParserTest {
} }
private void assertAllDefaults(OrmQueryPropertiesParser.Response res) { private void assertAllDefaults(OrmQueryPropertiesParser.Response res) {
assertThat(res.cache).isFalse();
assertThat(res.readOnly).isFalse();
assertThat(res.included).isNull(); assertThat(res.included).isNull();
} }
} }
@@ -21,7 +21,7 @@ public class TestLazyJoin extends BaseTestCase {
Query<Order> query = Ebean.find(Order.class) Query<Order> query = Ebean.find(Order.class)
.select("status") .select("status")
.fetch("customer", "+lazy(10) name, status") .fetchLazy("customer", "name, status")
.fetch("customer.contacts") .fetch("customer.contacts")
.order().asc("id"); .order().asc("id");
@@ -28,7 +28,7 @@ public class TestQueryJoin extends BaseTestCase {
Query<Order> query = Ebean.find(Order.class).select("status") Query<Order> query = Ebean.find(Order.class).select("status")
// .join("details","+query(10)") // .join("details","+query(10)")
.fetch("customer", "+lazy(10), name, status").fetch("customer.contacts").order().asc("id"); .fetchLazy("customer", "name, status").fetch("customer.contacts").order().asc("id");
// .join("customer.billingAddress"); // .join("customer.billingAddress");
List<Order> list = query.findList(); List<Order> list = query.findList();