Skip to content

Commit

Permalink
Merge remote-tracking branch 'github/3.0' into github3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
qmdx committed Mar 21, 2024
2 parents 7369e6a + cabd2c8 commit b6a44f6
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 19 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Java CI with Gradle

on:
push:
branches: [ "3.0" ]
pull_request:
branches: [ "3.0" ]

jobs:
build:

runs-on: ubuntu-latest
permissions:
contents: read

steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'

# Configure Gradle for optimal use in GiHub Actions, including caching of downloaded dependencies.
# See: https://github.com/gradle/actions/blob/main/setup-gradle/README.md
- name: Setup Gradle
uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0

- name: Build with Gradle Wrapper
run: ./gradlew build

# NOTE: The Gradle Wrapper is the default and recommended way to run Gradle (https://docs.gradle.org/current/userguide/gradle_wrapper.html).
# If your project does not have the Gradle Wrapper configured, you can use the following configuration to run Gradle with a specified version.
#
# - name: Setup Gradle
# uses: gradle/actions/setup-gradle@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
# with:
# gradle-version: '8.5'
#
# - name: Build with Gradle 8.5
# run: gradle build

dependency-submission:

runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v4
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
java-version: '21'
distribution: 'temurin'

# Generates and submits a dependency graph, enabling Dependabot Alerts for all project dependencies.
# See: https://github.com/gradle/actions/blob/main/dependency-submission/README.md
- name: Generate and submit dependency graph
uses: gradle/actions/dependency-submission@417ae3ccd767c252f5661f1ace9f835f9654f2b5 # v3.1.0
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@
*/
package com.baomidou.mybatisplus.extension.plugins.pagination;

import com.baomidou.mybatisplus.core.metadata.OrderItem;

import java.util.List;

