-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add LanguageDriver to ProviderSqlSource #1391
Conversation
This function is very useful. Does everyone have any ideas? |
@harawata I am interested in this PR, what do you think? |
If this PR will merged, I can support read an SQL template file by rule-based on mybatis-thymeleaf as follow: @Lang(ThymeleafLanguageDriver.class)
@SelectProvider(type = ThymeleafSqlTemplatePathProvider.class, method = "provide")
Name findById(int id);
class ThymeleafSqlTemplatePathProvider {
String provide(ProviderContext context) {
Class<?> type = context.getMapperType();
Method method = context.getMapperMethod();
return "/" + type.getName().replaceAll("\\.", "/") + "/" + method.getName() + ".sql";
}
} |
@kazuki43zoo , |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, @abel533 !
This version is a lot simpler than the previous ones. Thanks!
src/main/java/org/apache/ibatis/builder/annotation/ProviderSqlSource.java
Outdated
Show resolved
Hide resolved
src/test/java/org/apache/ibatis/submitted/sqlprovider/OurSqlBuilder.java
Outdated
Show resolved
Hide resolved
src/test/java/org/apache/ibatis/submitted/sqlprovider/OurSqlBuilder.java
Outdated
Show resolved
Hide resolved
src/test/java/org/apache/ibatis/submitted/sqlprovider/OurSqlBuilder.java
Outdated
Show resolved
Hide resolved
Resolved warnings, updated license years and reformatted some lines.
… Configuration - In ProviderSqlSource, it is better not to assume the driver is already registered. - Replaced Class#newInstance() with Constructor#newInstance().
@abel533 , Thank you for the updates! @kazuki43zoo , Could you do the final check and merge if everything is OK? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@harawata
I've added trivial comments.
src/main/java/org/apache/ibatis/builder/annotation/ProviderSqlSource.java
Show resolved
Hide resolved
@kazuki43zoo , Good catch! Thanks a lot! |
Based on current PR, new mybatis-mapper released 1.0.0 🎉🎉🎉 |
Add LanguageDriver to ProviderSqlSource
First, I closed several similar PRs, such as #1229, #1226, #1120, #1111
The new PR reduces the content of the changes.
The current changes are more in line with the definition of LanguageDriver.
in
MapperAnnotationBuilder
:When other LanguageDriver uses the Provider method, you can add
@Lang(XMLLanguageDriver.class)
to solve.This is the last PR for ProviderSqlSource. I hope everyone will consider it carefully.