diff --git a/docs/spring/cs7a9e6648-9733-11ee-a68f-acde48001122.java b/docs/spring/cs7a9e6648-9733-11ee-a68f-acde48001122.java new file mode 100644 index 00000000..31f8d031 --- /dev/null +++ b/docs/spring/cs7a9e6648-9733-11ee-a68f-acde48001122.java @@ -0,0 +1,85 @@ +/** + * Copyright 2009-2019 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 + *
+ * http://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.submitted.nestedresulthandler_association;
+
+import org.apache.ibatis.BaseDataTest;
+import org.apache.ibatis.io.Resources;
+import org.apache.ibatis.session.RowBounds;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.io.Reader;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class NestedResultHandlerAssociationTest {
+
+ private static SqlSessionFactory sqlSessionFactory;
+
+ @BeforeAll
+ static void setUp() throws Exception {
+ // create an SqlSessionFactory
+ try (Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler_association/mybatis-config.xml")) {
+ sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
+ }
+
+ // populate in-memory database
+ BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
+ "org/apache/ibatis/submitted/nestedresulthandler_association/CreateDB.sql");
+ }
+
+ @Test
+ void shouldHandleRowBounds() throws Exception {
+ final SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
+ Date targetMonth = fmt.parse("2014-01-01");
+ final List
+ * 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
+ *
+ * http://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.jdbc;
+
+/**
+ * @author Clinton Begin
+ */
+public class RuntimeSqlException extends RuntimeException {
+
+ private static final long serialVersionUID = 5224696788505678598L;
+
+ public RuntimeSqlException() {
+ super();
+ }
+
+ public RuntimeSqlException(String message) {
+ super(message);
+ }
+
+ public RuntimeSqlException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public RuntimeSqlException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/docs/spring/cs7b7b20ba-9733-11ee-a68f-acde48001122.java b/docs/spring/cs7b7b20ba-9733-11ee-a68f-acde48001122.java
new file mode 100644
index 00000000..c577ed38
--- /dev/null
+++ b/docs/spring/cs7b7b20ba-9733-11ee-a68f-acde48001122.java
@@ -0,0 +1,45 @@
+/**
+ * Copyright 2009-2017 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
+ *
+ * http://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.executor.keygen;
+
+import org.apache.ibatis.executor.Executor;
+import org.apache.ibatis.mapping.MappedStatement;
+
+import java.sql.Statement;
+
+/**
+ * @author Clinton Begin
+ * @author Kazuki Shimizu
+ */
+public class NoKeyGenerator implements KeyGenerator {
+
+ /**
+ * A shared instance.
+ * @since 3.4.3
+ */
+ public static final NoKeyGenerator INSTANCE = new NoKeyGenerator();
+
+ @Override
+ public void processBefore(Executor executor, MappedStatement ms, Statement stmt, Object parameter) {
+ // Do Nothing
+ }
+
+ @Override
+ public void processAfter(Executor executor, MappedStatement ms, Statement stmt, Object parameter) {
+ // Do Nothing
+ }
+
+}
diff --git a/docs/spring/cs7bd86464-9733-11ee-a68f-acde48001122.java b/docs/spring/cs7bd86464-9733-11ee-a68f-acde48001122.java
new file mode 100644
index 00000000..5cc655af
--- /dev/null
+++ b/docs/spring/cs7bd86464-9733-11ee-a68f-acde48001122.java
@@ -0,0 +1,437 @@
+/**
+ * Copyright 2009-2019 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
+ *
+ * http://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.reflection;
+
+import org.apache.ibatis.reflection.typeparam.Calculator;
+import org.apache.ibatis.reflection.typeparam.Calculator.SubCalculator;
+import org.apache.ibatis.reflection.typeparam.Level0Mapper;
+import org.apache.ibatis.reflection.typeparam.Level0Mapper.Level0InnerMapper;
+import org.apache.ibatis.reflection.typeparam.Level1Mapper;
+import org.apache.ibatis.reflection.typeparam.Level2Mapper;
+import org.junit.jupiter.api.Test;
+
+import java.lang.reflect.*;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class TypeParameterResolverTest {
+ @Test
+ void testReturn_Lv0SimpleClass() throws Exception {
+ Class> clazz = Level0Mapper.class;
+ Method method = clazz.getMethod("simpleSelect");
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertEquals(Double.class, result);
+ }
+
+ @Test
+ void testReturn_SimpleVoid() throws Exception {
+ Class> clazz = Level1Mapper.class;
+ Method method = clazz.getMethod("simpleSelectVoid", Integer.class);
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertEquals(void.class, result);
+ }
+
+ @Test
+ void testReturn_SimplePrimitive() throws Exception {
+ Class> clazz = Level1Mapper.class;
+ Method method = clazz.getMethod("simpleSelectPrimitive", int.class);
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertEquals(double.class, result);
+ }
+
+ @Test
+ void testReturn_SimpleClass() throws Exception {
+ Class> clazz = Level1Mapper.class;
+ Method method = clazz.getMethod("simpleSelect");
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertEquals(Double.class, result);
+ }
+
+ @Test
+ void testReturn_SimpleList() throws Exception {
+ Class> clazz = Level1Mapper.class;
+ Method method = clazz.getMethod("simpleSelectList");
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertTrue(result instanceof ParameterizedType);
+ ParameterizedType paramType = (ParameterizedType) result;
+ assertEquals(List.class, paramType.getRawType());
+ assertEquals(1, paramType.getActualTypeArguments().length);
+ assertEquals(Double.class, paramType.getActualTypeArguments()[0]);
+ }
+
+ @Test
+ void testReturn_SimpleMap() throws Exception {
+ Class> clazz = Level1Mapper.class;
+ Method method = clazz.getMethod("simpleSelectMap");
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertTrue(result instanceof ParameterizedType);
+ ParameterizedType paramType = (ParameterizedType) result;
+ assertEquals(Map.class, paramType.getRawType());
+ assertEquals(2, paramType.getActualTypeArguments().length);
+ assertEquals(Integer.class, paramType.getActualTypeArguments()[0]);
+ assertEquals(Double.class, paramType.getActualTypeArguments()[1]);
+ }
+
+ @Test
+ void testReturn_SimpleWildcard() throws Exception {
+ Class> clazz = Level1Mapper.class;
+ Method method = clazz.getMethod("simpleSelectWildcard");
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertTrue(result instanceof ParameterizedType);
+ ParameterizedType paramType = (ParameterizedType) result;
+ assertEquals(List.class, paramType.getRawType());
+ assertEquals(1, paramType.getActualTypeArguments().length);
+ assertTrue(paramType.getActualTypeArguments()[0] instanceof WildcardType);
+ WildcardType wildcard = (WildcardType) paramType.getActualTypeArguments()[0];
+ assertEquals(String.class, wildcard.getUpperBounds()[0]);
+ }
+
+ @Test
+ void testReturn_SimpleArray() throws Exception {
+ Class> clazz = Level1Mapper.class;
+ Method method = clazz.getMethod("simpleSelectArray");
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertTrue(result instanceof Class);
+ Class> resultClass = (Class>) result;
+ assertTrue(resultClass.isArray());
+ assertEquals(String.class, resultClass.getComponentType());
+ }
+
+ @Test
+ void testReturn_SimpleArrayOfArray() throws Exception {
+ Class> clazz = Level1Mapper.class;
+ Method method = clazz.getMethod("simpleSelectArrayOfArray");
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertTrue(result instanceof Class);
+ Class> resultClass = (Class>) result;
+ assertTrue(resultClass.isArray());
+ assertTrue(resultClass.getComponentType().isArray());
+ assertEquals(String.class, resultClass.getComponentType().getComponentType());
+ }
+
+ @Test
+ void testReturn_SimpleTypeVar() throws Exception {
+ Class> clazz = Level1Mapper.class;
+ Method method = clazz.getMethod("simpleSelectTypeVar");
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertTrue(result instanceof ParameterizedType);
+ ParameterizedType paramType = (ParameterizedType) result;
+ assertEquals(Calculator.class, paramType.getRawType());
+ assertEquals(1, paramType.getActualTypeArguments().length);
+ assertTrue(paramType.getActualTypeArguments()[0] instanceof WildcardType);
+ }
+
+ @Test
+ void testReturn_Lv1Class() throws Exception {
+ Class> clazz = Level1Mapper.class;
+ Method method = clazz.getMethod("select", Object.class);
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertEquals(String.class, result);
+ }
+
+ @Test
+ void testReturn_Lv2CustomClass() throws Exception {
+ Class> clazz = Level2Mapper.class;
+ Method method = clazz.getMethod("selectCalculator", Calculator.class);
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertTrue(result instanceof ParameterizedType);
+ ParameterizedType paramType = (ParameterizedType) result;
+ assertEquals(Calculator.class, paramType.getRawType());
+ assertEquals(1, paramType.getActualTypeArguments().length);
+ assertEquals(String.class, paramType.getActualTypeArguments()[0]);
+ }
+
+ @Test
+ void testReturn_Lv2CustomClassList() throws Exception {
+ Class> clazz = Level2Mapper.class;
+ Method method = clazz.getMethod("selectCalculatorList");
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertTrue(result instanceof ParameterizedType);
+ ParameterizedType paramTypeOuter = (ParameterizedType) result;
+ assertEquals(List.class, paramTypeOuter.getRawType());
+ assertEquals(1, paramTypeOuter.getActualTypeArguments().length);
+ ParameterizedType paramTypeInner = (ParameterizedType) paramTypeOuter.getActualTypeArguments()[0];
+ assertEquals(Calculator.class, paramTypeInner.getRawType());
+ assertEquals(Date.class, paramTypeInner.getActualTypeArguments()[0]);
+ }
+
+ @Test
+ void testReturn_Lv0InnerClass() throws Exception {
+ Class> clazz = Level0InnerMapper.class;
+ Method method = clazz.getMethod("select", Object.class);
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertEquals(Float.class, result);
+ }
+
+ @Test
+ void testReturn_Lv2Class() throws Exception {
+ Class> clazz = Level2Mapper.class;
+ Method method = clazz.getMethod("select", Object.class);
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertEquals(String.class, result);
+ }
+
+ @Test
+ void testReturn_Lv1List() throws Exception {
+ Class> clazz = Level1Mapper.class;
+ Method method = clazz.getMethod("selectList", Object.class, Object.class);
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertTrue(result instanceof ParameterizedType);
+ ParameterizedType type = (ParameterizedType) result;
+ assertEquals(List.class, type.getRawType());
+ assertEquals(1, type.getActualTypeArguments().length);
+ assertEquals(String.class, type.getActualTypeArguments()[0]);
+ }
+
+ @Test
+ void testReturn_Lv1Array() throws Exception {
+ Class> clazz = Level1Mapper.class;
+ Method method = clazz.getMethod("selectArray", List[].class);
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertTrue(result instanceof Class);
+ Class> resultClass = (Class>) result;
+ assertTrue(resultClass.isArray());
+ assertEquals(String.class, resultClass.getComponentType());
+ }
+
+ @Test
+ void testReturn_Lv2ArrayOfArray() throws Exception {
+ Class> clazz = Level2Mapper.class;
+ Method method = clazz.getMethod("selectArrayOfArray");
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertTrue(result instanceof Class);
+ Class> resultClass = (Class>) result;
+ assertTrue(result instanceof Class);
+ assertTrue(resultClass.isArray());
+ assertTrue(resultClass.getComponentType().isArray());
+ assertEquals(String.class, resultClass.getComponentType().getComponentType());
+ }
+
+ @Test
+ void testReturn_Lv2ArrayOfList() throws Exception {
+ Class> clazz = Level2Mapper.class;
+ Method method = clazz.getMethod("selectArrayOfList");
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertTrue(result instanceof GenericArrayType);
+ GenericArrayType genericArrayType = (GenericArrayType) result;
+ assertTrue(genericArrayType.getGenericComponentType() instanceof ParameterizedType);
+ ParameterizedType paramType = (ParameterizedType) genericArrayType.getGenericComponentType();
+ assertEquals(List.class, paramType.getRawType());
+ assertEquals(String.class, paramType.getActualTypeArguments()[0]);
+ }
+
+ @Test
+ void testReturn_Lv2WildcardList() throws Exception {
+ Class> clazz = Level2Mapper.class;
+ Method method = clazz.getMethod("selectWildcardList");
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertTrue(result instanceof ParameterizedType);
+ ParameterizedType type = (ParameterizedType) result;
+ assertEquals(List.class, type.getRawType());
+ assertEquals(1, type.getActualTypeArguments().length);
+ assertTrue(type.getActualTypeArguments()[0] instanceof WildcardType);
+ WildcardType wildcard = (WildcardType) type.getActualTypeArguments()[0];
+ assertEquals(0, wildcard.getLowerBounds().length);
+ assertEquals(1, wildcard.getUpperBounds().length);
+ assertEquals(String.class, wildcard.getUpperBounds()[0]);
+ }
+
+ @Test
+ void testReturn_LV2Map() throws Exception {
+ Class> clazz = Level2Mapper.class;
+ Method method = clazz.getMethod("selectMap");
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertTrue(result instanceof ParameterizedType);
+ ParameterizedType paramType = (ParameterizedType) result;
+ assertEquals(Map.class, paramType.getRawType());
+ assertEquals(2, paramType.getActualTypeArguments().length);
+ assertEquals(String.class, paramType.getActualTypeArguments()[0]);
+ assertEquals(Integer.class, paramType.getActualTypeArguments()[1]);
+ }
+
+ @Test
+ void testReturn_Subclass() throws Exception {
+ Class> clazz = SubCalculator.class;
+ Method method = clazz.getMethod("getId");
+ Type result = TypeParameterResolver.resolveReturnType(method, clazz);
+ assertEquals(String.class, result);
+ }
+
+ @Test
+ void testParam_Primitive() throws Exception {
+ Class> clazz = Level2Mapper.class;
+ Method method = clazz.getMethod("simpleSelectPrimitive", int.class);
+ Type[] result = TypeParameterResolver.resolveParamTypes(method, clazz);
+ assertEquals(1, result.length);
+ assertEquals(int.class, result[0]);
+ }
+
+ @Test
+ void testParam_Simple() throws Exception {
+ Class> clazz = Level1Mapper.class;
+ Method method = clazz.getMethod("simpleSelectVoid", Integer.class);
+ Type[] result = TypeParameterResolver.resolveParamTypes(method, clazz);
+ assertEquals(1, result.length);
+ assertEquals(Integer.class, result[0]);
+ }
+
+ @Test
+ void testParam_Lv1Single() throws Exception {
+ Class> clazz = Level1Mapper.class;
+ Method method = clazz.getMethod("select", Object.class);
+ Type[] result = TypeParameterResolver.resolveParamTypes(method, clazz);
+ assertEquals(1, result.length);
+ assertEquals(String.class, result[0]);
+ }
+
+ @Test
+ void testParam_Lv2Single() throws Exception {
+ Class> clazz = Level2Mapper.class;
+ Method method = clazz.getMethod("select", Object.class);
+ Type[] result = TypeParameterResolver.resolveParamTypes(method, clazz);
+ assertEquals(1, result.length);
+ assertEquals(String.class, result[0]);
+ }
+
+ @Test
+ void testParam_Lv2Multiple() throws Exception {
+ Class> clazz = Level2Mapper.class;
+ Method method = clazz.getMethod("selectList", Object.class, Object.class);
+ Type[] result = TypeParameterResolver.resolveParamTypes(method, clazz);
+ assertEquals(2, result.length);
+ assertEquals(Integer.class, result[0]);
+ assertEquals(String.class, result[1]);
+ }
+
+ @Test
+ void testParam_Lv2CustomClass() throws Exception {
+ Class> clazz = Level2Mapper.class;
+ Method method = clazz.getMethod("selectCalculator", Calculator.class);
+ Type[] result = TypeParameterResolver.resolveParamTypes(method, clazz);
+ assertEquals(1, result.length);
+ assertTrue(result[0] instanceof ParameterizedType);
+ ParameterizedType paramType = (ParameterizedType) result[0];
+ assertEquals(Calculator.class, paramType.getRawType());
+ assertEquals(1, paramType.getActualTypeArguments().length);
+ assertEquals(String.class, paramType.getActualTypeArguments()[0]);
+ }
+
+ @Test
+ void testParam_Lv1Array() throws Exception {
+ Class> clazz = Level1Mapper.class;
+ Method method = clazz.getMethod("selectArray", List[].class);
+ Type[] result = TypeParameterResolver.resolveParamTypes(method, clazz);
+ assertTrue(result[0] instanceof GenericArrayType);
+ GenericArrayType genericArrayType = (GenericArrayType) result[0];
+ assertTrue(genericArrayType.getGenericComponentType() instanceof ParameterizedType);
+ ParameterizedType paramType = (ParameterizedType) genericArrayType.getGenericComponentType();
+ assertEquals(List.class, paramType.getRawType());
+ assertEquals(String.class, paramType.getActualTypeArguments()[0]);
+ }
+
+ @Test
+ void testParam_Subclass() throws Exception {
+ Class> clazz = SubCalculator.class;
+ Method method = clazz.getMethod("setId", Object.class);
+ Type[] result = TypeParameterResolver.resolveParamTypes(method, clazz);
+ assertEquals(String.class, result[0]);
+ }
+
+ @Test
+ void testReturn_Anonymous() throws Exception {
+ Calculator> instance = new Calculator {
+ private S key1;
+ private T key2;
+
+ public S getKey1() {
+ return key1;
+ }
+
+ public void setKey1(S key1) {
+ this.key1 = key1;
+ }
+
+ public T getKey2() {
+ return key2;
+ }
+
+ public void setKey2(T key2) {
+ this.key2 = key2;
+ }
+ }
+ Class> clazz = KeyBean.class;
+ Method getter1 = clazz.getMethod("getKey1");
+ assertEquals(Key.class, TypeParameterResolver.resolveReturnType(getter1, clazz));
+ Method setter1 = clazz.getMethod("setKey1", Key.class);
+ assertEquals(Key.class, TypeParameterResolver.resolveParamTypes(setter1, clazz)[0]);
+ Method getter2 = clazz.getMethod("getKey2");
+ assertEquals(Key.class, TypeParameterResolver.resolveReturnType(getter2, clazz));
+ Method setter2 = clazz.getMethod("setKey2", Key.class);
+ assertEquals(Key.class, TypeParameterResolver.resolveParamTypes(setter2, clazz)[0]);
+ }
+
+ @Test
+ void testDeepHierarchy() throws Exception {
+ @SuppressWarnings("unused")
+ abstract class A {
+ protected S id;
+
+ public S getId() {
+ return this.id;
+ }
+
+ public void setId(S id) {
+ this.id = id;
+ }
+ }
+ abstract class B