Merge pull request #3416 from ebean-orm/feature/querybean-gen-suppresswarnings

Change QueryBean to use protected constructors, suppress warning on generated query beans
This commit is contained in:
Rob Bygrave
2024-06-10 12:39:53 +12:00
committed by GitHub
2 changed files with 7 additions and 6 deletions
@@ -88,14 +88,14 @@ public abstract class QueryBean<T, R> implements IQueryBean<T, R> {
/**
* Construct using the type of bean to query on and the default database.
*/
public QueryBean(Class<T> beanType) {
protected QueryBean(Class<T> beanType) {
this(beanType, DB.getDefault());
}
/**
* Construct using the type of bean to query on and a given database.
*/
public QueryBean(Class<T> beanType, Database database) {
protected QueryBean(Class<T> beanType, Database database) {
this(database.find(beanType));
}
@@ -119,7 +119,7 @@ public abstract class QueryBean<T, R> implements IQueryBean<T, R> {
* Construct using a query.
*/
@SuppressWarnings("unchecked")
public QueryBean(Query<T> query) {
protected QueryBean(Query<T> query) {
this.query = query;
this.root = (R) this;
}
@@ -129,7 +129,7 @@ public abstract class QueryBean<T, R> implements IQueryBean<T, R> {
* values for select() and fetch().
*/
@SuppressWarnings("unchecked")
public QueryBean(boolean aliasDummy) {
protected QueryBean(boolean aliasDummy) {
this.query = null;
this.root = (R) this;
}
@@ -217,9 +217,10 @@ class SimpleQueryBeanWriter {
private void writeClass() {
writer.append("/**").eol();
writer.append(" * Query bean for %s.", shortName).eol();
writer.append(" * ").eol();
writer.append(" * <p>").eol();
writer.append(" * THIS IS A GENERATED OBJECT, DO NOT MODIFY THIS CLASS.").eol();
writer.append(" */").eol();
writer.append("@SuppressWarnings(\"unused\")").eol();
writer.append(Constants.AT_GENERATED).eol();
if (embeddable) {
writer.append("public final class Q%s {", shortName).eol();
@@ -285,7 +286,7 @@ class SimpleQueryBeanWriter {
private void writeAssocFilterMany() {
writer.eol();
writer.append(" @SuppressWarnings({\"unchecked\", \"rawtypes\"})").eol();
writer.append(" public final R filterMany(java.util.function.Consumer<Q%s> apply) {", shortName).eol();
writer.append(" public R filterMany(java.util.function.Consumer<Q%s> apply) {", shortName).eol();
writer.append(" final io.ebean.ExpressionList list = io.ebean.Expr.factory().expressionList();", shortName).eol();
writer.append(" final var qb = new Q%s(list);", shortName).eol();
writer.append(" apply.accept(qb);").eol();