From 7d1745ba5309619c199effd8bffd2c3ce13fd067 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Sun, 31 Mar 2024 09:57:42 +1300 Subject: [PATCH 1/3] Add final modifier to TQRootBean methods As these are never expected to be overwritten --- .../java/io/ebean/typequery/TQRootBean.java | 280 +++++++----------- 1 file changed, 114 insertions(+), 166 deletions(-) diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java b/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java index 4584bea31e..113dd16ecd 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java @@ -147,7 +147,7 @@ protected TQRootBean(ExpressionList filter) { * Return the fetch group. */ public FetchGroup buildFetchGroup() { - return ((SpiFetchGroupQuery) query()).buildFetchGroup(); + return ((SpiFetchGroupQuery) query()).buildFetchGroup(); } /** @@ -311,7 +311,7 @@ public final R select(Query.Property... properties) { * * @param path the property path of an associated (OneToOne, OneToMany, ManyToOne or ManyToMany) bean. */ - public R fetch(String path) { + public final R fetch(String path) { query.fetch(path); return root; } @@ -331,7 +331,7 @@ public R fetch(String path) { * * @param path the property path of an associated (OneToOne, OneToMany, ManyToOne or ManyToMany) bean. */ - public R fetchQuery(String path) { + public final R fetchQuery(String path) { query.fetchQuery(path); return root; } @@ -351,7 +351,7 @@ public R fetchQuery(String path) { * * @param path the property path to load from L2 cache. */ - public R fetchCache(String path) { + public final R fetchCache(String path) { query.fetchCache(path); return root; } @@ -372,7 +372,7 @@ public R fetchCache(String path) { * @param path the property path of an associated (OneToOne, OneToMany, ManyToOne or ManyToMany) bean. * @param properties the properties to load for this path. */ - public R fetchQuery(String path, String properties) { + public final R fetchQuery(String path, String properties) { query.fetchQuery(path, properties); return root; } @@ -393,7 +393,7 @@ public R fetchQuery(String path, String properties) { * @param path the property path to load from L2 cache. * @param properties the properties to load for this path. */ - public R fetchCache(String path, String properties) { + public final R fetchCache(String path, String properties) { query.fetchCache(path, properties); return root; } @@ -438,7 +438,7 @@ public R fetchCache(String path, String properties) { * @param properties properties of the associated bean that you want to include in the * fetch (* means all properties, null also means all properties). */ - public R fetch(String path, String properties) { + public final R fetch(String path, String properties) { query.fetch(path, properties); return root; } @@ -458,7 +458,7 @@ public R fetch(String path, String properties) { * * } */ - public R fetch(String path, String properties, FetchConfig fetchConfig) { + public final R fetch(String path, String properties, FetchConfig fetchConfig) { query.fetch(path, properties, fetchConfig); return root; } @@ -478,7 +478,7 @@ public R fetch(String path, String properties, FetchConfig fetchConfig) { * * } */ - public R fetch(String path, FetchConfig fetchConfig) { + public final R fetch(String path, FetchConfig fetchConfig) { query.fetch(path, fetchConfig); return root; } @@ -489,7 +489,7 @@ public R fetch(String path, FetchConfig fetchConfig) { * This is typically used when the PathProperties is applied to both the query and the JSON output. *

*/ - public R apply(PathProperties pathProperties) { + public final R apply(PathProperties pathProperties) { query.apply(pathProperties); return root; } @@ -502,7 +502,7 @@ public R apply(PathProperties pathProperties) { * @param predicate The predicate which when true the changes are applied * @param apply The changes to apply to the query */ - public R alsoIf(BooleanSupplier predicate, Consumer apply) { + public final R alsoIf(BooleanSupplier predicate, Consumer apply) { if (predicate.getAsBoolean()) { apply.accept(root); } @@ -518,7 +518,7 @@ public R alsoIf(BooleanSupplier predicate, Consumer apply) { * * @param asOf the date time in the past at which you want to view the data */ - public R asOf(Timestamp asOf) { + public final R asOf(Timestamp asOf) { query.asOf(asOf); return root; } @@ -526,7 +526,7 @@ public R asOf(Timestamp asOf) { /** * Execute the query against the draft set of tables. */ - public R asDraft() { + public final R asDraft() { query.asDraft(); return root; } @@ -534,7 +534,7 @@ public R asDraft() { /** * Execute the query including soft deleted rows. */ - public R setIncludeSoftDeletes() { + public final R setIncludeSoftDeletes() { query.setIncludeSoftDeletes(); return root; } @@ -542,7 +542,7 @@ public R setIncludeSoftDeletes() { /** * Add an expression to the WHERE or HAVING clause. */ - public R add(Expression expression) { + public final R add(Expression expression) { peekExprList().add(expression); return root; } @@ -550,7 +550,7 @@ public R add(Expression expression) { /** * Set root table alias. */ - public R alias(String alias) { + public final R alias(String alias) { query.alias(alias); return root; } @@ -560,7 +560,7 @@ public R alias(String alias) { * * @param maxRows the maximum number of rows to return in the query. */ - public R setMaxRows(int maxRows) { + public final R setMaxRows(int maxRows) { query.setMaxRows(maxRows); return root; } @@ -570,7 +570,7 @@ public R setMaxRows(int maxRows) { * * @param firstRow the first row to include in the query result. */ - public R setFirstRow(int firstRow) { + public final R setFirstRow(int firstRow) { query.setFirstRow(firstRow); return root; } @@ -594,7 +594,7 @@ public R setFirstRow(int firstRow) { * * } */ - public R setAllowLoadErrors() { + public final R setAllowLoadErrors() { query.setAllowLoadErrors(); return root; } @@ -611,7 +611,7 @@ public R setAllowLoadErrors() { * fetch paths AutoTune will not remove them. *

*/ - public R setAutoTune(boolean autoTune) { + public final R setAutoTune(boolean autoTune) { query.setAutoTune(autoTune); return root; } @@ -623,7 +623,7 @@ public R setAutoTune(boolean autoTune) { * fetched from the database when more rows are needed for ResultSet. *

*/ - public R setBufferFetchSizeHint(int fetchSize) { + public final R setBufferFetchSizeHint(int fetchSize) { query.setBufferFetchSizeHint(fetchSize); return root; } @@ -631,7 +631,7 @@ public R setBufferFetchSizeHint(int fetchSize) { /** * Set whether this query uses DISTINCT. */ - public R setDistinct(boolean distinct) { + public final R setDistinct(boolean distinct) { query.setDistinct(distinct); return root; } @@ -671,7 +671,7 @@ public R setDistinct(boolean distinct) { * @param indexName The index or indexes to search against * @return This query */ - public R setDocIndexName(String indexName) { + public final R setDocIndexName(String indexName) { query.setDocIndexName(indexName); return root; } @@ -688,7 +688,7 @@ public R setDocIndexName(String indexName) { * * } */ - public R setInheritType(Class type) { + public final R setInheritType(Class type) { query.setInheritType(type); return root; } @@ -708,7 +708,7 @@ public R setInheritType(Class type) { * * } */ - public R setBaseTable(String baseTable) { + public final R setBaseTable(String baseTable) { query.setBaseTable(baseTable); return root; } @@ -722,7 +722,7 @@ public R setBaseTable(String baseTable) { * Provides us with the ability to explicitly use Postgres * SHARE, KEY SHARE, NO KEY UPDATE and UPDATE row locks. */ - public R withLock(Query.LockType lockType) { + public final R withLock(Query.LockType lockType) { query.withLock(lockType); return root; } @@ -736,7 +736,7 @@ public R withLock(Query.LockType lockType) { * Provides us with the ability to explicitly use Postgres * SHARE, KEY SHARE, NO KEY UPDATE and UPDATE row locks. */ - public R withLock(Query.LockType lockType, Query.LockWait lockWait) { + public final R withLock(Query.LockType lockType, Query.LockWait lockWait) { query.withLock(lockType, lockWait); return root; } @@ -744,7 +744,7 @@ public R withLock(Query.LockType lockType, Query.LockWait lockWait) { /** * Add EXISTS sub-query predicate. */ - public R exists(Query subQuery) { + public final R exists(Query subQuery) { peekExprList().exists(subQuery); return root; } @@ -752,7 +752,7 @@ public R exists(Query subQuery) { /** * Add NOT EXISTS sub-query predicate. */ - public R notExists(Query subQuery) { + public final R notExists(Query subQuery) { peekExprList().notExists(subQuery); return root; } @@ -782,7 +782,7 @@ public final R notExists(String sqlSubQuery, Object... bindValues) { /** * Execute using "for update" clause which results in the DB locking the record. */ - public R forUpdate() { + public final R forUpdate() { query.forUpdate(); return root; } @@ -792,7 +792,7 @@ public R forUpdate() { *

* This is typically a Postgres and Oracle only option at this stage. */ - public R forUpdateNoWait() { + public final R forUpdateNoWait() { query.forUpdateNoWait(); return root; } @@ -803,7 +803,7 @@ public R forUpdateNoWait() { * This is typically a Postgres and Oracle only option at this stage. *

*/ - public R forUpdateSkipLocked() { + public final R forUpdateSkipLocked() { query.forUpdateSkipLocked(); return root; } @@ -825,7 +825,7 @@ public R forUpdateSkipLocked() { * * @return This query as an UpdateQuery */ - public UpdateQuery asUpdate() { + public final UpdateQuery asUpdate() { return query.asUpdate(); } @@ -835,7 +835,7 @@ public UpdateQuery asUpdate() { * We effectively use the underlying ORM query to build the SQL and then execute * and map it into DTO beans. */ - public DtoQuery asDto(Class dtoClass) { + public final DtoQuery asDto(Class dtoClass) { return query.asDto(dtoClass); } @@ -859,7 +859,7 @@ public DtoQuery asDto(Class dtoClass) { * * } */ - public R setId(Object id) { + public final R setId(Object id) { query.setId(id); return root; } @@ -876,7 +876,7 @@ public R setId(Object id) { * * } */ - public R setIdIn(Object... ids) { + public final R setIdIn(Object... ids) { query.where().idIn(ids); return root; } @@ -895,7 +895,7 @@ public R setIdIn(Object... ids) { * * } */ - public R setIdIn(Collection ids) { + public final R setIdIn(Collection ids) { query.where().idIn(ids); return root; } @@ -907,7 +907,7 @@ public R setIdIn(Collection ids) { * profile location enhancement on Finders so for some that would be a better option. *

*/ - public R setLabel(String label) { + public final R setLabel(String label) { query.setLabel(label); return root; } @@ -918,7 +918,7 @@ public R setLabel(String label) { * This results in an inline comment that immediately follows * after the select keyword in the form: {@code /*+ hint *\/ } */ - public R setHint(String hint) { + public final R setHint(String hint) { query.setHint(hint); return root; } @@ -930,7 +930,7 @@ public R setHint(String hint) { * is turned on. It is generally not set by application code. *

*/ - public R setProfileLocation(ProfileLocation profileLocation) { + public final R setProfileLocation(ProfileLocation profileLocation) { query.setProfileLocation(profileLocation); return root; } @@ -943,7 +943,7 @@ public R setProfileLocation(ProfileLocation profileLocation) { * * @param lazyLoadBatchSize the number of beans to lazy load in a single batch */ - public R setLazyLoadBatchSize(int lazyLoadBatchSize) { + public final R setLazyLoadBatchSize(int lazyLoadBatchSize) { query.setLazyLoadBatchSize(lazyLoadBatchSize); return root; } @@ -968,7 +968,7 @@ public R setLazyLoadBatchSize(int lazyLoadBatchSize) { * * @param mapKey the property to use as keys for a map. */ - public R setMapKey(String mapKey) { + public final R setMapKey(String mapKey) { query.setMapKey(mapKey); return root; } @@ -986,7 +986,7 @@ public R setMapKey(String mapKey) { * * @param scope The scope to use for this query and subsequent lazy loading. */ - public R setPersistenceContextScope(PersistenceContextScope scope) { + public final R setPersistenceContextScope(PersistenceContextScope scope) { query.setPersistenceContextScope(scope); return root; } @@ -994,7 +994,7 @@ public R setPersistenceContextScope(PersistenceContextScope scope) { /** * Set RawSql to use for this query. */ - public R setRawSql(RawSql rawSql) { + public final R setRawSql(RawSql rawSql) { query.setRawSql(rawSql); return root; } @@ -1002,7 +1002,7 @@ public R setRawSql(RawSql rawSql) { /** * When set to true when you want the returned beans to be read only. */ - public R setReadOnly(boolean readOnly) { + public final R setReadOnly(boolean readOnly) { query.setReadOnly(readOnly); return root; } @@ -1012,9 +1012,8 @@ public R setReadOnly(boolean readOnly) { *

* If the query result is in cache then by default this same instance is * returned. In this sense it should be treated as a read only object graph. - *

*/ - public R setUseCache(boolean useCache) { + public final R setUseCache(boolean useCache) { query.setUseCache(useCache); return root; } @@ -1026,13 +1025,11 @@ public R setUseCache(boolean useCache) { * By default "find by id" and "find by natural key" will use the bean cache * when bean caching is enabled. Setting this to false means that the query * will not use the bean cache and instead hit the database. - *

*

- * By default findList() with natural keys will not use the bean cache. In that + * By default, findList() with natural keys will not use the bean cache. In that * case we need to explicitly use the bean cache. - *

*/ - public R setBeanCacheMode(CacheMode beanCacheMode) { + public final R setBeanCacheMode(CacheMode beanCacheMode) { query.setBeanCacheMode(beanCacheMode); return root; } @@ -1041,9 +1038,8 @@ public R setBeanCacheMode(CacheMode beanCacheMode) { * Set to true if this query should execute against the doc store. *

* When setting this you may also consider disabling lazy loading. - *

*/ - public R setUseDocStore(boolean useDocStore) { + public final R setUseDocStore(boolean useDocStore) { query.setUseDocStore(useDocStore); return root; } @@ -1052,9 +1048,8 @@ public R setUseDocStore(boolean useDocStore) { * Set true if you want to disable lazy loading. *

* That is, once the object graph is returned further lazy loading is disabled. - *

*/ - public R setDisableLazyLoading(boolean disableLazyLoading) { + public final R setDisableLazyLoading(boolean disableLazyLoading) { query.setDisableLazyLoading(disableLazyLoading); return root; } @@ -1065,9 +1060,8 @@ public R setDisableLazyLoading(boolean disableLazyLoading) { * This is intended to be used when the query is not a user initiated query and instead * part of the internal processing in an application to load a cache or document store etc. * In these cases we don't want the query to be part of read auditing. - *

*/ - public R setDisableReadAuditing() { + public final R setDisableReadAuditing() { query.setDisableReadAuditing(); return root; } @@ -1075,7 +1069,7 @@ public R setDisableReadAuditing() { /** * Set this to true to use the query cache. */ - public R setUseQueryCache(boolean useCache) { + public final R setUseQueryCache(boolean useCache) { query.setUseQueryCache(useCache); return root; } @@ -1083,7 +1077,7 @@ public R setUseQueryCache(boolean useCache) { /** * Set the {@link CacheMode} to use the query for executing this query. */ - public R setUseQueryCache(CacheMode cacheMode) { + public final R setUseQueryCache(CacheMode cacheMode) { query.setUseQueryCache(cacheMode); return root; } @@ -1094,11 +1088,10 @@ public R setUseQueryCache(CacheMode cacheMode) { * This will typically result in a call to setQueryTimeout() on a * preparedStatement. If the timeout occurs an exception will be thrown - this * will be a SQLException wrapped up in a PersistenceException. - *

* * @param secs the query timeout limit in seconds. Zero means there is no limit. */ - public R setTimeout(int secs) { + public final R setTimeout(int secs) { query.setTimeout(secs); return root; } @@ -1108,9 +1101,8 @@ public R setTimeout(int secs) { *

* Validate the query checking the where and orderBy expression paths to confirm if * they represent valid properties or paths for the given bean type. - *

*/ - public Set validate() { + public final Set validate() { return query.validate(); } @@ -1120,7 +1112,6 @@ public Set validate() { * When properties in the clause are fully qualified as table-column names * then they are not translated. logical property name names (not fully * qualified) will still be translated to their physical name. - *

*

*

{@code
    *
@@ -1135,7 +1126,7 @@ public Set validate() {
    *
    * }
*/ - public R raw(String rawExpression) { + public final R raw(String rawExpression) { peekExprList().raw(rawExpression); return root; } @@ -1145,14 +1136,12 @@ public R raw(String rawExpression) { *

* The raw expression should contain the same number of ? as there are * parameters. - *

*

* When properties in the clause are fully qualified as table-column names * then they are not translated. logical property name names (not fully * qualified) will still be translated to their physical name. - *

*/ - public R raw(String rawExpression, Object... bindValues) { + public final R raw(String rawExpression, Object... bindValues) { peekExprList().raw(rawExpression, bindValues); return root; } @@ -1217,7 +1206,7 @@ public R raw(String rawExpression, Object... bindValues) { * @param raw The raw expression that is typically a subquery * @param values The values which is typically a list or set of id values. */ - public R rawOrEmpty(String raw, Collection values) { + public final R rawOrEmpty(String raw, Collection values) { peekExprList().rawOrEmpty(raw, values); return root; } @@ -1249,7 +1238,7 @@ public R rawOrEmpty(String raw, Collection values) { * * } */ - public R raw(String rawExpression, Object bindValue) { + public final R raw(String rawExpression, Object bindValue) { peekExprList().raw(rawExpression, bindValue); return root; } @@ -1257,7 +1246,7 @@ public R raw(String rawExpression, Object bindValue) { /** * In expression using multiple columns. */ - public R inTuples(InTuples inTuples) { + public final R inTuples(InTuples inTuples) { peekExprList().inTuples(inTuples); return root; } @@ -1277,7 +1266,7 @@ public R inTuples(InTuples inTuples) { * * } */ - public R orderBy() { + public final R orderBy() { // Yes this does not actually do anything! We include it because style wise it makes // the query nicer to read and suggests that order by definitions are added after this return root; @@ -1287,7 +1276,7 @@ public R orderBy() { * @deprecated migrate to {@link #orderBy()}. */ @Deprecated(since = "13.19", forRemoval = true) - public R order() { + public final R order() { return root; } @@ -1298,7 +1287,7 @@ public R order() { * optional asc and desc keywords representing ascending and descending order * respectively. */ - public R orderBy(String orderByClause) { + public final R orderBy(String orderByClause) { query.orderBy(orderByClause); return root; } @@ -1307,7 +1296,7 @@ public R orderBy(String orderByClause) { * @deprecated migrate to {@link #orderBy(String)} */ @Deprecated(since = "13.19", forRemoval = true) - public R order(String orderByClause) { + public final R order(String orderByClause) { return orderBy(orderByClause); } @@ -1347,7 +1336,7 @@ public R order(String orderByClause) { * * } */ - public R or() { + public final R or() { pushExprList(peekExprList().or()); return root; } @@ -1391,7 +1380,7 @@ public R or() { * * } */ - public R and() { + public final R and() { pushExprList(peekExprList().and()); return root; } @@ -1400,9 +1389,8 @@ public R and() { * Begin a list of expressions added by NOT. *

* Use endNot() or endJunction() to stop added to NOT and 'pop' to the parent expression list. - *

*/ - public R not() { + public final R not() { pushExprList(peekExprList().not()); return root; } @@ -1411,12 +1399,10 @@ public R not() { * Begin a list of expressions added by MUST. *

* This automatically makes this query a document store query. - *

*

* Use endJunction() to stop added to MUST and 'pop' to the parent expression list. - *

*/ - public R must() { + public final R must() { pushExprList(peekExprList().must()); return root; } @@ -1425,12 +1411,10 @@ public R must() { * Begin a list of expressions added by MUST NOT. *

* This automatically makes this query a document store query. - *

*

* Use endJunction() to stop added to MUST NOT and 'pop' to the parent expression list. - *

*/ - public R mustNot() { + public final R mustNot() { return pushExprList(peekExprList().mustNot()); } @@ -1438,19 +1422,17 @@ public R mustNot() { * Begin a list of expressions added by SHOULD. *

* This automatically makes this query a document store query. - *

*

* Use endJunction() to stop added to SHOULD and 'pop' to the parent expression list. - *

*/ - public R should() { + public final R should() { return pushExprList(peekExprList().should()); } /** * End a list of expressions added by 'OR'. */ - public R endJunction() { + public final R endJunction() { if (textMode) { textStack.pop(); } else { @@ -1462,21 +1444,21 @@ public R endJunction() { /** * End OR junction - synonym for endJunction(). */ - public R endOr() { + public final R endOr() { return endJunction(); } /** * End AND junction - synonym for endJunction(). */ - public R endAnd() { + public final R endAnd() { return endJunction(); } /** * End NOT junction - synonym for endJunction(). */ - public R endNot() { + public final R endNot() { return endJunction(); } @@ -1496,15 +1478,13 @@ private R pushExprList(ExpressionList list) { * Add expression after this to the WHERE expression list. *

* For queries against the normal database (not the doc store) this has no effect. - *

*

* This is intended for use with Document Store / ElasticSearch where expressions can be put into either * the "query" section or the "filter" section of the query. Full text expressions like MATCH are in the * "query" section but many expression can be in either - expressions after the where() are put into the * "filter" section which means that they don't add to the relevance and are also cache-able. - *

*/ - public R where() { + public final R where() { textMode = false; return root; } @@ -1513,13 +1493,11 @@ public R where() { * Begin added expressions to the 'Text' expression list. *

* This automatically makes the query a document store query. - *

*

* For ElasticSearch expressions added to 'text' go into the ElasticSearch 'query context' * and expressions added to 'where' go into the ElasticSearch 'filter context'. - *

*/ - public R text() { + public final R text() { textMode = true; return root; } @@ -1528,9 +1506,8 @@ public R text() { * Add a Text Multi-match expression (document store only). *

* This automatically makes the query a document store query. - *

*/ - public R multiMatch(String query, MultiMatch multiMatch) { + public final R multiMatch(String query, MultiMatch multiMatch) { peekExprList().multiMatch(query, multiMatch); return root; } @@ -1539,9 +1516,8 @@ public R multiMatch(String query, MultiMatch multiMatch) { * Add a Text Multi-match expression (document store only). *

* This automatically makes the query a document store query. - *

*/ - public R multiMatch(String query, String... properties) { + public final R multiMatch(String query, String... properties) { peekExprList().multiMatch(query, properties); return root; } @@ -1550,9 +1526,8 @@ public R multiMatch(String query, String... properties) { * Add a Text common terms expression (document store only). *

* This automatically makes the query a document store query. - *

*/ - public R textCommonTerms(String query, TextCommonTerms options) { + public final R textCommonTerms(String query, TextCommonTerms options) { peekExprList().textCommonTerms(query, options); return root; } @@ -1561,9 +1536,8 @@ public R textCommonTerms(String query, TextCommonTerms options) { * Add a Text simple expression (document store only). *

* This automatically makes the query a document store query. - *

*/ - public R textSimple(String query, TextSimple options) { + public final R textSimple(String query, TextSimple options) { peekExprList().textSimple(query, options); return root; } @@ -1572,9 +1546,8 @@ public R textSimple(String query, TextSimple options) { * Add a Text query string expression (document store only). *

* This automatically makes the query a document store query. - *

*/ - public R textQueryString(String query, TextQueryString options) { + public final R textQueryString(String query, TextQueryString options) { peekExprList().textQueryString(query, options); return root; } @@ -1582,7 +1555,7 @@ public R textQueryString(String query, TextQueryString options) { /** * Execute the query using the given transaction. */ - public R usingTransaction(Transaction transaction) { + public final R usingTransaction(Transaction transaction) { query.usingTransaction(transaction); return root; } @@ -1590,7 +1563,7 @@ public R usingTransaction(Transaction transaction) { /** * Execute the query using the given connection. */ - public R usingConnection(Connection connection) { + public final R usingConnection(Connection connection) { query.usingConnection(connection); return root; } @@ -1605,7 +1578,7 @@ public R usingConnection(Connection connection) { * source. We we use {@code usingMaster()} to instead ensure that the query is executed * against the master data source. */ - public R usingMaster() { + public final R usingMaster() { query.usingMaster(); return root; } @@ -1616,7 +1589,6 @@ public R usingMaster() { * The query is executed using max rows of 1 and will only select the id property. * This method is really just a convenient way to optimise a query to perform a * 'does a row exist in the db' check. - *

* *

Example using a query bean:

*
{@code
@@ -1639,7 +1611,7 @@ public R usingMaster() {
    *
    * @return True if the query finds a matching row in the database
    */
-  public boolean exists() {
+  public final boolean exists() {
     return query.exists();
   }
 
@@ -1649,11 +1621,9 @@ public boolean exists() {
    * 

* If more than 1 row is found for this query then a PersistenceException is * thrown. - *

*

* This is useful when your predicates dictate that your query should only * return 0 or 1 results. - *

*

*

{@code
    *
@@ -1665,10 +1635,8 @@ public boolean exists() {
    * ...
    * }
*

- *

* It is also useful with finding objects by their id when you want to specify * further join information to optimise the query. - *

*

*

{@code
    *
@@ -1685,14 +1653,14 @@ public boolean exists() {
    * }
*/ @Nullable - public T findOne() { + public final T findOne() { return query.findOne(); } /** * Execute the query returning an optional bean. */ - public Optional findOneOrEmpty() { + public final Optional findOneOrEmpty() { return query.findOneOrEmpty(); } @@ -1700,7 +1668,6 @@ public Optional findOneOrEmpty() { * Execute the query returning the list of objects. *

* This query will execute against the EbeanServer that was used to create it. - *

*

*

{@code
    *
@@ -1713,7 +1680,7 @@ public Optional findOneOrEmpty() {
    *
    * @see Query#findList()
    */
-  public List findList() {
+  public final List findList() {
     return query.findList();
   }
 
@@ -1736,7 +1703,7 @@ public List findList() {
    *
    * }
*/ - public Stream findStream() { + public final Stream findStream() { return query.findStream(); } @@ -1744,7 +1711,6 @@ public Stream findStream() { * Execute the query returning the set of objects. *

* This query will execute against the EbeanServer that was used to create it. - *

*

*

{@code
    *
@@ -1757,7 +1723,7 @@ public Stream findStream() {
    *
    * @see Query#findSet()
    */
-  public Set findSet() {
+  public final Set findSet() {
     return query.findSet();
   }
 
@@ -1765,11 +1731,10 @@ public Set findSet() {
    * Execute the query returning the list of Id's.
    * 

* This query will execute against the EbeanServer that was used to create it. - *

* * @see Query#findIds() */ - public List findIds() { + public final List findIds() { return query.findIds(); } @@ -1777,11 +1742,9 @@ public List findIds() { * Execute the query returning a map of the objects. *

* This query will execute against the EbeanServer that was used to create it. - *

*

* You can use setMapKey() or asMapKey() to specify the property to be used as keys * on the map. If one is not specified then the id property is used. - *

*

*

{@code
    *
@@ -1794,7 +1757,7 @@ public  List findIds() {
    *
    * @see Query#findMap()
    */
-  public  Map findMap() {
+  public final  Map findMap() {
     return query.findMap();
   }
 
@@ -1804,15 +1767,12 @@ public  Map findMap() {
    * Note that findIterate (and findEach and findEachWhile) uses a "per graph"
    * persistence context scope and adjusts jdbc fetch buffer size for large
    * queries. As such it is better to use findList for small queries.
-   * 

*

* Remember that with {@link QueryIterator} you must call {@link QueryIterator#close()} * when you have finished iterating the results (typically in a finally block). - *

*

* findEach() and findEachWhile() are preferred to findIterate() as they ensure * the jdbc statement and resultSet are closed at the end of the iteration. - *

*

* This query will execute against the EbeanServer that was used to create it. *

@@ -1834,7 +1794,7 @@ public Map findMap() { * * }
*/ - public QueryIterator findIterate() { + public final QueryIterator findIterate() { return query.findIterate(); } @@ -1854,7 +1814,7 @@ public QueryIterator findIterate() { * * @return the list of values for the selected property */ - public List findSingleAttributeList() { + public final List findSingleAttributeList() { return query.findSingleAttributeList(); } @@ -1874,7 +1834,7 @@ public List findSingleAttributeList() { * @return a single value or null for the selected property */ @Nullable - public A findSingleAttribute() { + public final A findSingleAttribute() { return query.findSingleAttribute(); } @@ -1895,8 +1855,7 @@ public A findSingleAttribute() { * * @return an optional value for the selected property */ - @Nullable - public Optional findSingleAttributeOrEmpty() { + public final Optional findSingleAttributeOrEmpty() { return query.findSingleAttributeOrEmpty(); } @@ -1934,7 +1893,7 @@ public Optional findSingleAttributeOrEmpty() { * * @param consumer the consumer used to process the queried beans. */ - public void findEach(Consumer consumer) { + public final void findEach(Consumer consumer) { query.findEach(consumer); } @@ -1951,7 +1910,7 @@ public void findEach(Consumer consumer) { * @param batch The number of beans processed in the batch * @param consumer Process the batch of beans */ - public void findEach(int batch, Consumer> consumer) { + public final void findEach(int batch, Consumer> consumer) { query.findEach(batch, consumer); } @@ -1980,7 +1939,7 @@ public void findEach(int batch, Consumer> consumer) { * * @param consumer the consumer used to process the queried beans. */ - public void findEachWhile(Predicate consumer) { + public final void findEachWhile(Predicate consumer) { query.findEachWhile(consumer); } @@ -1989,9 +1948,8 @@ public void findEachWhile(Predicate consumer) { *

* Generally this query is expected to be a find by id or unique predicates query. * It will execute the query against the history returning the versions of the bean. - *

*/ - public List> findVersions() { + public final List> findVersions() { return query.findVersions(); } @@ -2000,9 +1958,8 @@ public List> findVersions() { *

* Generally this query is expected to be a find by id or unique predicates query. * It will execute the query against the history returning the versions of the bean. - *

*/ - public List> findVersionsBetween(Timestamp start, Timestamp end) { + public final List> findVersionsBetween(Timestamp start, Timestamp end) { return query.findVersionsBetween(start, end); } @@ -2010,9 +1967,8 @@ public List> findVersionsBetween(Timestamp start, Timestamp end) { * Return the count of entities this query should return. *

* This is the number of 'top level' or 'root level' entities. - *

*/ - public int findCount() { + public final int findCount() { return query.findCount(); } @@ -2022,11 +1978,10 @@ public int findCount() { * This returns a Future object which can be used to cancel, check the * execution status (isDone etc) and get the value (with or without a * timeout). - *

* * @return a Future object for the row count query */ - public FutureRowCount findFutureCount() { + public final FutureRowCount findFutureCount() { return query.findFutureCount(); } @@ -2036,11 +1991,10 @@ public FutureRowCount findFutureCount() { * This returns a Future object which can be used to cancel, check the * execution status (isDone etc) and get the value (with or without a * timeout). - *

* * @return a Future object for the list of Id's */ - public FutureIds findFutureIds() { + public final FutureIds findFutureIds() { return query.findFutureIds(); } @@ -2049,11 +2003,10 @@ public FutureIds findFutureIds() { *

* This query will execute in it's own PersistenceContext and using its own transaction. * What that means is that it will not share any bean instances with other queries. - *

* * @return a Future object for the list result of the query */ - public FutureList findFutureList() { + public final FutureList findFutureList() { return query.findFutureList(); } @@ -2062,11 +2015,9 @@ public FutureList findFutureList() { *

* The benefit of using this over findList() is that it provides functionality to get the * total row count etc. - *

*

* If maxRows is not set on the query prior to calling findPagedList() then a * PersistenceException is thrown. - *

*

*

{@code
    *
@@ -2086,7 +2037,7 @@ public FutureList findFutureList() {
    *
    * @return The PagedList
    */
-  public PagedList findPagedList() {
+  public final PagedList findPagedList() {
     return query.findPagedList();
   }
 
@@ -2096,11 +2047,10 @@ public PagedList findPagedList() {
    * 

* Note that if the query includes joins then the generated delete statement may not be * optimal depending on the database platform. - *

* * @return the number of beans/rows that were deleted. */ - public int delete() { + public final int delete() { return query.delete(); } @@ -2109,23 +2059,22 @@ public int delete() { *

* This is only available after the query has been executed and provided only * for informational purposes. - *

*/ - public String getGeneratedSql() { + public final String getGeneratedSql() { return query.getGeneratedSql(); } /** * Return the type of beans being queried. */ - public Class getBeanType() { + public final Class getBeanType() { return query.getBeanType(); } /** * Return the expression list that has been built for this query. */ - public ExpressionList getExpressionList() { + public final ExpressionList getExpressionList() { return query.where(); } @@ -2147,7 +2096,7 @@ public ExpressionList getExpressionList() { * * }
*/ - public R having() { + public final R having() { if (whereStack == null) { whereStack = new ArrayStack<>(); } @@ -2162,7 +2111,6 @@ public R having() { *

* Note that after this we no longer have the query bean so typically we use this right * at the end of the query. - *

* *
{@code
    *
@@ -2183,14 +2131,14 @@ public R having() {
    *
    * }
*/ - public ExpressionList havingClause() { + public final ExpressionList havingClause() { return query.having(); } /** * Return the current expression list that expressions should be added to. */ - protected ExpressionList peekExprList() { + protected final ExpressionList peekExprList() { if (textMode) { // return the current text expression list return _peekText(); @@ -2203,7 +2151,7 @@ protected ExpressionList peekExprList() { return whereStack.peek(); } - protected ExpressionList _peekText() { + protected final ExpressionList _peekText() { if (textStack == null) { textStack = new ArrayStack<>(); // empty so push on the queries base expression list From cf2ec4b81de3c8ae7ced0b844b7eddbc55d4eff5 Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Sun, 31 Mar 2024 10:02:41 +1300 Subject: [PATCH 2/3] Modify TQRootBean making root final Remove the unused setRoot() method --- .../java/io/ebean/typequery/TQRootBean.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java b/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java index 113dd16ecd..38bc4d52fc 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java @@ -68,6 +68,11 @@ public abstract class TQRootBean { */ private final Query query; + /** + * The root query bean instance. Used to provide fluid query construction. + */ + private final R root; + /** * The underlying expression lists held as a stack. Pushed and popped based on and/or (conjunction/disjunction). */ @@ -84,11 +89,6 @@ public abstract class TQRootBean { */ private boolean textMode; - /** - * The root query bean instance. Used to provide fluid query construction. - */ - private R root; - /** * Construct using the type of bean to query on and the default database. */ @@ -134,11 +134,13 @@ public TQRootBean(Query query) { */ public TQRootBean(boolean aliasDummy) { this.query = null; + this.root = null; } /** Construct for FilterMany */ protected TQRootBean(ExpressionList filter) { this.query = null; + this.root = null; this.whereStack = new ArrayStack<>(); whereStack.push(filter); } @@ -150,13 +152,6 @@ public FetchGroup buildFetchGroup() { return ((SpiFetchGroupQuery) query()).buildFetchGroup(); } - /** - * Sets the root query bean instance. Used to provide fluid query construction. - */ - protected void setRoot(R root) { - this.root = root; - } - /** * Return the underlying query. *

From 951f942c73a86f713e4abc8c0bb5ac0699ff8efb Mon Sep 17 00:00:00 2001 From: Rob Bygrave Date: Sun, 31 Mar 2024 11:19:39 +1300 Subject: [PATCH 3/3] Tidy TQRootBean constructor for alias. Note that this requires the updated ebean-agent, where it will not longer use the setRoot() method which has now been removed. --- ebean-postgis-types/pom.xml | 4 ++-- ebean-querybean/pom.xml | 4 ++-- .../src/main/java/io/ebean/typequery/TQRootBean.java | 3 ++- ebean-redis/pom.xml | 4 ++-- ebean-spring-txn/pom.xml | 4 ++-- pom.xml | 4 ++-- tests/test-java16/pom.xml | 4 ++-- 7 files changed, 14 insertions(+), 13 deletions(-) diff --git a/ebean-postgis-types/pom.xml b/ebean-postgis-types/pom.xml index 62d9d98948..08da65312b 100644 --- a/ebean-postgis-types/pom.xml +++ b/ebean-postgis-types/pom.xml @@ -82,11 +82,11 @@ io.repaint.maven tiles-maven-plugin - 2.34 + 2.40 true - io.ebean.tile:enhancement:13.22.0 + io.ebean.tile:enhancement:14.0.3 diff --git a/ebean-querybean/pom.xml b/ebean-querybean/pom.xml index 62256686de..97fa1dd459 100644 --- a/ebean-querybean/pom.xml +++ b/ebean-querybean/pom.xml @@ -96,11 +96,11 @@ io.repaint.maven tiles-maven-plugin - 2.34 + 2.40 true - io.ebean.tile:enhancement:13.22.0 + io.ebean.tile:enhancement:14.0.3 diff --git a/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java b/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java index 38bc4d52fc..aab9c375d3 100644 --- a/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java +++ b/ebean-querybean/src/main/java/io/ebean/typequery/TQRootBean.java @@ -132,9 +132,10 @@ public TQRootBean(Query query) { * Construct for using as an 'Alias' to use the properties as known string * values for select() and fetch(). */ + @SuppressWarnings("unchecked") public TQRootBean(boolean aliasDummy) { this.query = null; - this.root = null; + this.root = (R) this; } /** Construct for FilterMany */ diff --git a/ebean-redis/pom.xml b/ebean-redis/pom.xml index 802b2dcb1c..95e82aa5f0 100644 --- a/ebean-redis/pom.xml +++ b/ebean-redis/pom.xml @@ -68,11 +68,11 @@ io.repaint.maven tiles-maven-plugin - 2.34 + 2.40 true - io.ebean.tile:enhancement:13.22.0 + io.ebean.tile:enhancement:14.0.3 diff --git a/ebean-spring-txn/pom.xml b/ebean-spring-txn/pom.xml index f028743525..42b1653887 100644 --- a/ebean-spring-txn/pom.xml +++ b/ebean-spring-txn/pom.xml @@ -95,11 +95,11 @@ io.repaint.maven tiles-maven-plugin - 2.34 + 2.40 true - io.ebean.tile:enhancement:13.22.0 + io.ebean.tile:enhancement:14.0.3 diff --git a/pom.xml b/pom.xml index 84e81f13bb..750921fd74 100644 --- a/pom.xml +++ b/pom.xml @@ -53,8 +53,8 @@ 14.0.0 7.3 8.12 - 14.0.2 - 14.0.2 + 14.0.3 + 14.0.3 false diff --git a/tests/test-java16/pom.xml b/tests/test-java16/pom.xml index 01a3bfac6c..abefc8345f 100644 --- a/tests/test-java16/pom.xml +++ b/tests/test-java16/pom.xml @@ -48,11 +48,11 @@ io.repaint.maven tiles-maven-plugin - 2.34 + 2.40 true - io.ebean.tile:enhancement:13.22.0 + io.ebean.tile:enhancement:14.0.3