Coverage report

  %line %branch
ca.spaz.sql.SQLSelectableStatement
52% 
97% 

 1  
 /*
 2  
  *******************************************************************************
 3  
  * Copyright (c) 2005 Chris Rose and AIMedia
 4  
  * All rights reserved. SQLSelectableStatement and the accompanying materials
 5  
  * are made available under the terms of the Common Public License v1.0
 6  
  * which accompanies this distribution, and is available at
 7  
  * http://www.eclipse.org/legal/cpl-v10.html
 8  
  * 
 9  
  * Contributors:
 10  
  *     Chris Rose
 11  
  *******************************************************************************/
 12  
 package ca.spaz.sql;
 13  
 
 14  
 import java.util.ArrayList;
 15  
 
 16  
 /**
 17  
  * An abstract class encapsulating capabilities that are consistent across all selecting SQL
 18  
  * statements.
 19  
  *  
 20  
  * @author Chris Rose
 21  
  */
 22  
 public abstract class SQLSelectableStatement extends SQLStatement {
 23  
     
 24  
     private boolean and;
 25  
 
 26  
    protected SQLSelectableStatement(String table, boolean and, class="keyword">boolean querySupport, class="keyword">boolean executeSupport) {
 27  11
         super(table, querySupport, executeSupport);
 28  11
         this.and = and;
 29  11
     }
 30  
 
 31  11
     private final ArrayList where = new ArrayList();
 32  
     public static final String EQ = "=";
 33  
     public static final String GT = ">";
 34  
     public static final String LT = "<";
 35  
 
 36  
     /**
 37  
      * Added a WHERE constraint to the SELECT command.
 38  
      * 
 39  
      * @param name
 40  
      *            the field to constrain
 41  
      * @param val
 42  
      *            the value this field must equal as a constraint
 43  
      */
 44  
     public void addWhere(String name, Object val) {
 45  11
         addWhere(name, EQ, val);
 46  10
     }
 47  
 
 48  
     public void addWhere(String name, String operator, Object val) {
 49  18
         where.add("upper(" + name + ") " + operator + " '"
 50  8
                 + escape(fixClass(val).toString()).toUpperCase() + "' ");
 51  10
     }
 52  
     
 53  
     public void addWhere(String name, int val) {
 54  0
         addWhere(name, EQ, val);
 55  0
     }
 56  
     
 57  
     public void addWhere(String name, String op, int val) {
 58  0
         addWhere(name, op, new Integer(val));
 59  0
     }
 60  
 
 61  
     public void addWhere(String name, double val) {
 62  0
         addWhere(name, EQ, val);
 63  0
     }
 64  
     
 65  
     public void addWhere(String name, String op, double val) {
 66  0
         addWhere(name, op, new Double(val));
 67  0
     }
 68  
 
 69  
     public void addWhere(String name, char val) {
 70  0
         addWhere(name, EQ, val);
 71  0
     }
 72  
     
 73  
     public void addWhere(String name, String op, char val) {
 74  0
         addWhere(name, op, new Character(val));
 75  0
     }
 76  
 
 77  
     /**
 78  
      * Added a WHERE constraint to the SELECT command.
 79  
      * 
 80  
      * @param name
 81  
      *            the field to constrain
 82  
      * @param val
 83  
      *            the value this field must be like
 84  
      */
 85  
     public void addWhereLike(String name, String val) {
 86  0
         where.add("upper(" + name + ") like '"
 87  
                 + escape(val.toString()).toUpperCase() + "' ");
 88  0
     }
 89  
 
 90  
     /**
 91  
      */
 92  
     protected String getWhere() {
 93  10
         StringBuffer sb = new StringBuffer();
 94  10
         if (where.size() > 0) {
 95  10
             sb.append(" WHERE ");
 96  20
             for (int i = 0; i < where.size(); i++) {
 97  10
                 Object w = where.get(i);
 98  10
                 sb.append(w.toString());
 99  10
                 if (i < where.size() - 1) {
 100  0
                     sb.append(and ? " AND " : " OR ");
 101  
                 }
 102  
             }
 103  
         }
 104  10
         return sb.toString();
 105  
     }
 106  
 
 107  
 }

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