#1747 - Refactor io.ebeaninternal.server.query access and remove unused

This commit is contained in:
rob bygrave committed 2019-07-02 22:37:35 +12:00
1 parent cd9a43c3ab
commit 2f8a99c304
22 files changed
+45 -147

No files matched your search

@@ -2628,11 +2628,6 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
return autoTunable;
}
@Override
public boolean isElementType() {
return false;
}
/**
* Returns the Inheritance mapping information. This will be null if this type
* of bean is not involved in any ORM inheritance mapping.
@@ -32,11 +32,6 @@ abstract class BeanDescriptorElement<T> extends BeanDescriptor<T> {
return props[0].getScalarType();
}
@Override
public boolean isElementType() {
return true;
}
/**
* Our entity beans used are somewhat fake ones (ElementEntityBean) such that we hold the unidirectional property
* value (foreign key) and the actual element collection value (scalar or embedded plus map key).
@@ -521,7 +521,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery, SpiProfileTran
return result;
}
protected EntityBean next() {
EntityBean next() {
if (audit) {
auditNextBean();
}
@@ -532,7 +532,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery, SpiProfileTran
return nextBean;
}
protected boolean hasNext() throws SQLException {
boolean hasNext() throws SQLException {
synchronized (this) {
if (noMoreRows || cancelled) {
@@ -582,7 +582,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery, SpiProfileTran
/**
* Update execution stats and check for slow query.
*/
void updateExecutionStatistics() {
private void updateExecutionStatistics() {
updateStatistics();
request.slowQueryCheck(executionTimeMicros, rowCount);
}
@@ -114,7 +114,7 @@ class CQueryBuilder {
if (queryPlan != null) {
// skip building the SqlTree and Sql string
predicates.prepare(false);
return new CQueryUpdate(type, request, predicates, queryPlan);
return new CQueryUpdate(request, predicates, queryPlan);
}
predicates.prepare(true);
@@ -131,7 +131,7 @@ class CQueryBuilder {
// cache the query plan
queryPlan = new CQueryPlan(request, sql, sqlTree, false, predicates.getLogWhereSql());
request.putQueryPlan(queryPlan);
return new CQueryUpdate(type, request, predicates, queryPlan);
return new CQueryUpdate(request, predicates, queryPlan);
}
private <T> String buildDeleteSql(OrmQueryRequest<T> request, String rootTableAlias, CQueryPredicates predicates, SqlTree sqlTree) {
@@ -84,7 +84,7 @@ class CQueryFetchSingleAttribute implements SpiProfileTransactionEvent {
/**
* Return a summary description of this query.
*/
protected String getSummary() {
String getSummary() {
StringBuilder sb = new StringBuilder(80);
sb.append("FindAttr exeMicros[").append(executionTimeMicros)
.append("] rows[").append(rowCount)
@@ -98,7 +98,7 @@ class CQueryFetchSingleAttribute implements SpiProfileTransactionEvent {
/**
* Execute the query returning the row count.
*/
protected List<Object> findList() throws SQLException {
List<Object> findList() throws SQLException {
long startNano = System.nanoTime();
try {
@@ -136,14 +136,14 @@ class CQueryFetchSingleAttribute implements SpiProfileTransactionEvent {
/**
* Return the bind log.
*/
protected String getBindLog() {
String getBindLog() {
return bindLog;
}
/**
* Return the generated sql.
*/
protected String getGeneratedSql() {
String getGeneratedSql() {
return sql;
}
@@ -27,7 +27,6 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collections;
import java.util.Set;
/**
@@ -53,7 +52,7 @@ public class CQueryPlan {
private static final Logger logger = LoggerFactory.getLogger(CQueryPlan.class);
public static final String RESULT_SET_BASED_RAW_SQL = "--ResultSetBasedRawSql";
static final String RESULT_SET_BASED_RAW_SQL = "--ResultSetBasedRawSql";
private final SpiEbeanServer server;
@@ -89,7 +88,7 @@ public class CQueryPlan {
private final Class<?> beanType;
protected final DataTimeZone dataTimeZone;
final DataTimeZone dataTimeZone;
private final int asOfTableCount;
@@ -143,7 +142,7 @@ public class CQueryPlan {
this.label = query.getPlanLabel();
this.name = deriveName(label, query.getType());
this.location = location();
this.planKey = buildPlanKey(sql, false, rowNumberIncluded, logWhereSql);
this.planKey = buildPlanKey(sql, rowNumberIncluded, logWhereSql);
this.autoTuned = false;
this.asOfTableCount = 0;
this.sql = sql;
@@ -180,9 +179,8 @@ public class CQueryPlan {
return (profileLocation == null) ? "" : profileLocation.shortDescription();
}
private CQueryPlanKey buildPlanKey(String sql, boolean rawSql, boolean rowNumberIncluded, String logWhereSql) {
return new RawSqlQueryPlanKey(sql, rawSql, rowNumberIncluded, logWhereSql);
private CQueryPlanKey buildPlanKey(String sql, boolean rowNumberIncluded, String logWhereSql) {
return new RawSqlQueryPlanKey(sql, false, rowNumberIncluded, logWhereSql);
}
@Override
@@ -249,10 +247,6 @@ public class CQueryPlan {
return autoTuned;
}
CQueryPlanKey getPlanKey() {
return planKey;
}
/**
* Return a key used in audit logging to identify the query.
*/
@@ -281,7 +275,7 @@ public class CQueryPlan {
}
}
public String getSqlHash() {
String getSqlHash() {
return sqlHash;
}
@@ -351,7 +345,7 @@ public class CQueryPlan {
return stats.isEmpty();
}
public TimedMetric createTimedMetric() {
TimedMetric createTimedMetric() {
return MetricFactory.get().createTimedMetric(MetricType.ORM, label);
}
@@ -34,8 +34,6 @@ class CQueryUpdate implements SpiProfileTransactionEvent {
*/
private final String sql;
private final String type;
/**
* The statement used to create the resultSet.
*/
@@ -43,8 +41,6 @@ class CQueryUpdate implements SpiProfileTransactionEvent {
private String bindLog;
private long executionTimeMicros;
private int rowCount;
private long profileOffset;
@@ -52,8 +48,7 @@ class CQueryUpdate implements SpiProfileTransactionEvent {
/**
* Create the Sql select based on the request.
*/
CQueryUpdate(String type, OrmQueryRequest<?> request, CQueryPredicates predicates, CQueryPlan queryPlan) {
this.type = type;
CQueryUpdate(OrmQueryRequest<?> request, CQueryPredicates predicates, CQueryPlan queryPlan) {
this.request = request;
this.queryPlan = queryPlan;
this.query = request.getQuery();
@@ -63,19 +58,6 @@ class CQueryUpdate implements SpiProfileTransactionEvent {
query.setGeneratedSql(sql);
}
/**
* Return a summary description of this query.
*/
public String getSummary() {
StringBuilder sb = new StringBuilder(80);
sb.append(type).append(" exeMicros[").append(executionTimeMicros)
.append("] rows[").append(rowCount)
.append("] type[").append(desc.getName())
.append("] predicates[").append(predicates.getLogWhereSql())
.append("] bind[").append(bindLog).append("]");
return sb.toString();
}
/**
* Return the bind log.
*/
@@ -109,7 +91,7 @@ class CQueryUpdate implements SpiProfileTransactionEvent {
bindLog = predicates.bind(pstmt, conn);
rowCount = pstmt.executeUpdate();
executionTimeMicros = (System.nanoTime() - startNano) / 1000L;
long executionTimeMicros = (System.nanoTime() - startNano) / 1000L;
request.slowQueryCheck(executionTimeMicros, rowCount);
if (queryPlan.executionTime(rowCount, executionTimeMicros, null)) {
queryPlan.captureBindForQueryPlan(predicates, executionTimeMicros);
@@ -6,30 +6,18 @@ import io.ebeaninternal.api.SpiQuery;
/**
* Base object for making query execution into Callable's.
*
* @param <T> the entity bean type
* @author rbygrave
*/
abstract class CallableQuery<T> {
protected final SpiQuery<T> query;
final SpiQuery<T> query;
protected final SpiEbeanServer server;
final SpiEbeanServer server;
protected final Transaction transaction;
final Transaction transaction;
CallableQuery(SpiEbeanServer server, SpiQuery<T> query, Transaction t) {
this.server = server;
this.query = query;
this.transaction = t;
}
public SpiQuery<T> getQuery() {
return query;
}
public Transaction getTransaction() {
return transaction;
}
}
@@ -25,7 +25,7 @@ public class CallableQueryCount<T> extends CallableQuery<T> implements Callable<
* Execute the query returning the row count.
*/
@Override
public Integer call() throws Exception {
public Integer call() {
try {
return server.findCountWithCopy(query, transaction);
} finally {
@@ -23,7 +23,7 @@ public class CallableQueryIds<T> extends CallableQuery<T> implements Callable<Li
* Execute the find Id's query returning the list of Id's.
*/
@Override
public List<Object> call() throws Exception {
public List<Object> call() {
// we have already made a copy of the query
// this way the same query instance is available to the
// QueryFutureIds (as so has access to the List before it is done)
@@ -23,7 +23,7 @@ public class CallableQueryList<T> extends CallableQuery<T> implements Callable<L
* Execute the query returning the resulting List.
*/
@Override
public List<T> call() throws Exception {
public List<T> call() {
try {
return server.findList(query, transaction);
} finally {
@@ -2,7 +2,7 @@ package io.ebeaninternal.server.query;
import io.ebean.annotation.Platform;
public final class PlatformQueryPlan {
final class PlatformQueryPlan {
private static final QueryPlanLogger explainLogger = new QueryPlanLoggerExplain();
@@ -1,7 +1,6 @@
package io.ebeaninternal.server.query;
import io.ebean.FutureRowCount;
import io.ebean.Query;
import io.ebean.Transaction;
import java.util.concurrent.FutureTask;
@@ -26,10 +25,6 @@ public class QueryFutureRowCount<T> extends BaseFuture<Integer> implements Futur
return call.transaction;
}
public Query<T> getQuery() {
return call.query;
}
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
call.query.cancel();
@@ -25,7 +25,7 @@ public abstract class QueryPlanLogger {
return createPlan(plan, bind.toString(), sb.toString());
}
protected DQueryPlanOutput createPlan(CQueryPlan plan, String bind, String planString) {
DQueryPlanOutput createPlan(CQueryPlan plan, String bind, String planString) {
return new DQueryPlanOutput(plan.getBeanType(), plan.getName(), plan.getSql(), bind, planString, plan.getProfileLocation());
}
@@ -32,7 +32,6 @@ public class QueryPlanLoggerSqlServer extends QueryPlanLogger {
String xml = null;
if (explainStmt.getMoreResults()) {
try (ResultSet rset = explainStmt.getResultSet()) {
StringBuilder sb = new StringBuilder();
if (rset.next()) {
xml = rset.getString(1);
}
@@ -22,11 +22,6 @@ public interface STreeType {
*/
boolean hasId();
/**
* Return true if the type is for ElementCollection (not mapped to an entity type/class).
*/
boolean isElementType();
/**
* Return true if the type uses soft delete.
*/
@@ -49,13 +49,6 @@ public class SqlBeanLoad {
return ctx;
}
/**
* Increment the resultSet index 1.
*/
public void loadIgnore(int increment) {
ctx.getDataReader().incrementPos(increment);
}
public Object load(BeanProperty prop) {
if (!rawSql && !prop.isLoadProperty(ctx.isDraftQuery())) {
@@ -20,28 +20,21 @@ public enum SqlJoinType {
*/
AUTO("JOIN-TYPE-AUTO-LITERAL-NOT-USED");
final String literal;
private final String literal;
SqlJoinType(String literal) {
this.literal = literal;
}
/**
* Return the SQL join literal.
*/
public String getLiteral() {
return literal;
}
/**
* Return the actual SQL join literal taking into account the current join type and the 'default
* join type as per deployment cardinality and optionality'.
*/
public String getLiteral(SqlJoinType deploymentJoinType) {
if (this == SqlJoinType.AUTO) {
return deploymentJoinType.getLiteral();
return deploymentJoinType.literal;
}
return this.getLiteral();
return this.literal;
}
/**
@@ -19,13 +19,6 @@ class SqlTree {
*/
private final STreePropertyAssocMany manyProperty;
private final Set<String> includes;
/**
* Summary of the select being generated.
*/
private final String summary;
private final String distinctOn;
private final String selectSql;
@@ -49,10 +42,9 @@ class SqlTree {
/**
* Create the SqlSelectClause.
*/
SqlTree(String summary, SqlTreeNode rootNode, String distinctOn, String selectSql, String fromSql, String groupBy, String inheritanceWhereSql,
STreeProperty[] encryptedProps, STreePropertyAssocMany manyProperty, Set<String> includes, boolean includeJoins) {
SqlTree(SqlTreeNode rootNode, String distinctOn, String selectSql, String fromSql, String groupBy, String inheritanceWhereSql,
STreeProperty[] encryptedProps, STreePropertyAssocMany manyProperty, boolean includeJoins) {
this.summary = summary;
this.rootNode = rootNode;
this.distinctOn = distinctOn;
this.selectSql = selectSql;
@@ -61,7 +53,6 @@ class SqlTree {
this.inheritanceWhereSql = inheritanceWhereSql;
this.encryptedProps = encryptedProps;
this.manyProperty = manyProperty;
this.includes = includes;
this.includeJoins = includeJoins;
}
@@ -102,13 +93,6 @@ class SqlTree {
return list;
}
/**
* Return the includes. Associated beans lists etc.
*/
public Set<String> getIncludes() {
return includes;
}
String getDistinctOn() {
return distinctOn;
}
@@ -138,13 +122,6 @@ class SqlTree {
return inheritanceWhereSql;
}
/**
* Return a summary of the select clause.
*/
public String getSummary() {
return summary;
}
SqlTreeNode getRootNode() {
return rootNode;
}
@@ -148,9 +148,7 @@ public final class SqlTreeBuilder {
}
boolean includeJoins = alias != null && alias.isIncludeJoins();
return new SqlTree(summary.toString(), rootNode, distinctOn, selectSql, fromSql, groupBy, inheritanceWhereSql, encryptedProps,
manyProperty, queryDetail.getFetchPaths(), includeJoins);
return new SqlTree(rootNode, distinctOn, selectSql, fromSql, groupBy, inheritanceWhereSql, encryptedProps, manyProperty, includeJoins);
}
private String buildSelectClause() {
@@ -30,21 +30,21 @@ class SqlTreeNodeBean implements SqlTreeNode {
private static final SqlTreeNode[] NO_CHILDREN = new SqlTreeNode[0];
protected final STreeType desc;
final STreeType desc;
final IdBinder idBinder;
/**
* The children which will be other SelectBean or SelectProxyBean.
*/
protected final SqlTreeNode[] children;
final SqlTreeNode[] children;
/**
* Set to true if this is a partial object fetch.
*/
private final boolean partialObject;
protected final STreeProperty[] properties;
private final STreeProperty[] properties;
/**
* Extra where clause added by Where annotation on associated many.
@@ -60,9 +60,9 @@ class SqlTreeNodeBean implements SqlTreeNode {
private final boolean disableLazyLoad;
protected final InheritInfo inheritInfo;
private final InheritInfo inheritInfo;
protected final String prefix;
final String prefix;
private final Map<String, String> pathMap;
@@ -134,7 +134,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
pathMap = createPathMap(prefix, desc);
}
protected boolean isRoot() {
boolean isRoot() {
return false;
}
@@ -221,8 +221,8 @@ class SqlTreeNodeBean implements SqlTreeNode {
*/
private class LoadInherit extends Load {
LoadInherit(DbReadContext ctx, EntityBean parentBean, EntityBean contextParent) {
super(ctx, parentBean, contextParent);
LoadInherit(DbReadContext ctx, EntityBean parentBean) {
super(ctx, parentBean);
}
@Override
@@ -258,7 +258,6 @@ class SqlTreeNodeBean implements SqlTreeNode {
final DbReadContext ctx;
final EntityBean parentBean;
final EntityBean contextParent;
Object lazyLoadParentId;
Class<?> localType;
@@ -273,10 +272,9 @@ class SqlTreeNodeBean implements SqlTreeNode {
SqlBeanLoad sqlBeanLoad;
boolean lazyLoadMany;
Load(DbReadContext ctx, EntityBean parentBean, EntityBean contextParent) {
Load(DbReadContext ctx, EntityBean parentBean) {
this.ctx = ctx;
this.parentBean = parentBean;
this.contextParent = contextParent;
}
void initLazyParent() throws SQLException {
@@ -455,7 +453,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
@Override
public EntityBean load(DbReadContext ctx, EntityBean parentBean, EntityBean contextParent) throws SQLException {
Load load = (inheritInfo != null) ? new LoadInherit(ctx, parentBean, contextParent) : new Load(ctx, parentBean, contextParent);
Load load = (inheritInfo != null) ? new LoadInherit(ctx, parentBean) : new Load(ctx, parentBean);
load.initialise();
if (load.isLazyLoadManyRoot()) {
return load.getContextBean();
@@ -612,7 +610,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
}
}
protected void appendExtraWhere(DbSqlContext ctx) {
void appendExtraWhere(DbSqlContext ctx) {
if (extraWhere != null) {
if (ctx.length() > 0) {
ctx.append(" and");
@@ -691,7 +689,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
* Join to base table for this node. This includes a join to the intersection
* table if this is a ManyToMany node.
*/
public SqlJoinType appendFromBaseTable(DbSqlContext ctx, SqlJoinType joinType) {
SqlJoinType appendFromBaseTable(DbSqlContext ctx, SqlJoinType joinType) {
SqlJoinType sqlJoinType = appendFromAsJoin(ctx, joinType);
if (temporalMode != SpiQuery.TemporalMode.SOFT_DELETED && desc.isSoftDelete()) {
@@ -701,7 +699,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
return sqlJoinType;
}
protected SqlJoinType appendFromAsJoin(DbSqlContext ctx, SqlJoinType joinType) {
SqlJoinType appendFromAsJoin(DbSqlContext ctx, SqlJoinType joinType) {
if (nodeBeanProp instanceof STreePropertyAssocMany) {
STreePropertyAssocMany manyProp = (STreePropertyAssocMany) nodeBeanProp;
@@ -68,10 +68,6 @@ public class SqlTreeProperties {
return !allProperties;
}
public boolean isReadOnly() {
return readOnly;
}
public void setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
}