Skip to content

Commit 8044bee

Browse files
committed
Added issue142 Tests
1 parent bd6c993 commit 8044bee

File tree

3 files changed

+100
-0
lines changed

3 files changed

+100
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package lhg142;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.mybatis.dynamic.sql.render.RenderingStrategies;
5+
import org.mybatis.dynamic.sql.select.SelectDSL;
6+
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
7+
8+
import java.util.Objects;
9+
10+
import static issues.gh105.PersonDynamicSqlSupport.lastName;
11+
import static lhg142.MyMarkDynamicSqlSupport.*;
12+
import static org.assertj.core.api.Assertions.assertThat;
13+
import static org.mybatis.dynamic.sql.SqlBuilder.*;
14+
15+
public class Issue142Test {
16+
17+
@Test
18+
public void LimitWithSubqueries() {
19+
Page page = new Page(100L, 10L);
20+
SelectStatementProvider selectStatement = select(id,updateTime.as("mutime"),createTime.as("mctime")).from(myMark)
21+
.where(id, isLessThanOrEqualTo(
22+
select(id).from(myMark)
23+
.orderBy(updateTime.descending(), createTime.descending())
24+
.limit(1L)
25+
.offset(page.getOffset())
26+
)).orderBy(sortColumn("mutime").descending(), sortColumn("mctime").descending())
27+
.limit(page.getSize()).offset(0L).build()
28+
.render(RenderingStrategies.MYBATIS3);
29+
String expected = "select id, update_time as mutime, create_time as mctime from my_mark " +
30+
"where id <= (select id from my_mark order by update_time DESC, create_time DESC limit #{parameters._limit1} offset #{parameters._offset2})" +
31+
" order by mutime DESC, mctime DESC limit #{parameters._limit3} offset #{parameters._offset4}";
32+
assertThat(selectStatement.getSelectStatement()).isEqualTo(expected);
33+
assertThat(selectStatement.getParameters().get("_limit1")).isEqualTo(1L);
34+
assertThat(selectStatement.getParameters().get("_offset2")).isEqualTo(100L);
35+
assertThat(selectStatement.getParameters().get("_limit3")).isEqualTo(10L);
36+
assertThat(selectStatement.getParameters().get("_offset4")).isEqualTo(0L);
37+
}
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* Copyright 2016-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package lhg142;
17+
18+
import org.mybatis.dynamic.sql.SqlColumn;
19+
import org.mybatis.dynamic.sql.SqlTable;
20+
21+
import java.time.LocalDateTime;
22+
23+
public final class MyMarkDynamicSqlSupport {
24+
public static final MyMark myMark = new MyMark();
25+
public static final SqlColumn<Long> id = myMark.id;
26+
public static final SqlColumn<LocalDateTime> createTime = myMark.createTime;
27+
public static final SqlColumn<LocalDateTime> updateTime = myMark.updateTime;
28+
29+
public static final class MyMark extends SqlTable {
30+
public final SqlColumn<Long> id = column("id");
31+
public final SqlColumn<LocalDateTime> createTime = column("create_time");
32+
public final SqlColumn<LocalDateTime> updateTime = column("update_time");
33+
34+
public MyMark() {
35+
super("my_mark");
36+
}
37+
}
38+
}

src/test/java/lhg142/Page.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package lhg142;
2+
3+
public class Page {
4+
private Long offset;
5+
private Long size;
6+
public Page(Long offset, Long size) {
7+
this.offset = offset;
8+
this.size = size;
9+
}
10+
public Long getOffset() {
11+
return offset;
12+
}
13+
public void setOffset(Long offset) {
14+
this.offset = offset;
15+
}
16+
17+
public Long getSize() {
18+
return size;
19+
}
20+
21+
public void setSize(Long size) {
22+
this.size = size;
23+
}
24+
}

0 commit comments

Comments
 (0)