Skip to content

Commit

Permalink
Merge pull request #3186 from ebean-orm/feature/3183-deleteQueryIn
Browse files Browse the repository at this point in the history
#3183 - Fix for: Wrong limit using setMaxRows on delete between calls
  • Loading branch information
rbygrave authored Aug 24, 2023
2 parents 3279955 + f4ca4ec commit 26fa885
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class OrmQueryPlanKey implements CQueryPlanKey {

@Override
public CQueryPlanKey withDeleteByIds() {
return new OrmQueryPlanKey(description + "/deleteByIds", 0, 0, null);
return new OrmQueryPlanKey(description + "/deleteByIds", maxRows, firstRow, null);
}

@Override
Expand Down
46 changes: 46 additions & 0 deletions ebean-test/src/test/java/org/tests/delete/TestDeleteByQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,52 @@ private void createUser(String name) {
DB.save(u1);
}

@Test
void maxDelete_expect_singleDeleteStatement() {
LoggedSql.start();
DB.find(BBookmarkUser.class)
.where().eq("name", "a")
.setMaxRows(10)
.delete();

DB.find(BBookmarkUser.class)
.where().eq("name", "b")
.setMaxRows(20)
.delete();

List<String> loggedSql = LoggedSql.stop();
assertThat(loggedSql).hasSize(2);
if (isH2()) {
assertThat(loggedSql.get(0)).contains("delete from bbookmark_user where id in (select t0.id from bbookmark_user t0 where t0.name = ? limit 10)");
assertThat(loggedSql.get(1)).contains("delete from bbookmark_user where id in (select t0.id from bbookmark_user t0 where t0.name = ? limit 20)");
}
}

@Test
void maxDelete_when_beanCaching_expect_selectThenDelete() {
var a0 = new Article("deleteMe1", "auth1");
var a1 = new Article("deleteMe2", "auth1");
DB.saveAll(a0, a1);

LoggedSql.start();
DB.find(Article.class)
.where().eq("name", "deleteMe1")
.setMaxRows(10)
.delete();

DB.find(Article.class)
.where().eq("name", "deleteMe2")
.setMaxRows(20)
.delete();

List<String> loggedSql = LoggedSql.stop();
assertThat(loggedSql).hasSize(6);
if (isH2()) {
assertThat(loggedSql.get(0)).contains("select t0.id from article t0 where t0.name = ? limit 10");
assertThat(loggedSql.get(3)).contains("select t0.id from article t0 where t0.name = ? limit 20");
}
}

@Test
@IgnorePlatform({Platform.MYSQL, Platform.MARIADB})
public void deleteWithLimit() {
Expand Down

0 comments on commit 26fa885

Please sign in to comment.