Clover coverage report - brownies library - 1.0-beta-1
Coverage timestamp: 月 8 16 2004 17:14:42 GMT+09:00
file stats: LOC: 236   Methods: 18
NCLOC: 97   Classes: 5
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
ResultSetFilter.java 0% 0% 0% 0%
coverage
 1   
 /*
 2   
  * Joey and its relative products are published under the terms
 3   
  * of the Apache Software License.
 4   
  */
 5   
 package org.asyrinx.brownie.jdbc;
 6   
 
 7   
 import java.sql.Date;
 8   
 import java.sql.ResultSet;
 9   
 import java.sql.SQLException;
 10   
 import java.sql.Timestamp;
 11   
 
 12   
 import org.asyrinx.brownie.core.lang.StringUtils;
 13   
 import org.asyrinx.brownie.jdbc.wrapper.ResultSetWrapper;
 14   
 
 15   
 /**
 16   
  * @author Akima
 17   
  */
 18   
 public final class ResultSetFilter {
 19   
 
 20   
     /**
 21   
      *  
 22   
      */
 23  0
     private ResultSetFilter() {
 24  0
         super();
 25   
     }
 26   
 
 27   
     /**
 28   
      * getStringで得られる文字列にtrimをかけるフィルタ 文字列がnullだった場合、ヌル文字列に変換する。
 29   
      * 
 30   
      * @param source
 31   
      * @return
 32   
      */
 33  0
     public static ResultSet trim(ResultSet source) {
 34  0
         return stringNullTrim(stringTrim(source));
 35   
     }
 36   
 
 37   
     /**
 38   
      * getStringで得られる文字列がnullだった場合ヌル文字列に変換するフィルタ
 39   
      * 
 40   
      * @param source
 41   
      * @return
 42   
      */
 43  0
     public static ResultSet stringNullTrim(ResultSet source) {
 44  0
         return new ResultSetStringNullTrimFilter(source);
 45   
     }
 46   
 
 47   
     /**
 48   
      * getStringで得られる文字列にtrimを行うフィルタ
 49   
      * 
 50   
      * @param source
 51   
      * @return
 52   
      */
 53  0
     public static ResultSet stringTrim(ResultSet source) {
 54  0
         return new ResultSetStringTrimFilter(source);
 55   
     }
 56   
 
 57   
     /**
 58   
      * getDateで得られる日付(Date)は、 getTimestampから取得したミリ秒単位の日付時刻になります。
 59   
      */
 60  0
     public static ResultSet detailDate(ResultSet source) {
 61  0
         return new ResultSetDetailDateFilter(source);
 62   
     }
 63   
 
 64   
     /**
 65   
      * nextメソッドによって進めるレコード数が、指定したmaxCountまでになります。 maxCountが0以下ならフィルタリングしません。
 66   
      * 
 67   
      * @param source
 68   
      * @param maxCount
 69   
      * @return
 70   
      */
 71  0
     public static ResultSet maxCount(ResultSet source, int maxCount) {
 72  0
         return new ResultSetMaxCountFilter(source, maxCount);
 73   
     }
 74   
 
 75   
 }
 76   
 
 77   
 /**
 78   
  * getStringメソッドの戻り値に対して、trimを行うフィルタです。 戻り値がnullの場合にはヌル文字列を返します。
 79   
  * 
 80   
  * @author Akima
 81   
  */
 82   
 
 83   
 class ResultSetStringTrimFilter extends ResultSetWrapper {
 84   
     /**
 85   
      * Constructor for ResultSetStringTrimFilter.
 86   
      * 
 87   
      * @param impl
 88   
      */
 89  0
     public ResultSetStringTrimFilter(ResultSet impl) {
 90  0
         super(impl);
 91   
     }
 92   
 
 93   
     /**
 94   
      * @see org.asyrinx.jdbc.ResultSetWrapper#getString(int)
 95   
      */
 96  0
     public String getString(int columnIndex) throws SQLException {
 97  0
         final String result = super.getString(columnIndex);
 98  0
         if (result != null)
 99  0
             return result.trim();
 100   
         else
 101  0
             return null;
 102   
     }
 103   
 
 104   
     /**
 105   
      * @see org.asyrinx.jdbc.ResultSetWrapper#getString(String)
 106   
      */
 107  0
     public String getString(String columnName) throws SQLException {
 108  0
         final String result = super.getString(columnName);
 109  0
         if (result != null)
 110  0
             return result.trim();
 111   
         else
 112  0
             return null;
 113   
     }
 114   
 }
 115   
 /**
 116   
  * getStringメソッドの戻り値に対して、trimを行うフィルタです。 戻り値がnullの場合にはヌル文字列を返します。
 117   
  * 
 118   
  * @author Akima
 119   
  */
 120   
 
 121   
 class ResultSetStringNullTrimFilter extends ResultSetWrapper {
 122   
     /**
 123   
      * Constructor for ResultSetStringTrimFilter.
 124   
      * 
 125   
      * @param impl
 126   
      */
 127  0
     public ResultSetStringNullTrimFilter(ResultSet impl) {
 128  0
         super(impl);
 129   
     }
 130   
 
 131   
     /**
 132   
      * @see org.asyrinx.jdbc.ResultSetWrapper#getString(int)
 133   
      */
 134  0
     public String getString(int columnIndex) throws SQLException {
 135  0
         return StringUtils.nullTrim(super.getString(columnIndex));
 136   
     }
 137   
 
 138   
     /**
 139   
      * @see org.asyrinx.jdbc.ResultSetWrapper#getString(String)
 140   
      */
 141  0
     public String getString(String columnName) throws SQLException {
 142  0
         return StringUtils.nullTrim(super.getString(columnName));
 143   
     }
 144   
 }
 145   
 /**
 146   
  * getStringメソッドの戻り値に対して、trimを行うフィルタです。 戻り値がnullの場合にはヌル文字列を返します。
 147   
  * 
 148   
  * @author Akima
 149   
  */
 150   
 
 151   
 class ResultSetDetailDateFilter extends ResultSetWrapper {
 152   
     /**
 153   
      * Constructor for ResultSetStringTrimFilter.
 154   
      * 
 155   
      * @param impl
 156   
      */
 157  0
     public ResultSetDetailDateFilter(ResultSet impl) {
 158  0
         super(impl);
 159   
     }
 160   
 
 161   
     /**
 162   
      * @see org.asyrinx.jdbc.ResultSetWrapper#getDate(int)
 163   
      */
 164  0
     public Date getDate(int columnIndex) throws SQLException {
 165   
         //return super.getDate(columnIndex);
 166  0
         final Timestamp ts = super.getTimestamp(columnIndex);
 167  0
         if (ts == null)
 168  0
             return null;
 169  0
         return new Date(ts.getTime());
 170   
     }
 171   
 
 172   
     /**
 173   
      * @see org.asyrinx.jdbc.ResultSetWrapper#getDate(java.lang.String)
 174   
      */
 175  0
     public Date getDate(String columnName) throws SQLException {
 176   
         //return super.getDate(columnName);
 177  0
         final Timestamp ts = super.getTimestamp(columnName);
 178  0
         if (ts == null)
 179  0
             return null;
 180  0
         return new Date(ts.getTime());
 181   
     }
 182   
 
 183   
 }
 184   
 /**
 185   
  * <b>summary </b> <br>
 186   
  * <br>
 187   
  * 設定された件数以上nextできないResultSetのフィルタ <br>
 188   
  * <b>detail </b> <br>
 189   
  * <br>
 190   
  * 
 191   
  * @author Akima Created on 2003/05/23
 192   
  */
 193   
 
 194   
 class ResultSetMaxCountFilter extends ResultSetWrapper {
 195   
 
 196   
     /**
 197   
      * @param impl
 198   
      */
 199  0
     public ResultSetMaxCountFilter(ResultSet impl, int maxCount) {
 200  0
         super(impl);
 201  0
         this.maxCount = maxCount;
 202   
 
 203   
     }
 204   
 
 205   
     private final int maxCount;
 206   
 
 207   
     private int count = 0;
 208   
 
 209   
     /**
 210   
      * @see org.asyrinx.jdbc.wrapper.ResultSetWrapper#next()
 211   
      */
 212  0
     public boolean next() throws SQLException {
 213  0
         final boolean result = super.next();
 214  0
         if (result)
 215  0
             count++;
 216   
         // maxCountが0以下ならフィルタリングしない
 217  0
         if (maxCount < 1)
 218  0
             return result;
 219   
         //次がないっていう場合は何もしません
 220  0
         if (!result)
 221  0
             return false;
 222   
         //次はまだある場合に、既に上限より大きかったらfalseを返してしまいます。
 223  0
         return count <= maxCount;
 224   
     }
 225   
 
 226   
     /**
 227   
      * @see org.asyrinx.jdbc.wrapper.ResultSetWrapper#previous()
 228   
      */
 229  0
     public boolean previous() throws SQLException {
 230  0
         final boolean result = super.previous();
 231  0
         if (result)
 232  0
             count--;
 233  0
         return result;
 234   
     }
 235   
 
 236   
 }