camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject camel git commit: CAMEL-9063: Add useGetBytesForBlob option in camel-jdbc. Thanks to Joao Antonio for the patch.
Date Tue, 29 Sep 2015 06:32:53 GMT
Repository: camel
Updated Branches:
  refs/heads/master 1af80c07b -> 036abcc2f


CAMEL-9063: Add useGetBytesForBlob option in camel-jdbc. Thanks to Joao Antonio for the patch.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/036abcc2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/036abcc2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/036abcc2

Branch: refs/heads/master
Commit: 036abcc2f71e7223e356fc0b00458c8493306ce8
Parents: 1af80c0
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Sep 29 08:34:32 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Sep 29 08:34:32 2015 +0200

----------------------------------------------------------------------
 .../apache/camel/component/jdbc/JdbcEndpoint.java | 18 +++++++++++++++++-
 .../apache/camel/component/jdbc/JdbcProducer.java |  4 ++--
 .../camel/component/jdbc/ResultSetIterator.java   | 14 ++++++++++++--
 3 files changed, 31 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/036abcc2/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcEndpoint.java
b/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcEndpoint.java
index d1f037e..aedd920 100755
--- a/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcEndpoint.java
+++ b/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcEndpoint.java
@@ -37,7 +37,8 @@ public class JdbcEndpoint extends DefaultEndpoint {
 
     private DataSource dataSource;
 
-    @UriPath @Metadata(required = "true")
+    @UriPath
+    @Metadata(required = "true")
     private String dataSourceName;
     @UriParam
     private int readSize;
@@ -49,6 +50,8 @@ public class JdbcEndpoint extends DefaultEndpoint {
     @UriParam(defaultValue = "true")
     private boolean useJDBC4ColumnNameAndLabelSemantics = true;
     @UriParam
+    private boolean useGetBytesForBlob;
+    @UriParam
     private JdbcPrepareStatementStrategy prepareStatementStrategy = new DefaultJdbcPrepareStatementStrategy();
     @UriParam(defaultValue = "true")
     private boolean allowNamedParameters = true;
@@ -241,6 +244,19 @@ public class JdbcEndpoint extends DefaultEndpoint {
         this.beanRowMapper = beanRowMapper;
     }
 
+    public boolean isUseGetBytesForBlob() {
+        return this.useGetBytesForBlob;
+    }
+
+    /**
+     * To read BLOB columns as bytes instead of string data.
+     * <p/>
+     * This may be needed for certain databases such as Oracle where you must read BLOB columns
as bytes.
+     */
+    public void setUseGetBytesForBlob(boolean useGetBytesForBlob) {
+        this.useGetBytesForBlob = useGetBytesForBlob;
+    }
+
     @Override
     protected String createEndpointUri() {
         return dataSourceName != null ? "jdbc:" + dataSourceName : "jdbc";

http://git-wip-us.apache.org/repos/asf/camel/blob/036abcc2/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java
b/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java
index 13ecade..7efe001 100644
--- a/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java
+++ b/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/JdbcProducer.java
@@ -291,7 +291,7 @@ public class JdbcProducer extends DefaultProducer {
      */
     protected void setGeneratedKeys(Exchange exchange, Connection conn, ResultSet generatedKeys)
throws SQLException {
         if (generatedKeys != null) {
-            ResultSetIterator iterator = new ResultSetIterator(conn, generatedKeys, getEndpoint().isUseJDBC4ColumnNameAndLabelSemantics());
+            ResultSetIterator iterator = new ResultSetIterator(conn, generatedKeys, getEndpoint().isUseJDBC4ColumnNameAndLabelSemantics(),
getEndpoint().isUseGetBytesForBlob());
             List<Map<String, Object>> data = extractRows(iterator);
 
             exchange.getOut().setHeader(JdbcConstants.JDBC_GENERATED_KEYS_ROW_COUNT, data.size());
@@ -307,7 +307,7 @@ public class JdbcProducer extends DefaultProducer {
     protected boolean setResultSet(Exchange exchange, Connection conn, ResultSet rs) throws
SQLException {
         boolean answer = true;
 
-        ResultSetIterator iterator = new ResultSetIterator(conn, rs, getEndpoint().isUseJDBC4ColumnNameAndLabelSemantics());
+        ResultSetIterator iterator = new ResultSetIterator(conn, rs, getEndpoint().isUseJDBC4ColumnNameAndLabelSemantics(),
getEndpoint().isUseGetBytesForBlob());
 
         // preserve headers
         exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());

http://git-wip-us.apache.org/repos/asf/camel/blob/036abcc2/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/ResultSetIterator.java
----------------------------------------------------------------------
diff --git a/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/ResultSetIterator.java
b/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/ResultSetIterator.java
index 8055550..633e182 100644
--- a/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/ResultSetIterator.java
+++ b/components/camel-jdbc/src/main/java/org/apache/camel/component/jdbc/ResultSetIterator.java
@@ -41,12 +41,14 @@ public class ResultSetIterator implements Iterator<Map<String, Object>>
{
     private final Statement statement;
     private final ResultSet resultSet;
     private final Column[] columns;
+    private final boolean useGetBytes;
     private final AtomicBoolean closed = new AtomicBoolean();
 
-    public ResultSetIterator(Connection conn, ResultSet resultSet, boolean isJDBC4) throws
SQLException {
+    public ResultSetIterator(Connection conn, ResultSet resultSet, boolean isJDBC4, boolean
useGetBytes) throws SQLException {
         this.resultSet = resultSet;
         this.statement = this.resultSet.getStatement();
         this.connection = conn;
+        this.useGetBytes = useGetBytes;
 
         ResultSetMetaData metaData = resultSet.getMetaData();
         columns = new Column[metaData.getColumnCount()];
@@ -78,7 +80,11 @@ public class ResultSetIterator implements Iterator<Map<String, Object>>
{
         try {
             Map<String, Object> row = new LinkedHashMap<String, Object>();
             for (Column column : columns) {
-                row.put(column.getName(), column.getValue(resultSet));
+                if (useGetBytes && column instanceof BlobColumn) {
+                    row.put(column.getName(), ((BlobColumn) column).getBytes(resultSet));
+                } else {
+                    row.put(column.getName(), column.getValue(resultSet));
+                }
             }
             loadNext();
             return row;
@@ -203,5 +209,9 @@ public class ResultSetIterator implements Iterator<Map<String, Object>>
{
         public Object getValue(ResultSet resultSet) throws SQLException {
             return resultSet.getString(columnNumber);
         }
+
+        public Object getBytes(ResultSet resultSet) throws SQLException {
+            return resultSet.getBytes(columnNumber);
+        }
     }
 }


Mime
View raw message