Skip to content

Commit d10f123

Browse files
committed
Merge branch 'master' into bind-in-foreach
2 parents f2c04e1 + 1b2346c commit d10f123

File tree

55 files changed

+899
-206
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+899
-206
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
/release.properties
1111
/target
1212
.github/keys/
13+
.profiler/
1314

1415
# These are needed if running in IDE without properties set
1516
/ibderby

.mvn/extensions.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
1818
-->
1919
<extensions>
20+
<!-- Usage as -Dprofile -->
2021
<extension>
2122
<groupId>fr.jcgay.maven</groupId>
2223
<artifactId>maven-profiler</artifactId>

CONTRIBUTING.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,21 @@ Please use [the mailing list](https://groups.google.com/group/mybatis-user) inst
1212
- It is a good idea to discuss your changes on [the mailing list](https://groups.google.com/group/mybatis-user) to get feedback from the community.
1313
- If you have a patch with unit tests, send a pull request. Please see the [Contributing code](CONTRIBUTING.md#contributing-code) section.
1414

15-
1615
## Improving documentation
1716

1817
- Documentations are placed under [src/site](https://github.com/mybatis/mybatis-3/tree/master/src/site) directory in [the xdoc format](https://maven.apache.org/doxia/references/xdoc-format.html), so it is basically the same as creating a patch to contribute documentation changes. Please see the [Contributing code](CONTRIBUTING.md#contributing-code) section.
1918

2019
## Contributing code
2120

21+
### Formatting
22+
23+
Mybatis-core is now being auto formatted. Given nature of some code logic with mybatis, it is more appropriate to force a formatting structure manually for snippets such as sql statements. To do so, add following blocks around code.
24+
25+
- ```// @formatter:off``` to start the block of unformatted code
26+
- ```// @formatter:on``` to end the block of unformatted code
27+
28+
If comment sections need same behaviour such as javadocs, note that the entire block must be around entire comment as direct usage does not properly indicate that formatter treats it all as one comment block regardless.
29+
2230
### Copyright and License
2331

2432
- You are the author of your contributions and will always be.

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ MyBatis SQL Mapper Framework for Java
33

44
[![build](https://github.com/mybatis/mybatis-3/actions/workflows/ci.yaml/badge.svg)](https://github.com/mybatis/mybatis-3/actions?query=workflow%3A%22Java+CI%22)
55
[![Coverage Status](https://coveralls.io/repos/mybatis/mybatis-3/badge.svg?branch=master&service=github)](https://coveralls.io/github/mybatis/mybatis-3?branch=master)
6+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=mybatis_mybatis-3&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=mybatis_mybatis-3)
67
[![Maven central](https://maven-badges.herokuapp.com/maven-central/org.mybatis/mybatis/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.mybatis/mybatis)
78
[![Sonatype Nexus (Snapshots)](https://img.shields.io/nexus/s/https/oss.sonatype.org/org.mybatis/mybatis.svg)](https://oss.sonatype.org/content/repositories/snapshots/org/mybatis/mybatis/)
89
[![License](https://img.shields.io/:license-apache-brightgreen.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
@@ -25,12 +26,7 @@ Essentials
2526
Contributions
2627
-------------
2728

28-
Mybatis-core is now being auto formatted. Given nature of some code logic with mybatis, it is more appropriate to force a formatting structure manually for snippets such as sql statements. To do so, add following blocks around code.
29-
30-
- ```// @formatter:off``` to start the block of unformatted code
31-
- ```// @formatter:on``` to end the block of unformatted code
32-
33-
If comment sections need same behaviour such as javadocs, note that the entire block must be around entire comment as direct usage does not properly indicate that formatter treats it all as one comment block regardless.
29+
See [here](CONTRIBUTING.md)
3430

3531
Tests
3632
-----

hooks/pre-commit.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright 2009-2025 the original author or authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# https://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
set -eo pipefail
18+
19+
function format_and_sort() {
20+
# Run the validate and import check commands, suppressing all output and errors
21+
if ! mvn formatter:validate impsort:check > /dev/null 2>&1; then
22+
# If validation failed, fix it by ensuring code is formatted correctly
23+
# and that imports are sorted as some IDEs automatically change it on save
24+
mvn formatter:format impsort:sort
25+
26+
# Fail the commit, so the author can re-select what to commit
27+
echo "Formatting and/or import sorting were required. Please check and make another commit."
28+
exit 1
29+
fi
30+
31+
# If no error occurred, print a success message
32+
echo "All files are properly formatted and imports are sorted."
33+
}
34+
35+
format_and_sort

pom.xml

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,13 @@
7272

7373
<clirr.comparisonVersion>3.4.6</clirr.comparisonVersion>
7474

75-
<byte-buddy.version>1.15.11</byte-buddy.version>
75+
<byte-buddy.version>1.16.1</byte-buddy.version>
7676
<derby.version>10.17.1.0</derby.version>
7777
<log4j.version>2.24.3</log4j.version>
7878
<mockito.version>5.15.2</mockito.version>
7979
<mssql-jdbc.version>12.8.1.jre11</mssql-jdbc.version>
8080
<testcontainers.version>1.20.4</testcontainers.version>
81+
<git-build-hook.version>3.5.0</git-build-hook.version>
8182

8283
<!-- Add slow test groups here and annotate classes similar to @Tag('groupName'). -->
8384
<!-- Excluded groups are ran on github ci, to force here, pass -d"excludedGroups=" -->
@@ -106,7 +107,7 @@
106107
<dependency>
107108
<groupId>ognl</groupId>
108109
<artifactId>ognl</artifactId>
109-
<version>3.4.4</version>
110+
<version>3.4.5</version>
110111
<scope>compile</scope>
111112
<optional>true</optional>
112113
</dependency>
@@ -195,19 +196,25 @@
195196
<dependency>
196197
<groupId>org.postgresql</groupId>
197198
<artifactId>postgresql</artifactId>
198-
<version>42.7.4</version>
199+
<version>42.7.5</version>
199200
<scope>test</scope>
200201
</dependency>
201202
<dependency>
202203
<groupId>com.mysql</groupId>
203204
<artifactId>mysql-connector-j</artifactId>
204-
<version>9.1.0</version>
205+
<version>9.2.0</version>
206+
<scope>test</scope>
207+
</dependency>
208+
<dependency>
209+
<groupId>com.oracle.database.jdbc</groupId>
210+
<artifactId>ojdbc11</artifactId>
211+
<version>23.6.0.24.10</version>
205212
<scope>test</scope>
206213
</dependency>
207214
<dependency>
208215
<groupId>org.assertj</groupId>
209216
<artifactId>assertj-core</artifactId>
210-
<version>3.27.1</version>
217+
<version>3.27.3</version>
211218
<scope>test</scope>
212219
</dependency>
213220
<dependency>
@@ -254,6 +261,12 @@
254261
<version>${testcontainers.version}</version>
255262
<scope>test</scope>
256263
</dependency>
264+
<dependency>
265+
<groupId>org.testcontainers</groupId>
266+
<artifactId>oracle-free</artifactId>
267+
<version>${testcontainers.version}</version>
268+
<scope>test</scope>
269+
</dependency>
257270
<!-- For javadoc link -->
258271
<dependency>
259272
<groupId>com.microsoft.sqlserver</groupId>
@@ -292,7 +305,7 @@
292305
<dependency>
293306
<groupId>ch.qos.logback</groupId>
294307
<artifactId>logback-classic</artifactId>
295-
<version>1.5.15</version>
308+
<version>1.5.16</version>
296309
<scope>test</scope>
297310
</dependency>
298311
<dependency>
@@ -419,6 +432,24 @@
419432
</rules>
420433
</configuration>
421434
</plugin>
435+
436+
<plugin>
437+
<groupId>com.rudikershaw.gitbuildhook</groupId>
438+
<artifactId>git-build-hook-maven-plugin</artifactId>
439+
<version>${git-build-hook.version}</version>
440+
<configuration>
441+
<installHooks>
442+
<pre-commit>hooks/pre-commit.sh</pre-commit>
443+
</installHooks>
444+
</configuration>
445+
<executions>
446+
<execution>
447+
<goals>
448+
<goal>install</goal>
449+
</goals>
450+
</execution>
451+
</executions>
452+
</plugin>
422453
</plugins>
423454
</build>
424455

src/main/java/org/apache/ibatis/cursor/Cursor.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2023 the original author or authors.
2+
* Copyright 2009-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,16 +15,14 @@
1515
*/
1616
package org.apache.ibatis.cursor;
1717

18-
import java.io.Closeable;
19-
2018
/**
2119
* Cursor contract to handle fetching items lazily using an Iterator. Cursors are a perfect fit to handle millions of
2220
* items queries that would not normally fit in memory. If you use collections in resultMaps then cursor SQL queries
2321
* must be ordered (resultOrdered="true") using the id columns of the resultMap.
2422
*
2523
* @author Guillaume Darmont / [email protected]
2624
*/
27-
public interface Cursor<T> extends Closeable, Iterable<T> {
25+
public interface Cursor<T> extends AutoCloseable, Iterable<T> {
2826

2927
/**
3028
* @return true if the cursor has started to fetch items from database.
@@ -42,4 +40,10 @@ public interface Cursor<T> extends Closeable, Iterable<T> {
4240
* @return -1 if the first cursor item has not been retrieved. The index of the current item retrieved.
4341
*/
4442
int getCurrentIndex();
43+
44+
/**
45+
* Closes the cursor.
46+
*/
47+
@Override
48+
void close();
4549
}

src/main/java/org/apache/ibatis/executor/loader/ResultLoaderMap.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2024 the original author or authors.
2+
* Copyright 2009-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -235,7 +235,7 @@ private Configuration getConfiguration() {
235235
+ FACTORY_METHOD + "] is not static.");
236236
}
237237

238-
if (!factoryMethod.isAccessible()) {
238+
if (!factoryMethod.canAccess(null)) {
239239
configurationObject = AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () -> {
240240
try {
241241
factoryMethod.setAccessible(true);

src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -247,34 +247,49 @@ public <E> Cursor<E> handleCursorResultSets(Statement stmt) throws SQLException
247247
}
248248

249249
private ResultSetWrapper getFirstResultSet(Statement stmt) throws SQLException {
250-
ResultSet rs = stmt.getResultSet();
251-
while (rs == null) {
252-
// move forward to get the first resultset in case the driver
253-
// doesn't return the resultset as the first result (HSQLDB)
254-
if (stmt.getMoreResults()) {
255-
rs = stmt.getResultSet();
256-
} else if (stmt.getUpdateCount() == -1) {
257-
// no more results. Must be no resultset
258-
break;
250+
ResultSet rs = null;
251+
SQLException e1 = null;
252+
253+
try {
254+
rs = stmt.getResultSet();
255+
} catch (SQLException e) {
256+
// Oracle throws ORA-17283 for implicit cursor
257+
e1 = e;
258+
}
259+
260+
try {
261+
while (rs == null) {
262+
// move forward to get the first resultset in case the driver
263+
// doesn't return the resultset as the first result (HSQLDB)
264+
if (stmt.getMoreResults()) {
265+
rs = stmt.getResultSet();
266+
} else if (stmt.getUpdateCount() == -1) {
267+
// no more results. Must be no resultset
268+
break;
269+
}
259270
}
271+
} catch (SQLException e) {
272+
throw e1 != null ? e1 : e;
260273
}
274+
261275
return rs != null ? new ResultSetWrapper(rs, configuration) : null;
262276
}
263277

264278
private ResultSetWrapper getNextResultSet(Statement stmt) {
265279
// Making this method tolerant of bad JDBC drivers
266280
try {
267-
if (stmt.getConnection().getMetaData().supportsMultipleResultSets()) {
268-
// Crazy Standard JDBC way of determining if there are more results
269-
// DO NOT try to 'improve' the condition even if IDE tells you to!
270-
// It's important that getUpdateCount() is called here.
271-
if (!(!stmt.getMoreResults() && stmt.getUpdateCount() == -1)) {
272-
ResultSet rs = stmt.getResultSet();
273-
if (rs == null) {
274-
return getNextResultSet(stmt);
275-
} else {
276-
return new ResultSetWrapper(rs, configuration);
277-
}
281+
// We stopped checking DatabaseMetaData#supportsMultipleResultSets()
282+
// because Oracle driver (incorrectly) returns false
283+
284+
// Crazy Standard JDBC way of determining if there are more results
285+
// DO NOT try to 'improve' the condition even if IDE tells you to!
286+
// It's important that getUpdateCount() is called here.
287+
if (!(!stmt.getMoreResults() && stmt.getUpdateCount() == -1)) {
288+
ResultSet rs = stmt.getResultSet();
289+
if (rs == null) {
290+
return getNextResultSet(stmt);
291+
} else {
292+
return new ResultSetWrapper(rs, configuration);
278293
}
279294
}
280295
} catch (Exception e) {

src/main/java/org/apache/ibatis/mapping/ResultMap.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2024 the original author or authors.
2+
* Copyright 2009-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -116,7 +116,7 @@ public ResultMap build() {
116116
// #101
117117
Class<?> javaType = resultMapping.getJavaType();
118118
resultMap.hasResultMapsUsingConstructorCollection = resultMap.hasResultMapsUsingConstructorCollection
119-
|| (resultMapping.getNestedQueryId() == null && javaType != null
119+
|| (resultMapping.getNestedQueryId() == null && resultMapping.getTypeHandler() == null && javaType != null
120120
&& resultMap.configuration.getObjectFactory().isCollection(javaType));
121121

122122
if (resultMapping.getProperty() != null) {

0 commit comments

Comments
 (0)