Merge pull request #3304 from ebean-orm/feature/3296-querybean-copy

#3296 Add copy() method to query beans
This commit is contained in:
Rob Bygrave
2024-01-15 22:38:30 +13:00
committed by GitHub
3 changed files with 32 additions and 0 deletions
@@ -63,6 +63,25 @@ public class QCustomerTest {
}
@Test
public void copy() {
var origin = new QCustomer()
.setDistinct(true)
.status.equalTo(Customer.Status.BAD);
var copy1 = origin.copy().name.isNotNull();
var q1 = copy1.query();
copy1.findList();
assertThat(q1.getGeneratedSql()).contains("from be_customer t0 where t0.status = ? and t0.name is not null");
var copy2 = origin.copy().version.ge(1L);
var q2 = copy2.query();
copy2.findList();
assertThat(q2.getGeneratedSql()).contains("from be_customer t0 where t0.status = ? and t0.version >= ?");
}
@Test
public void findSingleAttribute() {
@@ -94,6 +94,13 @@ class KotlinLangAdapter implements LangAdapter {
writer.append(" * Private constructor for FetchGroup building.").eol();
writer.append(" */").eol();
writer.append(" private constructor(fetchGroupQuery: Query<%s>) : super(fetchGroupQuery)", shortName).eol();
writer.eol();
writer.append(" /** Return a copy of the query. */").eol();
writer.append(" fun copy() : Q%s {", shortName).eol();
writer.append(" return Q%s(query().copy())", shortName).eol();
writer.append(" }").eol();
writer.eol();
}
@Override
@@ -194,6 +194,12 @@ class SimpleQueryBeanWriter {
writer.append(" private Q%s(io.ebean.ExpressionList<%s> filter) {", shortName, shortName).eol();
writer.append(" super(filter);").eol();
writer.append(" }").eol();
writer.eol();
writer.append(" /** Return a copy of the query bean. */").eol();
writer.append(" public Q%s copy() {", shortName).eol();
writer.append(" return new Q%s(query().copy());", shortName).eol();
writer.append(" }").eol();
}
/**