-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Enhanced ProviderSqlSource to support dynamic sqlSource. #1111
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
Conversation
49d8cc5
to
737fc80
Compare
@harawata Thank you. |
There is a concurrent problem with the following code. @Override
public BoundSql getBoundSql(Object parameterObject) {
SqlSource sqlSource;
if (this.sqlSource != null) {
sqlSource = this.sqlSource;
} else {
sqlSource = createSqlSource(parameterObject);
if(this.cacheSqlSource){
this.sqlSource = sqlSource;
}
}
return sqlSource.getBoundSql(parameterObject);
} Since it was previously executed repeatedly, there is no problem with the repeated execution. There is no need to consider the lock. |
Hi @abel533 , Thanks for your contribution! I have an interesting for this PR. However, I will afraid to break a backward compatibility for the current version. Note: The Mybatis project provides two artifacts (velocity-scripting and freemarker-scripting) as related project. |
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.
I've added some comments.
@@ -54,11 +56,19 @@ public ProviderSqlSource(Configuration configuration, Object provider) { | |||
* @since 3.4.5 | |||
*/ | |||
public ProviderSqlSource(Configuration configuration, Object provider, Class<?> mapperType, Method mapperMethod) { | |||
this(configuration, provider, mapperType, mapperMethod, new XMLLanguageDriver()); |
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.
I think better using the Configuration#getDefaultScriptingLanguageInstance()
instead of new XMLLanguageDriver()
.
@@ -31,4 +31,6 @@ | |||
Class<?> type(); | |||
|
|||
String method(); | |||
|
|||
boolean cacheSqlSource() default false; |
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.
Please add API documentation(JavaDoc).
I think that we should explain an effect and caution for this attribute.
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.
@kazuki43zoo This attribute is used to configure whether to cache SqlSource and avoid generating SqlSource repeatedly. is this name appropriate?
By default, In order to be compatible with the other two LanguageDriver, can I first judge |
I will refer to the above comment to modify. |
String providerMethodName; | ||
try { | ||
this.configuration = configuration; | ||
this.sqlSourceParser = new SqlSourceBuilder(configuration); | ||
this.languageDriver = languageDriver; |
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.
@kazuki43zoo In order to be compatible with the other two LanguageDriver, can I judge languagedriver instanceof XMLLanguageDriver
here? If false, use the default XMLLanguageDriver.
@kazuki43zoo @harawata I have changed the source code. I use rebase to merge the commit, so the review information lost. Do I need rebase or commit directly ? |
if(languageDriver instanceof XMLLanguageDriver){ | ||
this.languageDriver = languageDriver; | ||
} else { | ||
this.languageDriver = new XMLLanguageDriver(); |
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.
Is there a reason to force languageDriver to XMLLanguageDriver?
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.
@h3adache Velocity and Freemarker's languageDriver do not support StaticSqlSource.
When call the configuration.getdefaultscriptinglanguageinstance( )
method, it is possible to return velocity and freemarker's the languageDriver.
The main purpose is to be compatible with the original method of ProviderSqlSource
.
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.
I would prefer that you leave those to the implementations and not take the current implementations. This is a hidden behavior that might surprise people who try to use this.
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.
@kazuki43zoo @h3adache @harawata Any other questions? I can change it. |
Major changes:
<script>
pattern.XXXProvider
annotation adds thecacheSqlSource
property to avoid duplicate calculations.A more powerful general-purpose Dao.
Test cases demonstrate a simple usage, with reference to the basic principles, and can achieve a powerful general-purpose Dao.
Test
Test method 1
This method dynamically generates the following SQL script:
The executed SQL is as follows:
Test method 2
This method dynamically generates the following SQL script:
The executed SQL is as follows:
Test method 3
This method dynamically generates the following SQL script:
The executed SQL is as follows: