s) {
54 | if (log.isTraceEnabled()) {
55 | log.trace(s.get());
56 | }
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/org/mybatis/logging/LoggerFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2022 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.mybatis.logging;
17 |
18 | import org.apache.ibatis.logging.LogFactory;
19 |
20 | /**
21 | * LoggerFactory is a wrapper around {@link LogFactory} to support {@link Logger}.
22 | *
23 | * @author Putthiphong Boonphong
24 | */
25 | public class LoggerFactory {
26 |
27 | private LoggerFactory() {
28 | // NOP
29 | }
30 |
31 | public static Logger getLogger(Class> aClass) {
32 | return new Logger(LogFactory.getLog(aClass));
33 | }
34 |
35 | public static Logger getLogger(String logger) {
36 | return new Logger(LogFactory.getLog(logger));
37 | }
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/main/java/org/mybatis/spring/MyBatisSystemException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2023 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.mybatis.spring;
17 |
18 | import org.springframework.dao.UncategorizedDataAccessException;
19 |
20 | /**
21 | * MyBatis specific subclass of {@code UncategorizedDataAccessException}, for MyBatis system errors that do not match
22 | * any concrete {@code org.springframework.dao} exceptions.
23 | *
24 | * In MyBatis 3 {@code org.apache.ibatis.exceptions.PersistenceException} is a {@code RuntimeException}, but using this
25 | * wrapper class to bring everything under a single hierarchy will be easier for client code to handle.
26 | *
27 | * @author Hunter Presnall
28 | */
29 | @SuppressWarnings("squid:MaximumInheritanceDepth") // It is the intended design
30 | public class MyBatisSystemException extends UncategorizedDataAccessException {
31 |
32 | private static final long serialVersionUID = -5284728621670758939L;
33 |
34 | @Deprecated(since = "3.0.4", forRemoval = true)
35 | public MyBatisSystemException(Throwable cause) {
36 | this(cause.getMessage(), cause);
37 | }
38 |
39 | public MyBatisSystemException(String msg, Throwable cause) {
40 | super(msg, cause);
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/main/java/org/mybatis/spring/annotation/MapperScans.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2022 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.mybatis.spring.annotation;
17 |
18 | import java.lang.annotation.Documented;
19 | import java.lang.annotation.ElementType;
20 | import java.lang.annotation.Retention;
21 | import java.lang.annotation.RetentionPolicy;
22 | import java.lang.annotation.Target;
23 |
24 | import org.springframework.context.annotation.Import;
25 |
26 | /**
27 | * The Container annotation that aggregates several {@link MapperScan} annotations.
28 | *
29 | * Can be used natively, declaring several nested {@link MapperScan} annotations. Can also be used in conjunction with
30 | * Java 8's support for repeatable annotations, where {@link MapperScan} can simply be declared several times on the
31 | * same method, implicitly generating this container annotation.
32 | *
33 | * @author Kazuki Shimizu
34 | *
35 | * @since 2.0.0
36 | *
37 | * @see MapperScan
38 | */
39 | @Retention(RetentionPolicy.RUNTIME)
40 | @Target(ElementType.TYPE)
41 | @Documented
42 | @Import(MapperScannerRegistrar.RepeatingRegistrar.class)
43 | public @interface MapperScans {
44 | MapperScan[] value();
45 | }
46 |
--------------------------------------------------------------------------------
/src/main/java/org/mybatis/spring/annotation/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2022 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 | /**
17 | * Contains MyBatis annotations
18 | */
19 | package org.mybatis.spring.annotation;
20 |
--------------------------------------------------------------------------------
/src/main/java/org/mybatis/spring/batch/builder/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2022 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 | /**
17 | * Contains classes to builder classes for {@link org.springframework.batch.item.ItemReader} and
18 | * {@link org.springframework.batch.item.ItemWriter}.
19 | *
20 | * @since 2.0.0
21 | */
22 | package org.mybatis.spring.batch.builder;
23 |
--------------------------------------------------------------------------------
/src/main/java/org/mybatis/spring/batch/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2022 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 | /**
17 | * Contains classes to facilitate the migration in Spring-Batch applications.
18 | */
19 | package org.mybatis.spring.batch;
20 |
--------------------------------------------------------------------------------
/src/main/java/org/mybatis/spring/config/NamespaceHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-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.mybatis.spring.config;
17 |
18 | import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
19 |
20 | /**
21 | * Namespace handler for the MyBatis namespace.
22 | *
23 | * @author Lishu Luo
24 | *
25 | * @see MapperScannerBeanDefinitionParser
26 | *
27 | * @since 1.2.0
28 | */
29 | public class NamespaceHandler extends NamespaceHandlerSupport {
30 |
31 | @Override
32 | public void init() {
33 | registerBeanDefinitionParser("scan", new MapperScannerBeanDefinitionParser());
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/org/mybatis/spring/config/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2022 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 | /**
17 | * Contains the MyBatis namespace schema and element handlers.
18 | */
19 | package org.mybatis.spring.config;
20 |
--------------------------------------------------------------------------------
/src/main/java/org/mybatis/spring/mapper/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2022 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 | /**
17 | * Contains classes for automatically building MyBatis mapper proxy classes at application startup.
18 | */
19 | package org.mybatis.spring.mapper;
20 |
--------------------------------------------------------------------------------
/src/main/java/org/mybatis/spring/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2022 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 | /**
17 | * Contains core classes to build the MyBatis integration with Spring3.X.
18 | */
19 | package org.mybatis.spring;
20 |
--------------------------------------------------------------------------------
/src/main/java/org/mybatis/spring/support/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2022 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 | /**
17 | * Contains Spring3.X support classes for MyBatis.
18 | */
19 | package org.mybatis.spring.support;
20 |
--------------------------------------------------------------------------------
/src/main/java/org/mybatis/spring/transaction/SpringManagedTransactionFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-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.mybatis.spring.transaction;
17 |
18 | import java.sql.Connection;
19 | import java.util.Properties;
20 |
21 | import javax.sql.DataSource;
22 |
23 | import org.apache.ibatis.session.TransactionIsolationLevel;
24 | import org.apache.ibatis.transaction.Transaction;
25 | import org.apache.ibatis.transaction.TransactionFactory;
26 |
27 | /**
28 | * Creates a {@code SpringManagedTransaction}.
29 | *
30 | * @author Hunter Presnall
31 | */
32 | public class SpringManagedTransactionFactory implements TransactionFactory {
33 |
34 | @Override
35 | public Transaction newTransaction(DataSource dataSource, TransactionIsolationLevel level, boolean autoCommit) {
36 | return new SpringManagedTransaction(dataSource);
37 | }
38 |
39 | @Override
40 | public Transaction newTransaction(Connection conn) {
41 | throw new UnsupportedOperationException("New Spring transactions require a DataSource");
42 | }
43 |
44 | @Override
45 | public void setProperties(Properties props) {
46 | // not needed in this version
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/org/mybatis/spring/transaction/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2022 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 | /**
17 | * Contains core classes to manage MyBatis transactions in Spring3.X.
18 | */
19 | package org.mybatis.spring.transaction;
20 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/spring.handlers:
--------------------------------------------------------------------------------
1 | http\://mybatis.org/schema/mybatis-spring=org.mybatis.spring.config.NamespaceHandler
2 |
--------------------------------------------------------------------------------
/src/main/resources/META-INF/spring.schemas:
--------------------------------------------------------------------------------
1 | http\://mybatis.org/schema/mybatis-spring-1.2.xsd=org/mybatis/spring/config/mybatis-spring.xsd
2 | http\://mybatis.org/schema/mybatis-spring.xsd=org/mybatis/spring/config/mybatis-spring.xsd
3 |
--------------------------------------------------------------------------------
/src/site/es/markdown/README.md:
--------------------------------------------------------------------------------
1 | # Tabla de contenido
2 |
3 | Esta página es para representar el índice en GitHub.
4 |
5 | > **NOTE:**
6 | >
7 | > Dado que el destino del enlace se especifica asumiendo que se convierte a html con maven-site-plugin, hay un ancla que se rompe en el renderizado en GitHub.
8 |
9 | * [Introducción](./index.md)
10 | * [Primeros pasos](./getting-started.md)
11 | * [SqlSessionFactoryBean](./factorybean.md)
12 | * [Transactions](./transactions.md)
13 | * [Uso de SqlSession](./sqlsession.md)
14 | * [Inyección de Mappers](./mappers.md)
15 | * [Spring Boot](./boot.md)
16 | * [Uso del API de MyBatis](./using-api.md)
17 | * [Spring Batch](./batch.md)
18 | * [Código de ejemplo](./sample.md)
19 |
--------------------------------------------------------------------------------
/src/site/es/markdown/boot.md:
--------------------------------------------------------------------------------
1 |
2 | # Using Spring Boot
3 |
4 | Please see the [MyBatis Spring-boot-starter](http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure) sub project docs for details.
5 |
--------------------------------------------------------------------------------
/src/site/es/markdown/using-api.md:
--------------------------------------------------------------------------------
1 |
2 | # Using the MyBatis API
3 |
4 | With MyBatis-Spring, you can continue to directly use the MyBatis API.
5 | Simply create an `SqlSessionFactory` in Spring using `SqlSessionFactoryBean` and use the factory in your code.
6 |
7 | ```java
8 | public class UserDaoImpl implements UserDao {
9 | // SqlSessionFactory would normally be set by SqlSessionDaoSupport
10 | private final SqlSessionFactory sqlSessionFactory;
11 |
12 | public UserDaoImpl(SqlSessionFactory sqlSessionFactory) {
13 | this.sqlSessionFactory = sqlSessionFactory;
14 | }
15 |
16 | public User getUser(String userId) {
17 | // note standard MyBatis API usage - opening and closing the session manually
18 | try (SqlSession session = sqlSessionFactory.openSession()) {
19 | return session.selectOne("org.mybatis.spring.sample.mapper.UserMapper.getUser", userId);
20 | }
21 | }
22 | }
23 | ```
24 |
25 | Use this option **with care** because wrong usage may produce runtime errors or worse, data integrity problems. Be aware of the following caveats with direct API usage:
26 |
27 | * It will **not** participate in any Spring transactions.
28 | * If the `SqlSession` is using a `DataSource` that is also being used by a Spring transaction manager and there is currently a transaction in progress, this code will throw an exception.
29 | * MyBatis' `DefaultSqlSession` is not thread safe. If you inject it in your beans you will get errors.
30 | * Mappers created using `DefaultSqlSession` are not thread safe either. If you inject them it in your beans you will get errors.
31 | * You must make sure that your `SqlSession`s are **always** closed in a finally block.
32 |
--------------------------------------------------------------------------------
/src/site/ja/markdown/README.md:
--------------------------------------------------------------------------------
1 | # 目次
2 |
3 | このページはGitHub上でドキュメントの目次を表示するため用意したものです。
4 |
5 | > **NOTE:**
6 | >
7 | > リンクはmaven-site-pluginでHTMLに変換することを前提に指定されているため、GitHubでのレンダリングではリンク切れになっているものがあります。
8 |
9 | * [イントロダクション](./index.md)
10 | * [スタートガイド](./getting-started.md)
11 | * [SqlSessionFactoryBean](./factorybean.md)
12 | * [トランザクション](./transactions.md)
13 | * [SqlSessionの利用](./sqlsession.md)
14 | * [Mapperの注入](./mappers.md)
15 | * [Spring Boot](./boot.md)
16 | * [MyBatis APIの利用](./using-api.md)
17 | * [Spring Batch](./batch.md)
18 | * [サンプルコード](./sample.md)
19 |
--------------------------------------------------------------------------------
/src/site/ja/markdown/boot.md:
--------------------------------------------------------------------------------
1 |
2 | # Using Spring Boot
3 |
4 | 詳細は [MyBatis Spring-boot-starter](http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure) のドキュメントを参照してください。
5 |
--------------------------------------------------------------------------------
/src/site/ja/markdown/using-api.md:
--------------------------------------------------------------------------------
1 |
2 | # MyBatis API の使用
3 |
4 | MyBatis-Spring を使っている場合でも、直接 MyBatis API を呼び出すことができます。
5 | Spring の設定で `SqlSessionFactoryBean` を使って `SqlSessionFactory` を生成すれば、コード内で使用することができます。
6 |
7 | ```java
8 | public class UserDaoImpl implements UserDao {
9 | // SqlSessionFactory would normally be set by SqlSessionDaoSupport
10 | private final SqlSessionFactory sqlSessionFactory;
11 |
12 | public UserDaoImpl(SqlSessionFactory sqlSessionFactory) {
13 | this.sqlSessionFactory = sqlSessionFactory;
14 | }
15 |
16 | public User getUser(String userId) {
17 | // note standard MyBatis API usage - opening and closing the session manually
18 | try (SqlSession session = sqlSessionFactory.openSession()) {
19 | return session.selectOne("org.mybatis.spring.sample.mapper.UserMapper.getUser", userId);
20 | }
21 | }
22 | }
23 | ```
24 |
25 | この方法を使う場合は注意が必要です。なぜなら、誤った使い方をすると実行時エラーや、最悪の場合データの不整合といった問題を生じる可能性があるからです。
26 | MyBatis API を直接使用する場合、次のような点に注意してください。
27 |
28 | * API の呼び出しは Spring で管理されているトランザクション内では実行されません。
29 | * `SqlSession` が Spring のトランザクションマネージャーが使っているのと同じ `DataSource` を使っていて、既に進行中のトランザクションが存在している場合、このコードは例外を投げます。
30 | * MyBatis の `DefaultSqlSession` はスレッドセーフではありません。もしあなたの Bean に注入した場合、エラーが発生します。
31 | * `DefaultSqlSession` を使って生成した Mapper もスレッドセーフとはなりません。もしあなたの Bean に注入した場合、エラーが発生します。
32 | * `SqlSession` は常に finally ブロックでクローズする必要があります。
33 |
--------------------------------------------------------------------------------
/src/site/ko/markdown/README.md:
--------------------------------------------------------------------------------
1 | # 목차
2 |
3 | 이 페이지는 GitHub에서 인덱스를 렌더링하기 위한 것입니다.
4 |
5 | > **NOTE:**
6 | >
7 | > 링크 대상은 maven-site-plugin을 사용하여 html로 변환된다는 가정하에 지정되므로 GitHub의 렌더링에서 끊어진 앵커가 있습니다.
8 |
9 | * [소개](./index.md)
10 | * [시작하기](./getting-started.md)
11 | * [SqlSessionFactoryBean](./factorybean.md)
12 | * [트랜잭션](./transactions.md)
13 | * [SqlSession 사용](./sqlsession.md)
14 | * [매퍼 주입](./mappers.md)
15 | * [Spring Boot](./boot.md)
16 | * [MyBatis API 사용](./using-api.md)
17 | * [Spring Batch](./batch.md)
18 | * [샘플 코드](./sample.md)
19 |
--------------------------------------------------------------------------------
/src/site/ko/markdown/boot.md:
--------------------------------------------------------------------------------
1 |
2 | # 스프링 부트 사용하기
3 |
4 | 자세한 내용은 [MyBatis Spring-boot-starter](http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure) 하위 프로젝트 문서를 참조하십시오.
5 |
--------------------------------------------------------------------------------
/src/site/ko/markdown/using-api.md:
--------------------------------------------------------------------------------
1 |
2 | # MyBatis API 사용하기
3 |
4 | MyBatis-Spring 연동 모듈을 사용해도 계속해서 MyBatis API를 직접 사용할 수 있다. `SqlSessionFactoryBean`을 사용해서 스프링에서 `SqlSessionFactory`를 생성하고 팩토리를 사용하면 된다.
5 |
6 | ```java
7 | public class UserDaoImpl implements UserDao {
8 | // SqlSessionFactory would normally be set by SqlSessionDaoSupport
9 | private final SqlSessionFactory sqlSessionFactory;
10 |
11 | public UserDaoImpl(SqlSessionFactory sqlSessionFactory) {
12 | this.sqlSessionFactory = sqlSessionFactory;
13 | }
14 |
15 | public User getUser(String userId) {
16 | // note standard MyBatis API usage - opening and closing the session manually
17 | try (SqlSession session = sqlSessionFactory.openSession()) {
18 | return session.selectOne("org.mybatis.spring.sample.mapper.UserMapper.getUser", userId);
19 | }
20 | }
21 | }
22 | ```
23 |
24 | 이 방법은 **신중히** 사용하자. 왜냐하면 잘못 사용하면 런타임 에러나 데이터 문제 등을 야기할 수 있기 때문이다. API를 직접 사용할 때는 다음의 규칙들에 유의해야 한다.
25 |
26 | * 스프링 트랜잭션에 **속하지 않고** 별도의 트랜잭션에서 동작한다.
27 | * `SqlSession`이 스프링 트랜잭션 관리자가 사용하는 `DataSource`를 사용하고 이미 트랜잭션이 동작하고 있다면 이 코드는 예외를 **발생시킬 것이다**.
28 | * 마이바티스의 `DefaultSqlSession`은 쓰레드에 안전하지 않다. 빈에 이 객체를 주입하면 아마도 에러를 **발생시킬 수 있다**.
29 | * `DefaultSqlSession`을 사용해서 생성한 매퍼 또한 쓰레드에 안전하지 않다. 이렇게 만든 매퍼를 빈에 주입하면 에러를 **발생시킬 수 있다**.
30 | * `SqlSession`은 **항상** 마지막에 `close()` 메서드를 호출해야 한다.
31 |
--------------------------------------------------------------------------------
/src/site/markdown/README.md:
--------------------------------------------------------------------------------
1 | # Table of contents
2 |
3 | This page is for rendering index on GitHub.
4 |
5 | > **NOTE:**
6 | >
7 | > Since the link destination is specified on the assumption that it is converted to html with maven-site-plugin, there is an anchor that is broken in the rendering on GitHub.
8 |
9 | * [Introduction](./index.md)
10 | * [Getting Started](./getting-started.md)
11 | * [SqlSessionFactoryBean](./factorybean.md)
12 | * [Transactions](./transactions.md)
13 | * [Using an SqlSession](./sqlsession.md)
14 | * [Injecting Mappers](./mappers.md)
15 | * [Spring Boot](./boot.md)
16 | * [Using the MyBatis API](./using-api.md)
17 | * [Spring Batch](./batch.md)
18 | * [Sample Code](./sample.md)
19 |
--------------------------------------------------------------------------------
/src/site/markdown/boot.md:
--------------------------------------------------------------------------------
1 |
2 | # Using Spring Boot
3 |
4 | Please see the [MyBatis Spring-boot-starter](http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure) sub project docs for details.
5 |
--------------------------------------------------------------------------------
/src/site/markdown/using-api.md:
--------------------------------------------------------------------------------
1 |
2 | # Using the MyBatis API
3 |
4 | With MyBatis-Spring, you can continue to directly use the MyBatis API. Simply create an `SqlSessionFactory` in Spring using `SqlSessionFactoryBean` and use the factory in your code.
5 |
6 | ```java
7 | public class UserDaoImpl implements UserDao {
8 | // SqlSessionFactory would normally be set by SqlSessionDaoSupport
9 | private final SqlSessionFactory sqlSessionFactory;
10 |
11 | public UserDaoImpl(SqlSessionFactory sqlSessionFactory) {
12 | this.sqlSessionFactory = sqlSessionFactory;
13 | }
14 |
15 | public User getUser(String userId) {
16 | // note standard MyBatis API usage - opening and closing the session manually
17 | try (SqlSession session = sqlSessionFactory.openSession()) {
18 | return session.selectOne("org.mybatis.spring.sample.mapper.UserMapper.getUser", userId);
19 | }
20 | }
21 | }
22 | ```
23 |
24 | Use this option with care because wrong usage may produce runtime errors or worse, data integrity problems. Be aware of the following caveats with direct API usage:
25 |
26 | * It will **not** participate in any Spring transactions.
27 | * If the `SqlSession` is using a `DataSource` that is also being used by a Spring transaction manager and there is currently a transaction in progress, this code **will** throw an exception.
28 | * MyBatis' `DefaultSqlSession` is not thread safe. If you inject it in your beans you **will** get errors.
29 | * Mappers created using `DefaultSqlSession` are not thread safe either. If you inject them it in your beans you **will** get errors.
30 | * You must make sure that your `SqlSession`s are **always** closed in a finally block.
31 |
--------------------------------------------------------------------------------
/src/site/resources/css/site.css:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2010-2022 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 | /*
17 | * when new flags are needed, take them from
18 | *
19 | * https://www.printableworldflags.com/flag-icon
20 | *
21 | * that are free for any kind of usage
22 | */
23 |
24 | ul.i18n {list-style-type:none;}
25 | li.en {background: url('../images/en.png') left no-repeat;padding-left: 32px; margin: 10px}
26 | li.es {background: url('../images/es.png') left no-repeat;padding-left: 32px; margin: 10px}
27 | li.ja {background: url('../images/ja.png') left no-repeat;padding-left: 32px; margin: 10px}
28 | li.zh {background: url('../images/zh.png') left no-repeat;padding-left: 32px; margin: 10px}
29 | li.ko {background: url('../images/ko.png') left no-repeat;padding-left: 32px; margin: 10px}
30 |
--------------------------------------------------------------------------------
/src/site/resources/es/css/site.css:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2010-2022 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 | /*
17 | * when new flags are needed, take them from
18 | *
19 | * https://www.printableworldflags.com/flag-icon
20 | *
21 | * that are free for any kind of usage
22 | */
23 |
24 | ul.i18n {list-style-type:none;}
25 | li.en {background: url('../../images/en.png') left no-repeat;padding-left: 32px; margin: 10px}
26 | li.es {background: url('../../images/es.png') left no-repeat;padding-left: 32px; margin: 10px}
27 | li.ja {background: url('../../images/ja.png') left no-repeat;padding-left: 32px; margin: 10px}
28 | li.zh {background: url('../../images/zh.png') left no-repeat;padding-left: 32px; margin: 10px}
29 | li.ko {background: url('../../images/ko.png') left no-repeat;padding-left: 32px; margin: 10px}
30 |
--------------------------------------------------------------------------------
/src/site/resources/images/en.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mybatis/spring/b651950b198e784aad926a37aa7b0b1a6f61a5e1/src/site/resources/images/en.png
--------------------------------------------------------------------------------
/src/site/resources/images/es.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mybatis/spring/b651950b198e784aad926a37aa7b0b1a6f61a5e1/src/site/resources/images/es.png
--------------------------------------------------------------------------------
/src/site/resources/images/ja.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mybatis/spring/b651950b198e784aad926a37aa7b0b1a6f61a5e1/src/site/resources/images/ja.png
--------------------------------------------------------------------------------
/src/site/resources/images/ko.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mybatis/spring/b651950b198e784aad926a37aa7b0b1a6f61a5e1/src/site/resources/images/ko.png
--------------------------------------------------------------------------------
/src/site/resources/images/zh.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mybatis/spring/b651950b198e784aad926a37aa7b0b1a6f61a5e1/src/site/resources/images/zh.png
--------------------------------------------------------------------------------
/src/site/resources/ja/css/site.css:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2010-2022 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 | /*
17 | * when new flags are needed, take them from
18 | *
19 | * https://www.printableworldflags.com/flag-icon
20 | *
21 | * that are free for any kind of usage
22 | */
23 |
24 | ul.i18n {list-style-type:none;}
25 | li.en {background: url('../../images/en.png') left no-repeat;padding-left: 32px; margin: 10px}
26 | li.es {background: url('../../images/es.png') left no-repeat;padding-left: 32px; margin: 10px}
27 | li.ja {background: url('../../images/ja.png') left no-repeat;padding-left: 32px; margin: 10px}
28 | li.zh {background: url('../../images/zh.png') left no-repeat;padding-left: 32px; margin: 10px}
29 | li.ko {background: url('../../images/ko.png') left no-repeat;padding-left: 32px; margin: 10px}
30 |
--------------------------------------------------------------------------------
/src/site/resources/ko/css/site.css:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2010-2022 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 | /*
17 | * when new flags are needed, take them from
18 | *
19 | * https://www.printableworldflags.com/flag-icon
20 | *
21 | * that are free for any kind of usage
22 | */
23 |
24 | ul.i18n {list-style-type:none;}
25 | li.en {background: url('../../images/en.png') left no-repeat;padding-left: 32px; margin: 10px}
26 | li.es {background: url('../../images/es.png') left no-repeat;padding-left: 32px; margin: 10px}
27 | li.ja {background: url('../../images/ja.png') left no-repeat;padding-left: 32px; margin: 10px}
28 | li.zh {background: url('../../images/zh.png') left no-repeat;padding-left: 32px; margin: 10px}
29 | li.ko {background: url('../../images/ko.png') left no-repeat;padding-left: 32px; margin: 10px}
30 |
--------------------------------------------------------------------------------
/src/site/resources/zh_CN/css/site.css:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2010-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 | /*
17 | * when new flags are needed, take them from
18 | *
19 | * https://www.printableworldflags.com/flag-icon
20 | *
21 | * that are free for any kind of usage
22 | */
23 |
24 | ul.i18n {list-style-type:none;}
25 | li.en {background: url('../../images/en.png') left no-repeat;padding-left: 32px; margin: 10px}
26 | li.es {background: url('../../images/es.png') left no-repeat;padding-left: 32px; margin: 10px}
27 | li.ja {background: url('../../images/ja.png') left no-repeat;padding-left: 32px; margin: 10px}
28 | li.zh {background: url('../../images/zh.png') left no-repeat;padding-left: 32px; margin: 10px}
29 | li.ko {background: url('../../images/ko.png') left no-repeat;padding-left: 32px; margin: 10px}
30 |
--------------------------------------------------------------------------------
/src/site/zh_CN/markdown/README.md:
--------------------------------------------------------------------------------
1 | # 目录
2 |
3 | 此页面用于在GitHub上呈现索引。
4 |
5 | > **NOTE:**
6 | >
7 | > 由于链接目标是在使用maven-site-plugin转换为html的假设下指定的,因此在GitHub上的呈现中有一个锚点已损坏。
8 |
9 | * [简介](./index.md)
10 | * [入门](./getting-started.md)
11 | * [SqlSessionFactoryBean](./factorybean.md)
12 | * [事务](./transactions.md)
13 | * [使用 SqlSession](./sqlsession.md)
14 | * [注入映射器](./mappers.md)
15 | * [Spring Boot](./boot.md)
16 | * [使用 MyBatis API](./using-api.md)
17 | * [Spring Batch](./batch.md)
18 | * [示例代码](./sample.md)
19 |
--------------------------------------------------------------------------------
/src/site/zh_CN/markdown/boot.md:
--------------------------------------------------------------------------------
1 |
2 | # 搭配 Spring Boot
3 |
4 | 请查看 [MyBatis Spring-boot-starter](http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure) 子项目获取更多信息。
5 |
--------------------------------------------------------------------------------
/src/site/zh_CN/markdown/sample.md:
--------------------------------------------------------------------------------
1 |
2 | # 示例代码
3 |
4 | 提示
5 | 查看 [JPetstore 6 demo](https://github.com/mybatis/jpetstore-6) 了解如何在完整的 Web 应用服务器上使用 Spring。
6 |
7 | 您可以在 MyBatis-Spring 的 [代码仓库](https://github.com/mybatis/spring/tree/master/src/test/java/org/mybatis/spring/sample) 中查看示例代码:
8 |
9 | 所有示例都能在 JUnit 5 下运行。
10 |
11 | 示例代码演示了事务服务从数据访问层获取域对象的典型设计。
12 |
13 | `FooService.java` 作为服务:
14 |
15 | ```java
16 | @Transactional
17 | public class FooService {
18 |
19 | private final UserMapper userMapper;
20 |
21 | public FooService(UserMapper userMapper) {
22 | this.userMapper = userMapper;
23 | }
24 |
25 | public User doSomeBusinessStuff(String userId) {
26 | return this.userMapper.getUser(userId);
27 | }
28 |
29 | }
30 | ```
31 |
32 | 它是一个事务 bean,所以当调用它的任何方法时,事务被启动,在方法结束且没有抛出任何未经检查的异常的时候事务将会被提交。注意,事务的行为可以通过 `@Transactional` 的属性进行配置。这不是必需的;你可以使用 Spring 提供的任何其他方式来划分你的事务范围。
33 |
34 | 此服务调用使用 MyBatis 构建的数据访问层.。该层只包含一个接口,`UserMapper.java`,这将被 MyBatis 构建的动态代理使用,在运行时通过 Spring 注入到服务之中。
35 |
36 | ```java
37 | public interface UserMapper {
38 |
39 | User getUser(String userId);
40 |
41 | }
42 | ```
43 |
44 | 注意,为了简单起见,我们使用了接口 `UserMapper.java`。在使用 DAO 的场景中,一个 DAO 类应该分为一个接口和一个实现类。回到这个例子里,准确来说,这个接口应该叫 `UserDao.java` 。
45 |
46 | 我们将看到不同的方法来发现映射器接口,将其注册到 Spring 并将其注入到服务 bean 中:
47 |
48 | ## 测试场景
49 |
50 | | 样例测试 | 描述 |
51 | | --- | --- |
52 | | `SampleMapperTest.java` | 演示基于 `MapperFactoryBean` 的基本配置,这将动态构建 `UserMapper` 的一个实现。 |
53 | | `SampleScannerTest.java` | 演示如何使用 `MapperScannerConfigurer` 来自动发现项目中所有的映射器。 |
54 | | `SampleSqlSessionTest.java` | 演示如何基于 Spring 管理的 `SqlSession` 手动编写 DAO,并在 `UserDaoImpl.java` 中提供你自己的实现。 |
55 | | `SampleEnableTest.java` | 演示如何使用 Spring 的 `@Configuration` 和 `@MapperScann` 注解来自动发现 mappers. |
56 | | `SampleNamespaceTest.java` | 演示如何使用自定义 MyBatis XML 命名空间. |
57 | | `SampleJavaConfigTest.java` | 演示如何基于 Spring 的 `@Configuration` 来手工创建 MyBatis 的 bean。 |
58 | | `SampleJobJavaConfigTest.java` | 演示如何在 Java 配置中使用 Spring Batch 中的 `ItemReader` 和 `ItemWriter`。 |
59 | | `SampleJobXmlConfigTest.java` | 演示如何在 XML 配置中使用 Spring Batch 中的 `ItemReader` 和 `ItemWriter`。 |
60 |
61 | 查看不同的 `applicationContext.xml` 文件以了解 MyBatis-Spring 在实践中是如何运用的。
62 |
63 |
--------------------------------------------------------------------------------
/src/site/zh_CN/markdown/using-api.md:
--------------------------------------------------------------------------------
1 |
2 | # 使用 MyBatis API
3 |
4 | 使用 MyBatis-Spring,你可以继续直接使用 MyBatis 的 API。只需简单地使用 `SqlSessionFactoryBean` 在 Spring 中创建一个 `SqlSessionFactory`,然后按你的方式在代码中使用工厂即可。
5 |
6 | ```java
7 | public class UserDaoImpl implements UserDao {
8 | // SqlSessionFactory 一般会由 SqlSessionDaoSupport 进行设置
9 | private final SqlSessionFactory sqlSessionFactory;
10 |
11 | public UserDaoImpl(SqlSessionFactory sqlSessionFactory) {
12 | this.sqlSessionFactory = sqlSessionFactory;
13 | }
14 |
15 | public User getUser(String userId) {
16 | // 注意对标准 MyBatis API 的使用 - 手工打开和关闭 session
17 | try (SqlSession session = sqlSessionFactory.openSession()) {
18 | return session.selectOne("org.mybatis.spring.sample.mapper.UserMapper.getUser", userId);
19 | }
20 | }
21 | }
22 | ```
23 |
24 | **小心使用**此选项,错误地使用会产生运行时错误,更糟糕地,会产生数据一致性的问题。直接使用 API 时,注意以下弊端:
25 |
26 | * 它不会参与到 Spring 的事务管理之中。
27 | * 如果 `SqlSession` 使用与 Spring 事务管理器使用的相同 `DataSource`,并且有进行中的事务,代码**将**会抛出异常。
28 | * MyBatis 的 `DefaultSqlSession` 是线程不安全的。如果在 bean 中注入了它,**将**会发生错误。
29 | * 使用 `DefaultSqlSession` 创建的映射器也不是线程安全的。如果你将它们注入到 bean 中,**将**会发生错误。
30 | * 你必须确保总是在 finally 块中来关闭 `SqlSession`。
31 |
--------------------------------------------------------------------------------
/src/test/java/org/mybatis/core/jdk/type/AtomicNumberTypeHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2022 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.mybatis.core.jdk.type;
17 |
18 | import java.sql.CallableStatement;
19 | import java.sql.PreparedStatement;
20 | import java.sql.ResultSet;
21 | import java.sql.SQLException;
22 | import java.util.concurrent.atomic.AtomicInteger;
23 | import java.util.concurrent.atomic.AtomicLong;
24 |
25 | import org.apache.ibatis.type.JdbcType;
26 | import org.apache.ibatis.type.MappedTypes;
27 | import org.apache.ibatis.type.TypeHandler;
28 |
29 | @MappedTypes({ AtomicInteger.class, AtomicLong.class })
30 | public class AtomicNumberTypeHandler implements TypeHandler {
31 |
32 | public AtomicNumberTypeHandler(Class> type) {
33 | }
34 |
35 | @Override
36 | public void setParameter(PreparedStatement ps, int i, Number parameter, JdbcType jdbcType) throws SQLException {
37 | }
38 |
39 | @Override
40 | public Number getResult(ResultSet rs, String columnName) throws SQLException {
41 | return null;
42 | }
43 |
44 | @Override
45 | public Number getResult(CallableStatement cs, int columnIndex) throws SQLException {
46 | return null;
47 | }
48 |
49 | @Override
50 | public Number getResult(ResultSet rs, int columnIndex) throws SQLException {
51 | return null;
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/src/test/java/org/mybatis/spring/PooledMockDataSource.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-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.mybatis.spring;
17 |
18 | import com.mockrunner.mock.jdbc.MockDataSource;
19 |
20 | import java.sql.Connection;
21 | import java.sql.SQLException;
22 | import java.util.LinkedList;
23 |
24 | final class PooledMockDataSource extends MockDataSource {
25 |
26 | private int connectionCount = 0;
27 |
28 | private LinkedList connections = new LinkedList<>();
29 |
30 | @Override
31 | public Connection getConnection() throws SQLException {
32 | if (connections.isEmpty()) {
33 | throw new SQLException("Sorry, I ran out of connections");
34 | }
35 | ++this.connectionCount;
36 | return this.connections.removeLast();
37 | }
38 |
39 | int getConnectionCount() {
40 | return this.connectionCount;
41 | }
42 |
43 | void reset() {
44 | this.connectionCount = 0;
45 | this.connections.clear();
46 | }
47 |
48 | @Override
49 | public void setupConnection(Connection connection) {
50 | throw new UnsupportedOperationException("used addConnection() instead");
51 | }
52 |
53 | public void addConnection(Connection c) {
54 | this.connections.add(c);
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/src/test/java/org/mybatis/spring/TestMapper.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-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.mybatis.spring;
17 |
18 | public interface TestMapper {
19 |
20 | int findTest();
21 |
22 | void insertTest(String test);
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/test/java/org/mybatis/spring/annotation/MyBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-2023 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.mybatis.spring.annotation;
17 |
18 | public class MyBean {
19 | private String id;
20 | private String name;
21 |
22 | public MyBean(String id) {
23 | this.id = id;
24 | }
25 |
26 | public String getId() {
27 | return id;
28 | }
29 |
30 | public void setName(String name) {
31 | this.name = name;
32 | }
33 |
34 | public String getName() {
35 | return name;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/test/java/org/mybatis/spring/annotation/factory/SimpleFactoryBean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2010-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.mybatis.spring.annotation.factory;
17 |
18 | import org.springframework.beans.factory.FactoryBean;
19 | import org.springframework.beans.factory.annotation.Autowired;
20 | import org.springframework.context.ApplicationContext;
21 | import org.springframework.stereotype.Component;
22 |
23 | @Component
24 | public class SimpleFactoryBean implements FactoryBean