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

This commit is contained in:
Rob Bygrave committed 2016-11-05 22:32:36 +13:00
1 parent 77e3346d9e
commit 670bac52f8
31 files changed
+139 -160

No files matched your search

@@ -12,11 +12,11 @@ import java.util.concurrent.TimeoutException;
* @param <T> the entity bean type * @param <T> the entity bean type
* @author rbygrave * @author rbygrave
*/ */
public abstract class BaseFuture<T> implements Future<T> { abstract class BaseFuture<T> implements Future<T> {
protected final FutureTask<T> futureTask; final FutureTask<T> futureTask;
public BaseFuture(FutureTask<T> futureTask) { BaseFuture(FutureTask<T> futureTask) {
this.futureTask = futureTask; this.futureTask = futureTask;
} }
@@ -28,9 +28,7 @@ public abstract class BaseFuture<T> implements Future<T> {
return futureTask.get(); return futureTask.get();
} }
public T get(long timeout, TimeUnit unit) public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
throws InterruptedException, ExecutionException, TimeoutException {
return futureTask.get(timeout, unit); return futureTask.get(timeout, unit);
} }
@@ -209,7 +209,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
this.objectGraphNode = query.getParentNode(); this.objectGraphNode = query.getParentNode();
this.profilingListener = query.getProfilingListener(); this.profilingListener = query.getProfilingListener();
this.autoTuneProfiling = profilingListener != null; this.autoTuneProfiling = profilingListener != null;
this.profilingListenerRef = autoTuneProfiling ? new WeakReference<NodeUsageListener>(profilingListener) : null; this.profilingListenerRef = autoTuneProfiling ? new WeakReference<>(profilingListener) : null;
// set the generated sql back to the query // set the generated sql back to the query
// so its available to the user... // so its available to the user...
@@ -276,7 +276,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
return predicates; return predicates;
} }
public SpiOrmQueryRequest<?> getQueryRequest() { SpiOrmQueryRequest<?> getQueryRequest() {
return request; return request;
} }
@@ -297,14 +297,14 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
/** /**
* Prepare bind and execute query with Forward only hints. * Prepare bind and execute query with Forward only hints.
*/ */
public boolean prepareBindExecuteQueryForwardOnly(boolean dbPlatformForwardOnlyHint) throws SQLException { boolean prepareBindExecuteQueryForwardOnly(boolean dbPlatformForwardOnlyHint) throws SQLException {
return prepareBindExecuteQueryWithOption(dbPlatformForwardOnlyHint); return prepareBindExecuteQueryWithOption(dbPlatformForwardOnlyHint);
} }
/** /**
* Prepare bind and execute the query normally. * Prepare bind and execute the query normally.
*/ */
public boolean prepareBindExecuteQuery() throws SQLException { boolean prepareBindExecuteQuery() throws SQLException {
return prepareBindExecuteQueryWithOption(false); return prepareBindExecuteQueryWithOption(false);
} }
@@ -494,11 +494,11 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
return true; return true;
} }
public long getQueryExecutionTimeMicros() { long getQueryExecutionTimeMicros() {
return executionTimeMicros; return executionTimeMicros;
} }
public boolean readBean() throws SQLException { boolean readBean() throws SQLException {
boolean result = hasNext(); boolean result = hasNext();
updateExecutionStatistics(); updateExecutionStatistics();
@@ -531,9 +531,9 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
* Read version beans and their effective dates. * Read version beans and their effective dates.
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public List<Version<T>> readVersions() throws SQLException { List<Version<T>> readVersions() throws SQLException {
List<Version<T>> versionList = new ArrayList<Version<T>>(); List<Version<T>> versionList = new ArrayList<>();
Version version; Version version;
while ((version = readNextVersion()) != null) { while ((version = readNextVersion()) != null) {
@@ -552,7 +552,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
return null; return null;
} }
public BeanCollection<T> readCollection() throws SQLException { BeanCollection<T> readCollection() throws SQLException {
while (hasNext()) { while (hasNext()) {
EntityBean bean = next(); EntityBean bean = next();
@@ -563,7 +563,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
return collection; return collection;
} }
protected void updateExecutionStatistics() { void updateExecutionStatistics() {
try { try {
long exeNano = System.nanoTime() - startNano; long exeNano = System.nanoTime() - startNano;
executionTimeMicros = TimeUnit.NANOSECONDS.toMicros(exeNano); executionTimeMicros = TimeUnit.NANOSECONDS.toMicros(exeNano);
@@ -578,17 +578,17 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
} }
} }
public QueryIterator<T> readIterate(int bufferSize, OrmQueryRequest<T> request) { QueryIterator<T> readIterate(int bufferSize, OrmQueryRequest<T> request) {
if (bufferSize > 0) { if (bufferSize > 0) {
return new CQueryIteratorWithBuffer<T>(this, request, bufferSize); return new CQueryIteratorWithBuffer<>(this, request, bufferSize);
} else { } else {
return new CQueryIteratorSimple<T>(this, request); return new CQueryIteratorSimple<>(this, request);
} }
} }
public String getLoadedRowDetail() { String getLoadedRowDetail() {
if (manyProperty == null) { if (manyProperty == null) {
return String.valueOf(rowCount); return String.valueOf(rowCount);
} else { } else {
@@ -618,7 +618,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
/** /**
* Return the where predicate for display in the transaction log. * Return the where predicate for display in the transaction log.
*/ */
public String getLogWhereSql() { String getLogWhereSql() {
return logWhereSql; return logWhereSql;
} }
@@ -641,7 +641,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
/** /**
* Return the short bean name. * Return the short bean name.
*/ */
public String getBeanName() { String getBeanName() {
return desc.getName(); return desc.getName();
} }
@@ -655,7 +655,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
/** /**
* Create a PersistenceException including interesting information like the bindLog and sql used. * Create a PersistenceException including interesting information like the bindLog and sql used.
*/ */
public PersistenceException createPersistenceException(SQLException e) { PersistenceException createPersistenceException(SQLException e) {
return createPersistenceException(e, getTransaction(), bindLog, sql); return createPersistenceException(e, getTransaction(), bindLog, sql);
} }
@@ -663,7 +663,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
/** /**
* Create a PersistenceException including interesting information like the bindLog and sql used. * Create a PersistenceException including interesting information like the bindLog and sql used.
*/ */
public static PersistenceException createPersistenceException(SQLException e, SpiTransaction t, String bindLog, String sql) { static PersistenceException createPersistenceException(SQLException e, SpiTransaction t, String bindLog, String sql) {
if (t.isLogSummary()) { if (t.isLogSummary()) {
// log the error to the transaction log // log the error to the transaction log
@@ -723,7 +723,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
/** /**
* A find bean query with read auditing so build and log the ReadEvent. * A find bean query with read auditing so build and log the ReadEvent.
*/ */
public void auditFind(EntityBean bean) { void auditFind(EntityBean bean) {
if (bean != null) { if (bean != null) {
// only audit when a bean was actually found // only audit when a bean was actually found
desc.readAuditBean(queryPlan.getAuditQueryKey(), bindLog, bean); desc.readAuditBean(queryPlan.getAuditQueryKey(), bindLog, bean);
@@ -733,7 +733,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
/** /**
* a find many query with read auditing so build the ReadEvent and log it. * a find many query with read auditing so build the ReadEvent and log it.
*/ */
public void auditFindMany() { void auditFindMany() {
if (!collection.isEmpty()) { if (!collection.isEmpty()) {
// get the id values of the underlying collection // get the id values of the underlying collection
@@ -760,7 +760,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
/** /**
* Indicate that read auditing is occurring on a this findIterate query. * Indicate that read auditing is occurring on a this findIterate query.
*/ */
public void auditFindIterate() { void auditFindIterate() {
auditFindIterate = true; auditFindIterate = true;
} }
@@ -779,7 +779,7 @@ public class CQuery<T> implements DbReadContext, CancelableQuery {
private void auditIterateNextBean() { private void auditIterateNextBean() {
if (auditFindIterateIds == null) { if (auditFindIterateIds == null) {
auditFindIterateIds = new ArrayList<Object>(100); auditFindIterateIds = new ArrayList<>(100);
} }
auditFindIterateIds.add(desc.getIdForJson(nextBean)); auditFindIterateIds.add(desc.getIdForJson(nextBean));
if (auditFindIterateIds.size() >= 100) { if (auditFindIterateIds.size() >= 100) {
@@ -31,7 +31,7 @@ import java.util.List;
* Generates the SQL SELECT statements taking into account the physical * Generates the SQL SELECT statements taking into account the physical
* deployment properties. * deployment properties.
*/ */
public class CQueryBuilder { class CQueryBuilder {
private final String tableAliasPlaceHolder; private final String tableAliasPlaceHolder;
private final String columnAliasPrefix; private final String columnAliasPrefix;
@@ -53,7 +53,7 @@ public class CQueryBuilder {
/** /**
* Create the SqlGenSelect. * Create the SqlGenSelect.
*/ */
public CQueryBuilder(DatabasePlatform dbPlatform, Binder binder, CQueryHistorySupport historySupport, CQueryDraftSupport draftSupport) { CQueryBuilder(DatabasePlatform dbPlatform, Binder binder, CQueryHistorySupport historySupport, CQueryDraftSupport draftSupport) {
this.dbPlatform = dbPlatform; this.dbPlatform = dbPlatform;
this.binder = binder; this.binder = binder;
@@ -70,7 +70,7 @@ public class CQueryBuilder {
* split the order by claus on the field delimiter and prefix each field with * split the order by claus on the field delimiter and prefix each field with
* the relation name * the relation name
*/ */
public static String prefixOrderByFields(String name, String orderBy) { static String prefixOrderByFields(String name, String orderBy) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
for (String token : orderBy.split(",")) { for (String token : orderBy.split(",")) {
if (sb.length() > 0) { if (sb.length() > 0) {
@@ -88,7 +88,7 @@ public class CQueryBuilder {
/** /**
* Build the delete query. * Build the delete query.
*/ */
public <T> CQueryUpdate buildUpdateQuery(String type, OrmQueryRequest<T> request) { <T> CQueryUpdate buildUpdateQuery(String type, OrmQueryRequest<T> request) {
SpiQuery<T> query = request.getQuery(); SpiQuery<T> query = request.getQuery();
String rootTableAlias = query.getAlias(); String rootTableAlias = query.getAlias();
@@ -165,7 +165,7 @@ public class CQueryBuilder {
return StringHelper.replaceString(sql, "${RTA}", replaceWith); return StringHelper.replaceString(sql, "${RTA}", replaceWith);
} }
public CQueryFetchSingleAttribute buildFetchAttributeQuery(OrmQueryRequest<?> request) { CQueryFetchSingleAttribute buildFetchAttributeQuery(OrmQueryRequest<?> request) {
SpiQuery<?> query = request.getQuery(); SpiQuery<?> query = request.getQuery();
query.setSingleAttribute(); query.setSingleAttribute();
@@ -191,7 +191,7 @@ public class CQueryBuilder {
/** /**
* Build the find ids query. * Build the find ids query.
*/ */
public <T> CQueryFetchSingleAttribute buildFetchIdsQuery(OrmQueryRequest<T> request) { <T> CQueryFetchSingleAttribute buildFetchIdsQuery(OrmQueryRequest<T> request) {
request.getQuery().setSelectId(); request.getQuery().setSelectId();
return buildFetchAttributeQuery(request); return buildFetchAttributeQuery(request);
@@ -214,7 +214,7 @@ public class CQueryBuilder {
/** /**
* Build the row count query. * Build the row count query.
*/ */
public <T> CQueryRowCount buildRowCountQuery(OrmQueryRequest<T> request) { <T> CQueryRowCount buildRowCountQuery(OrmQueryRequest<T> request) {
SpiQuery<T> query = request.getQuery(); SpiQuery<T> query = request.getQuery();
@@ -275,7 +275,7 @@ public class CQueryBuilder {
* Return the SQL Select statement as a String. Converts logical property * Return the SQL Select statement as a String. Converts logical property
* names to physical deployment column names. * names to physical deployment column names.
*/ */
public <T> CQuery<T> buildQuery(OrmQueryRequest<T> request) { <T> CQuery<T> buildQuery(OrmQueryRequest<T> request) {
CQueryPredicates predicates = new CQueryPredicates(binder, request); CQueryPredicates predicates = new CQueryPredicates(binder, request);
@@ -284,7 +284,7 @@ public class CQueryBuilder {
// Reuse the query plan so skip generating SqlTree and SQL. // Reuse the query plan so skip generating SqlTree and SQL.
// We do prepare and bind the new parameters // We do prepare and bind the new parameters
predicates.prepare(false); predicates.prepare(false);
return new CQuery<T>(request, predicates, queryPlan); return new CQuery<>(request, predicates, queryPlan);
} }
// RawSql or Generated Sql query // RawSql or Generated Sql query
@@ -327,7 +327,7 @@ public class CQueryBuilder {
// gather query performance statistics based on it. // gather query performance statistics based on it.
request.putQueryPlan(queryPlan); request.putQueryPlan(queryPlan);
return new CQuery<T>(request, predicates, queryPlan); return new CQuery<>(request, predicates, queryPlan);
} }
/** /**
@@ -11,7 +11,7 @@ import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.ebeaninternal.server.querydefn.OrmQueryLimitRequest; import com.avaje.ebeaninternal.server.querydefn.OrmQueryLimitRequest;
import com.avaje.ebeaninternal.server.util.BindParamsParser; import com.avaje.ebeaninternal.server.util.BindParamsParser;
public class CQueryBuilderRawSql { class CQueryBuilderRawSql {
private final SqlLimiter sqlLimiter; private final SqlLimiter sqlLimiter;
private final DatabasePlatform dbPlatform; private final DatabasePlatform dbPlatform;
@@ -24,7 +24,7 @@ public class CQueryBuilderRawSql {
/** /**
* Build the full SQL Select statement for the request. * Build the full SQL Select statement for the request.
*/ */
public SqlLimitResponse buildSql(OrmQueryRequest<?> request, CQueryPredicates predicates, RawSql.Sql rsql) { SqlLimitResponse buildSql(OrmQueryRequest<?> request, CQueryPredicates predicates, RawSql.Sql rsql) {
if (rsql == null) { if (rsql == null) {
// this is a ResultSet based RawSql query - just use some placeholder for the SQL // this is a ResultSet based RawSql query - just use some placeholder for the SQL
@@ -5,14 +5,14 @@ import java.util.Map;
/** /**
* Support 'asDraft' queries. * Support 'asDraft' queries.
*/ */
public class CQueryDraftSupport { class CQueryDraftSupport {
/** /**
* The mapping of base tables to their matching 'draft' table. * The mapping of base tables to their matching 'draft' table.
*/ */
private final Map<String, String> tableMap; private final Map<String, String> tableMap;
public CQueryDraftSupport(Map<String, String> tableMap) { CQueryDraftSupport(Map<String, String> tableMap) {
this.tableMap = tableMap; this.tableMap = tableMap;
} }
@@ -22,7 +22,7 @@ public class CQueryDraftSupport {
* This returns null for entities that are not draftable and in that case * This returns null for entities that are not draftable and in that case
* the usual base table is used. * the usual base table is used.
*/ */
public String getDraftTable(String table) { String getDraftTable(String table) {
return tableMap.get(table); return tableMap.get(table);
} }
} }
@@ -275,7 +275,7 @@ public class CQueryEngine {
} }
} }
// put an empty map into the last one // put an empty map into the last one
current.setDiff(new LinkedHashMap<String, ValuePair>()); current.setDiff(new LinkedHashMap<>());
} }
} }
@@ -299,8 +299,7 @@ public class CQueryEngine {
/** /**
* Find a list/map/set of beans. * Find a list/map/set of beans.
*/ */
public <T> BeanCollection<T> findMany(OrmQueryRequest<T> request) { <T> BeanCollection<T> findMany(OrmQueryRequest<T> request) {
SpiQuery<T> query = request.getQuery(); SpiQuery<T> query = request.getQuery();
if (!query.isDistinct() && (query.getMaxRows() > 1 || query.getFirstRow() > 0)) { if (!query.isDistinct() && (query.getMaxRows() > 1 || query.getFirstRow() > 0)) {
@@ -59,7 +59,7 @@ class CQueryFetchSingleAttribute {
/** /**
* Create the Sql select based on the request. * Create the Sql select based on the request.
*/ */
public CQueryFetchSingleAttribute(OrmQueryRequest<?> request, CQueryPredicates predicates, CQueryPlan plan) { CQueryFetchSingleAttribute(OrmQueryRequest<?> request, CQueryPredicates predicates, CQueryPlan plan) {
this.request = request; this.request = request;
this.query = request.getQuery(); this.query = request.getQuery();
this.sql = plan.getSql(); this.sql = plan.getSql();
@@ -94,7 +94,7 @@ class CQueryFetchSingleAttribute {
prepareExecute(); prepareExecute();
List<Object> result = new ArrayList<Object>(); List<Object> result = new ArrayList<>();
while (dataReader.next()) { while (dataReader.next()) {
result.add(scalarType.read(dataReader)); result.add(scalarType.read(dataReader));
@@ -7,7 +7,7 @@ import java.util.Map;
/** /**
* Helper to support history functions. * Helper to support history functions.
*/ */
public class CQueryHistorySupport { class CQueryHistorySupport {
/** /**
* The DB specific support. * The DB specific support.
@@ -24,7 +24,7 @@ public class CQueryHistorySupport {
*/ */
private final String sysPeriod; private final String sysPeriod;
public CQueryHistorySupport(DbHistorySupport dbHistorySupport, Map<String, String> asOfTableMap, String sysPeriod) { CQueryHistorySupport(DbHistorySupport dbHistorySupport, Map<String, String> asOfTableMap, String sysPeriod) {
this.dbHistorySupport = dbHistorySupport; this.dbHistorySupport = dbHistorySupport;
this.asOfTableMap = asOfTableMap; this.asOfTableMap = asOfTableMap;
this.sysPeriod = sysPeriod; this.sysPeriod = sysPeriod;
@@ -33,28 +33,28 @@ public class CQueryHistorySupport {
/** /**
* Return true if the underlying history support is standards based. * Return true if the underlying history support is standards based.
*/ */
public boolean isStandardsBased() { boolean isStandardsBased() {
return dbHistorySupport.isStandardsBased(); return dbHistorySupport.isStandardsBased();
} }
/** /**
* Return the 'as of' history view for the given base table. * Return the 'as of' history view for the given base table.
*/ */
public String getAsOfView(String table) { String getAsOfView(String table) {
return asOfTableMap.get(table); return asOfTableMap.get(table);
} }
/** /**
* Return the lower bound column. * Return the lower bound column.
*/ */
public String getSysPeriodLower(String tableAlias) { String getSysPeriodLower(String tableAlias) {
return dbHistorySupport.getSysPeriodLower(tableAlias, sysPeriod); return dbHistorySupport.getSysPeriodLower(tableAlias, sysPeriod);
} }
/** /**
* Return the upper bound column. * Return the upper bound column.
*/ */
public String getSysPeriodUpper(String tableAlias) { String getSysPeriodUpper(String tableAlias) {
return dbHistorySupport.getSysPeriodUpper(tableAlias, sysPeriod); return dbHistorySupport.getSysPeriodUpper(tableAlias, sysPeriod);
} }
@@ -63,7 +63,7 @@ public class CQueryHistorySupport {
* *
* Note used for Oracle total recall etc with the more standard approach. * Note used for Oracle total recall etc with the more standard approach.
*/ */
public String getAsOfPredicate(String tableAlias) { String getAsOfPredicate(String tableAlias) {
return dbHistorySupport.getAsOfPredicate(tableAlias, sysPeriod); return dbHistorySupport.getAsOfPredicate(tableAlias, sysPeriod);
} }
@@ -24,7 +24,7 @@ class CQueryIteratorWithBuffer<T> implements QueryIterator<T> {
this.cquery = cquery; this.cquery = cquery;
this.request = request; this.request = request;
this.bufferSize = bufferSize; this.bufferSize = bufferSize;
this.buffer = new ArrayList<T>(bufferSize); this.buffer = new ArrayList<>(bufferSize);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@@ -14,7 +14,7 @@ import com.avaje.ebeaninternal.server.el.ElPropertyValue;
/** /**
* Creates the order by expression clause. * Creates the order by expression clause.
*/ */
public class CQueryOrderBy { class CQueryOrderBy {
private final BeanDescriptor<?> desc; private final BeanDescriptor<?> desc;
@@ -12,11 +12,11 @@ import java.util.List;
/** /**
* RawSql based query plan. * RawSql based query plan.
*/ */
public class CQueryPlanRawSql extends CQueryPlan { class CQueryPlanRawSql extends CQueryPlan {
private final int[] rsetIndexPositions; private final int[] rsetIndexPositions;
public CQueryPlanRawSql(OrmQueryRequest<?> request, SqlLimitResponse sqlRes, SqlTree sqlTree, String logWhereSql) { CQueryPlanRawSql(OrmQueryRequest<?> request, SqlLimitResponse sqlRes, SqlTree sqlTree, String logWhereSql) {
super(request, sqlRes, sqlTree, true, logWhereSql); super(request, sqlRes, sqlTree, true, logWhereSql);
this.rsetIndexPositions = createIndexPositions(request, sqlTree); this.rsetIndexPositions = createIndexPositions(request, sqlTree);
} }
@@ -106,7 +106,7 @@ public class CQueryPredicates {
private Set<String> orderByIncludes; private Set<String> orderByIncludes;
public CQueryPredicates(Binder binder, OrmQueryRequest<?> request) { CQueryPredicates(Binder binder, OrmQueryRequest<?> request) {
this.binder = binder; this.binder = binder;
this.request = request; this.request = request;
this.query = request.getQuery(); this.query = request.getQuery();
@@ -252,7 +252,7 @@ public class CQueryPredicates {
} }
// create a copy of the includes required to support the orderBy // create a copy of the includes required to support the orderBy
orderByIncludes = new HashSet<String>(deployParser.getIncludes()); orderByIncludes = new HashSet<>(deployParser.getIncludes());
dbWhere = deriveWhere(deployParser); dbWhere = deriveWhere(deployParser);
dbFilterMany = deriveFilterMany(deployParser); dbFilterMany = deriveFilterMany(deployParser);
@@ -277,7 +277,7 @@ public class CQueryPredicates {
/** /**
* Replace the table alias place holders. * Replace the table alias place holders.
*/ */
public void parseTableAlias(SqlTreeAlias alias) { void parseTableAlias(SqlTreeAlias alias) {
if (dbWhere != null) { if (dbWhere != null) {
// use the where table alias // use the where table alias
dbWhere = alias.parseWhere(dbWhere); dbWhere = alias.parseWhere(dbWhere);
@@ -399,53 +399,53 @@ public class CQueryPredicates {
/** /**
* Return the db update set clause for an UpdateQuery. * Return the db update set clause for an UpdateQuery.
*/ */
public String getDbUpdateClause() { String getDbUpdateClause() {
return dbUpdateClause; return dbUpdateClause;
} }
/** /**
* Return the db column version of the combined where clause. * Return the db column version of the combined where clause.
*/ */
public String getDbHaving() { String getDbHaving() {
return dbHaving; return dbHaving;
} }
/** /**
* Return the db column version of the combined where clause. * Return the db column version of the combined where clause.
*/ */
public String getDbWhere() { String getDbWhere() {
return dbWhere; return dbWhere;
} }
/** /**
* Return a db filter for filtering many fetch joins. * Return a db filter for filtering many fetch joins.
*/ */
public String getDbFilterMany() { String getDbFilterMany() {
return dbFilterMany; return dbFilterMany;
} }
/** /**
* Return the db column version of the order by clause. * Return the db column version of the order by clause.
*/ */
public String getDbOrderBy() { String getDbOrderBy() {
return dbOrderBy; return dbOrderBy;
} }
/** /**
* Return the includes required for the where and order by clause. * Return the includes required for the where and order by clause.
*/ */
public Set<String> getPredicateIncludes() { Set<String> getPredicateIncludes() {
return predicateIncludes; return predicateIncludes;
} }
/** /**
* Return the orderBy includes. * Return the orderBy includes.
*/ */
public Set<String> getOrderByIncludes() { Set<String> getOrderByIncludes() {
return orderByIncludes; return orderByIncludes;
} }
public String getLogWhereSql() { String getLogWhereSql() {
if (dbWhere == null && dbFilterMany == null) { if (dbWhere == null && dbFilterMany == null) {
return ""; return "";
@@ -14,7 +14,7 @@ import java.sql.SQLException;
/** /**
* Executes the select row count query. * Executes the select row count query.
*/ */
public class CQueryRowCount { class CQueryRowCount {
/** /**
* The overall find request wrapper object. * The overall find request wrapper object.
@@ -54,16 +54,13 @@ public class CQueryRowCount {
/** /**
* Create the Sql select based on the request. * Create the Sql select based on the request.
*/ */
public CQueryRowCount(OrmQueryRequest<?> request, CQueryPredicates predicates, String sql) { CQueryRowCount(OrmQueryRequest<?> request, CQueryPredicates predicates, String sql) {
this.request = request; this.request = request;
this.query = request.getQuery(); this.query = request.getQuery();
this.sql = sql; this.sql = sql;
query.setGeneratedSql(sql); query.setGeneratedSql(sql);
this.desc = request.getBeanDescriptor(); this.desc = request.getBeanDescriptor();
this.predicates = predicates; this.predicates = predicates;
} }
/** /**
@@ -12,7 +12,7 @@ import java.sql.SQLException;
/** /**
* Executes the delete query. * Executes the delete query.
*/ */
public class CQueryUpdate { class CQueryUpdate {
private final OrmQueryRequest<?> request; private final OrmQueryRequest<?> request;
@@ -46,7 +46,7 @@ public class CQueryUpdate {
/** /**
* Create the Sql select based on the request. * Create the Sql select based on the request.
*/ */
public CQueryUpdate(String type, OrmQueryRequest<?> request, CQueryPredicates predicates, String sql) { CQueryUpdate(String type, OrmQueryRequest<?> request, CQueryPredicates predicates, String sql) {
this.type = type; this.type = type;
this.request = request; this.request = request;
this.query = request.getQuery(); this.query = request.getQuery();
@@ -10,7 +10,7 @@ import com.avaje.ebeaninternal.api.SpiQuery;
* @param <T> the entity bean type * @param <T> the entity bean type
* @author rbygrave * @author rbygrave
*/ */
public abstract class CallableQuery<T> { abstract class CallableQuery<T> {
protected final SpiQuery<T> query; protected final SpiQuery<T> query;
@@ -18,7 +18,7 @@ public abstract class CallableQuery<T> {
protected final Transaction transaction; protected final Transaction transaction;
public CallableQuery(SpiEbeanServer server, SpiQuery<T> query, Transaction t) { CallableQuery(SpiEbeanServer server, SpiQuery<T> query, Transaction t) {
this.server = server; this.server = server;
this.query = query; this.query = query;
this.transaction = t; this.transaction = t;
@@ -9,7 +9,7 @@ import com.avaje.ebeaninternal.server.util.ArrayStack;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
public class DefaultDbSqlContext implements DbSqlContext { class DefaultDbSqlContext implements DbSqlContext {
private static final String COMMA = ", "; private static final String COMMA = ", ";
@@ -20,11 +20,11 @@ public class DefaultDbSqlContext implements DbSqlContext {
private final String columnAliasPrefix; private final String columnAliasPrefix;
private final ArrayStack<String> tableAliasStack = new ArrayStack<String>(); private final ArrayStack<String> tableAliasStack = new ArrayStack<>();
private final ArrayStack<String> joinStack = new ArrayStack<String>(); private final ArrayStack<String> joinStack = new ArrayStack<>();
private final ArrayStack<String> prefixStack = new ArrayStack<String>(); private final ArrayStack<String> prefixStack = new ArrayStack<>();
private boolean useColumnAlias; private boolean useColumnAlias;
@@ -54,7 +54,7 @@ public class DefaultDbSqlContext implements DbSqlContext {
/** /**
* Construct for SELECT clause (with column alias settings). * Construct for SELECT clause (with column alias settings).
*/ */
public DefaultDbSqlContext(SqlTreeAlias alias, String tableAliasPlaceHolder, DefaultDbSqlContext(SqlTreeAlias alias, String tableAliasPlaceHolder,
String columnAliasPrefix, boolean alwaysUseColumnAlias, CQueryHistorySupport historySupport, CQueryDraftSupport draftSupport) { String columnAliasPrefix, boolean alwaysUseColumnAlias, CQueryHistorySupport historySupport, CQueryDraftSupport draftSupport) {
this.alias = alias; this.alias = alias;
@@ -73,7 +73,7 @@ public class DefaultDbSqlContext implements DbSqlContext {
public void addEncryptedProp(BeanProperty p) { public void addEncryptedProp(BeanProperty p) {
if (encryptedProps == null) { if (encryptedProps == null) {
encryptedProps = new ArrayList<BeanProperty>(); encryptedProps = new ArrayList<>();
} }
encryptedProps.add(p); encryptedProps.add(p);
} }
@@ -101,7 +101,7 @@ public class DefaultDbSqlContext implements DbSqlContext {
public void addJoin(String type, String table, TableJoinColumn[] cols, String a1, String a2, String inheritance) { public void addJoin(String type, String table, TableJoinColumn[] cols, String a1, String a2, String inheritance) {
if (tableJoins == null) { if (tableJoins == null) {
tableJoins = new HashSet<String>(); tableJoins = new HashSet<>();
} }
String joinKey = table + "-" + a1 + "-" + a2; String joinKey = table + "-" + a1 + "-" + a2;
@@ -213,7 +213,7 @@ public class DefaultDbSqlContext implements DbSqlContext {
String converted = StringHelper.replaceString(sqlFormulaJoin, tableAliasPlaceHolder, tableAlias); String converted = StringHelper.replaceString(sqlFormulaJoin, tableAliasPlaceHolder, tableAlias);
if (formulaJoins == null) { if (formulaJoins == null) {
formulaJoins = new HashSet<String>(); formulaJoins = new HashSet<>();
} else if (formulaJoins.contains(converted)) { } else if (formulaJoins.contains(converted)) {
// skip adding a formula join because // skip adding a formula join because
@@ -74,7 +74,7 @@ public class DefaultRelationalQueryEngine implements RelationalQueryEngine {
try { try {
request.executeSql(binder); request.executeSql(binder);
List<SqlRow> rows = new ArrayList<SqlRow>(); List<SqlRow> rows = new ArrayList<>();
while (request.next()) { while (request.next()) {
rows.add(readRow(request)); rows.add(readRow(request));
} }
@@ -102,7 +102,7 @@ public class DefaultRelationalQueryEngine implements RelationalQueryEngine {
/** /**
* Read the row from the ResultSet and return as a MapBean. * Read the row from the ResultSet and return as a MapBean.
*/ */
protected SqlRow readRow(RelationalQueryRequest request) throws SQLException { private SqlRow readRow(RelationalQueryRequest request) throws SQLException {
return request.createNewRow(dbTrueValue); return request.createNewRow(dbTrueValue);
} }
@@ -51,7 +51,7 @@ public class DefaultSqlRow implements SqlRow {
* </p> * </p>
*/ */
public DefaultSqlRow(int initialCapacity, float loadFactor, String dbTrueValue) { public DefaultSqlRow(int initialCapacity, float loadFactor, String dbTrueValue) {
this.map = new LinkedHashMap<String, Object>(initialCapacity, loadFactor); this.map = new LinkedHashMap<>(initialCapacity, loadFactor);
this.dbTrueValue = dbTrueValue; this.dbTrueValue = dbTrueValue;
} }
@@ -15,7 +15,7 @@ public class QueryFutureIds<T> extends BaseFuture<List<Object>> implements Futur
private final CallableQueryIds<T> call; private final CallableQueryIds<T> call;
public QueryFutureIds(CallableQueryIds<T> call) { public QueryFutureIds(CallableQueryIds<T> call) {
super(new FutureTask<List<Object>>(call)); super(new FutureTask<>(call));
this.call = call; this.call = call;
} }
@@ -20,7 +20,7 @@ public class QueryFutureList<T> extends BaseFuture<List<T>> implements FutureLis
private final CallableQueryList<T> call; private final CallableQueryList<T> call;
public QueryFutureList(CallableQueryList<T> call) { public QueryFutureList(CallableQueryList<T> call) {
super(new FutureTask<List<T>>(call)); super(new FutureTask<>(call));
this.call = call; this.call = call;
} }
@@ -14,7 +14,7 @@ public class QueryFutureRowCount<T> extends BaseFuture<Integer> implements Futur
private final CallableQueryRowCount<T> call; private final CallableQueryRowCount<T> call;
public QueryFutureRowCount(CallableQueryRowCount<T> call) { public QueryFutureRowCount(CallableQueryRowCount<T> call) {
super(new FutureTask<Integer>(call)); super(new FutureTask<>(call));
this.call = call; this.call = call;
} }
@@ -5,14 +5,14 @@ import com.avaje.ebeaninternal.api.CQueryPlanKey;
/** /**
* QueryPlanKey for RawSql queries. * QueryPlanKey for RawSql queries.
*/ */
public class RawSqlQueryPlanKey implements CQueryPlanKey { class RawSqlQueryPlanKey implements CQueryPlanKey {
private final String sql; private final String sql;
private final boolean rawSql; private final boolean rawSql;
private final boolean rowNumberIncluded; private final boolean rowNumberIncluded;
private final String logWhereSql; private final String logWhereSql;
public RawSqlQueryPlanKey(String sql, boolean rawSql, boolean rowNumberIncluded, String logWhereSql) { RawSqlQueryPlanKey(String sql, boolean rawSql, boolean rowNumberIncluded, String logWhereSql) {
this.sql = sql; this.sql = sql;
this.rawSql = rawSql; this.rawSql = rawSql;
this.rowNumberIncluded = rowNumberIncluded; this.rowNumberIncluded = rowNumberIncluded;
@@ -26,7 +26,7 @@ public class SqlBeanLoad {
private final boolean refreshLoading; private final boolean refreshLoading;
private final boolean rawSql; private final boolean rawSql;
public SqlBeanLoad(DbReadContext ctx, Class<?> type, EntityBean bean, Mode queryMode) { SqlBeanLoad(DbReadContext ctx, Class<?> type, EntityBean bean, Mode queryMode) {
this.ctx = ctx; this.ctx = ctx;
this.rawSql = ctx.isRawSql(); this.rawSql = ctx.isRawSql();
@@ -11,7 +11,7 @@ import java.util.Set;
/** /**
* Represents the SELECT clause part of the SQL query. * Represents the SELECT clause part of the SQL query.
*/ */
public class SqlTree { class SqlTree {
private final SqlTreeNode rootNode; private final SqlTreeNode rootNode;
@@ -48,7 +48,7 @@ public class SqlTree {
/** /**
* Create the SqlSelectClause. * Create the SqlSelectClause.
*/ */
public SqlTree(String summary, SqlTreeNode rootNode, String selectSql, String fromSql, String groupBy, String inheritanceWhereSql, SqlTree(String summary, SqlTreeNode rootNode, String selectSql, String fromSql, String groupBy, String inheritanceWhereSql,
BeanProperty[] encryptedProps, BeanPropertyAssocMany<?> manyProperty, Set<String> includes, boolean includeJoins) { BeanProperty[] encryptedProps, BeanPropertyAssocMany<?> manyProperty, Set<String> includes, boolean includeJoins) {
this.summary = summary; this.summary = summary;
@@ -66,21 +66,21 @@ public class SqlTree {
/** /**
* Return true if the query includes joins (not valid for rawSql). * Return true if the query includes joins (not valid for rawSql).
*/ */
public boolean isIncludeJoins() { boolean isIncludeJoins() {
return includeJoins; return includeJoins;
} }
/** /**
* Recurse through the tree adding an table alias' for @History entity beans. * Recurse through the tree adding an table alias' for @History entity beans.
*/ */
public void addAsOfTableAlias(SpiQuery<?> query) { void addAsOfTableAlias(SpiQuery<?> query) {
rootNode.addAsOfTableAlias(query); rootNode.addAsOfTableAlias(query);
} }
/** /**
* Recurse through the tree adding soft delete predicates as necessary. * Recurse through the tree adding soft delete predicates as necessary.
*/ */
public void addSoftDeletePredicate(SpiQuery<?> query) { void addSoftDeletePredicate(SpiQuery<?> query) {
rootNode.addSoftDeletePredicate(query); rootNode.addSoftDeletePredicate(query);
} }
@@ -88,7 +88,7 @@ public class SqlTree {
* Build a select expression chain for RawSql. * Build a select expression chain for RawSql.
*/ */
public List<String> buildRawSqlSelectChain() { public List<String> buildRawSqlSelectChain() {
ArrayList<String> list = new ArrayList<String>(); ArrayList<String> list = new ArrayList<>();
rootNode.buildRawSqlSelectChain(list); rootNode.buildRawSqlSelectChain(list);
return list; return list;
} }
@@ -103,25 +103,25 @@ public class SqlTree {
/** /**
* Return the String for the actual SQL. * Return the String for the actual SQL.
*/ */
public String getSelectSql() { String getSelectSql() {
return selectSql; return selectSql;
} }
public String getFromSql() { String getFromSql() {
return fromSql; return fromSql;
} }
/** /**
* Return the groupBy clause. * Return the groupBy clause.
*/ */
public String getGroupBy() { String getGroupBy() {
return groupBy; return groupBy;
} }
/** /**
* Return the where clause for inheritance. * Return the where clause for inheritance.
*/ */
public String getInheritanceWhereSql() { String getInheritanceWhereSql() {
return inheritanceWhereSql; return inheritanceWhereSql;
} }
@@ -132,7 +132,7 @@ public class SqlTree {
return summary; return summary;
} }
public SqlTreeNode getRootNode() { SqlTreeNode getRootNode() {
return rootNode; return rootNode;
} }
@@ -140,18 +140,18 @@ public class SqlTree {
* Return the property that is associated with the many. There can only be one * Return the property that is associated with the many. There can only be one
* per SqlSelect. This can be null. * per SqlSelect. This can be null.
*/ */
public BeanPropertyAssocMany<?> getManyProperty() { BeanPropertyAssocMany<?> getManyProperty() {
return manyProperty; return manyProperty;
} }
public BeanProperty[] getEncryptedProps() { BeanProperty[] getEncryptedProps() {
return encryptedProps; return encryptedProps;
} }
/** /**
* Return true if the query has a many join. * Return true if the query has a many join.
*/ */
public boolean hasMany() { boolean hasMany() {
return manyProperty != null || rootNode.hasMany(); return manyProperty != null || rootNode.hasMany();
} }
} }
@@ -13,32 +13,32 @@ import java.util.TreeSet;
/** /**
* Special Map of the logical property joins to table alias. * Special Map of the logical property joins to table alias.
*/ */
public class SqlTreeAlias { class SqlTreeAlias {
private int counter; private int counter;
private int manyWhereCounter; private int manyWhereCounter;
private final TreeSet<String> joinProps = new TreeSet<String>(); private final TreeSet<String> joinProps = new TreeSet<>();
private HashSet<String> embeddedPropertyJoins; private HashSet<String> embeddedPropertyJoins;
private final TreeSet<String> manyWhereJoinProps = new TreeSet<String>(); private final TreeSet<String> manyWhereJoinProps = new TreeSet<>();
private final HashMap<String, String> aliasMap = new HashMap<String, String>(); private final HashMap<String, String> aliasMap = new HashMap<>();
private final HashMap<String, String> manyWhereAliasMap = new HashMap<String, String>(); private final HashMap<String, String> manyWhereAliasMap = new HashMap<>();
private final String rootTableAlias; private final String rootTableAlias;
public SqlTreeAlias(String rootTableAlias) { SqlTreeAlias(String rootTableAlias) {
this.rootTableAlias = rootTableAlias; this.rootTableAlias = rootTableAlias;
} }
/** /**
* Add joins to support where predicates * Add joins to support where predicates
*/ */
public void addManyWhereJoins(Set<String> manyWhereJoins) { void addManyWhereJoins(Set<String> manyWhereJoins) {
if (manyWhereJoins != null) { if (manyWhereJoins != null) {
for (String include : manyWhereJoins) { for (String include : manyWhereJoins) {
addPropertyJoin(include, manyWhereJoinProps); addPropertyJoin(include, manyWhereJoinProps);
@@ -48,7 +48,7 @@ public class SqlTreeAlias {
private void addEmbeddedPropertyJoin(String embProp) { private void addEmbeddedPropertyJoin(String embProp) {
if (embeddedPropertyJoins == null) { if (embeddedPropertyJoins == null) {
embeddedPropertyJoins = new HashSet<String>(); embeddedPropertyJoins = new HashSet<>();
} }
embeddedPropertyJoins.add(embProp); embeddedPropertyJoins.add(embProp);
} }
@@ -85,7 +85,7 @@ public class SqlTreeAlias {
/** /**
* Build a set of table alias for the given bean and fetch joined properties. * Build a set of table alias for the given bean and fetch joined properties.
*/ */
public void buildAlias() { void buildAlias() {
for (String joinProp : joinProps) { for (String joinProp : joinProps) {
calcAlias(joinProp); calcAlias(joinProp);
@@ -125,7 +125,7 @@ public class SqlTreeAlias {
/** /**
* Return the table alias for a given property name. * Return the table alias for a given property name.
*/ */
public String getTableAlias(String prefix) { String getTableAlias(String prefix) {
if (prefix == null) { if (prefix == null) {
return rootTableAlias; return rootTableAlias;
} else { } else {
@@ -140,7 +140,7 @@ public class SqlTreeAlias {
/** /**
* Return an alias using "Many where joins". * Return an alias using "Many where joins".
*/ */
public String getTableAliasManyWhere(String prefix) { String getTableAliasManyWhere(String prefix) {
if (prefix == null) { if (prefix == null) {
return rootTableAlias; return rootTableAlias;
} }
@@ -158,7 +158,7 @@ public class SqlTreeAlias {
/** /**
* Parse for where clauses that uses "Many where joins" * Parse for where clauses that uses "Many where joins"
*/ */
public String parseWhere(String clause) { String parseWhere(String clause) {
clause = parseRootAlias(clause); clause = parseRootAlias(clause);
clause = parseAliasMap(clause, manyWhereAliasMap); clause = parseAliasMap(clause, manyWhereAliasMap);
return parseAliasMap(clause, aliasMap); return parseAliasMap(clause, aliasMap);
@@ -211,7 +211,7 @@ public class SqlTreeAlias {
/** /**
* Return true if there are joins included in the query. * Return true if there are joins included in the query.
*/ */
public boolean isIncludeJoins() { boolean isIncludeJoins() {
return !aliasMap.isEmpty() || !manyWhereAliasMap.isEmpty(); return !aliasMap.isEmpty() || !manyWhereAliasMap.isEmpty();
} }
} }
@@ -55,7 +55,7 @@ public class SqlTreeBuilder {
private final DefaultDbSqlContext ctx; private final DefaultDbSqlContext ctx;
private final HashSet<String> selectIncludes = new HashSet<String>(); private final HashSet<String> selectIncludes = new HashSet<>();
private final ManyWhereJoins manyWhereJoins; private final ManyWhereJoins manyWhereJoins;
@@ -139,7 +139,7 @@ public class SqlTreeBuilder {
encryptedProps = ctx.getEncryptedProps(); encryptedProps = ctx.getEncryptedProps();
} }
boolean includeJoins = (alias == null) ? false : alias.isIncludeJoins(); boolean includeJoins = alias != null && alias.isIncludeJoins();
return new SqlTree(summary.toString(), rootNode, selectSql, fromSql, groupBy, inheritanceWhereSql, encryptedProps, return new SqlTree(summary.toString(), rootNode, selectSql, fromSql, groupBy, inheritanceWhereSql, encryptedProps,
manyProperty, queryDetail.getFetchPaths(), includeJoins); manyProperty, queryDetail.getFetchPaths(), includeJoins);
@@ -216,7 +216,7 @@ public class SqlTreeBuilder {
private SqlTreeNode buildSelectChain(String prefix, BeanPropertyAssoc<?> prop, private SqlTreeNode buildSelectChain(String prefix, BeanPropertyAssoc<?> prop,
BeanDescriptor<?> desc, List<SqlTreeNode> joinList) { BeanDescriptor<?> desc, List<SqlTreeNode> joinList) {
List<SqlTreeNode> myJoinList = new ArrayList<SqlTreeNode>(); List<SqlTreeNode> myJoinList = new ArrayList<>();
BeanPropertyAssocOne<?>[] ones = desc.propertiesOne(); BeanPropertyAssocOne<?>[] ones = desc.propertiesOne();
for (int i = 0; i < ones.length; i++) { for (int i = 0; i < ones.length; i++) {
@@ -468,8 +468,6 @@ public class SqlTreeBuilder {
} }
} }
selectProps.setTableJoins(desc.tableJoins());
InheritInfo inheritInfo = desc.getInheritInfo(); InheritInfo inheritInfo = desc.getInheritInfo();
if (inheritInfo != null) { if (inheritInfo != null) {
// add sub type properties // add sub type properties
@@ -542,12 +540,12 @@ public class SqlTreeBuilder {
/** /**
* Contains the 'root' extra joins. We only return the roots back. * Contains the 'root' extra joins. We only return the roots back.
*/ */
private final Map<String, SqlTreeNodeExtraJoin> joinRegister = new HashMap<String, SqlTreeNodeExtraJoin>(); private final Map<String, SqlTreeNodeExtraJoin> joinRegister = new HashMap<>();
/** /**
* Register of all the extra join nodes. * Register of all the extra join nodes.
*/ */
private final Map<String, SqlTreeNodeExtraJoin> rootRegister = new HashMap<String, SqlTreeNodeExtraJoin>(); private final Map<String, SqlTreeNodeExtraJoin> rootRegister = new HashMap<>();
private final BeanDescriptor<?> desc; private final BeanDescriptor<?> desc;
@@ -142,7 +142,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
BeanPropertyAssocMany<?>[] manys = desc.propertiesMany(); BeanPropertyAssocMany<?>[] manys = desc.propertiesMany();
HashMap<String, String> m = new HashMap<String, String>(); HashMap<String, String> m = new HashMap<>();
for (int i = 0; i < manys.length; i++) { for (int i = 0; i < manys.length; i++) {
String name = manys[i].getName(); String name = manys[i].getName();
m.put(name, getPath(prefix, name)); m.put(name, getPath(prefix, name));
@@ -190,7 +190,7 @@ class SqlTreeNodeBean implements SqlTreeNode {
Timestamp end = ctx.getDataReader().getTimestamp(); Timestamp end = ctx.getDataReader().getTimestamp();
T bean = (T) load(ctx, null, null); T bean = (T) load(ctx, null, null);
return new Version<T>(bean, start, end); return new Version<>(bean, start, end);
} }
/** /**
@@ -77,7 +77,7 @@ class SqlTreeNodeExtraJoin implements SqlTreeNode {
* This means we need to add distinct to the sql query. * This means we need to add distinct to the sql query.
* </p> * </p>
*/ */
public boolean isManyJoin() { boolean isManyJoin() {
return manyJoin; return manyJoin;
} }
@@ -87,7 +87,7 @@ class SqlTreeNodeExtraJoin implements SqlTreeNode {
public void addChild(SqlTreeNodeExtraJoin child) { public void addChild(SqlTreeNodeExtraJoin child) {
if (children == null) { if (children == null) {
children = new ArrayList<SqlTreeNodeExtraJoin>(); children = new ArrayList<>();
} }
children.add(child); children.add(child);
} }
@@ -30,7 +30,7 @@ class SqlTreeNodeManyWhereJoin implements SqlTreeNode {
*/ */
private final SqlJoinType manyJoinType; private final SqlJoinType manyJoinType;
public SqlTreeNodeManyWhereJoin(String prefix, BeanPropertyAssoc<?> prop, SqlJoinType manyJoinType) { SqlTreeNodeManyWhereJoin(String prefix, BeanPropertyAssoc<?> prop, SqlJoinType manyJoinType) {
this.nodeBeanProp = prop; this.nodeBeanProp = prop;
this.prefix = prefix; this.prefix = prefix;
@@ -80,7 +80,7 @@ class SqlTreeNodeManyWhereJoin implements SqlTreeNode {
* Join to base table for this node. This includes a join to the * Join to base table for this node. This includes a join to the
* intersection table if this is a ManyToMany node. * intersection table if this is a ManyToMany node.
*/ */
public void appendFromBaseTable(DbSqlContext ctx, SqlJoinType joinType) { void appendFromBaseTable(DbSqlContext ctx, SqlJoinType joinType) {
String alias = ctx.getTableAliasManyWhere(prefix); String alias = ctx.getTableAliasManyWhere(prefix);
String parentAlias = ctx.getTableAliasManyWhere(parentPrefix); String parentAlias = ctx.getTableAliasManyWhere(parentPrefix);
@@ -18,7 +18,7 @@ final class SqlTreeNodeRoot extends SqlTreeNodeBean {
/** /**
* Specify for SqlSelect to include an Id property or not. * Specify for SqlSelect to include an Id property or not.
*/ */
public SqlTreeNodeRoot(BeanDescriptor<?> desc, SqlTreeProperties props, List<SqlTreeNode> myList, boolean withId, SqlTreeNodeRoot(BeanDescriptor<?> desc, SqlTreeProperties props, List<SqlTreeNode> myList, boolean withId,
TableJoin includeJoin, BeanPropertyAssocMany<?> many, SpiQuery.TemporalMode temporalMode, boolean disableLazyLoad) { TableJoin includeJoin, BeanPropertyAssocMany<?> many, SpiQuery.TemporalMode temporalMode, boolean disableLazyLoad) {
super(desc, props, myList, withId, many, temporalMode, disableLazyLoad); super(desc, props, myList, withId, many, temporalMode, disableLazyLoad);
@@ -1,45 +1,40 @@
package com.avaje.ebeaninternal.server.query; package com.avaje.ebeaninternal.server.query;
import com.avaje.ebeaninternal.api.ManyWhereJoins;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import com.avaje.ebeaninternal.api.ManyWhereJoins;
import com.avaje.ebeaninternal.server.deploy.BeanProperty;
import com.avaje.ebeaninternal.server.deploy.TableJoin;
/** /**
* The select properties for a node in the SqlTree. * The select properties for a node in the SqlTree.
*/ */
public class SqlTreeProperties { public class SqlTreeProperties {
private static final TableJoin[] EMPTY_TABLE_JOINS = new TableJoin[0];
/** /**
* True if this node of the tree should have read only entity beans. * True if this node of the tree should have read only entity beans.
*/ */
private boolean readOnly; private boolean readOnly;
private TableJoin[] tableJoins = EMPTY_TABLE_JOINS;
/** /**
* The bean properties in order. * The bean properties in order.
*/ */
private final List<BeanProperty> propsList = new ArrayList<BeanProperty>(); private final List<BeanProperty> propsList = new ArrayList<>();
/** /**
* Maintain a list of property names to detect embedded bean additions. * Maintain a list of property names to detect embedded bean additions.
*/ */
private final LinkedHashSet<String> propNames = new LinkedHashSet<String>(); private final LinkedHashSet<String> propNames = new LinkedHashSet<>();
private boolean allProperties; private boolean allProperties;
private boolean aggregation; private boolean aggregation;
public SqlTreeProperties() { SqlTreeProperties() {
} }
public boolean containsProperty(String propName) { boolean containsProperty(String propName) {
return propNames.contains(propName); return propNames.contains(propName);
} }
@@ -59,7 +54,7 @@ public class SqlTreeProperties {
return propsList.toArray(new BeanProperty[propsList.size()]); return propsList.toArray(new BeanProperty[propsList.size()]);
} }
public boolean isPartialObject() { boolean isPartialObject() {
return !allProperties; return !allProperties;
} }
@@ -71,15 +66,7 @@ public class SqlTreeProperties {
this.readOnly = readOnly; this.readOnly = readOnly;
} }
public TableJoin[] getTableJoins() { void setAllProperties() {
return tableJoins;
}
public void setTableJoins(TableJoin[] tableJoins) {
this.tableJoins = tableJoins;
}
public void setAllProperties() {
this.allProperties = true; this.allProperties = true;
} }
@@ -89,7 +76,7 @@ public class SqlTreeProperties {
* Return true if a Sql distinct is required. * Return true if a Sql distinct is required.
* </p> * </p>
*/ */
public boolean requireSqlDistinct(ManyWhereJoins manyWhereJoins) { boolean requireSqlDistinct(ManyWhereJoins manyWhereJoins) {
String joinProperty = aggregationJoin(); String joinProperty = aggregationJoin();
if (joinProperty != null) { if (joinProperty != null) {
aggregation = true; aggregation = true;