Skip to content
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 the @Options#timeoutString #2886

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kazuki43zoo
Copy link
Member

@kazuki43zoo kazuki43zoo commented Jun 10, 2023

I propose to add a new attribute that specify the query timeout using configuration's variables such as ${timeout.query1}.
There are cases that a timeout value want to specify other value per runtime environment.

@Select("SELECT 1")
@Options(timeoutString = "${timeout.query1}")
int select();
timeout.query1=30

For example for using on MyBatis Spring Boot:

mybatis:
  configuration:
    variables:
      timeout:
        query1: 30

NOTE

Already XML mapper can use the configuration's variables as follow:

<select id="select" resultType="int" timeout="${timeout.query1}">
  SELECT 1
</select>

Support a new attribute that specify the query timeout using configuration's variables such as ${timeout.query1}
@kazuki43zoo kazuki43zoo added the enhancement Improve a feature or add a new feature label Jun 10, 2023
@kazuki43zoo kazuki43zoo self-assigned this Jun 10, 2023
@coveralls
Copy link

coveralls commented Jun 10, 2023

Coverage Status

coverage: 87.557% (+0.01%) from 87.545% when pulling 6dd9c12 on kazuki43zoo:support-timeoutString-on-Options into c060395 on mybatis:master.

@@ -88,8 +88,9 @@ public String handleToken(String content) {
return variables.getProperty(key, defaultValue);
}
}
if (variables.containsKey(key)) {
return variables.getProperty(key);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kazuki43zoo Just a question on this. Historically, it was suggested to check contains before getting it for some performance reason. Has that changed? I have seen recently less of doing it via containsKey.

Copy link
Member Author

@kazuki43zoo kazuki43zoo Jun 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hazendaz Thanks for your review comment!
Your comment right!!! I was tried getting Benchmark. As result, processing using with containsKey was high performance rather than without containsKey. Therefore, I reverted my changes via c8ff596.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

学习了,看到了

@hazendaz
Copy link
Member

@kazuki43zoo Is there any reason 'timeoutString' has to be a string instead of just an int? Other than obvious to match the XML, I'm not so certain that is necessary never mind that the XML already is 'timeout' so it more naturally would be 'timeout' to match. I realize under the hood 'timeout' is there but thinking it would be cleaner to just be 'timeout' as int.

@kazuki43zoo
Copy link
Member Author

kazuki43zoo commented Jun 10, 2023

@kazuki43zoo Is there any reason 'timeoutString' has to be a string instead of just an int? Other than obvious to match the XML, I'm not so certain that is necessary never mind that the XML already is 'timeout' so it more naturally would be 'timeout' to match. I realize under the hood 'timeout' is there but thinking it would be cleaner to just be 'timeout' as int.

@hazendaz The 'timeout' as int already exists on @Options. Sometimes I want to configure a timeout using externalize configuration (e.g. k8s's ConfigMap, environmental variables, system properties, etc... ). For instance, to have a quick way to increase the timeout on a critical business operation without the code changes and keep business running. But if timeout define as int, we need build and release a new application for changing timeout. Therefore, I propose to add the 'timeoutString' option for improving it.

P.S.
I inspire with the @Transactional of Spring Framework.

@hazendaz
Copy link
Member

hazendaz commented Jun 10, 2023 via email

@kazuki43zoo
Copy link
Member Author

@hazendaz Thanks for approving! @harawata If you agree with this changes, I will merge this.

@harawata
Copy link
Member

Already XML mapper can use the configuration's variables as follow:

True, but I think this is not the designed behavior.
In other words, it works by accident and we should not promote this usage as a supported feature.

If we were to support this, we should add a new option (e.g. timeoutProperty) to both XML statement tags and @Options.
And the value of the option should be a key string i.e. timeoutProperty="timeout.select", not timeoutProperty="${timeout.select}".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve a feature or add a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants