#611 - findRowCount ignores @SoftDelete, does not add predicate

This commit is contained in:
Robin Bygrave
2016-03-22 10:35:20 +13:00
parent 5d3d73aac8
commit e57ce7a6c4
3 changed files with 30 additions and 5 deletions
@@ -234,6 +234,10 @@ public class CQueryBuilder {
predicates.prepare(true);
SqlTree sqlTree = createSqlTree(request, predicates, getHistorySupport(query), getDraftSupport(query));
if (SpiQuery.TemporalMode.CURRENT == query.getTemporalMode()) {
sqlTree.addSoftDeletePredicate(query);
}
SqlLimitResponse s = buildSql(sqlSelect, request, predicates, sqlTree);
String sql = s.getSql();
if (hasMany || query.isRawSql()) {
@@ -600,10 +600,7 @@ public class DefaultOrmQuery<T> implements SpiQuery<T> {
if (detail != null) {
copy.detail = detail.copy();
}
if (temporalMode == TemporalMode.DRAFT) {
copy.temporalMode = TemporalMode.DRAFT;
}
copy.temporalMode = temporalMode;
copy.firstRow = firstRow;
copy.maxRows = maxRows;
copy.rawWhereClause = rawWhereClause;
@@ -44,13 +44,37 @@ public class TestSoftDeleteBasic extends BaseTestCase {
}
@Test
public void testDeleteById() {
public void testDeleteById_and_findRowCount() {
EBasicSoftDelete bean = new EBasicSoftDelete();
bean.setName("two");
Ebean.save(bean);
int rowCountBefore = Ebean.find(EBasicSoftDelete.class).findRowCount();
Ebean.delete(EBasicSoftDelete.class, bean.getId());
// -- test .findRowCount()
LoggedSqlCollector.start();
int rowCountAfter = Ebean.find(EBasicSoftDelete.class).findRowCount();
List<String> loggedSql = LoggedSqlCollector.stop();
assertThat(loggedSql).hasSize(1);
assertThat(loggedSql.get(0)).contains("where coalesce(t0.deleted,false)=false");
assertThat(rowCountAfter).isEqualTo(rowCountBefore - 1);
// -- test includeSoftDeletes().findRowCount()
LoggedSqlCollector.start();
int rowCountFull = Ebean.find(EBasicSoftDelete.class).includeSoftDeletes().findRowCount();
assertThat(rowCountFull).isGreaterThan(rowCountAfter);
loggedSql = LoggedSqlCollector.stop();
assertThat(loggedSql).hasSize(1);
assertThat(loggedSql.get(0)).doesNotContain("where coalesce(t0.deleted,false)=false");
}
@Test