Skip to content

Commit 5a11f0d

Browse files
committed
Merge master into arg-name-based-constructor-automapping
2 parents f81a3f5 + b72067b commit 5a11f0d

File tree

27 files changed

+366
-26
lines changed

27 files changed

+366
-26
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
strategy:
2525
matrix:
2626
os: [ubuntu-latest, macOS-latest, windows-latest]
27-
java: [8, 11, 17, 18-ea, 19-ea]
27+
java: [8, 11, 17, 18, 19-ea]
2828
distribution: ['zulu']
2929
fail-fast: false
3030
max-parallel: 4

pom.xml

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@
166166
<dependency>
167167
<groupId>ch.qos.reload4j</groupId>
168168
<artifactId>reload4j</artifactId>
169-
<version>1.2.19</version>
169+
<version>1.2.20</version>
170170
<optional>true</optional>
171171
</dependency>
172172
<dependency>
@@ -210,7 +210,7 @@
210210
<dependency>
211211
<groupId>com.h2database</groupId>
212212
<artifactId>h2</artifactId>
213-
<version>2.1.210</version>
213+
<version>2.1.212</version>
214214
<scope>test</scope>
215215
</dependency>
216216
<dependency>
@@ -259,19 +259,19 @@
259259
<dependency>
260260
<groupId>org.testcontainers</groupId>
261261
<artifactId>junit-jupiter</artifactId>
262-
<version>1.16.3</version>
262+
<version>1.17.0</version>
263263
<scope>test</scope>
264264
</dependency>
265265
<dependency>
266266
<groupId>org.testcontainers</groupId>
267267
<artifactId>postgresql</artifactId>
268-
<version>1.16.3</version>
268+
<version>1.17.0</version>
269269
<scope>test</scope>
270270
</dependency>
271271
<dependency>
272272
<groupId>org.testcontainers</groupId>
273273
<artifactId>mysql</artifactId>
274-
<version>1.16.3</version>
274+
<version>1.17.0</version>
275275
<scope>test</scope>
276276
</dependency>
277277
<!-- For javadoc link -->
@@ -374,6 +374,16 @@
374374
</excludes>
375375
</configuration>
376376
</plugin>
377+
<plugin>
378+
<groupId>org.codehaus.mojo</groupId>
379+
<artifactId>animal-sniffer-maven-plugin</artifactId>
380+
<configuration>
381+
<ignores>
382+
<!-- https://github.com/mojohaus/animal-sniffer/issues/67 -->
383+
<ignore>java.lang.invoke.MethodHandle</ignore>
384+
</ignores>
385+
</configuration>
386+
</plugin>
377387
</plugins>
378388

