Skip to content

Commit 67b6d10

Browse files
committed
Merge branch 'master' of github.com:mybatis/mybatis-3 into dev
2 parents 96f5f19 + e3eaef7 commit 67b6d10

File tree

19 files changed

+343
-16
lines changed

19 files changed

+343
-16
lines changed

.github/dependabot.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: maven
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
open-pull-requests-limit: 10
8+
labels:
9+
- dependencies
10+
ignore:
11+
- dependency-name: org.apache.derby:derby
12+
versions:
13+
- "> 10.14.2.0"

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
language: java
22

33
jdk:
4-
# JDK15 is blocked due to maven-bundle-plugin and underlying bnd (see https://issues.apache.org/jira/browse/FELIX-6259)
5-
#- openjdk15
4+
- openjdk15
65
- openjdk14
76
- openjdk13
87
- openjdk11

pom.xml

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
<parent>
2323
<groupId>org.mybatis</groupId>
2424
<artifactId>mybatis-parent</artifactId>
25-
<version>31</version>
25+
<version>32-SNAPSHOT</version>
2626
<relativePath />
2727
</parent>
2828

2929
<artifactId>mybatis</artifactId>
30-
<version>3.5.5-SNAPSHOT</version>
30+
<version>3.5.6-SNAPSHOT</version>
3131
<packaging>jar</packaging>
3232

3333
<name>mybatis</name>
@@ -206,7 +206,7 @@
206206
<dependency>
207207
<groupId>org.hsqldb</groupId>
208208
<artifactId>hsqldb</artifactId>
209-
<version>2.5.0</version>
209+
<version>2.5.1</version>
210210
<scope>test</scope>
211211
</dependency>
212212
<dependency> <!-- 10.15+ need Java 9+ -->
@@ -243,7 +243,7 @@
243243
<dependency>
244244
<groupId>org.postgresql</groupId>
245245
<artifactId>postgresql</artifactId>
246-
<version>42.2.12</version>
246+
<version>42.2.14</version>
247247
<scope>test</scope>
248248
</dependency>
249249
<dependency>
@@ -267,19 +267,19 @@
267267
<dependency>
268268
<groupId>org.testcontainers</groupId>
269269
<artifactId>junit-jupiter</artifactId>
270-
<version>1.14.2</version>
270+
<version>1.14.3</version>
271271
<scope>test</scope>
272272
</dependency>
273273
<dependency>
274274
<groupId>org.testcontainers</groupId>
275275
<artifactId>postgresql</artifactId>
276-
<version>1.14.2</version>
276+
<version>1.14.3</version>
277277
<scope>test</scope>
278278
</dependency>
279279
<dependency>
280280
<groupId>org.testcontainers</groupId>
281281
<artifactId>mysql</artifactId>
282-
<version>1.14.2</version>
282+
<version>1.14.3</version>
283283
<scope>test</scope>
284284
</dependency>
285285
</dependencies>
@@ -406,4 +406,13 @@
406406
</profile>
407407
</profiles>
408408

