Author: gnodet
Date: Wed May  2 05:44:44 2007
New Revision: 534429

URL: http://svn.apache.org/viewvc?view=rev&rev=534429
Log:
SM-911: JDBCComponent: The first column index is 1 in a result from sql query 
(non zero)

Added:
    
incubator/servicemix/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/jdbc/JdbcComponentTest.java
   (with props)
Modified:
    incubator/servicemix/trunk/common/servicemix-components/pom.xml
    
incubator/servicemix/trunk/common/servicemix-components/src/main/java/org/apache/servicemix/components/jdbc/JdbcComponent.java
    
incubator/servicemix/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/jdbc/JdbcComponentUniqueNamesTest.java

Modified: incubator/servicemix/trunk/common/servicemix-components/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-components/pom.xml?view=diff&rev=534429&r1=534428&r2=534429
==============================================================================
--- incubator/servicemix/trunk/common/servicemix-components/pom.xml (original)
+++ incubator/servicemix/trunk/common/servicemix-components/pom.xml Wed May  2 
05:44:44 2007
@@ -253,6 +253,11 @@
       <version>${spring-version}</version>
       <optional>true</optional>
     </dependency>
+    <dependency>
+      <groupId>hsqldb</groupId>
+      <artifactId>hsqldb</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   
   <repositories>

Modified: 
incubator/servicemix/trunk/common/servicemix-components/src/main/java/org/apache/servicemix/components/jdbc/JdbcComponent.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-components/src/main/java/org/apache/servicemix/components/jdbc/JdbcComponent.java?view=diff&rev=534429&r1=534428&r2=534429
==============================================================================
--- 
incubator/servicemix/trunk/common/servicemix-components/src/main/java/org/apache/servicemix/components/jdbc/JdbcComponent.java
 (original)
+++ 
incubator/servicemix/trunk/common/servicemix-components/src/main/java/org/apache/servicemix/components/jdbc/JdbcComponent.java
 Wed May  2 05:44:44 2007
@@ -187,8 +187,8 @@
 
         while (rs.next()) {
             buff.append("<row ");
-            for (int i=1; i<=colCount; i++) {
-                buff.append(colNames[i].toLowerCase() + "='" + rs.getString(i) 
+ "' ");
+            for (int i = 0; i < colCount; i++) {
+                buff.append(colNames[i].toLowerCase() + "='" + rs.getString(i 
+ 1) + "' ");
             }
             buff.append("/>");
         }
@@ -213,7 +213,7 @@
         List colNames = new LinkedList();
         Map chanedNames = new HashMap();
 
-        for (int i = 0; i < metaData.getColumnCount(); i++) {
+        for (int i = 1; i <= metaData.getColumnCount(); i++) {
             String name = metaData.getColumnName(i);
 
             if (name.equals("")) {

Added: 
incubator/servicemix/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/jdbc/JdbcComponentTest.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/jdbc/JdbcComponentTest.java?view=auto&rev=534429
==============================================================================
--- 
incubator/servicemix/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/jdbc/JdbcComponentTest.java
 (added)
+++ 
incubator/servicemix/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/jdbc/JdbcComponentTest.java
 Wed May  2 05:44:44 2007
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.components.jdbc;
+
+import java.sql.Connection;
+import java.sql.Statement;
+
+import javax.jbi.messaging.InOut;
+import javax.sql.DataSource;
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.servicemix.client.DefaultServiceMixClient;
+import org.apache.servicemix.jbi.container.JBIContainer;
+import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.jbi.jaxp.StringSource;
+import org.hsqldb.jdbc.jdbcDataSource;
+
+public class JdbcComponentTest extends TestCase {
+
+       private JBIContainer jbi;
+       private DataSource dataSource;
+       private JdbcComponent jdbc;
+       
+       protected void setUp() throws Exception {
+        jdbcDataSource ds = new jdbcDataSource();
+        ds.setDatabase("jdbc:hsqldb:mem:aname");
+        ds.setUser("sa");
+               dataSource = ds;
+               
+               jbi = new JBIContainer();
+               jbi.setEmbedded(true);
+               jbi.init();
+               jbi.start();
+               
+               jdbc = new JdbcComponent();
+               jdbc.setService(new QName("urn:jdbc", "service"));
+               jdbc.setEndpoint("endpoint");
+               jdbc.setDataSource(dataSource);
+               jbi.activateComponent(jdbc, "jdbc");
+       }
+       
+       protected void tearDown() throws Exception {
+               jbi.shutDown();
+       }
+
+       public void testInOut() throws Exception {
+               Connection con = dataSource.getConnection("sa", "");
+               Statement st = con.createStatement();
+               st.execute("create table MyTable (id varchar(80) not null, name 
varchar(80))");
+               st.execute("insert into MyTable values ('1', 'One')");
+               st.execute("insert into MyTable values ('2', 'Two')");
+               
+               DefaultServiceMixClient client = new 
DefaultServiceMixClient(jbi);
+               InOut me = client.createInOutExchange();
+               me.setService(new QName("urn:jdbc", "service"));
+               me.getInMessage().setContent(new StringSource("<sql>select * 
from MyTable</sql>"));
+               client.sendSync(me);
+               String out = new 
SourceTransformer().contentToString(me.getOutMessage());
+               System.err.println(out);
+               assertTrue(out.contains("One"));
+               assertTrue(out.contains("Two"));
+       }
+}

Propchange: 
incubator/servicemix/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/jdbc/JdbcComponentTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
incubator/servicemix/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/jdbc/JdbcComponentTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: 
incubator/servicemix/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/jdbc/JdbcComponentTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
incubator/servicemix/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/jdbc/JdbcComponentUniqueNamesTest.java
URL: 
http://svn.apache.org/viewvc/incubator/servicemix/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/jdbc/JdbcComponentUniqueNamesTest.java?view=diff&rev=534429&r1=534428&r2=534429
==============================================================================
--- 
incubator/servicemix/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/jdbc/JdbcComponentUniqueNamesTest.java
 (original)
+++ 
incubator/servicemix/trunk/common/servicemix-components/src/test/java/org/apache/servicemix/components/jdbc/JdbcComponentUniqueNamesTest.java
 Wed May  2 05:44:44 2007
@@ -60,7 +60,7 @@
                }
 
                public String getColumnName(int column) throws SQLException {
-                       return names[column];
+                       return names[column-1];
                }
 
                public String getCatalogName(int column) throws SQLException {
@@ -139,11 +139,11 @@
                        throw new RuntimeException("not implemented");
                }
 
-               public boolean isWrapperFor(Class iface) throws SQLException {
+               public boolean isWrapperFor(Class arg0) throws SQLException {
                        throw new RuntimeException("not implemented");
                }
 
-               public Object unwrap(Class iface) throws SQLException {
+               public Object unwrap(Class arg0) throws SQLException {
                        throw new RuntimeException("not implemented");
                }
 


Reply via email to