Coverage report

  %line %branch
ca.spaz.sql.SQLUpdate
0% 
0% 

 1  
 package ca.spaz.sql;
 2  
 
 3  
 import java.sql.*;
 4  
 import java.util.*;
 5  
 
 6  
 import org.apache.log4j.Logger;
 7  
 
 8  
 /**
 9  
  * Simplifies constructing SQL Update Queries.
 10  
  */
 11  
 public class SQLUpdate extends SQLSelectableStatement implements Columns {
 12  
     /**
 13  
      * Logger for this class
 14  
      */
 15  0
     private static final Logger logger = Logger.getLogger(SQLUpdate.class);
 16  
 
 17  
     private SQLColumnSet cols;
 18  
 
 19  
    /**
 20  
     * Create a new SQLUpdate command for the given table
 21  
     * @param tableName the name of the table to update on
 22  
     */
 23  
    public SQLUpdate(String tableName) {
 24  0
       super(tableName, true, false, class="keyword">true);
 25  0
       cols = new SQLColumnSet();
 26  0
    }
 27  
 
 28  
    /** 
 29  
     * Overrides execute() and calls executeUpdate()
 30  
     */
 31  
    protected void doExecute(Connection con) throws SQLException {
 32  0
       Statement stmt = con.createStatement();      
 33  0
       String query = this.getQueryString();
 34  0
       if (logger.isDebugEnabled()) {
 35  0
           logger.debug("executeQuery() - Statement to be executed: " + query);
 36  
       }
 37  
      
 38  0
       stmt.executeUpdate(query);
 39  0
    }
 40  
 
 41  
    /**
 42  
     * Generate the SQL string for an UPDATE command.
 43  
     */
 44  
    protected String getQueryString() {
 45  0
       StringBuffer sb = new StringBuffer();
 46  0
       sb.append("UPDATE ");
 47  0
       sb.append(getTableName());
 48  0
       sb.append(" SET ");
 49  0
       List names = cols.getNames();
 50  0
       List terms = cols.getValues();
 51  0
       for (int i=0; i<names.size(); i++) {         
 52  0
          Object name = names.get(i);
 53  0
          Object term = terms.get(i);
 54  0
          if (term == null) {
 55  0
             term = "NULL"; 
 56  
          }
 57  0
          sb.append(name.toString());
 58  0
          sb.append(" = '");
 59  0
          sb.append(escape(term.toString()));
 60  0
          sb.append("' ");
 61  0
          if (i < names.size() - 1) {
 62  0
             sb.append(", ");
 63  
          }
 64  
       }
 65  0
       sb.append(getWhere());
 66  0
       return sb.toString();
 67  
    }
 68  
 
 69  
    /**
 70  
     * Retrieve the <code>cols</code> from the <code>SQLInsert</code>
 71  
     * @return Returns the cols.
 72  
     */
 73  
    public SQLColumnSet getColumns() {
 74  0
       return cols;
 75  
    }
 76  
 
 77  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.