Refactor - tidy up in com.avaje.ebeaninternal.server.querydefn, no effective change

This commit is contained in:
Rob Bygrave
2016-11-05 22:46:43 +13:00
parent 670bac52f8
commit 201a2826ab
11 changed files with 64 additions and 85 deletions
@@ -39,9 +39,4 @@ public interface SpiSqlQuery extends SqlQuery {
*/
int getBufferFetchSizeHint();
/**
* Set the PreparedStatement for the purposes of supporting cancel.
*/
void setPreparedStatement(PreparedStatement pstmt);
}
@@ -41,7 +41,7 @@ import java.util.Set;
*/
public class DefaultOrmQuery<T> implements SpiQuery<T> {
public static final String DEFAULT_QUERY_NAME = "default";
private static final String DEFAULT_QUERY_NAME = "default";
private static final FetchConfig FETCH_QUERY = new FetchConfig().query();
@@ -276,7 +276,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
@Override
public void addSoftDeletePredicate(String softDeletePredicate) {
if (softDeletePredicates == null) {
softDeletePredicates = new ArrayList<String>();
softDeletePredicates = new ArrayList<>();
}
softDeletePredicates.add(softDeletePredicate);
}
@@ -407,7 +407,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
return false;
}
protected List<OrmQueryProperties> removeQueryJoins() {
private List<OrmQueryProperties> removeQueryJoins() {
List<OrmQueryProperties> queryJoins = detail.removeSecondaryQueries();
if (queryJoins != null) {
if (orderBy != null) {
@@ -435,7 +435,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
return queryJoins;
}
protected List<OrmQueryProperties> removeLazyJoins() {
private List<OrmQueryProperties> removeLazyJoins() {
return detail.removeSecondaryLazyQueries();
}
@@ -470,10 +470,6 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
return true;
}
protected void setOrmQueryDetail(OrmQueryDetail detail) {
this.detail = detail;
}
@Override
public void setDefaultSelectClause() {
detail.setDefaultSelectClause(beanDescriptor);
@@ -603,7 +599,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
@Override
public DefaultOrmQuery<T> copy(EbeanServer server) {
DefaultOrmQuery<T> copy = new DefaultOrmQuery<T>(beanDescriptor, server, expressionFactory);
DefaultOrmQuery<T> copy = new DefaultOrmQuery<>(beanDescriptor, server, expressionFactory);
copy.m2mIncludeJoin = m2mIncludeJoin;
copy.profilingListener = profilingListener;
@@ -833,7 +829,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
@Override
public void logSecondaryQuery(SpiQuery<?> query) {
if (loggedSecondaryQueries == null) {
loggedSecondaryQueries = new ArrayList<SpiQuery<?>>();
loggedSecondaryQueries = new ArrayList<>();
}
loggedSecondaryQueries.add(query);
}
@@ -1093,7 +1089,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public List<Object> findIds() {
public <A> List<A> findIds() {
// a copy of this query is made in the server
// as the query needs to modified (so we modify
// the copy rather than this query instance)
@@ -1234,7 +1230,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
@Override
public OrderBy<T> order() {
if (orderBy == null) {
orderBy = new OrderBy<T>(this, null);
orderBy = new OrderBy<>(this, null);
}
return orderBy;
}
@@ -1249,7 +1245,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
if (orderByClause == null || orderByClause.trim().isEmpty()) {
this.orderBy = null;
} else {
this.orderBy = new OrderBy<T>(this, orderByClause);
this.orderBy = new OrderBy<>(this, orderByClause);
}
return this;
}
@@ -1393,7 +1389,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
public ExpressionList<T> text() {
if (textExpressions == null) {
useDocStore = true;
textExpressions = new DefaultExpressionList<T>(this);
textExpressions = new DefaultExpressionList<>(this);
}
return textExpressions;
}
@@ -1401,7 +1397,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
@Override
public ExpressionList<T> where() {
if (whereExpressions == null) {
whereExpressions = new DefaultExpressionList<T>(this, null);
whereExpressions = new DefaultExpressionList<>(this, null);
}
return whereExpressions;
}
@@ -1465,7 +1461,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
@Override
public SpiNamedParam createNamedParameter(String name) {
if (namedParams == null) {
namedParams = new HashMap<String, ONamedParam>();
namedParams = new HashMap<>();
}
ONamedParam param = namedParams.get(name);
@@ -1586,7 +1582,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
return validation.getUnknownProperties();
}
public void setUpdateProperties(OrmUpdateProperties updateProperties) {
void setUpdateProperties(OrmUpdateProperties updateProperties) {
this.updateProperties = updateProperties;
}
@@ -7,7 +7,6 @@ import com.avaje.ebean.SqlRow;
import com.avaje.ebeaninternal.api.BindParams;
import com.avaje.ebeaninternal.api.SpiSqlQuery;
import java.sql.PreparedStatement;
import java.util.List;
/**
@@ -27,11 +26,6 @@ public class DefaultRelationalQuery implements SpiSqlQuery {
private int timeout;
/**
* For the purposes of cancelling the query.
*/
private transient PreparedStatement pstmt;
private int bufferFetchSizeHint;
/**
@@ -128,10 +122,4 @@ public class DefaultRelationalQuery implements SpiSqlQuery {
return query;
}
public void setPreparedStatement(PreparedStatement pstmt) {
synchronized (this) {
this.pstmt = pstmt;
}
}
}
@@ -7,7 +7,7 @@ import javax.persistence.PersistenceException;
/**
* Named parameter used as placeholder in expressions created by EQL language parsing.
*/
public class ONamedParam implements SpiNamedParam {
class ONamedParam implements SpiNamedParam {
private final String name;
@@ -16,7 +16,7 @@ public class ONamedParam implements SpiNamedParam {
/**
* Create with the given name.
*/
public ONamedParam(String name) {
ONamedParam(String name) {
this.name = name;
}
@@ -37,7 +37,7 @@ public class ONamedParam implements SpiNamedParam {
/**
* Check the bind value has been set (so does not support null value).
*/
public void checkValueSet() {
void checkValueSet() {
if (value == null) {
throw new PersistenceException("Named parameter ["+name+"] has not had it's value set.");
}
@@ -42,7 +42,7 @@ public class OrmQueryDetail implements Serializable {
/**
* Contains the fetch/lazy/query joins and their properties.
*/
private LinkedHashMap<String, OrmQueryProperties> fetchPaths = new LinkedHashMap<String, OrmQueryProperties>();
private LinkedHashMap<String, OrmQueryProperties> fetchPaths = new LinkedHashMap<>();
/**
* Return a deep copy of the OrmQueryDetail.
@@ -168,7 +168,7 @@ public class OrmQueryDetail implements Serializable {
baseProps = new OrmQueryProperties(null, columns, null);
}
public boolean containsProperty(String property) {
boolean containsProperty(String property) {
return baseProps.isIncluded(property);
}
@@ -179,17 +179,17 @@ public class OrmQueryDetail implements Serializable {
this.baseProps = baseProps;
}
public List<OrmQueryProperties> removeSecondaryQueries() {
List<OrmQueryProperties> removeSecondaryQueries() {
return removeSecondaryQueries(false);
}
public List<OrmQueryProperties> removeSecondaryLazyQueries() {
List<OrmQueryProperties> removeSecondaryLazyQueries() {
return removeSecondaryQueries(true);
}
private List<OrmQueryProperties> removeSecondaryQueries(boolean lazyQuery) {
ArrayList<String> matchingPaths = new ArrayList<String>(2);
ArrayList<String> matchingPaths = new ArrayList<>(2);
for (OrmQueryProperties chunk : fetchPaths.values()) {
boolean match = lazyQuery ? chunk.isLazyFetch() : chunk.isQueryFetch();
@@ -206,7 +206,7 @@ public class OrmQueryDetail implements Serializable {
Collections.sort(matchingPaths);
// the list of secondary queries
ArrayList<OrmQueryProperties> props = new ArrayList<OrmQueryProperties>();
ArrayList<OrmQueryProperties> props = new ArrayList<>();
for (int i = 0; i < matchingPaths.size(); i++) {
String path = matchingPaths.get(i);
@@ -243,7 +243,7 @@ public class OrmQueryDetail implements Serializable {
return props;
}
public boolean tuneFetchProperties(OrmQueryDetail tunedDetail) {
boolean tuneFetchProperties(OrmQueryDetail tunedDetail) {
boolean tuned = false;
@@ -304,7 +304,7 @@ public class OrmQueryDetail implements Serializable {
public void sortFetchPaths(BeanDescriptor<?> d) {
if (!fetchPaths.isEmpty()) {
LinkedHashMap<String, OrmQueryProperties> sorted = new LinkedHashMap<String, OrmQueryProperties>();
LinkedHashMap<String, OrmQueryProperties> sorted = new LinkedHashMap<>();
for (OrmQueryProperties p : fetchPaths.values()) {
sortFetchPaths(d, p, sorted);
}
@@ -341,7 +341,7 @@ public class OrmQueryDetail implements Serializable {
/**
* Mark 'fetch joins' to 'many' properties over to 'query joins' where needed.
*/
public void markQueryJoins(BeanDescriptor<?> beanDescriptor, String lazyLoadManyPath, boolean allowOne) {
void markQueryJoins(BeanDescriptor<?> beanDescriptor, String lazyLoadManyPath, boolean allowOne) {
// the name of the many fetch property if there is one
String manyFetchProperty = null;
@@ -439,7 +439,7 @@ public class OrmQueryDetail implements Serializable {
}
}
public boolean hasSelectClause() {
private boolean hasSelectClause() {
return baseProps.hasSelectClause();
}
@@ -12,7 +12,7 @@ import com.avaje.ebeaninternal.server.deploy.TableJoin;
/**
* Query plan key for ORM queries.
*/
public class OrmQueryPlanKey implements CQueryPlanKey {
class OrmQueryPlanKey implements CQueryPlanKey {
private final String m2mIncludeTable;
private final String orderByAsSting;
@@ -35,7 +35,7 @@ public class OrmQueryPlanKey implements CQueryPlanKey {
private final int planHash;
private final int bindCount;
public OrmQueryPlanKey(TableJoin m2mIncludeTable, SpiQuery.Type type, OrmQueryDetail detail, int maxRows, int firstRow, boolean disableLazyLoading, OrderBy<?> orderBy, boolean distinct, boolean sqlDistinct, String mapKey, Object id, BindParams bindParams, SpiExpression whereExpressions, SpiExpression havingExpressions, SpiQuery.TemporalMode temporalMode, boolean forUpdate, String rootTableAlias, RawSql rawSql, OrmUpdateProperties updateProperties) {
OrmQueryPlanKey(TableJoin m2mIncludeTable, SpiQuery.Type type, OrmQueryDetail detail, int maxRows, int firstRow, boolean disableLazyLoading, OrderBy<?> orderBy, boolean distinct, boolean sqlDistinct, String mapKey, Object id, BindParams bindParams, SpiExpression whereExpressions, SpiExpression havingExpressions, SpiQuery.TemporalMode temporalMode, boolean forUpdate, String rootTableAlias, RawSql rawSql, OrmUpdateProperties updateProperties) {
this.m2mIncludeTable = m2mIncludeTable == null ? null : m2mIncludeTable.getTable();
this.type = type;
@@ -28,7 +28,7 @@ public class OrmQueryProperties implements Serializable {
private static final long serialVersionUID = -8785582703966455658L;
protected static final FetchConfig DEFAULT_FETCH = new FetchConfig();
static final FetchConfig DEFAULT_FETCH = new FetchConfig();
private final String parentPath;
private final String path;
@@ -160,9 +160,9 @@ public class OrmQueryProperties implements Serializable {
this.readOnly = source.readOnly;
this.fetchConfig = source.fetchConfig;
this.filterMany = source.filterMany;
this.included = (source.included == null) ? null : new LinkedHashSet<String>(source.included);
this.included = (source.included == null) ? null : new LinkedHashSet<>(source.included);
if (includedBeanJoin != null) {
this.includedBeanJoin = new HashSet<String>(source.includedBeanJoin);
this.includedBeanJoin = new HashSet<>(source.includedBeanJoin);
}
}
@@ -177,7 +177,7 @@ public class OrmQueryProperties implements Serializable {
* Move a OrderBy.Property from the main query to this query join.
*/
@SuppressWarnings("rawtypes")
public void addSecJoinOrderProperty(OrderBy.Property orderProp) {
void addSecJoinOrderProperty(OrderBy.Property orderProp) {
if (orderBy == null) {
orderBy = new OrderBy();
}
@@ -208,7 +208,7 @@ public class OrmQueryProperties implements Serializable {
/**
* Return the filterMany expression list (can be null).
*/
public SpiExpressionList<?> getFilterManyTrimPath(int trimPath) {
private SpiExpressionList<?> getFilterManyTrimPath(int trimPath) {
if (filterMany == null) {
return null;
}
@@ -264,7 +264,7 @@ public class OrmQueryProperties implements Serializable {
}
}
public boolean hasSelectClause() {
boolean hasSelectClause() {
if ("*".equals(trimmedProperties)) {
// explicitly selected all properties
return true;
@@ -297,7 +297,7 @@ public class OrmQueryProperties implements Serializable {
return sb.toString();
}
public boolean isChild(OrmQueryProperties possibleChild) {
boolean isChild(OrmQueryProperties possibleChild) {
return possibleChild.getPath().startsWith(path + ".");
}
@@ -306,7 +306,7 @@ public class OrmQueryProperties implements Serializable {
*/
public void add(OrmQueryProperties child) {
if (secondaryChildren == null) {
secondaryChildren = new ArrayList<OrmQueryProperties>();
secondaryChildren = new ArrayList<>();
}
secondaryChildren.add(child);
}
@@ -339,9 +339,9 @@ public class OrmQueryProperties implements Serializable {
/**
* Add a bean join property.
*/
public void includeBeanJoin(String propertyName) {
void includeBeanJoin(String propertyName) {
if (includedBeanJoin == null) {
includedBeanJoin = new HashSet<String>();
includedBeanJoin = new HashSet<>();
}
includedBeanJoin.add(propertyName);
}
@@ -358,15 +358,15 @@ public class OrmQueryProperties implements Serializable {
return included;
}
LinkedHashSet<String> temp = new LinkedHashSet<String>(2 * (secondaryQueryJoins.size() + included.size()));
LinkedHashSet<String> temp = new LinkedHashSet<>(2 * (secondaryQueryJoins.size() + included.size()));
temp.addAll(included);
temp.addAll(secondaryQueryJoins);
return temp;
}
public void addSecondaryQueryJoin(String property) {
void addSecondaryQueryJoin(String property) {
if (secondaryQueryJoins == null) {
secondaryQueryJoins = new HashSet<String>(4);
secondaryQueryJoins = new HashSet<>(4);
}
secondaryQueryJoins.add(property);
}
@@ -378,7 +378,7 @@ public class OrmQueryProperties implements Serializable {
return included;
}
public boolean isIncluded(String propName) {
boolean isIncluded(String propName) {
if (includedBeanJoin != null && includedBeanJoin.contains(propName)) {
return false;
@@ -390,7 +390,7 @@ public class OrmQueryProperties implements Serializable {
/**
* Mark this path as needing to be a query join.
*/
public void markForQueryJoin() {
void markForQueryJoin() {
markForQueryJoin = true;
}
@@ -404,14 +404,14 @@ public class OrmQueryProperties implements Serializable {
/**
* Return true if this path is a 'fetch join'.
*/
public boolean isFetchJoin() {
boolean isFetchJoin() {
return !isQueryFetch() && !isLazyFetch();
}
/**
* Return true if this path is a lazy fetch.
*/
public boolean isLazyFetch() {
boolean isLazyFetch() {
return getLazyFetchBatch() > -1;
}
@@ -453,7 +453,7 @@ public class OrmQueryProperties implements Serializable {
/**
* Return the parent path.
*/
public String getParentPath() {
String getParentPath() {
return parentPath;
}
@@ -467,7 +467,7 @@ public class OrmQueryProperties implements Serializable {
/**
* Return true if the properties are the same for autoTune purposes.
*/
public boolean isSameByAutoTune(OrmQueryProperties p2) {
boolean isSameByAutoTune(OrmQueryProperties p2) {
if (included == null) {
return p2 == null || p2.included == null;
} else if (p2 == null) {
@@ -8,14 +8,14 @@ import java.util.LinkedHashSet;
/**
* Parses the path properties string.
*/
public class OrmQueryPropertiesParser {
class OrmQueryPropertiesParser {
private static Response EMPTY = new Response();
/**
* Immutable response of the parsed properties and options.
*/
public static class Response {
static class Response {
final boolean readOnly;
final boolean cache;
@@ -23,7 +23,7 @@ public class OrmQueryPropertiesParser {
final String properties;
final LinkedHashSet<String> included;
public Response(boolean readOnly, boolean cache, int queryFetchBatch, int lazyFetchBatch, String properties, LinkedHashSet<String> included) {
Response(boolean readOnly, boolean cache, int queryFetchBatch, int lazyFetchBatch, String properties, LinkedHashSet<String> included) {
this.readOnly = readOnly;
this.cache = cache;
this.properties = properties;
@@ -35,7 +35,7 @@ public class OrmQueryPropertiesParser {
}
}
public Response() {
Response() {
this.readOnly = false;
this.cache = false;
this.fetchConfig = OrmQueryProperties.DEFAULT_FETCH;
@@ -116,7 +116,7 @@ public class OrmQueryPropertiesParser {
String[] res = inputProperties.split(",");
StringBuilder sb = new StringBuilder(70);
LinkedHashSet<String> propertySet = new LinkedHashSet<String>(res.length * 2);
LinkedHashSet<String> propertySet = new LinkedHashSet<>(res.length * 2);
int count = 0;
String temp;
@@ -7,7 +7,7 @@ import java.util.List;
/**
* The secondary query paths for 'query joins' and 'lazy loading'.
*/
public class OrmQuerySecondary implements SpiQuerySecondary {
class OrmQuerySecondary implements SpiQuerySecondary {
private final List<OrmQueryProperties> queryJoins;
@@ -16,7 +16,7 @@ public class OrmQuerySecondary implements SpiQuerySecondary {
/**
* Construct with the 'query join' and 'lazy join' path properties.
*/
public OrmQuerySecondary(List<OrmQueryProperties> queryJoins, List<OrmQueryProperties> lazyJoins) {
OrmQuerySecondary(List<OrmQueryProperties> queryJoins, List<OrmQueryProperties> lazyJoins) {
this.queryJoins = queryJoins;
this.lazyJoins = lazyJoins;
}
@@ -41,7 +41,7 @@ public class OrmUpdateProperties {
/**
* Set property to null.
*/
static class NullValue extends Value {
private static class NullValue extends Value {
@Override
public String bindClause() {
return "=null";
@@ -51,7 +51,7 @@ public class OrmUpdateProperties {
/**
* Set property to a simple value.
*/
static class SimpleValue extends Value {
private static class SimpleValue extends Value {
final Object value;
@@ -79,7 +79,7 @@ public class OrmUpdateProperties {
/**
* Set using an expression with no bind value.
*/
static class NoneValue extends Value {
private static class NoneValue extends Value {
@Override
public String bindClause() {
return "";
@@ -89,11 +89,11 @@ public class OrmUpdateProperties {
/**
* Set using an expression with many bind values.
*/
static class RawArrayValue extends Value {
private static class RawArrayValue extends Value {
final Object[] bindValues;
public RawArrayValue(Object[] bindValues) {
RawArrayValue(Object[] bindValues) {
this.bindValues = bindValues;
}
@@ -114,7 +114,7 @@ public class OrmUpdateProperties {
/**
* The set properties/expressions and their bind values.
*/
private LinkedHashMap<String, Value> values = new LinkedHashMap<String, Value>();
private LinkedHashMap<String, Value> values = new LinkedHashMap<>();
/**
* Normal set property.
@@ -138,7 +138,7 @@ public class OrmUpdateProperties {
/**
* Set a raw expression with many bind values.
*/
public void setRaw(String propertyExpression, Object... vals) {
void setRaw(String propertyExpression, Object... vals) {
if (vals.length == 0) {
setRaw(propertyExpression);
} else {
@@ -157,7 +157,7 @@ public class OrmUpdateProperties {
/**
* Build the hash for the query plan caching.
*/
public void buildQueryPlanHash(HashQueryPlanBuilder builder) {
void buildQueryPlanHash(HashQueryPlanBuilder builder) {
builder.add(OrmUpdateProperties.class);
Set<Map.Entry<String, Value>> entries = values.entrySet();
for (Map.Entry<String, Value> entry : entries) {
@@ -24,7 +24,7 @@ public class SimpleTextParser {
return pos;
}
public String getOql() {
String getOql() {
return oql;
}
@@ -32,7 +32,7 @@ public class SimpleTextParser {
return word;
}
public String peekNextWord() {
private String peekNextWord() {
int origPos = pos;
String nw = nextWordInternal();
pos = origPos;