Skip to content

Commit be53709

Browse files
committed
Merge branch 'master' into pr/3108
# Conflicts: # pom.xml
2 parents 462d890 + 266542a commit be53709

File tree

13 files changed

+561
-117
lines changed

13 files changed

+561
-117
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
matrix:
1010
cache: [maven]
1111
distribution: [temurin]
12-
java: [17, 21, 22, 23-ea, 24-ea]
12+
java: [17, 21, 23, 24-ea, 25-ea]
1313
os: [ubuntu-latest, macos-latest, windows-latest]
1414
fail-fast: false
1515
max-parallel: 4

pom.xml

Lines changed: 24 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
1818
-->
1919
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
2021
<modelVersion>4.0.0</modelVersion>
2122

2223
<parent>
2324
<groupId>org.mybatis</groupId>
2425
<artifactId>mybatis-parent</artifactId>
25-
<version>46</version>
26+
<version>48</version>
2627
<relativePath />
2728
</parent>
2829

@@ -39,77 +40,6 @@
3940

4041
<inceptionYear>2009</inceptionYear>
4142

42-
<contributors>
43-
<contributor>
44-
<name>Adam Gent</name>
45-
<email>[email protected]</email>
46-
</contributor>
47-
<contributor>
48-
<name>Andrea Selva</name>
49-
<email>[email protected]</email>
50-
</contributor>
51-
<contributor>
52-
<name>Antonio Sánchez</name>
53-
<email>[email protected]</email>
54-
</contributor>
55-
<contributor>
56-
<name>Arkadi Shishlov</name>
57-
<email>[email protected]</email>
58-
</contributor>
59-
<contributor>
60-
<name>Axel Doerfler</name>
61-
<email>[email protected]</email>
62-
</contributor>
63-
<contributor>
64-
<name>Chris Dadej</name>
65-
<email>[email protected]</email>
66-
</contributor>
67-
<contributor>
68-
<name>Denis Vygovskiy</name>
69-
<email>[email protected]</email>
70-
</contributor>
71-
<contributor>
72-
<name>Franta Mejta</name>
73-
<email>[email protected]</email>
74-
</contributor>
75-
<contributor>
76-
<name>Jurriaan Pruys</name>
77-
<email>[email protected]</email>
78-
</contributor>
79-
<contributor>
80-
<name>Keith Wong</name>
81-
<email>[email protected]</email>
82-
</contributor>
83-
<contributor>
84-
<name>Lasse Voss</name>
85-
<email>[email protected]</email>
86-
</contributor>
87-
<contributor>
88-
<name>Luke Stevens</name>
89-
<email>[email protected]</email>
90-
</contributor>
91-
<contributor>
92-
<name>Paul Krause</name>
93-
<email>[email protected]</email>
94-
</contributor>
95-
<contributor>
96-
<name>Peter Leibiger</name>
97-
<email>[email protected]</email>
98-
</contributor>
99-
<contributor>
100-
<name>Riccardo Cossu</name>
101-
<email>[email protected]</email>
102-
</contributor>
103-
<contributor>
104-
<name>Tomáš Neuberg</name>
105-
<email>[email protected]</email>
106-
</contributor>
107-
<contributor>
108-
<name>Willie Scholtz</name>
109-
<email>[email protected]</email>
110-
</contributor>
111-
</contributors>
112-
11343
<scm>
11444
<connection>scm:git:ssh://[email protected]/mybatis/mybatis-3.git</connection>
11545
<developerConnection>scm:git:ssh://[email protected]/mybatis/mybatis-3.git</developerConnection>
@@ -133,6 +63,13 @@
13363
</distributionManagement>
13464

13565
<properties>
66+
<!-- Java Usage -->
67+
<java.version>8</java.version>
68+
<java.release.version>8</java.release.version>
69+
70+
<!-- Override impsort comliance to 17 (remove after parent 49 release) -->
71+
<impsort.compliance>17</impsort.compliance>
72+
13673
<clirr.comparisonVersion>3.4.6</clirr.comparisonVersion>
13774

13875
<byte-buddy.version>1.15.11</byte-buddy.version>
@@ -168,7 +105,7 @@
168105
<dependency>
169106
<groupId>ognl</groupId>
170107
<artifactId>ognl</artifactId>
171-
<version>3.4.3</version>
108+
<version>3.4.4</version>
172109
<scope>compile</scope>
173110
<optional>true</optional>
174111
</dependency>
@@ -459,55 +396,31 @@
459396
</excludes>
460397
</configuration>
461398
</plugin>
399+
400+
<!-- Remove enforcer entirely after parent 49 release -->
401+
<plugin>
402+
<groupId>org.apache.maven.plugins</groupId>
403+
<artifactId>maven-enforcer-plugin</artifactId>
404+
<configuration>
405+
<rules>
406+
<enforceBytecodeVersion>
407+
<maxJdkVersion>${java.version}</maxJdkVersion>
408+
<ignoredScopes>provided,test</ignoredScopes>
409+
</enforceBytecodeVersion>
410+
</rules>
411+
</configuration>
412+
</plugin>
462413
</plugins>
463414
</build>
464415