379389
<resources>
@@ -415,6 +425,38 @@
415425
<excludedGroups />
416426
</properties>
417427
</profile>
428+
<profile>
429+
<id>pre16</id>
430+
<activation>
431+
<jdk>(,16)</jdk>
432+
</activation>
433+
<build>
434+
<pluginManagement>
435+
<plugins>
436+
<plugin>
437+
<groupId>org.apache.maven.plugins</groupId>
438+
<artifactId>maven-compiler-plugin</artifactId>
439+
<configuration>
440+
<testExcludes>
441+
<testExclude>**/record_type/*.java</testExclude>
442+
</testExcludes>
443+
</configuration>
444+
</plugin>
445+
</plugins>
446+
</pluginManagement>
447+
</build>
448+
</profile>
449+
<profile>
450+
<id>16</id>
451+
<activation>
452+
<jdk>[16,)</jdk>
453+
</activation>
454+
<properties>
455+
<maven.compiler.testTarget>16</maven.compiler.testTarget>
456+
<maven.compiler.testSource>16</maven.compiler.testSource>
457+
<excludedGroups>TestcontainersTests,RequireIllegalAccess</excludedGroups>
458+
</properties>
459+
</profile>
418460
</profiles>
419461

420462
</project>

src/main/java/org/apache/ibatis/cache/decorators/BlockingCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public Object getObject(Object key) {
7676

7777
@Override
7878
public Object removeObject(Object key) {
79-
// despite of its name, this method is called only to release locks
79+
// despite its name, this method is called only to release locks
8080
releaseLock(key);
8181
return null;
8282
}

src/main/java/org/apache/ibatis/datasource/pooled/PooledDataSource.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,8 @@ private PooledConnection popConnection(String username, String password) throws
479479
state.wait(poolTimeToWait);
480480
state.accumulatedWaitTime += System.currentTimeMillis() - wt;
481481
} catch (InterruptedException e) {
482+
// set interrupt flag
483+
Thread.currentThread().interrupt();
482484
break;
483485
}
484486
}

src/main/java/org/apache/ibatis/executor/loader/cglib/CglibProxyFactory.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141

4242
/**
4343
* @author Clinton Begin
44+
* @deprecated Since 3.5.10, use Javassist instead.
4445
*/
46+
@Deprecated
4547
public class CglibProxyFactory implements ProxyFactory {
4648

4749
private static final String FINALIZE_METHOD = "finalize";
@@ -65,6 +67,7 @@ public Object createDeserializationProxy(Object target, Map<String, ResultLoader
6567
}
6668

6769
static Object crateProxy(Class<?> type, Callback callback, List<Class<?>> constructorArgTypes, List<Object> constructorArgs) {
70+
LogHolder.log.warn("CglibProxyFactory is deprecated. Use another proxy factory implementation.");
6871
Enhancer enhancer = new Enhancer();
6972
enhancer.setCallback(callback);
7073
enhancer.setSuperclass(type);

src/main/java/org/apache/ibatis/executor/loader/cglib/CglibSerialStateHolder.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424

2525
/**
2626
* @author Eduardo Macarron
27+
* @deprecated Since 3.5.10, use Javassist instead.
2728
*/
29+
@Deprecated
2830
class CglibSerialStateHolder extends AbstractSerialStateHolder {
2931

3032
private static final long serialVersionUID = 8940388717901644661L;

src/main/java/org/apache/ibatis/jdbc/SqlBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*
2121
* @author Jeff Butler
2222
*/
23+
@Deprecated
2324
public class SqlBuilder {
2425

2526
private static final ThreadLocal<SQL> localSQL = new ThreadLocal<>();

src/main/java/org/apache/ibatis/reflection/Reflector.java

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2009-2021 the original author or authors.
2+
* Copyright 2009-2022 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,6 +15,9 @@
1515
*/
1616
package org.apache.ibatis.reflection;
1717

18+
import java.lang.invoke.MethodHandle;
19+
import java.lang.invoke.MethodHandles;
20+
import java.lang.invoke.MethodType;
1821
import java.lang.reflect.Array;
1922
import java.lang.reflect.Constructor;
2023
import java.lang.reflect.Field;
@@ -50,6 +53,7 @@
5053
*/
5154
public class Reflector {
5255

56+
private static final MethodHandle isRecordMethodHandle = getIsRecordMethodHandle();
5357
private final Class<?> type;
5458
private final String[] readablePropertyNames;
5559
private final String[] writablePropertyNames;
@@ -65,9 +69,13 @@ public Reflector(Class<?> clazz) {
6569
type = clazz;
6670
addDefaultConstructor(clazz);
6771
Method[] classMethods = getClassMethods(clazz);
68-
addGetMethods(classMethods);
69-
addSetMethods(classMethods);
70-
addFields(clazz);
72+
if (isRecord(type)) {
73+
addRecordGetMethods(classMethods);
74+
} else {
75+
addGetMethods(classMethods);
76+
addSetMethods(classMethods);
77+
addFields(clazz);
78+
}
7179
readablePropertyNames = getMethods.keySet().toArray(new String[0]);
7280
writablePropertyNames = setMethods.keySet().toArray(new String[0]);
7381
for (String propName : readablePropertyNames) {
@@ -78,6 +86,11 @@ public Reflector(Class<?> clazz) {
7886
}
7987
}
8088

89+
private void addRecordGetMethods(Method[] methods) {
90+
Arrays.stream(methods).filter(m -> m.getParameterTypes().length == 0)
91+
.forEach(m -> addGetMethod(m.getName(), m, false));
92+
}
93+
8194
private void addDefaultConstructor(Class<?> clazz) {
8295
Constructor<?>[] constructors = clazz.getDeclaredConstructors();
8396
Arrays.stream(constructors).filter(constructor -> constructor.getParameterTypes().length == 0)
@@ -445,4 +458,25 @@ public boolean hasGetter(String propertyName) {
445458
public String findPropertyName(String name) {
446459
return caseInsensitivePropertyMap.get(name.toUpperCase(Locale.ENGLISH));
447460
}
461+
462+
/**
463+
* Class.isRecord() alternative for Java 15 and older.
464+
*/
465+
private static boolean isRecord(Class<?> clazz) {
466+
try {
467+
return isRecordMethodHandle != null && (boolean)isRecordMethodHandle.invokeExact(clazz);
468+
} catch (Throwable e) {
469+
throw new ReflectionException("Failed to invoke 'Class.isRecord()'.", e);
470+
}
471+
}
472+
473+
private static MethodHandle getIsRecordMethodHandle() {
474+
MethodHandles.Lookup lookup = MethodHandles.lookup();
475+
MethodType mt = MethodType.methodType(boolean.class);
476+
try {
477+
return lookup.findVirtual(Class.class, "isRecord", mt);
478+
} catch (NoSuchMethodException | IllegalAccessException e) {
479+
return null;
480+
}
481+
}
448482
}

src/site/es/xdoc/configuration.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, environ
496496
Permite especificar qué herramienta de generación de proxys se usará para crear los objetos con capacidad de carga lazy.
497497
</td>
498498
<td>
499-
CGLIB | JAVASSIST
499+
CGLIB (deprecated since 3.5.10) | JAVASSIST
500500
</td>
501501
<td>
502502
JAVASSIST (MyBatis 3.3 or above)

src/site/es/xdoc/dynamic-sql.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ AND title like ‘someTitle’]]></source>
136136
where id=#{id}
137137
</update>]]></source>
138138
<p>En este caso, el elemento set prefijará dinámicamente el valor SET y además eliminará todas las comas sobrantes que pudieran quedar tras las asignaciones de valor después de que se hayan aplicado las condiciones.</p>
139-
<p>Si tienes curiosidad de qué aspecto tendría el elemento trim equivalente, aquí lo tienes:</p>
139+
<p>Alternativamente, puede utilizar el elemento <em>trim</em> para obtener el mismo efecto:</p>
140140
<source><![CDATA[<trim prefix="SET" suffixOverrides=",">
141141
...
142142
</trim>]]></source>

0 commit comments

Comments
 (0)