Skip to content

Commit f98140c

Browse files
committed
Supports the statement switching feature that correspond database on the annotation driven mapper
Add databaseId attribute on following annotations * Select * SelectProvider * Insert * InsertProvider * Update * UpdateProvider * Delete * DeleteProvider * SelectKey * Options
1 parent fd49061 commit f98140c

25 files changed

+1547
-70
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@
212212
<version>10.14.2.0</version>
213213
<scope>test</scope>
214214
</dependency>
215+
<dependency>
216+
<groupId>com.h2database</groupId>
217+
<artifactId>h2</artifactId>
218+
<version>1.4.197</version>
219+
<scope>test</scope>
220+
</dependency>
215221
<dependency>
216222
<groupId>org.mockito</groupId>
217223
<artifactId>mockito-core</artifactId>

src/main/java/org/apache/ibatis/annotations/Delete.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2016 the original author or authors.
2+
* Copyright 2009-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,8 +15,12 @@
1515
*/
1616
package org.apache.ibatis.annotations;
1717

18+
import org.apache.ibatis.builder.annotation.StatementAnnotationMetadata;
19+
import org.apache.ibatis.mapping.SqlCommandType;
20+
1821
import java.lang.annotation.Documented;
1922
import java.lang.annotation.ElementType;
23+
import java.lang.annotation.Repeatable;
2024
import java.lang.annotation.Retention;
2125
import java.lang.annotation.RetentionPolicy;
2226
import java.lang.annotation.Target;
@@ -27,6 +31,28 @@
2731
@Documented
2832
@Retention(RetentionPolicy.RUNTIME)
2933
@Target(ElementType.METHOD)
34+
@Repeatable(Delete.List.class)
35+
@StatementAnnotationMetadata(commandType = SqlCommandType.DELETE)
3036
public @interface Delete {
3137
String[] value();
38+
39+
/**
40+
* @return A database id that correspond this statement
41+
* @since 3.5.1
42+
*/
43+
String databaseId() default "";
44+
45+
/**
46+
* The container annotation for {@link Delete}.
47+
* @author Kazuki Shimizu
48+
* @since 3.5.1
49+
*/
50+
@Documented
51+
@Retention(RetentionPolicy.RUNTIME)
52+
@Target(ElementType.METHOD)
53+
@StatementAnnotationMetadata(commandType = SqlCommandType.DELETE)
54+
@interface List {
55+
Delete[] value();
56+
}
57+
3258
}

src/main/java/org/apache/ibatis/annotations/DeleteProvider.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
*/
1616
package org.apache.ibatis.annotations;
1717

18+
import org.apache.ibatis.builder.annotation.StatementAnnotationMetadata;
19+
import org.apache.ibatis.mapping.SqlCommandType;
20+
1821
import java.lang.annotation.Documented;
1922
import java.lang.annotation.ElementType;
23+
import java.lang.annotation.Repeatable;
2024
import java.lang.annotation.Retention;
2125
import java.lang.annotation.RetentionPolicy;
2226
import java.lang.annotation.Target;
@@ -27,6 +31,8 @@
2731
@Documented
2832
@Retention(RetentionPolicy.RUNTIME)
2933
@Target(ElementType.METHOD)
34+
@Repeatable(DeleteProvider.List.class)
35+
@StatementAnnotationMetadata(commandType = SqlCommandType.DELETE)
3036
public @interface DeleteProvider {
3137

3238
/**
@@ -57,4 +63,23 @@
5763
*/
5864
String method() default "";
5965

66+
/**
67+
* @return A database id that correspond this provider
68+
* @since 3.5.1
69+
*/
70+
String databaseId() default "";
71+
72+
/**
73+
* The container annotation for {@link DeleteProvider}.
74+
* @author Kazuki Shimizu
75+
* @since 3.5.1
76+
*/
77+
@Documented
78+
@Retention(RetentionPolicy.RUNTIME)
79+
@Target(ElementType.METHOD)
80+
@StatementAnnotationMetadata(commandType = SqlCommandType.DELETE)
81+
@interface List {
82+
DeleteProvider[] value();
83+
}
84+
6085
}

src/main/java/org/apache/ibatis/annotations/Insert.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2016 the original author or authors.
2+
* Copyright 2009-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,8 +15,12 @@
1515
*/
1616
package org.apache.ibatis.annotations;
1717