409+
<!-- Will remove after released mybatis-parent 32+ (See https://github.com/mybatis/mybatis-3/issues/1926) -->
410+
<repositories>
411+
<repository>
412+
<id>sonatype-oss-snapshots</id>
413+
<name>Sonatype OSS Snapshots Repository</name>
414+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
415+
</repository>
416+
</repositories>
417+
409418
</project>

src/main/java/org/apache/ibatis/builder/annotation/ProviderSqlSource.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public ProviderSqlSource(Configuration configuration, Annotation provider, Class
100100
this.mapperMethod = mapperMethod;
101101
Lang lang = mapperMethod == null ? null : mapperMethod.getAnnotation(Lang.class);
102102
this.languageDriver = configuration.getLanguageDriver(lang == null ? null : lang.value());
103-
this.providerType = getProviderType(provider, mapperMethod);
103+
this.providerType = getProviderType(configuration, provider, mapperMethod);
104104
candidateProviderMethodName = (String) provider.annotationType().getMethod("method").invoke(provider);
105105

106106
if (candidateProviderMethodName.length() == 0 && ProviderMethodResolver.class.isAssignableFrom(this.providerType)) {
@@ -235,11 +235,14 @@ private String invokeProviderMethod(Object... args) throws Exception {
235235
return sql != null ? sql.toString() : null;
236236
}
237237

238-
private Class<?> getProviderType(Annotation providerAnnotation, Method mapperMethod)
238+
private Class<?> getProviderType(Configuration configuration, Annotation providerAnnotation, Method mapperMethod)
239239
throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
240240
Class<?> type = (Class<?>) providerAnnotation.annotationType().getMethod("type").invoke(providerAnnotation);
241241
Class<?> value = (Class<?>) providerAnnotation.annotationType().getMethod("value").invoke(providerAnnotation);
242242
if (value == void.class && type == void.class) {
243+
if (configuration.getDefaultSqlProviderType() != null) {
244+
return configuration.getDefaultSqlProviderType();
245+
}
243246
throw new BuilderException("Please specify either 'value' or 'type' attribute of @"
244247
+ providerAnnotation.annotationType().getSimpleName()
245248
+ " at the '" + mapperMethod.toString() + "'.");

src/main/java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ private void settingsElement(Properties props) {
269269
configuration.setLogPrefix(props.getProperty("logPrefix"));
270270
configuration.setConfigurationFactory(resolveClass(props.getProperty("configurationFactory")));
271271
configuration.setShrinkWhitespacesInSql(booleanValueOf(props.getProperty("shrinkWhitespacesInSql"), false));
272+
configuration.setDefaultSqlProviderType(resolveClass(props.getProperty("defaultSqlProviderType")));
272273
}
273274

274275
private void environmentsElement(XNode context) throws Exception {

src/main/java/org/apache/ibatis/session/Configuration.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ public class Configuration {
118118
protected String logPrefix;
119119
protected Class<? extends Log> logImpl;
120120
protected Class<? extends VFS> vfsImpl;
121+
protected Class<?> defaultSqlProviderType;
121122
protected LocalCacheScope localCacheScope = LocalCacheScope.SESSION;
122123
protected JdbcType jdbcTypeForNull = JdbcType.OTHER;
123124
protected Set<String> lazyLoadTriggerMethods = new HashSet<>(Arrays.asList("equals", "clone", "hashCode", "toString"));
@@ -243,6 +244,27 @@ public void setVfsImpl(Class<? extends VFS> vfsImpl) {
243244
}
244245
}
245246

247+
/**
248+
* Gets an applying type when omit a type on sql provider annotation(e.g. {@link org.apache.ibatis.annotations.SelectProvider}).
249+
*
250+
* @return the default type for sql provider annotation
251+
* @since 3.5.6
252+
*/
253+
public Class<?> getDefaultSqlProviderType() {
254+
return defaultSqlProviderType;
255+
}
256+
257+
/**
258+
* Sets an applying type when omit a type on sql provider annotation(e.g. {@link org.apache.ibatis.annotations.SelectProvider}).
259+
*
260+
* @param defaultSqlProviderType
261+
* the default type for sql provider annotation
262+
* @since 3.5.6
263+
*/
264+
public void setDefaultSqlProviderType(Class<?> defaultSqlProviderType) {
265+
this.defaultSqlProviderType = defaultSqlProviderType;
266+
}
267+
246268
public boolean isCallSettersOnNulls() {
247269
return callSettersOnNulls;
248270
}

src/site/es/xdoc/configuration.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,22 @@ SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, environ
561561
false
562562
</td>
563563
</tr>
564+
<tr>
565+
<td>
566+
defaultSqlProviderType
567+
</td>
568+
<td>
569+
Specifies an sql provider class that holds provider method (Since 3.5.6).
570+
This class apply to the <code>type</code>(or <code>value</code>) attribute on sql provider annotation(e.g. <code>@SelectProvider</code>),
571+
when these attribute was omitted.
572+
</td>
573+
<td>
574+
A type alias or fully qualified class name
575+
</td>
576+
<td>
577+
Not set
578+
</td>
579+
</tr>
564580
</tbody>
565581
</table>
566582
<p>

src/site/es/xdoc/java-api.xml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ void rollback(boolean force)</source>
480480
via the <code>ProviderContext</code>(available since MyBatis 3.4.5 or later) as method argument.(In MyBatis 3.4 or later, it's allow multiple parameters)
481481
Atributos: value, type y method.
482482
El atributo value y type es el nombre completamente cualificado de una clase
483-
(The <code>type</code> attribute is alias for <code>value</code>, you must be specify either one).
483+
(The <code>type</code> attribute is alias for <code>value</code>, you must be specify either one.
484+
But both attributes can be omit when specify the <code>defaultSqlProviderType</code> as global configuration).
484485
El method es el nombre un método de dicha clase
485486
(Since 3.5.1, you can omit <code>method</code> attribute, the MyBatis will resolve a target method via the
486487
<code>ProviderMethodResolver</code> interface.
@@ -635,6 +636,29 @@ class UserSqlProvider implements ProviderMethodResolver {
635636
}
636637
}]]></source>
637638

639+
<p>This example shows usage that share an sql provider class to all mapper methods using global configuration(Available since 3.5.6):</p>
640+
<source><![CDATA[
641+
Configuration configuration = new Configuration();
642+
configuration.setDefaultSqlProviderType(TemplateFilePathProvider.class); // Specify an sql provider class for sharing on all mapper methods
643+
// ...]]></source>
644+
<source><![CDATA[
645+
// Can omit the type/value attribute on sql provider annotation
646+
// If omit it, the MyBatis apply the class that specified on defaultSqlProviderType.
647+
public interface UserMapper {
648+
649+
@SelectProvider // Same with @SelectProvider(TemplateFilePathProvider.class)
650+
User findUser(int id);
651+
652+
@InsertProvider // Same with @InsertProvider(TemplateFilePathProvider.class)
653+
void createUser(User user);
654+
655+
@UpdateProvider // Same with @UpdateProvider(TemplateFilePathProvider.class)
656+
void updateUser(User user);
657+
658+
@DeleteProvider // Same with @DeleteProvider(TemplateFilePathProvider.class)
659+
void deleteUser(int id);
660+
}]]></source>
661+
638662
<p>This example shows usage the default implementation of <code>ProviderMethodResolver</code>(available since MyBatis 3.5.1 or later):</p>
639663
<source><![CDATA[@SelectProvider(UserSqlProvider.class)
640664
List<User> getUsersByName(String name);

src/site/ja/xdoc/configuration.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,21 @@ SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, environ
586586
false
587587
</td>
588588
</tr>
589+
<tr>
590+
<td>
591+
defaultSqlProviderType
592+
</td>
593+
<td>
594+
SQLを提供するメソッドを保持するSQLプロバイダクラスを指定します(導入されたバージョン: 3.5.6)。
595+
ここで指定したクラスは、SQLプロバイダアノテーション(例: <code>@SelectProvider</code>)の<code>type</code>(または <code>value</code>) 属性を省略した際に適用されます。
596+
</td>
597+
<td>
598+
タイプエイリアスまたは完全修飾クラス名
599+
</td>
600+
<td>
601+
未指定
602+
</td>
603+
</tr>
589604
</tbody>
590605
</table>
591606
<p>

src/site/ja/xdoc/java-api.xml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,8 @@ void rollback(boolean force)</source>
491491
なお、メソッド引数にはMapperメソッドの引数に渡したオブジェクトに加え、<code>ProviderContext</code>(MyBatis 3.4.5以降で利用可能)を介して「Mapperインタフェースの型」「Mapperメソッド」「データベースID」を渡すことができます。(MyBatis 3.4以降では、複数の引数を渡すことができます)
492492
キー: <code>value</code>, <code>type</code>, <code>method</code>.
493493
<code>value</code> と <code>type</code> にはクラスオブジェクトを指定します
494-
(<code>type</code> は <code>value</code> の別名で、どちらか一方を指定する必要があります)。
494+
(<code>type</code> は <code>value</code> の別名で、どちらか一方を指定する必要があります。
495+
ただし、グローバル設定として<code>defaultSqlProviderType</code>を指定している場合は両方とも省略することができます)。
495496
<code>method</code> にはメソッド名を指定します
496497
(MyBatis 3.5.1以降では、<code>method</code> 属性を省略することができます。その際MyBatisは、<code>ProviderMethodResolver</code> インタフェースを介して対象メソッドの解決を試み、
497498
対象メソッドが解決できない場合は、<code>provideSql</code>という名前のメソッドを代替メソッドとして利用します)。
@@ -619,6 +620,29 @@ class UserSqlBuilder {
619620
}
620621
}]]></source>
621622

623+
<p>次のコードは、グローバル設定を利用して全てのマッパーメソッドで同じSQLプロバイダクラスを利用する例です。(3.5.6以降で利用可能)</p>
624+
<source><![CDATA[
625+
Configuration configuration = new Configuration();
626+
configuration.setDefaultSqlProviderType(TemplateFilePathProvider.class); // 全てのマッパーメソッドで利用するSQLプロバイダクラスを指定する
627+
// ...]]></source>
628+
<source><![CDATA[
629+
// 各メソッドのSQLプロバイダアノテーションの type または value 属性は省略することができ、
630+
// 省略した場合はMyBaitsはグローバル設定の defaultSqlProviderType に指定されているクラスを適用する
631+
public interface UserMapper {
632+
633+
@SelectProvider // @SelectProvider(TemplateFilePathProvider.class) と同義
634+
User findUser(int id);
635+
636+
@InsertProvider // @InsertProvider(TemplateFilePathProvider.class) と同義
637+
void createUser(User user);
638+
639+
@UpdateProvider // @UpdateProvider(TemplateFilePathProvider.class) と同義
640+
void updateUser(User user);
641+
642+
@DeleteProvider // @DeleteProvider(TemplateFilePathProvider.class) と同義
643+
void deleteUser(int id);
644+
}]]></source>
645+
622646
<p>次のコードは、<code>ProviderMethodResolver</code>(MyBatis 3.5.1以降で利用可能)のデフォルト実装の利用例です。</p>
623647
<source><![CDATA[@SelectProvider(UserSqlProvider.class)
624648
List<User> getUsersByName(String name);

0 commit comments

Comments
 (0)