diff --git a/docs/spring/cs0df1635c-6a5e-11ef-8f2f-acde48001122.java b/docs/spring/cs0df1635c-6a5e-11ef-8f2f-acde48001122.java new file mode 100644 index 00000000..3f45c1f6 --- /dev/null +++ b/docs/spring/cs0df1635c-6a5e-11ef-8f2f-acde48001122.java @@ -0,0 +1,79 @@ +/** + * 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.result_handler_type;
+
+import org.apache.ibatis.BaseDataTest;
+import org.apache.ibatis.io.Resources;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.junit.jupiter.api.Test;
+
+import java.io.Reader;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class DefaultResultHandlerTypeTest {
+
+ @Test
+ void testSelectList() throws Exception {
+ String xmlConfig = "org/apache/ibatis/submitted/result_handler_type/MapperConfig.xml";
+ SqlSessionFactory sqlSessionFactory = getSqlSessionFactoryXmlConfig(xmlConfig);
+ try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
+ 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.submitted.named_constructor_args;
+
+import org.apache.ibatis.BaseDataTest;
+import org.apache.ibatis.annotations.Arg;
+import org.apache.ibatis.annotations.ConstructorArgs;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.builder.BuilderException;
+import org.apache.ibatis.io.Resources;
+import org.apache.ibatis.session.Configuration;
+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 static com.googlecode.catchexception.apis.BDDCatchException.caughtException;
+import static com.googlecode.catchexception.apis.BDDCatchException.when;
+import static org.assertj.core.api.BDDAssertions.then;
+
+class InvalidNamedConstructorArgsTest {
+
+ private static SqlSessionFactory sqlSessionFactory;
+
+ @BeforeAll
+ static void setUp() throws Exception {
+ // create an SqlSessionFactory
+ try (Reader reader = Resources.getResourceAsReader(
+ "org/apache/ibatis/submitted/named_constructor_args/mybatis-config.xml")) {
+ sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
+ }
+
+ // populate in-memory database
+ BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
+ "org/apache/ibatis/submitted/named_constructor_args/CreateDB.sql");
+ }
+
+ @Test
+ void noMatchingConstructorArgName() {
+ Configuration configuration = sqlSessionFactory.getConfiguration();
+ when(() -> configuration.addMapper(NoMatchingConstructorMapper.class));
+
+ then(caughtException()).isInstanceOf(BuilderException.class)
+ .hasMessageContaining(
+ "'org.apache.ibatis.submitted.named_constructor_args.InvalidNamedConstructorArgsTest$NoMatchingConstructorMapper.select-void'")
+ .hasMessageContaining("'org.apache.ibatis.submitted.named_constructor_args.User'")
+ .hasMessageContaining("[noSuchConstructorArg]");
+ }
+
+ @Test
+ void wrongJavaType() {
+ Configuration configuration = sqlSessionFactory.getConfiguration();
+ when(() -> configuration.addMapper(ConstructorWithWrongJavaType.class));
+ then(caughtException()).isInstanceOf(BuilderException.class)
+ .hasMessageContaining(
+ "'org.apache.ibatis.submitted.named_constructor_args.InvalidNamedConstructorArgsTest$ConstructorWithWrongJavaType.select-void'")
+ .hasMessageContaining("'org.apache.ibatis.submitted.named_constructor_args.User'")
+ .hasMessageContaining("[id]");
+ }
+
+ @Test
+ void missingRequiredJavaType() {
+ Configuration configuration = sqlSessionFactory.getConfiguration();
+ when(() -> configuration.addMapper(ConstructorMissingRequiresJavaType.class));
+ then(caughtException()).isInstanceOf(BuilderException.class)
+ .hasMessageContaining(
+ "'org.apache.ibatis.submitted.named_constructor_args.InvalidNamedConstructorArgsTest$ConstructorMissingRequiresJavaType.select-void'")
+ .hasMessageContaining("'org.apache.ibatis.submitted.named_constructor_args.User'")
+ .hasMessageContaining("[id]");
+ }
+
+ interface NoMatchingConstructorMapper {
+ @ConstructorArgs({
+ @Arg(column = "id", name = "noSuchConstructorArg"),
+ })
+ @Select("select * from users ")
+ User select();
+ }
+
+ interface ConstructorWithWrongJavaType {
+ // There is a constructor with arg name 'id', but
+ // its type is different from the specified javaType.
+ @ConstructorArgs({
+ @Arg(column = "id", name = "id", javaType = Integer.class),
+ })
+ @Select("select * from users ")
+ User select();
+ }
+
+ interface ConstructorMissingRequiresJavaType {
+ // There is a constructor with arg name 'id', but its type
+ // is different from the type of a property with the same name.
+ // javaType is required in this case.
+ // Debug log shows the detail of the matching error.
+ @ConstructorArgs({
+ @Arg(column = "id", name = "id"),
+ })
+ @Select("select * from users ")
+ User select();
+ }
+}
diff --git a/docs/spring/cs1134f8a8-6a5e-11ef-8f2f-acde48001122.java b/docs/spring/cs1134f8a8-6a5e-11ef-8f2f-acde48001122.java
new file mode 100644
index 00000000..72ddd356
--- /dev/null
+++ b/docs/spring/cs1134f8a8-6a5e-11ef-8f2f-acde48001122.java
@@ -0,0 +1,141 @@
+/**
+ * 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.logging;
+
+import java.lang.reflect.Constructor;
+
+/**
+ * 日志工厂,实现内容:
+ * 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.flush_statement_npe;
+
+public class Person {
+ private Integer id;
+ private String firstName;
+ private String lastName;
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+}
diff --git a/docs/spring/cs13c3275c-6a5e-11ef-8f2f-acde48001122.java b/docs/spring/cs13c3275c-6a5e-11ef-8f2f-acde48001122.java
new file mode 100644
index 00000000..70ce0175
--- /dev/null
+++ b/docs/spring/cs13c3275c-6a5e-11ef-8f2f-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.collectionparameters;
+
+import org.apache.ibatis.BaseDataTest;
+import org.apache.ibatis.io.Resources;
+import org.apache.ibatis.session.SqlSession;
+import org.apache.ibatis.session.SqlSessionFactory;
+import org.apache.ibatis.session.SqlSessionFactoryBuilder;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+class CollectionParametersTest {
+
+ private static SqlSessionFactory sqlSessionFactory;
+
+ @BeforeAll
+ static void setUp() throws Exception {
+ // create an SqlSessionFactory
+ try (Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/collectionparameters/mybatis-config.xml")) {
+ sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
+ }
+
+ // populate in-memory database
+ BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(),
+ "org/apache/ibatis/submitted/collectionparameters/CreateDB.sql");
+ }
+
+ @Test
+ void shouldGetTwoUsersPassingAList() {
+ try (SqlSession sqlSession = sqlSessionFactory.openSession()) {
+ Mapper mapper = sqlSession.getMapper(Mapper.class);
+ ArrayList
+ *
+ * @author Clinton Begin
+ * @author Eduardo Macarron
+ */
+public final class LogFactory {
+
+ /**
+ * Marker to be used by logging implementations that support markers.
+ */
+ public static final String MARKER = "MYBATIS";
+
+ private static Constructor extends Log> logConstructor;
+
+ /**
+ * 日志的实现类的具体选择
+ */
+ static {
+ // slf4j 日志
+ tryImplementation(LogFactory::useSlf4jLogging);
+ // apache 日志
+ tryImplementation(LogFactory::useCommonsLogging);
+ // log4j2 日志
+ tryImplementation(LogFactory::useLog4J2Logging);
+ // log4 日志
+ tryImplementation(LogFactory::useLog4JLogging);
+ // JDK 日志
+ tryImplementation(LogFactory::useJdkLogging);
+ // 空 日志
+ tryImplementation(LogFactory::useNoLogging);
+ }
+
+ /**
+ * 私有化构造方法,这是一个单例
+ */
+ private LogFactory() {
+ // disable construction
+ }
+
+ public static Log getLog(Class> aClass) {
+ return getLog(aClass.getName());
+ }
+
+ public static Log getLog(String logger) {
+ try {
+ return logConstructor.newInstance(logger);
+ } catch (Throwable t) {
+ throw new LogException("Error creating logger for logger " + logger + ". Cause: " + t, t);
+ }
+ }
+
+ public static synchronized void useCustomLogging(Class extends Log> clazz) {
+ setImplementation(clazz);
+ }
+
+ public static synchronized void useSlf4jLogging() {
+ setImplementation(org.apache.ibatis.logging.slf4j.Slf4jImpl.class);
+ }
+
+ public static synchronized void useCommonsLogging() {
+ setImplementation(org.apache.ibatis.logging.commons.JakartaCommonsLoggingImpl.class);
+ }
+
+ public static synchronized void useLog4JLogging() {
+ setImplementation(org.apache.ibatis.logging.log4j.Log4jImpl.class);
+ }
+
+ public static synchronized void useLog4J2Logging() {
+ setImplementation(org.apache.ibatis.logging.log4j2.Log4j2Impl.class);
+ }
+
+ public static synchronized void useJdkLogging() {
+ setImplementation(org.apache.ibatis.logging.jdk14.Jdk14LoggingImpl.class);
+ }
+
+ public static synchronized void useStdOutLogging() {
+ setImplementation(org.apache.ibatis.logging.stdout.StdOutImpl.class);
+ }
+
+ public static synchronized void useNoLogging() {
+ setImplementation(org.apache.ibatis.logging.nologging.NoLoggingImpl.class);
+ }
+
+ /**
+ * 选择具体的日志实现
+ */
+ private static void tryImplementation(Runnable runnable) {
+ if (logConstructor == null) {
+ try {
+ // run()? 似乎违背了代码的语义, 看静态方法.静态方法多行同类型的操作我认为是一个多线程
+ runnable.run();
+ } catch (Throwable t) {
+ // ignore
+ }
+ }
+ }
+
+ /**
+ * 选择具体的日志实现
+ */
+ private static void setImplementation(Class extends Log> implClass) {
+ try {
+ Constructor extends Log> candidate = implClass.getConstructor(String.class);
+ Log log = candidate.newInstance(LogFactory.class.getName());
+ if (log.isDebugEnabled()) {
+ log.debug("Logging initialized using '" + implClass + "' adapter.");
+ }
+ logConstructor = candidate;
+ } catch (Throwable t) {
+ throw new LogException("Error setting Log implementation. Cause: " + t, t);
+ }
+ }
+
+}
diff --git a/docs/spring/cs1278cad2-6a5e-11ef-8f2f-acde48001122.java b/docs/spring/cs1278cad2-6a5e-11ef-8f2f-acde48001122.java
new file mode 100644
index 00000000..a1361b56
--- /dev/null
+++ b/docs/spring/cs1278cad2-6a5e-11ef-8f2f-acde48001122.java
@@ -0,0 +1,46 @@
+/**
+ * Copyright 2009-2015 the original author or authors.
+ *