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

In BatchExecutor, close each statement right after it is executed. #1110

Merged
merged 2 commits into from
Oct 15, 2017

Conversation

vlastimil-dolejs
Copy link
Contributor

fix for #1109

@@ -149,9 +150,6 @@ public int doUpdate(MappedStatement ms, Object parameterObject) throws SQLExcept
}
return results;
} finally {
for (Statement stmt : statementList) {
Copy link
Member

@kazuki43zoo kazuki43zoo Oct 5, 2017

Choose a reason for hiding this comment

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

In this changes, If an exception occurred during statement execution, I think there is a case that statement does not close.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for review - you are right. I will improve the code.

@harawata harawata changed the title statement is closed immediately after execution In BatchExecutor, close each statement right after it is executed. Oct 15, 2017
@harawata harawata merged commit e72aa99 into mybatis:master Oct 15, 2017
@harawata
Copy link
Member

@vlastimil-dolejs Thank you for the PR!

@kazuki43zoo Any idea for testing this? I couldn't think of a good one.

@harawata harawata added this to the 3.4.6 milestone Oct 15, 2017
@harawata harawata self-assigned this Oct 15, 2017
@harawata harawata added the enhancement Improve a feature or add a new feature label Oct 15, 2017
@kazuki43zoo
Copy link
Member

Hi @harawata, it's difficult .. :(

@kazuki43zoo
Copy link
Member

May possible if use the mock mechanism like Mockito...

@kazuki43zoo
Copy link
Member

@harawata @vlastimil-dolejs I have one question.
By this changes, probably the Statement.close() is called twice. Is no problem as JDBC specification?

@kazuki43zoo
Copy link
Member

(Probably) Calling the close method at twice is no problem because the JDBC 4.2 specification("13.1.4 Closing Statement Objects") says as follows:
However, I think changing as calling only once is a good code.

Once a Statement has been closed, any attempt to access any of its methods with the exception of the isClosed or close methods will result in a SQLException being thrown.

@harawata
Copy link
Member

@kazuki43zoo ,

May possible if use the mock mechanism like Mockito...

OK. Let's just leave it for now.
I'll add a comment later.

However, I think changing as calling only once is a good code.

+1

@vlastimil-dolejs
Copy link
Contributor Author

@kazuki43zoo
JavaDoc of Statement.close() says:

Calling the method close on a Statement object that is already closed has no effect.

So it's safe to call it twice. I think that code that ensures the close() method is called exactly once will add a lot of complexity.

harawata added a commit that referenced this pull request Oct 23, 2017
pulllock pushed a commit to pulllock/mybatis-3 that referenced this pull request Oct 19, 2023
In BatchExecutor, close each statement right after it is executed.
Although proper flushing should be sufficient in most cases, this could lower the possibility of an error like "ORA-01000: maximum open cursors exceeded".
pulllock pushed a commit to pulllock/mybatis-3 that referenced this pull request Oct 19, 2023
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.

3 participants