Clover coverage report - Diasparsoft Toolkit - 0.22
Coverage timestamp: Mon Jun 7 2004 22:02:31 EDT
file stats: LOC: 145   Methods: 9
NCLOC: 81   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
JdbcUtil.java 12.5% 7.1% 22.2% 10.2%
coverage coverage
 1   
 package com.diasparsoftware.jdbc;
 2   
 
 3   
 import java.sql.*;
 4   
 import java.util.*;
 5   
 import java.util.Date;
 6   
 
 7   
 import org.easymock.MockControl;
 8   
 
 9   
 import com.diasparsoftware.java.util.*;
 10   
 
 11   
 public class JdbcUtil {
 12   
 
 13   
     /**
 14   
      * Provide a human-readable view of a JDBC result set.
 15   
      * 
 16   
      * Here is sample output, showing two rows and the column names.
 17   
      * 
 18   
      * <pre>
 19   
      *  [[EMPLOYEE_NUMBER, NAME, PHONE], [019, Joe, 416 555-1212], [092, Sarah, 416 555-1212]] * </pre>
 20   
      * 
 21   
      * @param resultSet
 22   
      * @return A string representation that looks like a <code>List</code>
 23   
      *         of <code>List</code>s.
 24   
      * @throws SQLException
 25   
      */
 26  0
     public static List resultSetAsTable(ResultSet resultSet)
 27   
             throws SQLException {
 28   
 
 29  0
         List rows = new LinkedList();
 30   
 
 31  0
         ResultSetMetaData resultSetMetaData = resultSet.getMetaData();
 32  0
         int columnCount = resultSetMetaData.getColumnCount();
 33   
 
 34  0
         List columnNames = new LinkedList();
 35  0
         for (int i = 1; i <= columnCount; i++) {
 36  0
             String columnName = resultSetMetaData.getColumnName(i);
 37  0
             columnNames.add(columnName);
 38   
         }
 39   
 
 40  0
         rows.add(columnNames);
 41  0
         int rowCount = 1;
 42   
 
 43  0
         while (resultSet.next()) {
 44  0
             List rowData = new LinkedList();
 45  0
             for (int i = 1; i <= columnCount; i++) {
 46  0
                 Object columnData = resultSet.getObject(i);
 47  0
                 rowData.add(columnData);
 48   
             }
 49   
 
 50  0
             rows.add(rowData);
 51  0
             rowCount++;
 52   
         }
 53   
 
 54  0
         return rows;
 55   
     }
 56   
 
 57   
     /**
 58   
      * Creates a <code>Timestamp</code> object from the specified
 59   
      * year, month, day, but at 12 noon local time.
 60   
      * 
 61   
      * @param year
 62   
      * @param month
 63   
      * @param day
 64   
      * @return
 65   
      */
 66  8
     public static Timestamp makeTimestamp(int year, int month, int day) {
 67   
 
 68   
         // Look at the hoops you have to go through to avoid deprecated
 69   
         // APIs!
 70  8
         return new Timestamp(DateUtil.makeDate(year, month, day).getTime());
 71   
     }
 72   
 
 73  0
     public static Timestamp makeTimestamp(Date date) {
 74  0
         return new Timestamp(date.getTime());
 75   
     }
 76   
 
 77   
     /**
 78   
      * A way to make timestamps for normal people &mdash; none of this
 79   
      * "year minus 1900" and "month minus 1" nonsense.
 80   
      * 
 81   
      * @param year
 82   
      * @param month
 83   
      * @param day
 84   
      * @param hour
 85   
      * @param minute
 86   
      * @param second
 87   
      * @param millisecond
 88   
      * @return
 89   
      */
 90  0
     public static Timestamp makeTimestamp(int year, int month, int day,
 91   
             int hour, int minute, int second, int millisecond) {
 92   
 
 93  0
         Calendar calendar = new GregorianCalendar();
 94  0
         calendar.set(Calendar.YEAR, year);
 95  0
         calendar.set(Calendar.MONTH, month - 1);
 96  0
         calendar.set(Calendar.DATE, day);
 97  0
         calendar.set(Calendar.HOUR_OF_DAY, hour);
 98  0
         calendar.set(Calendar.MINUTE, minute);
 99  0
         calendar.set(Calendar.SECOND, second);
 100  0
         calendar.set(Calendar.MILLISECOND, millisecond);
 101   
 
 102  0
         return new Timestamp(calendar.getTimeInMillis());
 103   
     }
 104   
 
 105  0
     public static Date toJavaUtilDate(Timestamp timestamp) {
 106  0
         return new Date(timestamp.getTime());
 107   
     }
 108   
 
 109  24
     public static void setPreparedStatementParameters(
 110   
             PreparedStatement preparedStatement, List parameters) throws SQLException {
 111   
 
 112  24
         int index = 1;
 113  24
         for (Iterator i = parameters.iterator(); i.hasNext(); ) {
 114  0
             Object each = (Object) i.next();
 115  0
             preparedStatement.setObject(index, each);
 116  0
             index++;
 117   
         }
 118   
     }
 119   
 
 120  0
     public static ResultSet createFakeResultSet(Map rowData,
 121   
             final MockControl resultSetControl) {
 122   
 
 123  0
         final ResultSet resultSet = (ResultSet) resultSetControl.getMock();
 124   
 
 125  0
         CollectionUtil.forEachDo(rowData, new MapEntryClosure() {
 126  0
             public void eachMapEntry(Object key, Object value) {
 127  0
                 try {
 128  0
                     resultSet.getObject((String) key);
 129  0
                     resultSetControl.setReturnValue(value,
 130   
                             MockControl.ONE_OR_MORE);
 131   
                 }
 132   
                 catch (SQLException e) {
 133  0
                     throw new RuntimeException(
 134   
                             "Unable to create fake ResultSet", e);
 135   
                 }
 136   
             }
 137   
         });
 138   
 
 139  0
         return resultSet;
 140   
     }
 141   
 
 142  0
     public static java.sql.Date makeDate(int year, int month, int day) {
 143  0
         return new java.sql.Date(DateUtil.makeDate(year, month, day).getTime());
 144   
     }
 145   
 }