You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "zhfeng (via GitHub)" <gi...@apache.org> on 2023/04/07 02:32:42 UTC

[GitHub] [camel] zhfeng opened a new pull request, #9827: CAMEL-19256: camel-jdbc - close stmt in the finnal block

zhfeng opened a new pull request, #9827:
URL: https://github.com/apache/camel/pull/9827

   # Description
   
   <!--
   - Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
   -->
   
   # Target
   
   - [ ] I checked that the commit is targeting the correct branch (note that Camel 3 uses `camel-3.x`, whereas Camel 4 uses the `main` branch)
   
   # Tracking
   - [ ] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it).
   
   <!--
   # *Note*: trivial changes like, typos, minor documentation fixes and other small items do not require a JIRA issue. In this case your pull request should address just this issue, without pulling in other changes.
   -->
   
   # Apache Camel coding standards and style
   
   - [ ] I checked that each commit in the pull request has a meaningful subject line and body.
   
   <!--  
   If you're unsure, you can format the pull request title like `[CAMEL-XXX] Fixes bug in camel-file component`, where you replace `CAMEL-XXX` with the appropriate JIRA issue.
   -->
   
   - [ ] I formatted the code using `mvn -Pformat,fastinstall install && mvn -Psourcecheck`
   
   <!-- 
   You can run the aforementioned command in your module so that the build auto-formats your code and the source check verifies that is complies with our coding style. This will also be verified as part of the checks and your PR may be rejected if the checkstyle does not pass.
   
   You can learn more about the contribution guidelines at https://github.com/apache/camel/blob/main/CONTRIBUTING.md
   -->
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #9827: CAMEL-19256: camel-jdbc - close stmt in the finnal block

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9827:
URL: https://github.com/apache/camel/pull/9827#issuecomment-1499887905

   ### Components tested:
   
   | Total | Tested | Failed :x: | Passed :white_check_mark: | 
   | --- | --- | --- |  --- |
   | 1 | 1 | 1 | 0 |


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] zhfeng merged pull request #9827: CAMEL-19256: camel-jdbc - close stmt in the finnal block

Posted by "zhfeng (via GitHub)" <gi...@apache.org>.
zhfeng merged PR #9827:
URL: https://github.com/apache/camel/pull/9827


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] davsclaus commented on pull request #9827: CAMEL-19256: camel-jdbc - close stmt in the finnal block

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on PR #9827:
URL: https://github.com/apache/camel/pull/9827#issuecomment-1501462871

   Ah yeah its a bit of a mess as ResultSetIterator also has some close code, and some of the other methods does not seem to close PreparedStatement if you use StreamList as output type.
   
   I guess we need to look deeper into this code, and ensure all that jdbc stuff is closed correctly in normal and streamlist mode (close in UoW).
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] zhfeng commented on a diff in pull request #9827: CAMEL-19256: camel-jdbc - close stmt in the finnal block

Posted by "zhfeng (via GitHub)" <gi...@apache.org>.
zhfeng commented on code in PR #9827:
URL: https://github.com/apache/camel/pull/9827#discussion_r1161571501


