No effective change - change DefaultOrmQuery methods to return Query<T> rather than DefaultOrmQuery<T>

This is no effective functional change but we do need to update the test OrmQueryPlanKeyTest to cast now.
This commit is contained in:
Robin Bygrave committed 2021-03-02 14:44:54 +13:00
1 parent dcf5e7a15c
commit f416309863
2 files changed
+97 -98

No files matched your search

@@ -391,7 +391,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> setUseDocStore(boolean useDocStore) {
public Query<T> setUseDocStore(boolean useDocStore) {
this.useDocStore = useDocStore;
return this;
}
@@ -431,7 +431,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> setAllowLoadErrors() {
public Query<T> setAllowLoadErrors() {
this.allowLoadErrors = true;
return this;
}
@@ -452,21 +452,21 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> asOf(Timestamp asOfDateTime) {
public Query<T> asOf(Timestamp asOfDateTime) {
this.temporalMode = (asOfDateTime != null) ? TemporalMode.AS_OF : TemporalMode.CURRENT;
this.asOf = asOfDateTime;
return this;
}
@Override
public DefaultOrmQuery<T> asDraft() {
public Query<T> asDraft() {
this.temporalMode = TemporalMode.DRAFT;
this.useBeanCache = CacheMode.OFF;
return this;
}
@Override
public DefaultOrmQuery<T> setIncludeSoftDeletes() {
public Query<T> setIncludeSoftDeletes() {
this.temporalMode = TemporalMode.SOFT_DELETED;
return this;
}
@@ -489,7 +489,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> setRawSql(RawSql rawSql) {
public Query<T> setRawSql(RawSql rawSql) {
this.rawSql = (SpiRawSql) rawSql;
return this;
}
@@ -802,12 +802,12 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> copy() {
public SpiQuery<T> copy() {
return copy(server);
}
@Override
public DefaultOrmQuery<T> copy(SpiEbeanServer server) {
public SpiQuery<T> copy(SpiEbeanServer server) {
DefaultOrmQuery<T> copy = new DefaultOrmQuery<>(beanDescriptor, server, expressionFactory);
copy.transaction = transaction;
copy.m2mIncludeJoin = m2mIncludeJoin;
@@ -955,7 +955,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> setAutoTune(boolean autoTune) {
public Query<T> setAutoTune(boolean autoTune) {
this.autoTune = autoTune;
return this;
}
@@ -971,21 +971,21 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> forUpdate() {
public Query<T> forUpdate() {
return setForUpdateWithMode(LockWait.WAIT, LockType.DEFAULT);
}
@Override
public DefaultOrmQuery<T> forUpdateNoWait() {
public Query<T> forUpdateNoWait() {
return setForUpdateWithMode(LockWait.NOWAIT, LockType.DEFAULT);
}
@Override
public DefaultOrmQuery<T> forUpdateSkipLocked() {
public Query<T> forUpdateSkipLocked() {
return setForUpdateWithMode(LockWait.SKIPLOCKED, LockType.DEFAULT);
}
private DefaultOrmQuery<T> setForUpdateWithMode(LockWait mode, LockType lockType) {
private Query<T> setForUpdateWithMode(LockWait mode, LockType lockType) {
this.forUpdate = mode;
this.lockType = lockType;
this.useBeanCache = CacheMode.OFF;
@@ -1329,7 +1329,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> setReadOnly(boolean readOnly) {
public Query<T> setReadOnly(boolean readOnly) {
this.readOnly = readOnly;
return this;
}
@@ -1375,19 +1375,19 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> setUseQueryCache(CacheMode useQueryCache) {
public Query<T> setUseQueryCache(CacheMode useQueryCache) {
this.useQueryCache = useQueryCache;
return this;
}
@Override
public DefaultOrmQuery<T> setLoadBeanCache(boolean loadBeanCache) {
public Query<T> setLoadBeanCache(boolean loadBeanCache) {
this.useBeanCache = CacheMode.PUT;
return this;
}
@Override
public DefaultOrmQuery<T> setTimeout(int secs) {
public Query<T> setTimeout(int secs) {
this.timeout = secs;
return this;
}
@@ -1413,19 +1413,19 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> select(String columns) {
public Query<T> select(String columns) {
detail.select(columns);
return this;
}
@Override
public DefaultOrmQuery<T> select(FetchGroup<T> fetchGroup) {
public Query<T> select(FetchGroup<T> fetchGroup) {
this.detail = ((SpiFetchGroup<T>) fetchGroup).detail();
return this;
}
@Override
public DefaultOrmQuery<T> fetch(String property) {
public Query<T> fetch(String property) {
return fetch(property, null, null);
}
@@ -1444,12 +1444,12 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> fetch(String property, FetchConfig joinConfig) {
public Query<T> fetch(String property, FetchConfig joinConfig) {
return fetch(property, null, joinConfig);
}
@Override
public DefaultOrmQuery<T> fetch(String property, String columns) {
public Query<T> fetch(String property, String columns) {
return fetch(property, columns, null);
}
@@ -1469,7 +1469,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> fetch(String property, String columns, FetchConfig config) {
public Query<T> fetch(String property, String columns, FetchConfig config) {
detail.fetch(property, columns, config);
return this;
}
@@ -1633,7 +1633,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> setParameter(Object value) {
public Query<T> setParameter(Object value) {
if (bindParams == null) {
bindParams = new BindParams();
}
@@ -1642,7 +1642,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> setParameters(Object... values) {
public Query<T> setParameters(Object... values) {
if (bindParams == null) {
bindParams = new BindParams();
}
@@ -1656,7 +1656,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
* have in the query.
*/
@Override
public DefaultOrmQuery<T> setParameter(int position, Object value) {
public Query<T> setParameter(int position, Object value) {
if (bindParams == null) {
bindParams = new BindParams();
}
@@ -1668,7 +1668,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
* Set a named bind parameter. Named parameters have a colon to prefix the name.
*/
@Override
public DefaultOrmQuery<T> setParameter(String name, Object value) {
public Query<T> setParameter(String name, Object value) {
if (namedParams != null) {
ONamedParam param = namedParams.get(name);
if (param != null) {
@@ -1714,12 +1714,12 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
@Override
@Deprecated
public DefaultOrmQuery<T> orderBy(String orderByClause) {
public Query<T> orderBy(String orderByClause) {
return order(orderByClause);
}
@Override
public DefaultOrmQuery<T> order(String orderByClause) {
public Query<T> order(String orderByClause) {
if (orderByClause == null || orderByClause.trim().isEmpty()) {
this.orderBy = null;
} else {
@@ -1730,12 +1730,12 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
@Override
@Deprecated
public DefaultOrmQuery<T> setOrderBy(OrderBy<T> orderBy) {
public Query<T> setOrderBy(OrderBy<T> orderBy) {
return setOrder(orderBy);
}
@Override
public DefaultOrmQuery<T> setOrder(OrderBy<T> orderBy) {
public Query<T> setOrder(OrderBy<T> orderBy) {
this.orderBy = orderBy;
if (orderBy != null) {
orderBy.setQuery(this);
@@ -1767,13 +1767,13 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
* Internally set to use SQL DISTINCT on the query but still have id property included.
*/
@Override
public DefaultOrmQuery<T> setDistinct(boolean distinct) {
public Query<T> setDistinct(boolean distinct) {
this.distinct = distinct;
return this;
}
@Override
public DefaultOrmQuery<T> setCountDistinct(CountDistinctOrder countDistinctOrder) {
public Query<T> setCountDistinct(CountDistinctOrder countDistinctOrder) {
this.countDistinctOrder = countDistinctOrder;
return this;
}
@@ -1824,7 +1824,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> setDisableLazyLoading(boolean disableLazyLoading) {
public Query<T> setDisableLazyLoading(boolean disableLazyLoading) {
this.disableLazyLoading = disableLazyLoading;
return this;
}
@@ -1840,7 +1840,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> setFirstRow(int firstRow) {
public Query<T> setFirstRow(int firstRow) {
this.firstRow = firstRow;
return this;
}
@@ -1851,7 +1851,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> setMaxRows(int maxRows) {
public Query<T> setMaxRows(int maxRows) {
this.maxRows = maxRows;
return this;
}
@@ -1862,7 +1862,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> setMapKey(String mapKey) {
public Query<T> setMapKey(String mapKey) {
this.mapKey = mapKey;
return this;
}
@@ -1873,7 +1873,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> setId(Object id) {
public Query<T> setId(Object id) {
if (id == null) {
throw new NullPointerException("The id is null");
}
@@ -1887,7 +1887,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> where(Expression expression) {
public Query<T> where(Expression expression) {
where().add(expression);
return this;
}
@@ -1917,7 +1917,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> having(Expression expression) {
public Query<T> having(Expression expression) {
having().add(expression);
return this;
}
@@ -2043,7 +2043,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
}
@Override
public DefaultOrmQuery<T> alias(String alias) {
public Query<T> alias(String alias) {
this.rootTableAlias = alias;
return this;
}
@@ -18,8 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class OrmQueryPlanKeyTest extends BaseExpressionTest {
@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "rawtypes"})
private DefaultOrmQuery<Customer> query() {
return (DefaultOrmQuery) server().find(Customer.class);
}
@@ -85,41 +84,40 @@ public class OrmQueryPlanKeyTest extends BaseExpressionTest {
@Test
public void equals_when_firstRowsDifferent() {
CQueryPlanKey key1 = query().setFirstRow(10).createQueryPlanKey();
CQueryPlanKey key2 = query().createQueryPlanKey();
CQueryPlanKey key1 = planKey(query().setFirstRow(10));
CQueryPlanKey key2 = planKey(query());
assertDifferent(key1, key2);
key1 = query().setFirstRow(10).createQueryPlanKey();
key2 = query().setFirstRow(9).createQueryPlanKey();
key1 = planKey(query().setFirstRow(10));
key2 = planKey(query().setFirstRow(9));
assertDifferent(key1, key2);
key1 = query().createQueryPlanKey();
key2 = query().setFirstRow(9).createQueryPlanKey();
key1 = planKey(query());
key2 = planKey(query().setFirstRow(9));
assertDifferent(key1, key2);
}
@Test
public void equals_when_maxRowsDifferent() {
CQueryPlanKey key1 = query().setMaxRows(10).createQueryPlanKey();
CQueryPlanKey key2 = query().createQueryPlanKey();
CQueryPlanKey key1 = planKey(query().setMaxRows(10));
CQueryPlanKey key2 = planKey(query());
assertDifferent(key1, key2);
key1 = query().setMaxRows(10).createQueryPlanKey();
key2 = query().setMaxRows(9).createQueryPlanKey();
key1 = planKey(query().setMaxRows(10));
key2 = planKey(query().setMaxRows(9));
assertDifferent(key1, key2);
key1 = query().createQueryPlanKey();
key2 = query().setMaxRows(9).createQueryPlanKey();
key1 = planKey(query());
key2 = planKey(query().setMaxRows(9));
assertDifferent(key1, key2);
}
@Test
public void equals_when_firstRowsMaxRowsSame() {
CQueryPlanKey key1 = query().setMaxRows(10).setFirstRow(20).createQueryPlanKey();
CQueryPlanKey key2 = query().setFirstRow(20).setMaxRows(10).createQueryPlanKey();
CQueryPlanKey key1 = planKey(query().setMaxRows(10).setFirstRow(20));
CQueryPlanKey key2 = planKey(query().setFirstRow(20).setMaxRows(10));
assertSame(key1, key2);
}
@@ -132,43 +130,43 @@ public class OrmQueryPlanKeyTest extends BaseExpressionTest {
@Test
public void equals_when_diffOrderByNull() {
CQueryPlanKey key1 = query().order("id").createQueryPlanKey();
CQueryPlanKey key2 = query().createQueryPlanKey();
CQueryPlanKey key1 = planKey(query().order("id"));
CQueryPlanKey key2 = planKey(query());
assertDifferent(key1, key2);
key1 = ((DefaultOrmQuery) query().order().asc("id")).createQueryPlanKey();
key2 = query().createQueryPlanKey();
key1 = planKey(query().order().asc("id"));
key2 = planKey(query());
assertDifferent(key1, key2);
}
@Test
public void equals_when_orderBySame() {
CQueryPlanKey key1 = query().order("id, name").createQueryPlanKey();
CQueryPlanKey key2 = query().order("id, name").createQueryPlanKey();
CQueryPlanKey key1 = planKey(query().order("id, name"));
CQueryPlanKey key2 = planKey(query().order("id, name"));
assertSame(key1, key2);
}
@Test
public void equals_when_diffDistinct() {
CQueryPlanKey key1 = query().setDistinct(true).createQueryPlanKey();
CQueryPlanKey key2 = query().createQueryPlanKey();
CQueryPlanKey key1 = planKey(query().setDistinct(true));
CQueryPlanKey key2 = planKey(query());
assertDifferent(key1, key2);
}
@Test
public void equals_when_sameDistinct() {
CQueryPlanKey key1 = query().setDistinct(true).createQueryPlanKey();
CQueryPlanKey key2 = query().setDistinct(true).createQueryPlanKey();
CQueryPlanKey key1 = planKey(query().setDistinct(true));
CQueryPlanKey key2 = planKey(query().setDistinct(true));
assertSame(key1, key2);
}
@Test
public void equals_when_useDocStore() {
CQueryPlanKey key1 = query().setUseDocStore(true).createQueryPlanKey();
CQueryPlanKey key2 = query().createQueryPlanKey();
CQueryPlanKey key1 = planKey(query().setUseDocStore(true));
CQueryPlanKey key2 = planKey(query());
assertDifferent(key1, key2);
}
@@ -176,79 +174,78 @@ public class OrmQueryPlanKeyTest extends BaseExpressionTest {
@Test
public void equals_when_diffMapKey() {
CQueryPlanKey key1 = query().setMapKey("name").createQueryPlanKey();
CQueryPlanKey key2 = query().createQueryPlanKey();
CQueryPlanKey key1 = planKey(query().setMapKey("name"));
CQueryPlanKey key2 = planKey(query());
assertDifferent(key1, key2);
CQueryPlanKey key3 = query().setMapKey("email").createQueryPlanKey();
CQueryPlanKey key3 = planKey(query().setMapKey("email"));
assertDifferent(key1, key3);
CQueryPlanKey key4 = query().setMapKey("name").createQueryPlanKey();
CQueryPlanKey key4 = planKey(query().setMapKey("name"));
assertSame(key1, key4);
}
@Test
public void equals_when_diffIdNull() {
CQueryPlanKey key1 = query().setId(42).createQueryPlanKey();
CQueryPlanKey key2 = query().createQueryPlanKey();
CQueryPlanKey key1 = planKey(query().setId(42));
CQueryPlanKey key2 = planKey(query());
assertDifferent(key1, key2);
}
@Test
public void equals_when_idBothGiven() {
CQueryPlanKey key1 = query().setId(42).createQueryPlanKey();
CQueryPlanKey key2 = query().setId(23).createQueryPlanKey();
CQueryPlanKey key1 = planKey(query().setId(42));
CQueryPlanKey key2 = planKey(query().setId(23));
assertSame(key1, key2);
}
@Test
public void equals_when_diffTemporalMode() {
CQueryPlanKey key1 = query().createQueryPlanKey();
CQueryPlanKey key2 = query().asDraft().createQueryPlanKey();
CQueryPlanKey key1 = planKey(query());
CQueryPlanKey key2 = planKey(query().asDraft());
assertDifferent(key1, key2);
CQueryPlanKey key3 = query().asOf(new Timestamp(System.currentTimeMillis())).createQueryPlanKey();
CQueryPlanKey key3 = planKey(query().asOf(new Timestamp(System.currentTimeMillis())));
assertDifferent(key1, key3);
CQueryPlanKey key4 = query().setIncludeSoftDeletes().createQueryPlanKey();
CQueryPlanKey key4 = planKey(query().setIncludeSoftDeletes());
assertDifferent(key1, key4);
}
@Test
public void equals_when_diffForUpdate() {
CQueryPlanKey key1 = query().forUpdate().createQueryPlanKey();
CQueryPlanKey key2 = query().createQueryPlanKey();
CQueryPlanKey key1 = planKey(query().forUpdate());
CQueryPlanKey key2 = planKey(query());
assertDifferent(key1, key2);
CQueryPlanKey key3 = query().forUpdateNoWait().createQueryPlanKey();
CQueryPlanKey key3 = planKey(query().forUpdateNoWait());
assertDifferent(key1, key3);
CQueryPlanKey key4 = query().forUpdateSkipLocked().createQueryPlanKey();
CQueryPlanKey key4 = planKey(query().forUpdateSkipLocked());
assertDifferent(key1, key4);
CQueryPlanKey key5 = query().forUpdate().createQueryPlanKey();
CQueryPlanKey key5 = planKey(query().forUpdate());
assertSame(key1, key5);
}
@Test
public void equals_when_diffRootAliasNull() {
CQueryPlanKey key1 = query().alias("alias").createQueryPlanKey();
CQueryPlanKey key2 = query().createQueryPlanKey();
CQueryPlanKey key1 = planKey(query().alias("alias"));
CQueryPlanKey key2 = planKey(query());
assertDifferent(key1, key2);
CQueryPlanKey key3 = query().alias("diff").createQueryPlanKey();
CQueryPlanKey key3 = planKey(query().alias("diff"));
assertDifferent(key1, key3);
CQueryPlanKey key4 = query().alias("alias").createQueryPlanKey();
CQueryPlanKey key4 = planKey(query().alias("alias"));
assertSame(key1, key4);
}
private DefaultOrmQuery<Customer> list_id_eq_42() {
return (DefaultOrmQuery<Customer>) server().find(Customer.class)
.where().eq("id", 42).query();
@@ -298,7 +295,6 @@ public class OrmQueryPlanKeyTest extends BaseExpressionTest {
assertDifferent(key1, key4);
}
@Test
public void equals_when_sameHaving() {
@@ -309,7 +305,7 @@ public class OrmQueryPlanKeyTest extends BaseExpressionTest {
@Test
public void equals_when_manualId_andSelectClause() {
DefaultOrmQuery<Customer> q1 = query().select("name");
DefaultOrmQuery<Customer> q1 = (DefaultOrmQuery<Customer>)query().select("name");
q1.setManualId();
assertDifferent(q1, query().select("name"));
@@ -327,16 +323,19 @@ public class OrmQueryPlanKeyTest extends BaseExpressionTest {
return planKey(id.query());
}
@SuppressWarnings({"rawtypes"})
private CQueryPlanKey planKey(Query<Customer> query) {
return ((DefaultOrmQuery) query).createQueryPlanKey();
}
private void assertDifferent(DefaultOrmQuery q1, DefaultOrmQuery q2) {
assertDifferent(q1.createQueryPlanKey(), q2.createQueryPlanKey());
@SuppressWarnings({"unchecked", "rawtypes"})
private void assertDifferent(Query q1, Query q2) {
assertDifferent(planKey(q1), planKey(q2));
}
private void assertSame(DefaultOrmQuery q1, DefaultOrmQuery q2) {
assertSame(q1.createQueryPlanKey(), q2.createQueryPlanKey());
@SuppressWarnings({"unchecked", "rawtypes"})
private void assertSame(Query q1, Query q2) {
assertSame(planKey(q1), planKey(q2));
}
private void assertDifferent(CQueryPlanKey key1, CQueryPlanKey key2) {