Skip to content

Commit 6795230

Browse files
authored
Merge pull request #1466 from kazuki43zoo/supports-databaseid-on-annotation-mapper
Supports the statement switching feature that correspond database on the annotation driven mapper
2 parents c67c2db + 4aba814 commit 6795230

25 files changed

+1513
-109
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@
215215
<version>10.14.2.0</version>
216216
<scope>test</scope>
217217
</dependency>
218+
<dependency>
219+
<groupId>com.h2database</groupId>
220+
<artifactId>h2</artifactId>
221+
<version>1.4.197</version>
222+
<scope>test</scope>
223+
</dependency>
218224
<dependency>
219225
<groupId>org.mockito</groupId>
220226
<artifactId>mockito-core</artifactId>

src/main/java/org/apache/ibatis/annotations/Delete.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;
@@ -39,11 +40,31 @@
3940
@Documented
4041
@Retention(RetentionPolicy.RUNTIME)
4142
@Target(ElementType.METHOD)
43+
@Repeatable(Delete.List.class)
4244
public @interface Delete {
4345
/**
4446
* Returns an SQL for deleting record(s).
4547
*
4648
* @return an SQL for deleting record(s)
4749
*/
4850
String[] value();
51+
52+
/**
53+
* @return A database id that correspond this statement
54+
* @since 3.5.5
55+
*/
56+
String databaseId() default "";
57+
58+
/**
59+
* The container annotation for {@link Delete}.
60+
* @author Kazuki Shimizu
61+
* @since 3.5.5
62+
*/
63+
@Documented
64+
@Retention(RetentionPolicy.RUNTIME)
65+
@Target(ElementType.METHOD)
66+
@interface List {
67+
Delete[] value();
68+
}
69+
4970
}

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

Lines changed: 20 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;
@@ -47,6 +48,7 @@
4748
@Documented
4849
@Retention(RetentionPolicy.RUNTIME)
4950
@Target(ElementType.METHOD)
51+
@Repeatable(DeleteProvider.List.class)
5052
public @interface DeleteProvider {
5153

5254
/**
@@ -91,4 +93,22 @@
9193
*/
9294
String method() default "";
9395

96+
/**
97+
* @return A database id that correspond this provider
98+
* @since 3.5.5
99+
*/
100+
String databaseId() default "";
101+
102+
/**
103+
* The container annotation for {@link DeleteProvider}.
104+
* @author Kazuki Shimizu
105+
* @since 3.5.5
106+
*/
107+
@Documented
108+
@Retention(RetentionPolicy.RUNTIME)
109+
@Target(ElementType.METHOD)
110+
@interface List {
111+
DeleteProvider[] value();
112+
}
113+
94114
}

src/main/java/org/apache/ibatis/annotations/Insert.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;
@@ -39,11 +40,31 @@
3940
@Documented
4041
@Retention(RetentionPolicy.RUNTIME)
4142
@Target(ElementType.METHOD)
43+
@Repeatable(Insert.List.class)
4244
public @interface Insert {
4345
/**
4446
* Returns an SQL for inserting record(s).
4547
*
4648
* @return an SQL for inserting record(s)
4749
*/
4850
String[] value();
51+
52+
/**
53+
* @return A database id that correspond this statement
54+
* @since 3.5.5
55+
*/
56+
String databaseId() default "";
57+
58+
/**
59+
* The container annotation for {@link Insert}.
60+
* @author Kazuki Shimizu
61+
* @since 3.5.5
62+
*/
63+
@Documented
64+
@Retention(RetentionPolicy.RUNTIME)
65+
@Target(ElementType.METHOD)
66+
@interface List {
67+
Insert[] value();
68+
}
69+
4970
}

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

Lines changed: 20 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;
@@ -47,6 +48,7 @@
4748
@Documented
4849
@Retention(RetentionPolicy.RUNTIME)
4950
@Target(ElementType.METHOD)
51+
@Repeatable(InsertProvider.List.class)
5052
public @interface InsertProvider {
5153

5254
/**
@@ -91,4 +93,22 @@
9193
*/
9294
String method() default "";
9395

96+
/**
97+
* @return A database id that correspond this provider
98+
* @since 3.5.5
99+
*/
100+
String databaseId() default "";
101+
102+
/**
103+
* The container annotation for {@link InsertProvider}.
104+
* @author Kazuki Shimizu
105+
* @since 3.5.5
106+
*/
107+
@Documented
108+
@Retention(RetentionPolicy.RUNTIME)
109+
@Target(ElementType.METHOD)
110+
@interface List {
111+
InsertProvider[] value();
112+
}
113+
94114
}

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;
@@ -43,6 +44,7 @@
4344
@Documented
4445
@Retention(RetentionPolicy.RUNTIME)
4546
@Target(ElementType.METHOD)
47+
@Repeatable(Options.List.class)
4648
public @interface Options {
4749
/**
4850
* The options for the {@link Options#flushCache()}.
@@ -135,4 +137,23 @@ enum FlushCachePolicy {
135137
* @return result set names that separate with comma(',')
136138
*/
137139
String resultSets() default "";
140+
141+
/**
142+
* @return A database id that correspond this options
143+
* @since 3.5.5
144+
*/
145+
String databaseId() default "";
146+
147+
/**
148+
* The container annotation for {@link Options}.
149+
* @author Kazuki Shimizu
150+
* @since 3.5.5
151+
*/
152+
@Documented
153+
@Retention(RetentionPolicy.RUNTIME)
154+
@Target(ElementType.METHOD)
155+
@interface List {
156+
Options[] value();
157+
}
158+
138159
}

