Add databaseId attribute on following annotations
- Select
- SelectProvider
- Insert
- InsertProvider
- Update
- UpdateProvider
- Delete
- DeleteProvider
- SelectKey
- Options
Normally usage
public interface MyMapper {
@Select(value = "SELECT * FROM users WHERE ... /* use oracle specific functions */ ... ", databaseId = "oracle")
@Select(value = "SELECT * FROM users WHERE ...")
User selectUser(Integer id);
@InsertProvider(type = OracleSqlProvider.class, method = "insertUser", databaseId = "oracle")
@InsertProvider(type = DefaultSqlProvider.class, method = "insertUser")
@SelectKey(statement = "SELECT COUNT(*) + 1 FROM users", keyProperty = "id", before = true, resultType = Integer.class, databaseId = "oracle")
@Options(useGeneratedKeys = true, keyProperty = "id")
void insertUser(User user);
// ...
}
````
Equivalent to following XML:
```xml
<select id="selectUser" resultType="User" databaseId="oracle">
SELECT * FROM users WHERE ... /* use oracle specific functions */ ...
</select>
<select id="selectUser" resultType="User">
SELECT * FROM users WHERE ...
</select>
@mybatis/committers WDYT for this enhancement?
Comment From: harawata
Thank you, @kazuki43zoo !
I'm still reading, but for @*Providers
, it might be better to pass database ID via ProviderContext if that's possible. WDYT?
Comment From: kazuki43zoo
it might be better to pass database ID via ProviderContext if that's possible. WDYT?
I agree with your suggestion! I was planning to deal with another Issue. Is not need the databaseId
attribute in @*Provider
annotation?
Comment From: harawata
Probably not.
Comment From: Runrioter
Good job.
<select id="selectUser" resultType="User" databaseId="oracle">
SELECT * FROM users WHERE ... /* use oracle specific functions */ ...
</select>
<select id="selectUser" resultType="User">
SELECT * FROM users WHERE ...
</select>
But can we use two same ids in xml ? (strict mode) I suggest that we can use name
attribute.
<select name="selectUser" resultType="User" databaseId="oracle">
SELECT * FROM users WHERE ... /* use oracle specific functions */ ...
</select>
<select name="selectUser" resultType="User">
SELECT * FROM users WHERE ...
</select>
Comment From: harawata
@Runrioter ,
databaseId
is supported in XML mappers already. This PR is for the annotations.
The same ID is allowed only with a different databaseId, so it should be strict enough.
@kazuki43zoo , I'm really sorry about the delay! I'll look into it as soon as time allows.
Comment From: harawata
I have managed to resolve the conflict.
The annotation handling is very sophisticated which would be nice if we need to support user-defined annotations, but it seems a little bit overkill as we only deal with the built-in annotations here. Please let me try an uglier but simpler approach.
Comment From: harawata
Hi @kazuki43zoo ,
Here's the modified version. https://github.com/harawata/mybatis-3/commit/4aba8143639f110d3963fe014ba75f428e89e326 Could you take a look when you have time? It might be a matter of preference, so if you prefer the reflection approach, let's proceed with this PR as-is.
Comment From: kazuki43zoo
@harawata
Could you take a look when you have time? It might be a matter of preference, so if you prefer the reflection approach, let's proceed with this PR as-is.
Sorry for late replay.. I take with your suggestion!! Could you apply your change into this PR and merge?
Thanks !
Comment From: harawata
Merged. Thank you, @kazuki43zoo !