18+
import org.apache.ibatis.builder.annotation.StatementAnnotationMetadata;
19+
import org.apache.ibatis.mapping.SqlCommandType;
20+
1821
import java.lang.annotation.Documented;
1922
import java.lang.annotation.ElementType;
23+
import java.lang.annotation.Repeatable;
2024
import java.lang.annotation.Retention;
2125
import java.lang.annotation.RetentionPolicy;
2226
import java.lang.annotation.Target;
@@ -27,6 +31,28 @@
2731
@Documented
2832
@Retention(RetentionPolicy.RUNTIME)
2933
@Target(ElementType.METHOD)
34+
@Repeatable(Insert.List.class)
35+
@StatementAnnotationMetadata(commandType = SqlCommandType.INSERT)
3036
public @interface Insert {
3137
String[] value();
38+
39+
/**
40+
* @return A database id that correspond this statement
41+
* @since 3.5.1
42+
*/
43+
String databaseId() default "";
44+
45+
/**
46+
* The container annotation for {@link Insert}.
47+
* @author Kazuki Shimizu
48+
* @since 3.5.1
49+
*/
50+
@Documented
51+
@Retention(RetentionPolicy.RUNTIME)
52+
@Target(ElementType.METHOD)
53+
@StatementAnnotationMetadata(commandType = SqlCommandType.INSERT)
54+
@interface List {
55+
Insert[] value();
56+
}
57+
3258
}

src/main/java/org/apache/ibatis/annotations/InsertProvider.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
*/
1616
package org.apache.ibatis.annotations;
1717

18+
import org.apache.ibatis.builder.annotation.StatementAnnotationMetadata;
19+
import org.apache.ibatis.mapping.SqlCommandType;
20+
1821
import java.lang.annotation.Documented;
1922
import java.lang.annotation.ElementType;
23+
import java.lang.annotation.Repeatable;
2024
import java.lang.annotation.Retention;
2125
import java.lang.annotation.RetentionPolicy;
2226
import java.lang.annotation.Target;
@@ -27,6 +31,8 @@
2731
@Documented
2832
@Retention(RetentionPolicy.RUNTIME)
2933
@Target(ElementType.METHOD)
34+
@Repeatable(InsertProvider.List.class)
35+
@StatementAnnotationMetadata(commandType = SqlCommandType.INSERT)
3036
public @interface InsertProvider {
3137

3238
/**
@@ -57,4 +63,23 @@
5763
*/
5864
String method() default "";
5965

66+
/**
67+
* @return A database id that correspond this provider
68+
* @since 3.5.1
69+
*/
70+
String databaseId() default "";
71+
72+
/**
73+
* The container annotation for {@link InsertProvider}.
74+
* @author Kazuki Shimizu
75+
* @since 3.5.1
76+
*/
77+
@Documented
78+
@Retention(RetentionPolicy.RUNTIME)
79+
@Target(ElementType.METHOD)
80+
@StatementAnnotationMetadata(commandType = SqlCommandType.INSERT)
81+
@interface List {
82+
InsertProvider[] value();
83+
}
84+
6085
}

src/main/java/org/apache/ibatis/annotations/Options.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.lang.annotation.Documented;
1919
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Repeatable;
2021
import java.lang.annotation.Retention;
2122
import java.lang.annotation.RetentionPolicy;
2223
import java.lang.annotation.Target;
@@ -30,6 +31,7 @@
3031
@Documented
3132
@Retention(RetentionPolicy.RUNTIME)
3233
@Target(ElementType.METHOD)
34+
@Repeatable(Options.List.class)
3335
public @interface Options {
3436
/**
3537
* The options for the {@link Options#flushCache()}.
@@ -63,4 +65,23 @@ enum FlushCachePolicy {
6365
String keyColumn() default "";
6466

6567
String resultSets() default "";
68+
69+
/**
70+
* @return A database id that correspond this options
71+
* @since 3.5.1
72+
*/
73+
String databaseId() default "";
74+
75+
/**
76+
* The container annotation for {@link Options}.
77+
* @author Kazuki Shimizu
78+
* @since 3.5.1
79+
*/
80+
@Documented
81+
@Retention(RetentionPolicy.RUNTIME)
82+
@Target(ElementType.METHOD)
83+
@interface List {
84+
Options[] value();
85+
}
86+
6687
}

src/main/java/org/apache/ibatis/annotations/Select.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2016 the original author or authors.
2+
* Copyright 2009-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -15,8 +15,12 @@
1515
*/
1616
package org.apache.ibatis.annotations;
1717

