camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rom...@apache.org
Subject svn commit: r955155 - in /camel/trunk/components/camel-sql/src: main/java/org/apache/camel/component/sql/SqlComponent.java test/java/org/apache/camel/component/sql/SqlRouteTest.java
Date Wed, 16 Jun 2010 08:33:23 GMT
Author: romkal
Date: Wed Jun 16 08:33:22 2010
New Revision: 955155

URL: http://svn.apache.org/viewvc?rev=955155&view=rev
Log:
CAMEL-2805: placeholder parameter added to sql endpoint that can be used to substitute default
# character for parameter placeholder

Modified:
    camel/trunk/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlComponent.java
    camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlRouteTest.java

Modified: camel/trunk/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlComponent.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlComponent.java?rev=955155&r1=955154&r2=955155&view=diff
==============================================================================
--- camel/trunk/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlComponent.java
(original)
+++ camel/trunk/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlComponent.java
Wed Jun 16 08:33:22 2010
@@ -45,12 +45,12 @@ public class SqlComponent extends Defaul
         if (dataSourceRef != null) {
             dataSource = CamelContextHelper.mandatoryLookup(getCamelContext(), dataSourceRef,
DataSource.class);
         }
+        String parameterPlaceholderSubstitute = getAndRemoveParameter(parameters, "placeholder",
String.class, "#");
         
         JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
         IntrospectionSupport.setProperties(jdbcTemplate, parameters, "template.");
 
-        String query = remaining.replaceAll("#", "?");
-
+        String query = remaining.replaceAll(parameterPlaceholderSubstitute, "?");
         return new SqlEndpoint(uri, this, jdbcTemplate, query);
     }
 

Modified: camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlRouteTest.java?rev=955155&r1=955154&r2=955155&view=diff
==============================================================================
--- camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlRouteTest.java
(original)
+++ camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlRouteTest.java
Wed Jun 16 08:33:22 2010
@@ -153,6 +153,19 @@ public class SqlRouteTest extends CamelT
     }
     
     @Test
+    public void testHashesInQuery() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(1);
+        template.sendBody("direct:no-param-insert", "GPL");
+        mock.assertIsSatisfied();
+        Number received = assertIsInstanceOf(Number.class, mock.getReceivedExchanges().get(0).getIn().getHeader(SqlConstants.SQL_UPDATE_COUNT));
+        assertEquals(1, received.intValue());
+        Map projectNameInserted = jdbcTemplate.queryForMap("select project, license from
projects where id = 5");
+        assertEquals("#", projectNameInserted.get("PROJECT"));
+        assertEquals("GPL", projectNameInserted.get("LICENSE"));
+    }
+    
+    @Test
     public void testBodyButNoParams() throws Exception {
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
@@ -208,6 +221,8 @@ public class SqlRouteTest extends CamelT
                 from("direct:insert").to("sql:insert into projects values (#, #, #)").to("mock:result");
                 
                 from("direct:no-param").to("sql:select * from projects order by id").to("mock:result");
+                
+                from("direct:no-param-insert").to("sql:insert into projects values (5, '#',
param)?placeholder=param").to("mock:result");
             }
         };
     }



Mime
View raw message