/**
* 简单分页模型 DTO 用于解决跨服务数据传输问题,不影响 Page 作为返回对象序列化 JSON 产生不必要的数据
*
* @author hubin
* @since 2021-05-20
*/
public class PageDTO<T> extends Page<T> {

private static final long serialVersionUID = 1L;

public PageDTO() {
Expand Down Expand Up @@ -59,4 +64,25 @@ public static <T> Page<T> of(long current, long size, boolean searchCount) {
public static <T> Page<T> of(long current, long size, long total, boolean searchCount) {
return new PageDTO<>(current, size, total, searchCount);
}

public String getCountId() {
return this.countId;
}

public Long getMaxLimit() {
return this.maxLimit;
}

public List<OrderItem> getOrders() {
return this.orders;
}

public boolean isOptimizeCountSql() {
return this.optimizeCountSql;
}

public boolean isSearchCount() {
return this.searchCount;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@

/**
* Mybatis Plus H2 Junit Test
* JDK 8 run test:
* <p>"Error: Could not create the Java Virtual Machine."</p>
* <p>Go to build.gradle: remove below configuration:</p>
* <p>
* // jvmArgs += ["--add-opens", "java.base/java.lang=ALL-UNNAMED",
* // "--add-opens", "java.base/java.lang.invoke=ALL-UNNAMED"]
* </p>
*
* @author Caratacus
* @since 2017/4/1
Expand Down Expand Up @@ -309,7 +302,6 @@ void testOptLocker4WrapperIsNull() {
userService.update(new H2User().setPrice(BigDecimal.ZERO), null);
Assertions.fail("SHOULD NOT REACH HERE");
} catch (Exception e) {
e.printStackTrace();
Assertions.assertTrue(checkIsDataUpdateLimitationException(e));
}
}
Expand Down Expand Up @@ -360,10 +352,10 @@ void testSaveOrUpdateBatchTransactional() {
@Test
@Order(21)
void testSaveBatch() {
Assertions.assertTrue(userService.saveBatch(Arrays.asList(new H2User("saveBatch0"))));
Assertions.assertTrue(userService.saveBatch(Arrays.asList(new H2User("saveBatch1"), new H2User("saveBatch2"), new H2User("saveBatch3"), new H2User("saveBatch4"))));
Assertions.assertTrue(userService.saveBatch(List.of(new H2User("saveBatch0"))));
Assertions.assertTrue(userService.saveBatch(List.of(new H2User("saveBatch1"), new H2User("saveBatch2"), new H2User("saveBatch3"), new H2User("saveBatch4"))));
Assertions.assertEquals(5, userService.count(new QueryWrapper<H2User>().like("name", "saveBatch")));
Assertions.assertTrue(userService.saveBatch(Arrays.asList(new H2User("saveBatch5"), new H2User("saveBatch6"), new H2User("saveBatch7"), new H2User("saveBatch8")), 2));
Assertions.assertTrue(userService.saveBatch(List.of(new H2User("saveBatch5"), new H2User("saveBatch6"), new H2User("saveBatch7"), new H2User("saveBatch8")), 2));
Assertions.assertEquals(9, userService.count(new QueryWrapper<H2User>().like("name", "saveBatch")));
}

Expand Down Expand Up @@ -451,7 +443,7 @@ void testSaveBatchException() {
new H2User(1L, "andy")
));
} catch (Exception e) {
Assertions.assertTrue(e instanceof DataAccessException);
Assertions.assertInstanceOf(DataAccessException.class, e);
}
}

Expand Down Expand Up @@ -501,7 +493,7 @@ void testSqlInjectionByCustomSqlSegment() {
// Preparing: select * from h2user WHERE (name LIKE ?)
// Parameters: %y%%(String)
List<H2User> h2Users = userService.testCustomSqlSegment(new QueryWrapper<H2User>().like("name", "y%"));
Assertions.assertTrue(2 == h2Users.size());
Assertions.assertEquals(3, h2Users.size());
}

@Test
Expand Down Expand Up @@ -544,7 +536,7 @@ void batchInsertPerformanceTest() {
* @return 返回模拟的一群人
*/
private List<H2User> mockUser(int size, long cardinal) {
return new AbstractList<H2User>() {
return new AbstractList<>() {

@Override
public H2User get(int index) {
Expand Down Expand Up @@ -641,7 +633,7 @@ void testRemove() {
@Test
void testPageOrderBy() {
// test https://gitee.com/baomidou/mybatis-plus/issues/I4BGE2
Page page = Page.of(1, 10);
Page<H2User> page = Page.of(1, 10);
Assertions.assertTrue(userService.page(page, Wrappers.<H2User>query().select("test_id,name")
.orderByDesc("test_id")).getPages() > 0);
Assertions.assertTrue(userService.page(page, Wrappers.<H2User>lambdaQuery()
Expand All @@ -650,7 +642,7 @@ void testPageOrderBy() {

@Test
void testPageNegativeSize() {
Page page = Page.of(1, -1);
Page<H2User> page = Page.of(1, -1);
userService.lambdaQuery().page(page);
Assertions.assertEquals(page.getTotal(), 0);
Assertions.assertEquals(userService.lambdaQuery().list(Page.of(1, -1, false)).size(), page.getRecords().size());
Expand Down Expand Up @@ -682,10 +674,10 @@ void testServiceImplInnerLambdaQueryConstructorSetEntity() {
condition.setName("Tomcat");
H2User user = userService.lambdaQuery(condition).one();
Assertions.assertNotNull(user);
Assertions.assertTrue("Tomcat".equals(user.getName()));
Assertions.assertEquals("Tomcat", user.getName());
H2User h2User = userService.lambdaQuery().setEntity(condition).one();
Assertions.assertNotNull(h2User);
Assertions.assertTrue("Tomcat".equals(h2User.getName()));
Assertions.assertEquals("Tomcat", h2User.getName());
}

@Test
Expand Down Expand Up @@ -870,7 +862,7 @@ void testUnchecked() {
.groupBy(H2User::getAge, H2User::getTestType).groupBy(true, H2User::getAge, H2User::getTestType);

// 重写方法保留支持.
new LambdaQueryChainWrapper<H2User>(H2User.class) {
new LambdaQueryChainWrapper<>(H2User.class) {
@Override
protected LambdaQueryChainWrapper<H2User> doOrderByDesc(boolean condition, SFunction<H2User, ?> column, List<SFunction<H2User, ?>> columns) {
System.out.println("-------处理OrderByDesc----------");
Expand Down

0 comments on commit b6a44f6

Please sign in to comment.