camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/2] git commit: CAMEL-6473: Support NULL values in named parameters in camel-sql. Thanks to Sergey Galkin for the patch.
Date Sun, 23 Jun 2013 07:39:37 GMT
Updated Branches:
  refs/heads/camel-2.11.x 0530c21fb -> 5467ef1fc
  refs/heads/master b2cd9f1c8 -> 27e92dfcb


CAMEL-6473: Support NULL values in named parameters in camel-sql. Thanks to Sergey Galkin
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/27e92dfc
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/27e92dfc
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/27e92dfc

Branch: refs/heads/master
Commit: 27e92dfcb97bcd1e35ab9175e3a2fbbf7b31246a
Parents: b2cd9f1
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sun Jun 23 09:38:59 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sun Jun 23 09:38:59 2013 +0200

----------------------------------------------------------------------
 .../sql/DefaultSqlPrepareStatementStrategy.java | 48 ++++++++++----------
 1 file changed, 25 insertions(+), 23 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/27e92dfc/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlPrepareStatementStrategy.java
----------------------------------------------------------------------
diff --git a/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlPrepareStatementStrategy.java
b/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlPrepareStatementStrategy.java
index 5928f64..f8719a2 100644
--- a/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlPrepareStatementStrategy.java
+++ b/components/camel-sql/src/main/java/org/apache/camel/component/sql/DefaultSqlPrepareStatementStrategy.java
@@ -22,6 +22,7 @@ import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.NoSuchElementException;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -73,7 +74,7 @@ public class DefaultSqlPrepareStatementStrategy implements SqlPrepareStatementSt
 
                 return new Iterator<Object>() {
                     private NamedQueryParser parser = new NamedQueryParser(query);
-                    private Object next;
+                    private Object nextParam;
                     private boolean done;
 
                     @Override
@@ -81,35 +82,36 @@ public class DefaultSqlPrepareStatementStrategy implements SqlPrepareStatementSt
                         if (done) {
                             return false;
                         }
-                        if (next == null) {
-                            next = next();
+
+                        if (nextParam == null) {
+                            nextParam = parser.next();
+                            if (nextParam == null) {
+                                done = true;
+                            }
                         }
-                        return next != null;
+                        return nextParam != null;
                     }
 
                     @Override
                     public Object next() {
+                        if (!hasNext()) {
+                            throw new NoSuchElementException();
+                        }
+
+                        boolean contains = bodyMap != null && bodyMap.containsKey(nextParam);
+                        contains |= headerMap != null && headerMap.containsKey(nextParam);
+                        if (!contains) {
+                            throw new RuntimeExchangeException("Cannot find key [" + nextParam
+ "] in message body or headers to use when setting named parameter in query [" + query +
"]", exchange);
+                        }
+
+                        // get from body before header
+                        Object next = bodyMap != null ? bodyMap.get(nextParam) : null;
                         if (next == null) {
-                            String key = parser.next();
-                            if (key == null) {
-                                done = true;
-                                return null;
-                            }
-                            // the key is expected to exist, if not report so end user can
see this
-                            boolean contains = bodyMap != null ? bodyMap.containsKey(key)
: false;
-                            contains |= headerMap != null ? headerMap.containsKey(key) :
false;
-                            if (!contains) {
-                                throw new RuntimeExchangeException("Cannot find key [" +
key + "] in message body or headers to use when setting named parameter in query [" + query
+ "]", exchange);
-                            }
-                            // get from body before header
-                            next = bodyMap != null ? bodyMap.get(key) : null;
-                            if (next == null) {
-                                next = headerMap != null ? headerMap.get(key) : null;
-                            }
+                            next = headerMap != null ? headerMap.get(nextParam) : null;
                         }
-                        Object answer = next;
-                        next = null;
-                        return answer;
+
+                        nextParam = null;
+                        return next;
                     }
 
                     @Override


Mime
View raw message