18+
import org.apache.ibatis.builder.annotation.StatementAnnotationMetadata;
19+
import org.apache.ibatis.mapping.SqlCommandType;
20+
1821
import java.lang.annotation.Documented;
1922
import java.lang.annotation.ElementType;
23+
import java.lang.annotation.Repeatable;
2024
import java.lang.annotation.Retention;
2125
import java.lang.annotation.RetentionPolicy;
2226
import java.lang.annotation.Target;
@@ -27,6 +31,28 @@
2731
@Documented
2832
@Retention(RetentionPolicy.RUNTIME)
2933
@Target(ElementType.METHOD)
34+
@Repeatable(Select.List.class)
35+
@StatementAnnotationMetadata(commandType = SqlCommandType.SELECT)
3036
public @interface Select {
3137
String[] value();
38+
39+
/**
40+
* @return A database id that correspond this statement
41+
* @since 3.5.1
42+
*/
43+
String databaseId() default "";
44+
45+
/**
46+
* The container annotation for {@link Select}.
47+
* @author Kazuki Shimizu
48+
* @since 3.5.1
49+
*/
50+
@Documented
51+
@Retention(RetentionPolicy.RUNTIME)
52+
@Target(ElementType.METHOD)
53+
@StatementAnnotationMetadata(commandType = SqlCommandType.SELECT)
54+
@interface List {
55+
Select[] value();
56+
}
57+
3258
}

src/main/java/org/apache/ibatis/annotations/SelectKey.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2016 the original author or authors.
2+
* Copyright 2009-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717

1818
import java.lang.annotation.Documented;
1919
import java.lang.annotation.ElementType;
20+
import java.lang.annotation.Repeatable;
2021
import java.lang.annotation.Retention;
2122
import java.lang.annotation.RetentionPolicy;
2223
import java.lang.annotation.Target;
@@ -29,6 +30,7 @@
2930
@Documented
3031
@Retention(RetentionPolicy.RUNTIME)
3132
@Target(ElementType.METHOD)
33+
@Repeatable(SelectKey.List.class)
3234
public @interface SelectKey {
3335
String[] statement();
3436

@@ -41,4 +43,23 @@
4143
Class<?> resultType();
4244

4345
StatementType statementType() default StatementType.PREPARED;
46+
47+
/**
48+
* @return A database id that correspond this select key
49+
* @since 3.5.1
50+
*/
51+
String databaseId() default "";
52+
53+
/**
54+
* The container annotation for {@link SelectKey}.
55+
* @author Kazuki Shimizu
56+
* @since 3.5.1
57+
*/
58+
@Documented
59+
@Retention(RetentionPolicy.RUNTIME)
60+
@Target(ElementType.METHOD)
61+
@interface List {
62+
SelectKey[] value();
63+
}
64+
4465
}

src/main/java/org/apache/ibatis/annotations/SelectProvider.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@
1515
*/
1616
package org.apache.ibatis.annotations;
1717

18+
import org.apache.ibatis.builder.annotation.StatementAnnotationMetadata;
19+
import org.apache.ibatis.mapping.SqlCommandType;
20+
1821
import java.lang.annotation.Documented;
1922
import java.lang.annotation.ElementType;
23+
import java.lang.annotation.Repeatable;
2024
import java.lang.annotation.Retention;
2125
import java.lang.annotation.RetentionPolicy;
2226
import java.lang.annotation.Target;
@@ -27,6 +31,8 @@
2731
@Documented
2832
@Retention(RetentionPolicy.RUNTIME)
2933
@Target(ElementType.METHOD)
34+
@Repeatable(SelectProvider.List.class)
35+
@StatementAnnotationMetadata(commandType = SqlCommandType.SELECT)
3036
public @interface SelectProvider {
3137

3238
/**
@@ -57,4 +63,23 @@
5763
*/
5864
String method() default "";
5965

66+
/**
67+
* @return A database id that correspond this provider
68+
* @since 3.5.1
69+
*/
70+
String databaseId() default "";
71+
72+
/**
73+
* The container annotation for {@link SelectProvider}.
74+
* @author Kazuki Shimizu
75+
* @since 3.5.1
76+
*/
77+
@Documented
78+
@Retention(RetentionPolicy.RUNTIME)
79+
@Target(ElementType.METHOD)
80+
@StatementAnnotationMetadata(commandType = SqlCommandType.SELECT)
81+
@interface List {
82+
SelectProvider[] value();
83+
}
84+
6085
}

0 commit comments

Comments
 (0)