From 77606300fc897642b04cb55f90045a178e9fbbf1 Mon Sep 17 00:00:00 2001 From: Iwao AVE! Date: Wed, 1 Jan 2025 15:45:04 +0900 Subject: [PATCH 1/5] Remove MapUtil We no longer support Java 8. --- src/main/java/org/apache/ibatis/binding/MapperProxy.java | 3 +-- .../apache/ibatis/cache/TransactionalCacheManager.java | 3 +-- .../ibatis/datasource/unpooled/UnpooledDataSource.java | 3 +-- .../apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java | 9 ++++----- .../executor/resultset/DefaultResultSetHandler.java | 5 ++--- src/main/java/org/apache/ibatis/plugin/Plugin.java | 3 +-- .../ibatis/reflection/DefaultReflectorFactory.java | 4 +--- .../java/org/apache/ibatis/reflection/Reflector.java | 3 +-- .../apache/ibatis/scripting/LanguageDriverRegistry.java | 4 +--- 9 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/apache/ibatis/binding/MapperProxy.java b/src/main/java/org/apache/ibatis/binding/MapperProxy.java index 80c774da23a..901929d4ece 100644 --- a/src/main/java/org/apache/ibatis/binding/MapperProxy.java +++ b/src/main/java/org/apache/ibatis/binding/MapperProxy.java @@ -28,7 +28,6 @@ import org.apache.ibatis.reflection.ExceptionUtil; import org.apache.ibatis.session.SqlSession; -import org.apache.ibatis.util.MapUtil; /** * @author Clinton Begin @@ -91,7 +90,7 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl private MapperMethodInvoker cachedInvoker(Method method) throws Throwable { try { - return MapUtil.computeIfAbsent(methodCache, method, m -> { + return methodCache.computeIfAbsent(method, m -> { if (!m.isDefault()) { return new PlainMethodInvoker(new MapperMethod(mapperInterface, method, sqlSession.getConfiguration())); } diff --git a/src/main/java/org/apache/ibatis/cache/TransactionalCacheManager.java b/src/main/java/org/apache/ibatis/cache/TransactionalCacheManager.java index 88cae573c2e..618a87e4a91 100644 --- a/src/main/java/org/apache/ibatis/cache/TransactionalCacheManager.java +++ b/src/main/java/org/apache/ibatis/cache/TransactionalCacheManager.java @@ -19,7 +19,6 @@ import java.util.Map; import org.apache.ibatis.cache.decorators.TransactionalCache; -import org.apache.ibatis.util.MapUtil; /** * @author Clinton Begin @@ -53,7 +52,7 @@ public void rollback() { } private TransactionalCache getTransactionalCache(Cache cache) { - return MapUtil.computeIfAbsent(transactionalCaches, cache, TransactionalCache::new); + return transactionalCaches.computeIfAbsent(cache, TransactionalCache::new); } } diff --git a/src/main/java/org/apache/ibatis/datasource/unpooled/UnpooledDataSource.java b/src/main/java/org/apache/ibatis/datasource/unpooled/UnpooledDataSource.java index 1b5c769d7c6..c22a95b589a 100644 --- a/src/main/java/org/apache/ibatis/datasource/unpooled/UnpooledDataSource.java +++ b/src/main/java/org/apache/ibatis/datasource/unpooled/UnpooledDataSource.java @@ -31,7 +31,6 @@ import javax.sql.DataSource; import org.apache.ibatis.io.Resources; -import org.apache.ibatis.util.MapUtil; /** * @author Clinton Begin @@ -233,7 +232,7 @@ private Connection doGetConnection(Properties properties) throws SQLException { private void initializeDriver() throws SQLException { try { - MapUtil.computeIfAbsent(registeredDrivers, driver, x -> { + registeredDrivers.computeIfAbsent(driver, x -> { Class driverType; try { if (driverClassLoader != null) { diff --git a/src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java b/src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java index fad23476cfb..d2d04562dcf 100644 --- a/src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java +++ b/src/main/java/org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java @@ -41,7 +41,6 @@ import org.apache.ibatis.type.JdbcType; import org.apache.ibatis.type.TypeHandler; import org.apache.ibatis.type.TypeHandlerRegistry; -import org.apache.ibatis.util.MapUtil; /** * @author Clinton Begin @@ -156,8 +155,8 @@ private void assignKeysToParamMap(Configuration configuration, ResultSet rs, Res for (int i = 0; i < keyProperties.length; i++) { Entry entry = getAssignerForParamMap(configuration, rsmd, i + 1, paramMap, keyProperties[i], keyProperties, true); - Entry, List> iteratorPair = MapUtil.computeIfAbsent(assignerMap, entry.getKey(), - k -> MapUtil.entry(collectionize(paramMap.get(k)).iterator(), new ArrayList<>())); + Entry, List> iteratorPair = assignerMap.computeIfAbsent(entry.getKey(), + k -> Map.entry(collectionize(paramMap.get(k)).iterator(), new ArrayList<>())); iteratorPair.getValue().add(entry.getValue()); } long counter = 0; @@ -193,7 +192,7 @@ private Entry getAssignerForParamMap(Configuration config, if (keySet.contains(paramName)) { String argParamName = omitParamName ? null : paramName; String argKeyProperty = keyProperty.substring(firstDot + 1); - return MapUtil.entry(paramName, new KeyAssigner(config, rsmd, columnPosition, argParamName, argKeyProperty)); + return Map.entry(paramName, new KeyAssigner(config, rsmd, columnPosition, argParamName, argKeyProperty)); } if (singleParam) { return getAssignerForSingleParam(config, rsmd, columnPosition, paramMap, keyProperty, omitParamName); @@ -210,7 +209,7 @@ private Entry getAssignerForSingleParam(Configuration confi // Assume 'keyProperty' to be a property of the single param. String singleParamName = nameOfSingleParam(paramMap); String argParamName = omitParamName ? null : singleParamName; - return MapUtil.entry(singleParamName, new KeyAssigner(config, rsmd, columnPosition, argParamName, keyProperty)); + return Map.entry(singleParamName, new KeyAssigner(config, rsmd, columnPosition, argParamName, keyProperty)); } private static String nameOfSingleParam(Map paramMap) { diff --git a/src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java b/src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java index c089302a254..167bc41579f 100644 --- a/src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java +++ b/src/main/java/org/apache/ibatis/executor/resultset/DefaultResultSetHandler.java @@ -66,7 +66,6 @@ import org.apache.ibatis.type.JdbcType; import org.apache.ibatis.type.TypeHandler; import org.apache.ibatis.type.TypeHandlerRegistry; -import org.apache.ibatis.util.MapUtil; /** * @author Clinton Begin @@ -618,7 +617,7 @@ private void addPendingChildRelation(ResultSet rs, MetaObject metaResultObject, PendingRelation deferLoad = new PendingRelation(); deferLoad.metaObject = metaResultObject; deferLoad.propertyMapping = parentMapping; - List relations = MapUtil.computeIfAbsent(pendingRelations, cacheKey, k -> new ArrayList<>()); + List relations = pendingRelations.computeIfAbsent(cacheKey, k -> new ArrayList<>()); // issue #255 relations.add(deferLoad); ResultMapping previous = nextResultMaps.get(parentMapping.getResultSet()); @@ -820,7 +819,7 @@ private boolean applyArgNameBasedConstructorAutoMapping(ResultSetWrapper rsw, Re constructorArgs.add(value); final String mapKey = resultMap.getId() + ":" + columnPrefix; if (!autoMappingsCache.containsKey(mapKey)) { - MapUtil.computeIfAbsent(constructorAutoMappingColumns, mapKey, k -> new ArrayList<>()).add(columnName); + constructorAutoMappingColumns.computeIfAbsent(mapKey, k -> new ArrayList<>()).add(columnName); } columnNotFound = false; foundValues = value != null || foundValues; diff --git a/src/main/java/org/apache/ibatis/plugin/Plugin.java b/src/main/java/org/apache/ibatis/plugin/Plugin.java index e4f829221ed..ce0ad659897 100644 --- a/src/main/java/org/apache/ibatis/plugin/Plugin.java +++ b/src/main/java/org/apache/ibatis/plugin/Plugin.java @@ -24,7 +24,6 @@ import java.util.Set; import org.apache.ibatis.reflection.ExceptionUtil; -import org.apache.ibatis.util.MapUtil; /** * @author Clinton Begin @@ -74,7 +73,7 @@ private static Map, Set> getSignatureMap(Interceptor intercepto Signature[] sigs = interceptsAnnotation.value(); Map, Set> signatureMap = new HashMap<>(); for (Signature sig : sigs) { - Set methods = MapUtil.computeIfAbsent(signatureMap, sig.type(), k -> new HashSet<>()); + Set methods = signatureMap.computeIfAbsent(sig.type(), k -> new HashSet<>()); try { Method method = sig.type().getMethod(sig.method(), sig.args()); methods.add(method); diff --git a/src/main/java/org/apache/ibatis/reflection/DefaultReflectorFactory.java b/src/main/java/org/apache/ibatis/reflection/DefaultReflectorFactory.java index eff6c7f896c..d78e89b8fd1 100644 --- a/src/main/java/org/apache/ibatis/reflection/DefaultReflectorFactory.java +++ b/src/main/java/org/apache/ibatis/reflection/DefaultReflectorFactory.java @@ -18,8 +18,6 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -import org.apache.ibatis.util.MapUtil; - public class DefaultReflectorFactory implements ReflectorFactory { private boolean classCacheEnabled = true; private final ConcurrentMap, Reflector> reflectorMap = new ConcurrentHashMap<>(); @@ -41,7 +39,7 @@ public void setClassCacheEnabled(boolean classCacheEnabled) { public Reflector findForClass(Class type) { if (classCacheEnabled) { // synchronized (type) removed see issue #461 - return MapUtil.computeIfAbsent(reflectorMap, type, Reflector::new); + return reflectorMap.computeIfAbsent(type, Reflector::new); } return new Reflector(type); } diff --git a/src/main/java/org/apache/ibatis/reflection/Reflector.java b/src/main/java/org/apache/ibatis/reflection/Reflector.java index 7ae50d0e0d5..d294afd1b5b 100644 --- a/src/main/java/org/apache/ibatis/reflection/Reflector.java +++ b/src/main/java/org/apache/ibatis/reflection/Reflector.java @@ -43,7 +43,6 @@ import org.apache.ibatis.reflection.invoker.MethodInvoker; import org.apache.ibatis.reflection.invoker.SetFieldInvoker; import org.apache.ibatis.reflection.property.PropertyNamer; -import org.apache.ibatis.util.MapUtil; /** * This class represents a cached set of class definition information that allows for easy mapping between property @@ -155,7 +154,7 @@ private void addSetMethods(Method[] methods) { private void addMethodConflict(Map> conflictingMethods, String name, Method method) { if (isValidPropertyName(name)) { - List list = MapUtil.computeIfAbsent(conflictingMethods, name, k -> new ArrayList<>()); + List list = conflictingMethods.computeIfAbsent(name, k -> new ArrayList<>()); list.add(method); } } diff --git a/src/main/java/org/apache/ibatis/scripting/LanguageDriverRegistry.java b/src/main/java/org/apache/ibatis/scripting/LanguageDriverRegistry.java index cfe44257e22..f425d80204f 100644 --- a/src/main/java/org/apache/ibatis/scripting/LanguageDriverRegistry.java +++ b/src/main/java/org/apache/ibatis/scripting/LanguageDriverRegistry.java @@ -18,8 +18,6 @@ import java.util.HashMap; import java.util.Map; -import org.apache.ibatis.util.MapUtil; - /** * @author Frank D. Martinez [mnesarco] */ @@ -33,7 +31,7 @@ public void register(Class cls) { if (cls == null) { throw new IllegalArgumentException("null is not a valid Language Driver"); } - MapUtil.computeIfAbsent(languageDriverMap, cls, k -> { + languageDriverMap.computeIfAbsent(cls, k -> { try { return k.getDeclaredConstructor().newInstance(); } catch (Exception ex) { From d02328e9fe2833a607485f5ca72127e44168cf54 Mon Sep 17 00:00:00 2001 From: Iwao AVE! Date: Wed, 1 Jan 2025 15:56:58 +0900 Subject: [PATCH 2/5] Remove Java 8 fallback using Lookup constructor We no longer support Java 8. --- .../apache/ibatis/binding/MapperProxy.java | 40 +++---------------- 1 file changed, 5 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/apache/ibatis/binding/MapperProxy.java b/src/main/java/org/apache/ibatis/binding/MapperProxy.java index 901929d4ece..c26f22620b5 100644 --- a/src/main/java/org/apache/ibatis/binding/MapperProxy.java +++ b/src/main/java/org/apache/ibatis/binding/MapperProxy.java @@ -20,7 +20,6 @@ import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles.Lookup; import java.lang.invoke.MethodType; -import java.lang.reflect.Constructor; import java.lang.reflect.InvocationHandler; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -36,9 +35,6 @@ public class MapperProxy implements InvocationHandler, Serializable { private static final long serialVersionUID = -4724728412955527868L; - private static final int ALLOWED_MODES = MethodHandles.Lookup.PRIVATE | MethodHandles.Lookup.PROTECTED - | MethodHandles.Lookup.PACKAGE | MethodHandles.Lookup.PUBLIC; - private static final Constructor lookupConstructor; private static final Method privateLookupInMethod; private final SqlSession sqlSession; private final Class mapperInterface; @@ -51,29 +47,13 @@ public MapperProxy(SqlSession sqlSession, Class mapperInterface, Map lookup = null; - if (privateLookupInMethod == null) { - // JDK 1.8 - try { - lookup = MethodHandles.Lookup.class.getDeclaredConstructor(Class.class, int.class); - lookup.setAccessible(true); - } catch (NoSuchMethodException e) { - throw new IllegalStateException( - "There is neither 'privateLookupIn(Class, Lookup)' nor 'Lookup(Class, int)' method in java.lang.invoke.MethodHandles.", - e); - } catch (Exception e) { - lookup = null; - } - } - lookupConstructor = lookup; } @Override @@ -95,12 +75,8 @@ private MapperMethodInvoker cachedInvoker(Method method) throws Throwable { return new PlainMethodInvoker(new MapperMethod(mapperInterface, method, sqlSession.getConfiguration())); } try { - if (privateLookupInMethod == null) { - return new DefaultMethodInvoker(getMethodHandleJava8(method)); - } return new DefaultMethodInvoker(getMethodHandleJava9(method)); - } catch (IllegalAccessException | InstantiationException | InvocationTargetException - | NoSuchMethodException e) { + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } }); @@ -118,12 +94,6 @@ private MethodHandle getMethodHandleJava9(Method method) declaringClass); } - private MethodHandle getMethodHandleJava8(Method method) - throws IllegalAccessException, InstantiationException, InvocationTargetException { - final Class declaringClass = method.getDeclaringClass(); - return lookupConstructor.newInstance(declaringClass, ALLOWED_MODES).unreflectSpecial(method, declaringClass); - } - interface MapperMethodInvoker { Object invoke(Object proxy, Method method, Object[] args, SqlSession sqlSession) throws Throwable; } From 0c2f85c5c726a712900b9490e4074c73b7867c6e Mon Sep 17 00:00:00 2001 From: Iwao AVE! Date: Wed, 1 Jan 2025 16:05:37 +0900 Subject: [PATCH 3/5] =?UTF-8?q?Forgot=20to=20actually=20remove=20MapUtil?= =?UTF-8?q?=20=F0=9F=98=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/org/apache/ibatis/util/MapUtil.java | 48 ------------------- 1 file changed, 48 deletions(-) delete mode 100644 src/main/java/org/apache/ibatis/util/MapUtil.java diff --git a/src/main/java/org/apache/ibatis/util/MapUtil.java b/src/main/java/org/apache/ibatis/util/MapUtil.java deleted file mode 100644 index 6ac26fa744a..00000000000 --- a/src/main/java/org/apache/ibatis/util/MapUtil.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2009-2023 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ibatis.util; - -import java.util.AbstractMap; -import java.util.Map; -import java.util.Map.Entry; -import java.util.function.Function; - -public class MapUtil { - /** - * A temporary workaround for Java 8 specific performance issue JDK-8161372 .
- * This class should be removed once we drop Java 8 support. - * - * @see https://bugs.openjdk.java.net/browse/JDK-8161372 - */ - public static V computeIfAbsent(Map map, K key, Function mappingFunction) { - V value = map.get(key); - if (value != null) { - return value; - } - return map.computeIfAbsent(key, mappingFunction); - } - - /** - * Map.entry(key, value) alternative for Java 8. - */ - public static Entry entry(K key, V value) { - return new AbstractMap.SimpleImmutableEntry<>(key, value); - } - - private MapUtil() { - } -} From 8b88a59f046192bc3a4038ed4a2caef96e3dc03b Mon Sep 17 00:00:00 2001 From: Iwao AVE! Date: Wed, 1 Jan 2025 16:22:56 +0900 Subject: [PATCH 4/5] Remove obsolete annotations --- .../org/apache/ibatis/lang/UsesJava7.java | 31 ------------------- .../org/apache/ibatis/lang/UsesJava8.java | 31 ------------------- .../org/apache/ibatis/lang/package-info.java | 19 ------------ 3 files changed, 81 deletions(-) delete mode 100644 src/main/java/org/apache/ibatis/lang/UsesJava7.java delete mode 100644 src/main/java/org/apache/ibatis/lang/UsesJava8.java delete mode 100644 src/main/java/org/apache/ibatis/lang/package-info.java diff --git a/src/main/java/org/apache/ibatis/lang/UsesJava7.java b/src/main/java/org/apache/ibatis/lang/UsesJava7.java deleted file mode 100644 index 29763663796..00000000000 --- a/src/main/java/org/apache/ibatis/lang/UsesJava7.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2009-2024 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ibatis.lang; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Indicates that the element uses Java 7 API. - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD }) -public @interface UsesJava7 { -} diff --git a/src/main/java/org/apache/ibatis/lang/UsesJava8.java b/src/main/java/org/apache/ibatis/lang/UsesJava8.java deleted file mode 100644 index 4dfcaee0957..00000000000 --- a/src/main/java/org/apache/ibatis/lang/UsesJava8.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2009-2024 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.ibatis.lang; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Indicates that the element uses Java 8 API. - */ -@Documented -@Retention(RetentionPolicy.RUNTIME) -@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.FIELD }) -public @interface UsesJava8 { -} diff --git a/src/main/java/org/apache/ibatis/lang/package-info.java b/src/main/java/org/apache/ibatis/lang/package-info.java deleted file mode 100644 index d852561738d..00000000000 --- a/src/main/java/org/apache/ibatis/lang/package-info.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright 2009-2022 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -/** - * Java Language Package. - */ -package org.apache.ibatis.lang; From 68bba510b51473de827bc55b80dfaab1abb29540 Mon Sep 17 00:00:00 2001 From: Iwao AVE! Date: Wed, 1 Jan 2025 18:25:51 +0900 Subject: [PATCH 5/5] License years --- src/main/java/org/apache/ibatis/binding/MapperProxy.java | 5 ++--- .../org/apache/ibatis/cache/TransactionalCacheManager.java | 2 +- .../ibatis/datasource/unpooled/UnpooledDataSource.java | 2 +- .../org/apache/ibatis/executor/keygen/Jdbc3KeyGenerator.java | 2 +- .../ibatis/executor/resultset/DefaultResultSetHandler.java | 2 +- src/main/java/org/apache/ibatis/plugin/Plugin.java | 2 +- .../apache/ibatis/reflection/DefaultReflectorFactory.java | 2 +- src/main/java/org/apache/ibatis/reflection/Reflector.java | 2 +- .../org/apache/ibatis/scripting/LanguageDriverRegistry.java | 2 +- 9 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/apache/ibatis/binding/MapperProxy.java b/src/main/java/org/apache/ibatis/binding/MapperProxy.java index c26f22620b5..4f3399199b8 100644 --- a/src/main/java/org/apache/ibatis/binding/MapperProxy.java +++ b/src/main/java/org/apache/ibatis/binding/MapperProxy.java @@ -1,5 +1,5 @@ /* - * Copyright 2009-2024 the original author or authors. + * Copyright 2009-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -51,8 +51,7 @@ public MapperProxy(SqlSession sqlSession, Class mapperInterface, Map