mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
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:
@@ -33,16 +33,13 @@ public class OrmQueryProperties implements Serializable {
|
||||
private final String properties;
|
||||
private final Set<String> included;
|
||||
private final FetchConfig fetchConfig;
|
||||
private final boolean cache;
|
||||
|
||||
/**
|
||||
* Flag set when this fetch path needs to be a query join.
|
||||
*/
|
||||
private boolean markForQueryJoin;
|
||||
|
||||
private boolean cache;
|
||||
|
||||
private boolean readOnly;
|
||||
|
||||
/**
|
||||
* Included bean joins.
|
||||
*/
|
||||
@@ -82,6 +79,7 @@ public class OrmQueryProperties implements Serializable {
|
||||
this.parentPath = SplitName.parent(path);
|
||||
this.properties = null;
|
||||
this.included = null;
|
||||
this.cache = false;
|
||||
this.fetchConfig = DEFAULT_FETCH;
|
||||
}
|
||||
|
||||
@@ -96,26 +94,16 @@ public class OrmQueryProperties implements Serializable {
|
||||
OrmQueryPropertiesParser.Response response = OrmQueryPropertiesParser.parse(rawProperties);
|
||||
this.properties = response.properties;
|
||||
this.included = response.included;
|
||||
this.cache = response.cache;
|
||||
this.readOnly = response.readOnly;
|
||||
if (fetchConfig != null) {
|
||||
this.fetchConfig = fetchConfig;
|
||||
if (fetchConfig.isCache()) {
|
||||
this.cache = true;
|
||||
}
|
||||
} else {
|
||||
this.fetchConfig = response.fetchConfig;
|
||||
}
|
||||
this.fetchConfig = fetchConfig != null ? fetchConfig : DEFAULT_FETCH;
|
||||
this.cache = fetchConfig.isCache();
|
||||
}
|
||||
|
||||
public OrmQueryProperties(String path, Set<String> included) {
|
||||
this.path = path;
|
||||
this.parentPath = SplitName.parent(path);
|
||||
// for rawSql parsedProperties can be empty (when only fetching Id property)
|
||||
this.included = included;
|
||||
this.properties = String.join(",", included);
|
||||
this.cache = false;
|
||||
this.readOnly = false;
|
||||
this.fetchConfig = DEFAULT_FETCH;
|
||||
}
|
||||
|
||||
@@ -128,7 +116,6 @@ public class OrmQueryProperties implements Serializable {
|
||||
this.path = source.path;
|
||||
this.properties = source.properties;
|
||||
this.cache = source.cache;
|
||||
this.readOnly = source.readOnly;
|
||||
this.filterMany = source.filterMany;
|
||||
this.markForQueryJoin = source.markForQueryJoin;
|
||||
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.
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
void addSecJoinOrderProperty(OrderBy.Property orderProp) {
|
||||
if (orderBy == null) {
|
||||
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
|
||||
* method.
|
||||
*/
|
||||
@SuppressWarnings({"unchecked"})
|
||||
@SuppressWarnings({"rawtypes","unchecked"})
|
||||
public <T> SpiExpressionList<T> filterMany(Query<T> rootQuery) {
|
||||
if (filterMany == null) {
|
||||
FilterExprPath exprPath = new FilterExprPath(path);
|
||||
@@ -371,14 +359,7 @@ public class OrmQueryProperties implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this path has the +readonly option.
|
||||
*/
|
||||
public boolean isReadOnly() {
|
||||
return readOnly;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this path has the +cache option to hit the cache.
|
||||
* Return true if this path should hit the L2 cache.
|
||||
*/
|
||||
public boolean isCache() {
|
||||
return cache;
|
||||
|
||||
+8
-59
@@ -1,9 +1,7 @@
|
||||
package io.ebeaninternal.server.querydefn;
|
||||
|
||||
import io.ebean.FetchConfig;
|
||||
import io.ebeaninternal.server.util.DSelectColumnsParser;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -18,30 +16,15 @@ class OrmQueryPropertiesParser {
|
||||
*/
|
||||
static class Response {
|
||||
|
||||
final boolean readOnly;
|
||||
final boolean cache;
|
||||
final FetchConfig fetchConfig;
|
||||
final String properties;
|
||||
final Set<String> included;
|
||||
|
||||
Response(boolean readOnly, boolean cache, int queryFetchBatch, int lazyFetchBatch, String properties, Set<String> included) {
|
||||
this.readOnly = readOnly;
|
||||
this.cache = cache;
|
||||
private Response(String properties, Set<String> included) {
|
||||
this.properties = properties;
|
||||
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() {
|
||||
this.readOnly = false;
|
||||
this.cache = false;
|
||||
this.fetchConfig = OrmQueryProperties.DEFAULT_FETCH;
|
||||
private Response() {
|
||||
this.properties = "";
|
||||
this.included = null;
|
||||
}
|
||||
@@ -57,10 +40,6 @@ class OrmQueryPropertiesParser {
|
||||
|
||||
private final String inputProperties;
|
||||
private boolean allProperties;
|
||||
private boolean readOnly;
|
||||
private boolean cache;
|
||||
private int queryFetchBatch;
|
||||
private int lazyFetchBatch;
|
||||
|
||||
private OrmQueryPropertiesParser(String inputProperties) {
|
||||
this.inputProperties = inputProperties;
|
||||
@@ -74,50 +53,20 @@ class OrmQueryPropertiesParser {
|
||||
return EMPTY;
|
||||
}
|
||||
if (inputProperties.equals("*")) {
|
||||
// explicit all properties
|
||||
allProperties = true;
|
||||
return new Response(readOnly, cache, queryFetchBatch, lazyFetchBatch, "*", null);
|
||||
return new Response("*", null);
|
||||
}
|
||||
boolean hints = false;
|
||||
Set<String> fields = splitRawSelect(inputProperties);
|
||||
final Iterator<String> iterator = fields.iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String val = iterator.next();
|
||||
if (val.startsWith("+")) {
|
||||
hints = true;
|
||||
iterator.remove();
|
||||
parseHint(val);
|
||||
} else if (val.equals("*")) {
|
||||
for (String val : fields) {
|
||||
if (val.equals("*")) {
|
||||
allProperties = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
String properties = allProperties ? "*" : hints ? String.join(",", fields) : inputProperties;
|
||||
String properties = allProperties ? "*" : inputProperties;
|
||||
if (fields.isEmpty()) {
|
||||
fields = null;
|
||||
}
|
||||
return new Response(readOnly, cache, queryFetchBatch, lazyFetchBatch, 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;
|
||||
return new Response(properties, fields);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user