Clover coverage report - brownies library - 1.0-beta-1
Coverage timestamp: 月 8 16 2004 17:14:42 GMT+09:00
file stats: LOC: 262   Methods: 17
NCLOC: 161   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
LogStatement.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   
 /*
 6   
  * Created on 2004/03/01
 7   
  */
 8   
 package org.asyrinx.brownie.jdbc.logger;
 9   
 
 10   
 import java.sql.ResultSet;
 11   
 import java.sql.SQLException;
 12   
 import java.sql.Statement;
 13   
 import java.util.ArrayList;
 14   
 import java.util.Iterator;
 15   
 import java.util.List;
 16   
 
 17   
 import org.asyrinx.brownie.core.log.CascadeNamedLog;
 18   
 import org.asyrinx.brownie.jdbc.wrapper.StatementWrapper;
 19   
 
 20   
 /**
 21   
  * @author akima
 22   
  */
 23   
 public class LogStatement extends StatementWrapper {
 24   
     /**
 25   
      * @param wrapped
 26   
      */
 27  0
     public LogStatement(Statement wrapped, CascadeNamedLog parentLog) {
 28  0
         super(wrapped);
 29  0
         this.log = parentLog.subLog(this.wrapped);
 30   
     }
 31   
 
 32   
     protected final CascadeNamedLog log;
 33   
 
 34  0
     protected void log(Object message) {
 35  0
         log.log(message);
 36   
     }
 37   
 
 38  0
     protected void log(Object message, Throwable t) {
 39  0
         log.log(message, t);
 40   
     }
 41   
 
 42  0
     protected void logBatch(int[] results) {
 43  0
         final StringBuffer result = new StringBuffer("batch executed:\n");
 44  0
         final Iterator iterator = batches.iterator();
 45  0
         int idx = 0;
 46  0
         while (iterator.hasNext()) {
 47  0
             if (idx > results.length - 1)
 48  0
                 break;
 49  0
             String sql = (String) iterator.next();
 50  0
             result.append(idx).append(" [").append(results[idx]).append("]");
 51  0
             result.append(sql).append("\n");
 52  0
             idx++;
 53   
         }
 54  0
         log.log(result.toString());
 55   
     }
 56   
 
 57  0
     protected void logBatch(Throwable t) {
 58  0
         final StringBuffer result = new StringBuffer("batch executed:\n");
 59  0
         final Iterator iterator = batches.iterator();
 60  0
         int idx = 0;
 61  0
         while (iterator.hasNext()) {
 62  0
             String sql = (String) iterator.next();
 63  0
             result.append(idx).append(" [?]");
 64  0
             result.append(sql).append("\n");
 65  0
             idx++;
 66   
         }
 67  0
         log.log((Object) result.toString(), t);
 68   
     }
 69   
 
 70   
     protected final List batches = new ArrayList();
 71   
 
 72   
     /*
 73   
      * (non-Javadoc)
 74   
      * 
 75   
      * @see org.asyrinx.brownie.jdbc.logger.StatementWrapper#addBatch(java.lang.String)
 76   
      */
 77  0
     public void addBatch(String sql) throws SQLException {
 78  0
         super.addBatch(sql);
 79  0
         batches.add(sql);
 80   
     }
 81   
 
 82   
     /*
 83   
      * (non-Javadoc)
 84   
      * 
 85   
      * @see org.asyrinx.brownie.jdbc.logger.StatementWrapper#clearBatch()
 86   
      */
 87  0
     public void clearBatch() throws SQLException {
 88  0
         super.clearBatch();
 89  0
         batches.clear();
 90   
     }
 91   
 
 92   
     /*
 93   
      * (non-Javadoc)
 94   
      * 
 95   
      * @see org.asyrinx.brownie.jdbc.logger.StatementWrapper#execute(java.lang.String)
 96   
      */
 97  0
     public boolean execute(String sql) throws SQLException {
 98  0
         try {
 99  0
             boolean result = super.execute(sql);
 100  0
             log(sql);
 101  0
             return result;
 102   
         } catch (SQLException e) {
 103  0
             log(sql, e);
 104  0
             throw e;
 105   
         }
 106   
     }
 107   
 
 108   
     /*
 109   
      * (non-Javadoc)
 110   
      * 
 111   
      * @see org.asyrinx.brownie.jdbc.logger.StatementWrapper#execute(java.lang.String,
 112   
      *      int)
 113   
      */
 114  0
     public boolean execute(String sql, int autoGeneratedKeys)
 115   
             throws SQLException {
 116  0
         try {
 117  0
             boolean result = super.execute(sql, autoGeneratedKeys);
 118  0
             log(sql);
 119  0
             return result;
 120   
         } catch (SQLException e) {
 121  0
             log(sql, e);
 122  0
             throw e;
 123   
         }
 124   
     }
 125   
 
 126   
     /*
 127   
      * (non-Javadoc)
 128   
      * 
 129   
      * @see org.asyrinx.brownie.jdbc.logger.StatementWrapper#execute(java.lang.String,
 130   
      *      int[])
 131   
      */
 132  0
     public boolean execute(String sql, int[] columnIndexes) throws SQLException {
 133  0
         try {
 134  0
             boolean result = super.execute(sql, columnIndexes);
 135  0
             log(sql);
 136  0
             return result;
 137   
         } catch (SQLException e) {
 138  0
             log(sql, e);
 139  0
             throw e;
 140   
         }
 141   
     }
 142   
 
 143   
     /*
 144   
      * (non-Javadoc)
 145   
      * 
 146   
      * @see org.asyrinx.brownie.jdbc.logger.StatementWrapper#execute(java.lang.String,
 147   
      *      java.lang.String[])
 148   
      */
 149  0
     public boolean execute(String sql, String[] columnNames)
 150   
             throws SQLException {
 151  0
         try {
 152  0
             boolean result = super.execute(sql, columnNames);
 153  0
             log(sql);
 154  0
             return result;
 155   
         } catch (SQLException e) {
 156  0
             log(sql, e);
 157  0
             throw e;
 158   
         }
 159   
     }
 160   
 
 161   
     /*
 162   
      * (non-Javadoc)
 163   
      * 
 164   
      * @see org.asyrinx.brownie.jdbc.logger.StatementWrapper#executeBatch()
 165   
      */
 166  0
     public int[] executeBatch() throws SQLException {
 167  0
         try {
 168  0
             final int[] result = super.executeBatch();
 169  0
             logBatch(result);
 170  0
             return result;
 171   
         } catch (SQLException e) {
 172  0
             logBatch(e);
 173  0
             throw e;
 174   
         }
 175   
     }
 176   
 
 177   
     /*
 178   
      * (non-Javadoc)
 179   
      * 
 180   
      * @see org.asyrinx.brownie.jdbc.logger.StatementWrapper#executeQuery(java.lang.String)
 181   
      */
 182  0
     public ResultSet executeQuery(String sql) throws SQLException {
 183  0
         try {
 184  0
             final ResultSet result = super.executeQuery(sql);
 185  0
             log(sql);
 186  0
             return result;
 187   
         } catch (SQLException e) {
 188  0
             log(sql, e);
 189  0
             throw e;
 190   
         }
 191   
     }
 192   
 
 193   
     /*
 194   
      * (non-Javadoc)
 195   
      * 
 196   
      * @see org.asyrinx.brownie.jdbc.logger.StatementWrapper#executeUpdate(java.lang.String)
 197   
      */
 198  0
     public int executeUpdate(String sql) throws SQLException {
 199  0
         try {
 200  0
             final int result = super.executeUpdate(sql);
 201  0
             log(sql);
 202  0
             return result;
 203   
         } catch (SQLException e) {
 204  0
             log(sql, e);
 205  0
             throw e;
 206   
         }
 207   
     }
 208   
 
 209   
     /*
 210   
      * (non-Javadoc)
 211   
      * 
 212   
      * @see org.asyrinx.brownie.jdbc.logger.StatementWrapper#executeUpdate(java.lang.String,
 213   
      *      int)
 214   
      */
 215  0
     public int executeUpdate(String sql, int autoGeneratedKeys)
 216   
             throws SQLException {
 217  0
         try {
 218  0
             final int result = super.executeUpdate(sql, autoGeneratedKeys);
 219  0
             log(sql);
 220  0
             return result;
 221   
         } catch (SQLException e) {
 222  0
             log(sql, e);
 223  0
             throw e;
 224   
         }
 225   
     }
 226   
 
 227   
     /*
 228   
      * (non-Javadoc)
 229   
      * 
 230   
      * @see org.asyrinx.brownie.jdbc.logger.StatementWrapper#executeUpdate(java.lang.String,
 231   
      *      int[])
 232   
      */
 233  0
     public int executeUpdate(String sql, int[] columnIndexes)
 234   
             throws SQLException {
 235  0
         try {
 236  0
             final int result = super.executeUpdate(sql, columnIndexes);
 237  0
             log(sql);
 238  0
             return result;
 239   
         } catch (SQLException e) {
 240  0
             log(sql, e);
 241  0
             throw e;
 242   
         }
 243   
     }
 244   
 
 245   
     /*
 246   
      * (non-Javadoc)
 247   
      * 
 248   
      * @see org.asyrinx.brownie.jdbc.logger.StatementWrapper#executeUpdate(java.lang.String,
 249   
      *      java.lang.String[])
 250   
      */
 251  0
     public int executeUpdate(String sql, String[] columnNames)
 252   
             throws SQLException {
 253  0
         try {
 254  0
             final int result = super.executeUpdate(sql, columnNames);
 255  0
             log(sql);
 256  0
             return result;
 257   
         } catch (SQLException e) {
 258  0
             log(sql, e);
 259  0
             throw e;
 260   
         }
 261   
     }
 262   
 }