Skip to content

Commit 2d8f0c1

Browse files
authored
Merge pull request #717 from kazuki43zoo/gh-716
Apply Spring 6, Spring Batch 5 and more
2 parents 5847bb0 + 5e6cb83 commit 2d8f0c1

File tree

15 files changed

+97
-164
lines changed

15 files changed

+97
-164
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ name: Java CI
1818

1919
on:
2020
push:
21-
branches-ignore:
22-
- 'compatibility-check-spring6'
2321
pull_request:
2422

2523
jobs:
@@ -28,7 +26,7 @@ jobs:
2826
strategy:
2927
matrix:
3028
os: [ubuntu-latest, macOS-latest, windows-latest]
31-
java: [11, 17, 18, 19-ea]
29+
java: [17, 18, 19-ea]
3230
distribution: ['zulu']
3331
fail-fast: false
3432
max-parallel: 5
@@ -42,4 +40,4 @@ jobs:
4240
java-version: ${{ matrix.java }}
4341
distribution: ${{ matrix.distribution }}
4442
- name: Test with Maven
45-
run: ./mvnw test -B -D"license.skip=true"
43+
run: ./mvnw test -B -D"license.skip=true" -D"enforcer.skip=true"

.github/workflows/compatibility-check-spring6.yaml

Lines changed: 0 additions & 57 deletions
This file was deleted.

.github/workflows/coveralls.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ name: Coveralls
1818

1919
on:
2020
push:
21-
branches-ignore:
22-
- 'compatibility-check-spring6'
2321
pull_request:
2422

2523
jobs:
@@ -31,16 +29,16 @@ jobs:
3129
- name: Set up JDK
3230
uses: actions/setup-java@v3
3331
with:
34-
java-version: 11
32+
java-version: 17
3533
distribution: zulu
3634
- name: Report Coverage to Coveralls for Pull Requests
3735
if: github.event_name == 'pull_request'
38-
run: ./mvnw test jacoco:report coveralls:report -q -Dlicense.skip=true -DrepoToken=$GITHUB_TOKEN -DserviceName=github -DpullRequest=$PR_NUMBER
36+
run: ./mvnw test jacoco:report coveralls:report -q -Dlicense.skip=true -Denforcer.skip=true -DrepoToken=$GITHUB_TOKEN -DserviceName=github -DpullRequest=$PR_NUMBER
3937
env:
4038
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4139
PR_NUMBER: ${{ github.event.number }}
4240
- name: Report Coverage to Coveralls for General Push
4341
if: github.event_name == 'push'
44-
run: ./mvnw test jacoco:report coveralls:report -q -Dlicense.skip=true -DrepoToken=$GITHUB_TOKEN -DserviceName=github
42+
run: ./mvnw test jacoco:report coveralls:report -q -Dlicense.skip=true -Denforcer.skip=true -DrepoToken=$GITHUB_TOKEN -DserviceName=github
4543
env:
4644
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/sonar.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ name: SonarCloud
1919
on:
2020
push:
2121
branches:
22-
- master
22+
- 3.x
2323

2424
jobs:
2525
build:
@@ -36,7 +36,7 @@ jobs:
3636
java-version: 17
3737
distribution: zulu
3838
- name: Analyze with SonarCloud
39-
run: ./mvnw verify jacoco:report sonar:sonar -B -Dsonar.projectKey=mybatis_spring -Dsonar.organization=mybatis -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN -Dlicense.skip=true
39+
run: ./mvnw verify jacoco:report sonar:sonar -B -Dsonar.projectKey=mybatis_spring -Dsonar.organization=mybatis -Dsonar.host.url=https://sonarcloud.io -Dsonar.login=$SONAR_TOKEN -Dlicense.skip=true -Denforcer.skip=true
4040
env:
4141
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4242
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.github/workflows/sonatype.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ name: Sonatype
1919
on:
2020
push:
2121
branches:
22-
- master
22+
- 3.x
2323

2424
jobs:
2525
build:
@@ -33,7 +33,7 @@ jobs:
3333
java-version: 17
3434
distribution: zulu
3535
- name: Deploy to Sonatype
36-
run: ./mvnw deploy -DskipTests -B --settings ./.mvn/settings.xml -Dlicense.skip=true
36+
run: ./mvnw deploy -DskipTests -Denforcer.skip=true -B --settings ./.mvn/settings.xml -Dlicense.skip=true
3737
env:
3838
CI_DEPLOY_USERNAME: ${{ secrets.CI_DEPLOY_USERNAME }}
3939
CI_DEPLOY_PASSWORD: ${{ secrets.CI_DEPLOY_PASSWORD }}

.github/workflows/support.yaml

Lines changed: 0 additions & 47 deletions
This file was deleted.

pom.xml

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,13 @@
106106
<osgi.dynamicImport>*</osgi.dynamicImport>
107107