##########
components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java:
##########
@@ -194,21 +193,12 @@ private boolean doCreateAndExecuteSqlStatementWithHeaders(Exchange exchange, Str
 
     private boolean doCreateAndExecuteSqlStatement(Exchange exchange, String sql, Connection conn) throws Exception {
 
+        Statement stmt = null;
         ResultSet rs = null;
         boolean shouldCloseResources = true;
 
         try {
-            // We might need to leave it open to allow post-processing of the result set. This is why we

Review Comment:
   Or it should be better to move these codes
   ```java
   try {
   ...
   shouldCloseResources = setResultSet(exchange, conn, rs);
   ...
   
   } finally {
               if (shouldCloseResources) {
                   closeQuietly(rs);
                   closeQuietly(stmt);
               } else {
                   exchange.getExchangeExtension().addOnCompletion(new SynchronizationAdapter() {
                   @Override
                   public void onDone(Exchange exchange) {
                       closeQuietly(rs);
                       closeQuietly(stmt);
                   }
               });
              }
           }       
   
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #9827: CAMEL-19256: camel-jdbc - close stmt in the finnal block

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9827:
URL: https://github.com/apache/camel/pull/9827#issuecomment-1499866066

   :star2: Thank you for your contribution to the Apache Camel project! :star2: 
   
   :warning: Please note that the changes on this PR may be **tested automatically**. 
   
   If necessary Apache Camel Committers may access logs and test results in the job summaries!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] davsclaus commented on a diff in pull request #9827: CAMEL-19256: camel-jdbc - close stmt in the finnal block

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #9827:
URL: https://github.com/apache/camel/pull/9827#discussion_r1161645903


##########
components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java:
##########
@@ -194,21 +193,12 @@ private boolean doCreateAndExecuteSqlStatementWithHeaders(Exchange exchange, Str
 
     private boolean doCreateAndExecuteSqlStatement(Exchange exchange, String sql, Connection conn) throws Exception {
 
+        Statement stmt = null;
         ResultSet rs = null;
         boolean shouldCloseResources = true;
 
         try {
-            // We might need to leave it open to allow post-processing of the result set. This is why we

Review Comment:
   Yeah then the closing logic is at the same place and easier to ensure is correct



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] zhfeng commented on pull request #9827: CAMEL-19256: camel-jdbc - close stmt in the finnal block

Posted by "zhfeng (via GitHub)" <gi...@apache.org>.
zhfeng commented on PR #9827:
URL: https://github.com/apache/camel/pull/9827#issuecomment-1499868115

   The stmt and rs could be closed in `ResultSetIteratorCompletion` if the outputType is `JdbcOutputType.StreamList`. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #9827: CAMEL-19256: camel-jdbc - close stmt in the finnal block

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9827:
URL: https://github.com/apache/camel/pull/9827#issuecomment-1503156852

   ### Components tested:
   
   | Total | Tested | Failed :x: | Passed :white_check_mark: | 
   | --- | --- | --- |  --- |
   | 1 | 1 | 0 | 1 |


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] davsclaus commented on a diff in pull request #9827: CAMEL-19256: camel-jdbc - close stmt in the finnal block

Posted by "davsclaus (via GitHub)" <gi...@apache.org>.
davsclaus commented on code in PR #9827:
URL: https://github.com/apache/camel/pull/9827#discussion_r1161477598


##########
components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java:
##########
@@ -194,21 +193,12 @@ private boolean doCreateAndExecuteSqlStatementWithHeaders(Exchange exchange, Str
 
     private boolean doCreateAndExecuteSqlStatement(Exchange exchange, String sql, Connection conn) throws Exception {
 
+        Statement stmt = null;
         ResultSet rs = null;
         boolean shouldCloseResources = true;
 
         try {
-            // We might need to leave it open to allow post-processing of the result set. This is why we

Review Comment:
   This is a bit wrong, in case you use JdbcOutputType.StreamList then we need to close it in the UoW, eg its when setResultSet returns false.
   
   But I think we can keep the closing in the finally block if setResultSet returns true. Then its closed eager in finally, and then again in UoW done, but its already closed and isClosed will return true.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] github-actions[bot] commented on pull request #9827: CAMEL-19256: camel-jdbc - close stmt in the finnal block

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #9827:
URL: https://github.com/apache/camel/pull/9827#issuecomment-1499937721

   ### Components tested:
   
   | Total | Tested | Failed :x: | Passed :white_check_mark: | 
   | --- | --- | --- |  --- |
   | 1 | 1 | 0 | 1 |


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [camel] zhfeng commented on a diff in pull request #9827: CAMEL-19256: camel-jdbc - close stmt in the finnal block

Posted by "zhfeng (via GitHub)" <gi...@apache.org>.
zhfeng commented on code in PR #9827:
URL: https://github.com/apache/camel/pull/9827#discussion_r1161568304


##########
components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java:
##########
@@ -194,21 +193,12 @@ private boolean doCreateAndExecuteSqlStatementWithHeaders(Exchange exchange, Str
 
     private boolean doCreateAndExecuteSqlStatement(Exchange exchange, String sql, Connection conn) throws Exception {
 
+        Statement stmt = null;
         ResultSet rs = null;
         boolean shouldCloseResources = true;
 
         try {
-            // We might need to leave it open to allow post-processing of the result set. This is why we

Review Comment:
   if `setResultSet` resturns `false`, it has added `exchange.getExchangeExtension().addOnCompletion(new ResultSetIteratorCompletion(iterator))`. So I think we don't need to close it in the UoW here. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@camel.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org