camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1172710 - in /camel/branches/camel-2.8.x: ./ components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcEndpoint.java components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java
Date Mon, 19 Sep 2011 17:11:32 GMT
Author: dkulp
Date: Mon Sep 19 17:11:32 2011
New Revision: 1172710

URL: http://svn.apache.org/viewvc?rev=1172710&view=rev
Log:
Merged revisions 1151126 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r1151126 | ningjiang | 2011-07-26 11:05:42 -0400 (Tue, 26 Jul 2011) | 1 line
  
   CAMEL-4272 camel-jdbc should provide a option not set the autoCommit flag
........

Modified:
    camel/branches/camel-2.8.x/   (props changed)
    camel/branches/camel-2.8.x/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcEndpoint.java
    camel/branches/camel-2.8.x/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java

Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Sep 19 17:11:32 2011
@@ -1 +1 @@
-/camel/trunk:1148706,1148710,1149570,1150651,1151000,1151054,1151087,1151362,1152170,1152569,1152733,1152755,1153620,1153812,1153829,1154684,1155230,1156108,1156260,1156277,1156479,1156524,1157348,1157749,1157798,1157831,1157878,1158153,1159171,1159174,1159326,1159457,1159460,1159606,1159682-1159683,1159867,1160547,1160637,1161010,1161082,1161524,1162309,1162395,1163231,1163420,1163656-1163669,1163725,1164544,1164557,1164633,1164972-1165000,1165152,1165157,1165658,1165971,1165987,1167098,1167131,1167448,1167487,1167555,1169610,1169620,1170122,1170226,1170397,1170956,1171396,1171755,1171941,1171947
+/camel/trunk:1148706,1148710,1149570,1150651,1151000,1151054,1151087,1151126,1151362,1152170,1152569,1152733,1152755,1153620,1153812,1153829,1154684,1155230,1156108,1156260,1156277,1156479,1156524,1157348,1157749,1157798,1157831,1157878,1158153,1159171,1159174,1159326,1159457,1159460,1159606,1159682-1159683,1159867,1160547,1160637,1161010,1161082,1161524,1162309,1162395,1163231,1163420,1163656-1163669,1163725,1164544,1164557,1164633,1164972-1165000,1165152,1165157,1165658,1165971,1165987,1167098,1167131,1167448,1167487,1167555,1169610,1169620,1170122,1170226,1170397,1170956,1171396,1171755,1171941,1171947

Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.8.x/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcEndpoint.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcEndpoint.java?rev=1172710&r1=1172709&r2=1172710&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcEndpoint.java
(original)
+++ camel/branches/camel-2.8.x/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcEndpoint.java
Mon Sep 19 17:11:32 2011
@@ -31,6 +31,7 @@ import org.apache.camel.impl.DefaultEndp
 public class JdbcEndpoint extends DefaultEndpoint {
     private int readSize;
     private boolean transacted;
+    private boolean resetAutoCommit = true;
     private DataSource dataSource;
     private Map<String, Object> parameters;
     private boolean useJDBC4ColumnNameAndLabelSemantics = true;
@@ -71,6 +72,14 @@ public class JdbcEndpoint extends Defaul
         this.transacted = transacted;
     }
 
+    public boolean isResetAutoCommit() {
+        return resetAutoCommit;
+    }
+
+    public void setResetAutoCommit(boolean resetAutoCommit) {
+        this.resetAutoCommit = resetAutoCommit;
+    }
+
     public DataSource getDataSource() {
         return dataSource;
     }

Modified: camel/branches/camel-2.8.x/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java?rev=1172710&r1=1172709&r2=1172710&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java
(original)
+++ camel/branches/camel-2.8.x/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java
Mon Sep 19 17:11:32 2011
@@ -58,23 +58,34 @@ public class JdbcProducer extends Defaul
      * Execute sql of exchange and set results on output
      */
     public void process(Exchange exchange) throws Exception {
+        if (getEndpoint().isResetAutoCommit()) {
+            processingSqlBySettingAutoCommit(exchange);
+        } else {
+            processingSqlWithoutSettingAutoCommit(exchange);
+        }
+        // populate headers
+        exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
+    }
+
+    private void processingSqlBySettingAutoCommit(Exchange exchange) throws Exception {
         String sql = exchange.getIn().getBody(String.class);
         Connection conn = null;
         Statement stmt = null;
         ResultSet rs = null;
         Boolean autoCommit = null;
-        
         try {
             conn = dataSource.getConnection();
             autoCommit = conn.getAutoCommit();
-            conn.setAutoCommit(false);
-            
+            if (autoCommit) {
+                conn.setAutoCommit(false);
+            }
+
             stmt = conn.createStatement();
-            
+
             if (parameters != null && !parameters.isEmpty()) {
                 IntrospectionSupport.setProperties(stmt, parameters);
             }
-            
+
             LOG.debug("Executing JDBC statement: {}", sql);
 
             if (stmt.execute(sql)) {
@@ -98,9 +109,36 @@ public class JdbcProducer extends Defaul
             resetAutoCommit(conn, autoCommit);
             closeQuietly(conn);
         }
+    }
 
-        // populate headers
-        exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
+    private void processingSqlWithoutSettingAutoCommit(Exchange exchange) throws Exception
{
+        String sql = exchange.getIn().getBody(String.class);
+        Connection conn = null;
+        Statement stmt = null;
+        ResultSet rs = null;
+        try {
+            conn = dataSource.getConnection();
+
+            stmt = conn.createStatement();
+
+            if (parameters != null && !parameters.isEmpty()) {
+                IntrospectionSupport.setProperties(stmt, parameters);
+            }
+
+            LOG.debug("Executing JDBC statement: {}", sql);
+
+            if (stmt.execute(sql)) {
+                rs = stmt.getResultSet();
+                setResultSet(exchange, rs);
+            } else {
+                int updateCount = stmt.getUpdateCount();
+                exchange.getOut().setHeader(JdbcConstants.JDBC_UPDATE_COUNT, updateCount);
+            }
+        } finally {
+            closeQuietly(rs);
+            closeQuietly(stmt);
+            closeQuietly(conn);
+        }
     }
 
     private void closeQuietly(ResultSet rs) {



Mime
View raw message