108108
<mybatis.version>3.5.10</mybatis.version>
109-
<spring.version>5.3.22</spring.version>
110-
<spring-batch.version>4.3.6</spring-batch.version>
109+
<spring.version>6.0.0-SNAPSHOT</spring.version>
110+
<spring-batch.version>5.0.0-SNAPSHOT</spring-batch.version>
111111
<module.name>org.mybatis.spring</module.name>
112112

113113
<junit.version>5.9.0</junit.version>
114114
<project.build.outputTimestamp>1645112687</project.build.outputTimestamp>
115+
115116
</properties>
116117

117118
<dependencies>
@@ -295,13 +296,13 @@
295296
<dependency>
296297
<groupId>jakarta.transaction</groupId>
297298
<artifactId>jakarta.transaction-api</artifactId>
298-
<version>1.3.3</version>
299+
<version>2.0.1</version>
299300
<scope>test</scope>
300301
</dependency>
301302
<dependency>
302303
<groupId>jakarta.servlet</groupId>
303304
<artifactId>jakarta.servlet-api</artifactId>
304-
<version>4.0.4</version>
305+
<version>6.0.0</version>
305306
<scope>test</scope>
306307
</dependency>
307308

@@ -371,6 +372,40 @@
371372
<name>Sonatype OSS Snapshots Repository</name>
372373
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
373374
</repository>
375+
<repository>
376+
<id>spring-snapshot</id>
377+
<name>Spring Snapshots</name>
378+
<url>https://repo.spring.io/snapshot</url>
379+
<releases>
380+
<enabled>false</enabled>
381+
</releases>
382+
</repository>
383+
<repository>
384+
<id>spring-milestone</id>
385+
<name>Spring Milestone</name>
386+
<url>https://repo.spring.io/milestone</url>
387+
<snapshots>
388+
<enabled>false</enabled>
389+
</snapshots>
390+
</repository>
374391
</repositories>
375392

393+
<pluginRepositories>
394+
<pluginRepository>
395+
<id>spring-snapshot</id>
396+
<name>Spring Snapshots</name>
397+
<url>https://repo.spring.io/snapshot</url>
398+
<releases>
399+
<enabled>false</enabled>
400+
</releases>
401+
</pluginRepository>
402+
<pluginRepository>
403+
<id>spring-milestone</id>
404+
<name>Spring Milestone</name>
405+
<url>https://repo.spring.io/milestone</url>
406+
<snapshots>
407+
<enabled>false</enabled>
408+
</snapshots>
409+
</pluginRepository>
410+
</pluginRepositories>
376411
</project>

