Coverage report

  %line %branch
ca.spaz.sql.SQLStatement
52% 
88% 

 1  
 package ca.spaz.sql;
 2  
 
 3  
 import java.sql.*;
 4  
 
 5  
 /**
 6  
  * Base class for SQL command generators
 7  
  * 
 8  
  * @author davidson
 9  
  */
 10  
 public abstract class SQLStatement {
 11  
 
 12  
     public final void execute(Connection con) throws SQLException {
 13  0
         if (!isExecuteSupported()) {
 14  0
             throw new UnsupportedOperationException("Execute not supported on "
 15  
                     + getClass().getName());
 16  
         }
 17  0
         doExecute(con);
 18  0
     }
 19  
 
 20  0
     protected void doExecute(Connection con) throws SQLException { }
 21  
 
 22  
     public final boolean isExecuteSupported() {
 23  0
         return executeSupport;
 24  
     }
 25  
 
 26  
     public final ResultSet executeQuery(Connection con) throws SQLException {
 27  10
         if (!isQuerySupported()) {
 28  0
             throw new UnsupportedOperationException("Query not supported on "
 29  
                     + getClass().getName());
 30  
         }
 31  10
         return doExecuteQuery(con);
 32  
     }
 33  
 
 34  
     protected ResultSet doExecuteQuery(Connection con) throws SQLException {
 35  0
         return null;
 36  
     }
 37  
 
 38  
     public final boolean isQuerySupported() {
 39  10
         return querySupport;
 40  
     }
 41  
 
 42  
     protected String table;
 43  
 
 44  
     private boolean querySupport;
 45  
 
 46  
     private boolean executeSupport;
 47  
 
 48  8
     protected SQLStatement(String table, boolean querySupport,
 49  3
             boolean executeSupport) {
 50  11
         this.table = table;
 51  11
         this.querySupport = querySupport;
 52  11
         this.executeSupport = executeSupport;
 53  11
     }
 54  
 
 55  
     public String getTableName() {
 56  10
         return table;
 57  
     }
 58  
 
 59  
     static String escape(String s) {
 60  10
         return s.replaceAll("\\'", "\\'\\'");
 61  
     }
 62  
 
 63  
     protected abstract String getQueryString();
 64  
 
 65  
     public String toString() {
 66  0
         return getQueryString();
 67  
     }
 68  
     
 69  
     /**
 70  
      * Ensure that correct classes (with respect to toString()) ge
 71  
      * passed on
 72  
      * @param o the class to check.
 73  
      * @return a valid class for SQL
 74  
      */
 75  
     static Object fixClass(Object o) {
 76  11
        if (o instanceof java.util.Date) {
 77  0
           o = new java.sql.Date(((java.util.Date)o).getTime());
 78  
        }
 79  11
        return o;
 80  
     }
 81  
     
 82  
 
 83  
 }

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