465416
<profiles>
466-
<profile>
467-
<id>pre16</id>
468-
<activation>
469-
<jdk>(,16)</jdk>
470-
</activation>
471-
<properties>
472-
<derby.version>10.15.2.0</derby.version>
473-
<mssql-jdbc.version>12.4.2.jre8</mssql-jdbc.version>
474-
</properties>
475-
<build>
476-
<pluginManagement>
477-
<plugins>
478-
<plugin>
479-
<groupId>org.apache.maven.plugins</groupId>
480-
<artifactId>maven-compiler-plugin</artifactId>
481-
<configuration>
482-
<testExcludes>
483-
<testExclude>**/record_type/*.java</testExclude>
484-
</testExcludes>
485-
</configuration>
486-
</plugin>
487-
<plugin>
488-
<groupId>net.revelc.code</groupId>
489-
<artifactId>impsort-maven-plugin</artifactId>
490-
<configuration>
491-
<skip>true</skip>
492-
</configuration>
493-
</plugin>
494-
</plugins>
495-
</pluginManagement>
496-
</build>
497-
</profile>
498417
<profile>
499418
<id>16</id>
500419
<activation>
501420
<jdk>[16,)</jdk>
502421
</activation>
503422
<properties>
504-
<derby.version>10.15.2.0</derby.version>
505-
<java.version>16</java.version>
506-
<java.release.version>16</java.release.version>
507-
<java.test.version>16</java.test.version>
508-
<java.test.release.version>16</java.test.release.version>
509423
<excludedGroups>TestcontainersTests,RequireIllegalAccess</excludedGroups>
510-
<allowed.build.jdks>[11,12),[17,18),[21,22),[22,23),[23,24),[24,25)</allowed.build.jdks>
511424
</properties>
512425
</profile>
513426
<profile>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,13 @@ private Object applyConstructorAutomapping(ResultSetWrapper rsw, ResultMap resul
842842
private boolean applyColumnOrderBasedConstructorAutomapping(ResultSetWrapper rsw, List<Class<?>> constructorArgTypes,
843843
List<Object> constructorArgs, Constructor<?> constructor, boolean foundValues) throws SQLException {
844844
Class<?>[] parameterTypes = constructor.getParameterTypes();
845+
846+
if (parameterTypes.length > rsw.getClassNames().size()) {
847+
throw new ExecutorException(MessageFormat.format(
848+
"Constructor auto-mapping of ''{0}'' failed. The constructor takes ''{1}'' arguments, but there are only ''{2}'' columns in the result set.",
849+
constructor, parameterTypes.length, rsw.getClassNames().size()));
850+
}
851+
845852
for (int i = 0; i < parameterTypes.length; i++) {
846853
Class<?> parameterType = parameterTypes[i];
847854
String columnName = rsw.getColumnNames().get(i);

src/main/java/org/apache/ibatis/type/DateOnlyTypeHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ public void setNonNullParameter(PreparedStatement ps, int i, Date parameter, Jdb
3333

3434
@Override
3535
public Date getNullableResult(ResultSet rs, String columnName) throws SQLException {
36-
return toSqlDate(rs.getDate(columnName));
36+
return toDate(rs.getDate(columnName));
3737
}
3838

3939
@Override
4040
public Date getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
41-
return toSqlDate(rs.getDate(columnIndex));
41+
return toDate(rs.getDate(columnIndex));
4242
}
4343

4444
@Override
4545
public Date getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
46-
return toSqlDate(cs.getDate(columnIndex));
46+
return toDate(cs.getDate(columnIndex));
4747
}
4848

49-
private java.sql.Date toSqlDate(Date date) {
50-
return date == null ? null : new java.sql.Date(date.getTime());
49+
private Date toDate(java.sql.Date date) {
50+
return date == null ? null : new Date(date.getTime());
5151
}
5252

5353
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright 2009-2024 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+
* https://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 org.apache.ibatis.submitted.column_order_based_constructor_automapping;
17+
18+
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertNotNull;
20+
import static org.junit.jupiter.api.Assertions.assertNull;
21+
import static org.junit.jupiter.api.Assertions.assertThrows;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
23+
24+
import java.io.Reader;
25+
import java.text.MessageFormat;
26+
import java.util.List;
27+
28+
import org.apache.ibatis.BaseDataTest;
29+
import org.apache.ibatis.exceptions.PersistenceException;
30+
import org.apache.ibatis.io.Resources;
31+
import org.apache.ibatis.session.SqlSession;
32+
import org.apache.ibatis.session.SqlSessionFactory;
33+
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
34+
import org.junit.jupiter.api.BeforeAll;
35+
import org.junit.jupiter.api.Test;
36+
37+
class ColumnOrderBasedConstructorAutomappingTest {
38+
39+
private static SqlSessionFactory sqlSessionFactory;
40+
41+
@BeforeAll
42+
static void setUp() throws Exception {
43+
// create an SqlSessionFactory
44+
try (Reader reader = Resources.getResourceAsReader(
45+
"org/apache/ibatis/submitted/column_order_based_constructor_automapping/mybatis-config.xml")) {
46+
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
47+
sqlSessionFactory.getConfiguration().setArgNameBasedConstructorAutoMapping(false);
48+
}
49+
50+
// populate in-memory database
51+
BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
52+
"org/apache/ibatis/submitted/column_order_based_constructor_automapping/CreateDB.sql");
53+
}
54+
55+
@Test
56+
void shouldHandleNoArgsConstructor() {
57+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
58+
Mapper mapper = sqlSession.getMapper(Mapper.class);
59+
List<UserNoArgsConstructor> userList = mapper.finaAllByNoArgsConstructor();
60+
61+
assertEquals(2, userList.size());
62+
UserNoArgsConstructor user1 = userList.get(0);
63+
UserNoArgsConstructor user2 = userList.get(1);
64+
65+
assertEquals(1, user1.getId());
66+
assertEquals("Tom", user1.getName());
67+
assertEquals(7, user1.getAge());
68+
assertNull(user1.getEmail());
69+
70+
assertEquals(2, user2.getId());
71+
assertEquals("Cat", user2.getName());
72+
assertEquals(3, user2.getAge());
73+
assertNull(user2.getEmail());
74+
}
75+
}
76+
77+
@Test
78+
void shouldHandleConstructorEqualsResultSet() {
79+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
80+
Mapper mapper = sqlSession.getMapper(Mapper.class);
81+
List<UserConstructorEqualsResultSet> userList = mapper.finaAllByConstructorEqualsResultSet();
82+
83+
assertEquals(2, userList.size());
84+
UserConstructorEqualsResultSet user1 = userList.get(0);
85+
UserConstructorEqualsResultSet user2 = userList.get(1);
86+
87+
assertEquals(1, user1.getId());
88+
assertEquals("Tom", user1.getName());
89+
assertEquals(7, user1.getAge());
90+
assertNull(user1.getEmail());
91+
92+
assertEquals(2, user2.getId());
93+
assertEquals("Cat", user2.getName());
94+
assertEquals(3, user2.getAge());
95+
assertNull(user2.getEmail());
96+
}
97+
}
98+
99+
@Test
100+
void shouldHandleConstructorLessThanResultSet() {
101+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
102+
Mapper mapper = sqlSession.getMapper(Mapper.class);
103+
List<UserConstructorLessThanResultSet> userList = mapper.finaAllByConstructorLessThanResultSet();
104+
105+
assertEquals(2, userList.size());
106+
UserConstructorLessThanResultSet user1 = userList.get(0);
107+
UserConstructorLessThanResultSet user2 = userList.get(1);
108+
109+
assertEquals(1, user1.getId());
110+
assertEquals("Tom", user1.getName());
111+
assertEquals(7, user1.getAge());
112+
assertNull(user1.getEmail());
113+
114+
assertEquals(2, user2.getId());
115+
assertEquals("Cat", user2.getName());
116+
assertEquals(3, user2.getAge());
117+
assertNull(user2.getEmail());
118+
}
119+
}
120+
121+
@Test
122+
void shouldNotHandleConstructorGreaterThanResultSet() {
123+
try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
124+
Mapper mapper = sqlSession.getMapper(Mapper.class);
125+
126+
PersistenceException persistenceException = assertThrows(PersistenceException.class,
127+
mapper::finaAllByConstructorGreaterThanResultSet);
128+
assertNotNull(persistenceException);
129+
String message = persistenceException.getMessage();
130+
assertNotNull(message);
131+
assertTrue(message.contains(MessageFormat.format(
132+
"Constructor auto-mapping of ''{0}'' failed. The constructor takes ''{1}'' arguments, but there are only ''{2}'' columns in the result set.",
133+
UserConstructorGreaterThanResultSet.class.getConstructors()[0], 4, 3)));
134+
}
135+
}
136+
}

0 commit comments

Comments
 (0)