src/main/java/org/mybatis/spring/batch/MyBatisBatchItemWriter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.mybatis.logging.Logger;
2828
import org.mybatis.logging.LoggerFactory;
2929
import org.mybatis.spring.SqlSessionTemplate;
30+
import org.springframework.batch.item.Chunk;
3031
import org.springframework.batch.item.ItemWriter;
3132
import org.springframework.beans.factory.InitializingBean;
3233
import org.springframework.core.convert.converter.Converter;
@@ -136,7 +137,7 @@ public void afterPropertiesSet() {
136137
* {@inheritDoc}
137138
*/
138139
@Override
139-
public void write(final List<? extends T> items) {
140+
public void write(final Chunk<? extends T> items) {
140141

141142
if (!items.isEmpty()) {
142143
LOGGER.debug(() -> "Executing batch with " + items.size() + " items.");
@@ -158,8 +159,8 @@ public void write(final List<? extends T> items) {
158159
for (int i = 0; i < updateCounts.length; i++) {
159160
int value = updateCounts[i];
160161
if (value == 0) {
161-
throw new EmptyResultDataAccessException(
162-
"Item " + i + " of " + updateCounts.length + " did not update any rows: [" + items.get(i) + "]", 1);
162+
throw new EmptyResultDataAccessException("Item " + i + " of " + updateCounts.length
163+
+ " did not update any rows: [" + items.getItems().get(i) + "]", 1);
163164
}
164165
}
165166
}

src/test/java/org/mybatis/spring/MyBatisSpringTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import static org.junit.jupiter.api.Assertions.assertThrows;
2020
import static org.junit.jupiter.api.Assertions.fail;
2121

22-
import com.mockrunner.mock.ejb.MockUserTransaction;
2322
import com.mockrunner.mock.jdbc.MockConnection;
2423
import com.mockrunner.mock.jdbc.MockDataSource;
2524
import com.mockrunner.mock.jdbc.MockPreparedStatement;
@@ -32,12 +31,15 @@
3231
import org.apache.ibatis.transaction.managed.ManagedTransactionFactory;
3332
import org.junit.jupiter.api.AfterEach;
3433
import org.junit.jupiter.api.Test;
34+
import org.mockito.Mockito;
3535
import org.springframework.dao.DataAccessException;
3636
import org.springframework.dao.TransientDataAccessResourceException;
3737
import org.springframework.transaction.TransactionStatus;
3838
import org.springframework.transaction.jta.JtaTransactionManager;
3939
import org.springframework.transaction.support.DefaultTransactionDefinition;
4040

41+
import jakarta.transaction.UserTransaction;
42+
4143
class MyBatisSpringTest extends AbstractMyBatisSpringTest {
4244

4345
private SqlSession session;
@@ -275,7 +277,7 @@ void testChangeExecutorTypeInTxRequiresNew() throws Exception {
275277

276278
@Test
277279
void testWithJtaTxManager() {
278-
JtaTransactionManager jtaManager = new JtaTransactionManager(new MockUserTransaction());
280+
JtaTransactionManager jtaManager = new JtaTransactionManager(Mockito.mock(UserTransaction.class));
279281

280282
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
281283
txDef.setPropagationBehaviorName("PROPAGATION_REQUIRED");
@@ -304,7 +306,7 @@ void testWithJtaTxManagerAndNonSpringTxManager() throws java.sql.SQLException {
304306
Environment nonSpring = new Environment("non-spring", new ManagedTransactionFactory(), mockDataSource);
305307
sqlSessionFactory.getConfiguration().setEnvironment(nonSpring);
306308

307-
JtaTransactionManager jtaManager = new JtaTransactionManager(new MockUserTransaction());
309+
JtaTransactionManager jtaManager = new JtaTransactionManager(Mockito.mock(UserTransaction.class));
308310

309311
DefaultTransactionDefinition txDef = new DefaultTransactionDefinition();
310312
txDef.setPropagationBehaviorName("PROPAGATION_REQUIRED");

src/test/java/org/mybatis/spring/batch/MyBatisBatchItemWriterTest.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@
2222
import java.time.Instant;
2323
import java.time.LocalDateTime;
2424
import java.time.ZoneId;
25-
import java.util.Arrays;
2625
import java.util.Collections;
2726
import java.util.HashMap;
2827
import java.util.List;
2928
import java.util.Map;
3029

3130
import org.apache.ibatis.executor.BatchResult;
3231
import org.apache.ibatis.session.ExecutorType;
33-
import org.assertj.core.util.Lists;
3432
import org.junit.jupiter.api.BeforeEach;
3533
import org.junit.jupiter.api.Test;
3634
import org.mockito.InjectMocks;
@@ -39,6 +37,7 @@
3937
import org.mockito.MockitoAnnotations;
4038
import org.mybatis.spring.SqlSessionTemplate;
4139
import org.mybatis.spring.batch.domain.Employee;
40+
import org.springframework.batch.item.Chunk;
4241
import org.springframework.dao.EmptyResultDataAccessException;
4342
import org.springframework.dao.InvalidDataAccessResourceUsageException;
4443

@@ -60,8 +59,8 @@ void setUp() {
6059

6160
@Test
6261
void testZeroBatchResultShouldThrowException() {
63-
List<Employee> employees = Arrays.asList(new Employee(), new Employee());
64-
List<BatchResult> batchResults = Lists.emptyList();
62+
Chunk<Employee> employees = Chunk.of(new Employee(), new Employee());
63+
List<BatchResult> batchResults = Collections.emptyList();
6564

6665
given(mockSqlSessionTemplate.flushStatements()).willReturn(batchResults);
6766

@@ -70,7 +69,7 @@ void testZeroBatchResultShouldThrowException() {
7069

7170
@Test
7271
void testZeroUpdateCountShouldThrowException() {
73-
List<Employee> employees = Arrays.asList(new Employee(), new Employee());
72+
Chunk<Employee> employees = Chunk.of(new Employee(), new Employee());
7473

7574
BatchResult batchResult = new BatchResult(null, null);
7675
batchResult.setUpdateCounts(new int[] { 1, 0 });
@@ -87,7 +86,7 @@ void testItemToParameterConverterIsDefault() {
8786
this.writer.setStatementId("updateEmployee");
8887

8988
Employee employee = new Employee();
90-
List<Employee> employees = Collections.singletonList(employee);
89+
Chunk<Employee> employees = Chunk.of(employee);
9190
writer.write(employees);
9291

9392
Mockito.verify(this.mockSqlSessionTemplate).update("updateEmployee", employee);
@@ -105,7 +104,7 @@ void testSetItemToParameterConverter() {
105104
});
106105

107106
Employee employee = new Employee();
108-
List<Employee> employees = Collections.singletonList(employee);
107+
Chunk<Employee> employees = Chunk.of(employee);
109108
writer.write(employees);
110109

111110
Map<String, Object> parameter = new HashMap<>();

0 commit comments

Comments
 (0)