Coverage Report - org.mule.transport.jdbc.ColumnAliasRowProcessor
 
Classes in this File Line Coverage Branch Coverage Complexity
ColumnAliasRowProcessor
0%
0/7
0%
0/2
0
 
 1  
 /*
 2  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
 3  
  * The software in this package is published under the terms of the CPAL v1.0
 4  
  * license, a copy of which has been included with this distribution in the
 5  
  * LICENSE.txt file.
 6  
  */
 7  
 package org.mule.transport.jdbc;
 8  
 
 9  
 import org.mule.util.CaseInsensitiveHashMap;
 10  
 
 11  
 import java.sql.ResultSet;
 12  
 import java.sql.ResultSetMetaData;
 13  
 import java.sql.SQLException;
 14  
 import java.util.Map;
 15  
 
 16  
 import org.apache.commons.dbutils.BasicRowProcessor;
 17  
 
 18  
 /**
 19  
  * Processes a row from a {@link ResultSet} using the column labels
 20  
  * instead of the column names.
 21  
  * <p/>
 22  
  * This is needed because some database drivers return different values for the
 23  
  * column name and column label. {@link BasicRowProcessor} uses column names,
 24  
  * so in the mentioned cases column aliases are lost and are only available for
 25  
  * calculated values.
 26  
  */
 27  0
 public class ColumnAliasRowProcessor extends BasicRowProcessor
 28  
 {
 29  
 
 30  
     @Override
 31  
     public Map toMap(ResultSet rs) throws SQLException
 32  
     {
 33  0
         Map result = new CaseInsensitiveHashMap();
 34  0
         ResultSetMetaData rsmd = rs.getMetaData();
 35  0
         int cols = rsmd.getColumnCount();
 36  
 
 37  0
         for (int i = 1; i <= cols; i++)
 38  
         {
 39  0
             result.put(rsmd.getColumnLabel(i), rs.getObject(i));
 40  
         }
 41  
 
 42  0
         return result;
 43  
     }
 44  
 }