src/main/java/org/apache/ibatis/annotations/Select.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;
@@ -39,11 +40,31 @@
3940
@Documented
4041
@Retention(RetentionPolicy.RUNTIME)
4142
@Target(ElementType.METHOD)
43+
@Repeatable(Select.List.class)
4244
public @interface Select {
4345
/**
4446
* Returns an SQL for retrieving record(s).
4547
*
4648
* @return an SQL for retrieving record(s)
4749
*/
4850
String[] value();
51+
52+
/**
53+
* @return A database id that correspond this statement
54+
* @since 3.5.5
55+
*/
56+
String databaseId() default "";
57+
58+
/**
59+
* The container annotation for {@link Select}.
60+
* @author Kazuki Shimizu
61+
* @since 3.5.5
62+
*/
63+
@Documented
64+
@Retention(RetentionPolicy.RUNTIME)
65+
@Target(ElementType.METHOD)
66+
@interface List {
67+
Select[] value();
68+
}
69+
4970
}

src/main/java/org/apache/ibatis/annotations/SelectKey.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;
@@ -42,6 +43,7 @@
4243
@Documented
4344
@Retention(RetentionPolicy.RUNTIME)
4445
@Target(ElementType.METHOD)
46+
@Repeatable(SelectKey.List.class)
4547
public @interface SelectKey {
4648
/**
4749
* Returns an SQL for retrieving a key value.
@@ -90,4 +92,23 @@
9092
* @return the statement type
9193
*/
9294
StatementType statementType() default StatementType.PREPARED;
95+
96+
/**
97+
* @return A database id that correspond this select key
98+
* @since 3.5.5
99+
*/
100+
String databaseId() default "";
101+
102+
/**
103+
* The container annotation for {@link SelectKey}.
104+
* @author Kazuki Shimizu
105+
* @since 3.5.5
106+
*/
107+
@Documented
108+
@Retention(RetentionPolicy.RUNTIME)
109+
@Target(ElementType.METHOD)
110+
@interface List {
111+
SelectKey[] value();
112+
}
113+
93114
}

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

Lines changed: 20 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;
@@ -47,6 +48,7 @@
4748
@Documented
4849
@Retention(RetentionPolicy.RUNTIME)
4950
@Target(ElementType.METHOD)
51+
@Repeatable(SelectProvider.List.class)
5052
public @interface SelectProvider {
5153

5254
/**
@@ -91,4 +93,22 @@
9193
*/
9294
String method() default "";
9395

96+
/**
97+
* @return A database id that correspond this provider
98+
* @since 3.5.5
99+
*/
100+
String databaseId() default "";
101+
102+
/**
103+
* The container annotation for {@link SelectProvider}.
104+
* @author Kazuki Shimizu
105+
* @since 3.5.5
106+
*/
107+
@Documented
108+
@Retention(RetentionPolicy.RUNTIME)
109+
@Target(ElementType.METHOD)
110+
@interface List {
111+
SelectProvider[] value();
112+
}
113+
94114
}

src/main/java/org/apache/ibatis/annotations/Update.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;
@@ -39,11 +40,31 @@
3940
@Documented
4041
@Retention(RetentionPolicy.RUNTIME)
4142
@Target(ElementType.METHOD)
43+
@Repeatable(Update.List.class)
4244
public @interface Update {
4345
/**
4446
* Returns an SQL for updating record(s).
4547
*
4648
* @return an SQL for updating record(s)
4749
*/
4850
String[] value();
51+
52+
/**
53+
* @return A database id that correspond this statement
54+
* @since 3.5.5
55+
*/
56+
String databaseId() default "";
57+
58+
/**
59+
* The container annotation for {@link Update}.
60+
* @author Kazuki Shimizu
61+
* @since 3.5.5
62+
*/
63+
@Documented
64+
@Retention(RetentionPolicy.RUNTIME)
65+
@Target(ElementType.METHOD)
66+
@interface List {
67+
Update[] value();
68+
}
69+
4970
}

0 commit comments

Comments
 (0)