svn commit: r713295 - in /activemq/camel/trunk/components/camel-sql/src: main/java/org/apache/camel/component/sql/SqlProducer.java test/java/org/apache/camel/component/sql/SqlDataSourceRefTest.java

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r713295 - in /activemq/camel/trunk/components/camel-sql/src: main/java/org/apache/camel/component/sql/SqlProducer.java test/java/org/apache/camel/component/sql/SqlDataSourceRefTest.java

davsclaus-2
Author: davsclaus
Date: Tue Nov 11 23:50:26 2008
New Revision: 713295

URL: http://svn.apache.org/viewvc?rev=713295&view=rev
Log:
CAMEL-1063: Added dataSourceRef option to lookup DS in registry

Modified:
    activemq/camel/trunk/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java
    activemq/camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlDataSourceRefTest.java

Modified: activemq/camel/trunk/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java?rev=713295&r1=713294&r2=713295&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java (original)
+++ activemq/camel/trunk/components/camel-sql/src/main/java/org/apache/camel/component/sql/SqlProducer.java Tue Nov 11 23:50:26 2008
@@ -30,11 +30,8 @@
 import org.springframework.jdbc.core.RowMapperResultSetExtractor;
 
 public class SqlProducer extends DefaultProducer {
-
     public static final String UPDATE_COUNT = "org.apache.camel.sql.update-count";
-
     private String query;
-
     private JdbcTemplate jdbcTemplate;
 
     public SqlProducer(SqlEndpoint endpoint, String query, JdbcTemplate jdbcTemplate) {
@@ -44,10 +41,7 @@
     }
 
     public void process(final Exchange exchange) throws Exception {
-
-
         jdbcTemplate.execute(query, new PreparedStatementCallback() {
-
             public Object doInPreparedStatement(PreparedStatement ps) throws SQLException,
                 DataAccessException {
                 int argNumber = 1;
@@ -56,18 +50,15 @@
                 }
                 boolean isResultSet = ps.execute();
                 if (isResultSet) {
-                    RowMapperResultSetExtractor mapper = new RowMapperResultSetExtractor(
-                                                                                         new ColumnMapRowMapper());
-                    List<?> result = (List<?>)mapper.extractData(ps.getResultSet());
+                    RowMapperResultSetExtractor mapper = new RowMapperResultSetExtractor(new ColumnMapRowMapper());
+                    List<?> result = (List<?>) mapper.extractData(ps.getResultSet());
                     exchange.getOut().setBody(result);
                 } else {
                     exchange.getIn().setHeader(UPDATE_COUNT, ps.getUpdateCount());
                 }
                 return null;
             }
-
         });
-
     }
 
 }

Modified: activemq/camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlDataSourceRefTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlDataSourceRefTest.java?rev=713295&r1=713294&r2=713295&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlDataSourceRefTest.java (original)
+++ activemq/camel/trunk/components/camel-sql/src/test/java/org/apache/camel/component/sql/SqlDataSourceRefTest.java Tue Nov 11 23:50:26 2008
@@ -45,13 +45,27 @@
     }
 
     public void testSimpleBody() throws Exception {
+        // END SNIPPET: e3
         MockEndpoint mock = getMockEndpoint("mock:result");
         mock.expectedMessageCount(1);
+
+        // send the query to direct that will route it to the sql where we will execute the query
+        // and bind the parameters with the data from the body. The body only contains one value
+        // in this case (GPL) but if we should use multi values then the body will be iterated
+        // so we could supply a List<String> instead containing each binding value.
         template.sendBody("direct:simple", "GPL");
+
         mock.assertIsSatisfied();
+
+        // the result is a List
         List received = assertIsInstanceOf(List.class, mock.getReceivedExchanges().get(0).getIn().getBody());
+
+        // and each row in the list is a Map
         Map row = assertIsInstanceOf(Map.class, received.get(0));
+
+        // and we should be able the get the project from the map that should be Linux
         assertEquals("Linux", row.get("PROJECT"));
+        // END SNIPPET: e3
     }
 
     protected void setUp() throws Exception {
@@ -59,11 +73,14 @@
         super.setUp();
 
         jdbcTemplate = new JdbcTemplate(createDataSource());
+        // START SNIPPET: e2
+        // this is the database we create with some initial data for our unit test
         jdbcTemplate.execute("create table projects (id integer primary key,"
                              + "project varchar(10), license varchar(5))");
         jdbcTemplate.execute("insert into projects values (1, 'Camel', 'ASF')");
         jdbcTemplate.execute("insert into projects values (2, 'AMQ', 'ASF')");
         jdbcTemplate.execute("insert into projects values (3, 'Linux', 'GPL')");
+        // END SNIPPET: e2
     }
 
     protected void tearDown() throws Exception {