Coverage Report - net.admin4j.jdbc.driver.sql.PreparedStatementWrapper30Base
 
Classes in this File Line Coverage Branch Coverage Complexity
PreparedStatementWrapper30Base
100%
87/87
25%
3/12
1.14
 
 1  
 /*
 2  
  * This software is licensed under the Apache License, Version 2.0
 3  
  * (the "License") agreement; you may not use this file except in compliance with
 4  
  * the License.  You may obtain a copy of the License at
 5  
  * 
 6  
  *      http://www.apache.org/licenses/LICENSE-2.0
 7  
  * 
 8  
  * Unless required by applicable law or agreed to in writing, software
 9  
  * distributed under the License is distributed on an "AS IS" BASIS,
 10  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 11  
  * See the License for the specific language governing permissions and
 12  
  * limitations under the License.
 13  
  */
 14  
 package net.admin4j.jdbc.driver.sql;
 15  
 
 16  
 import java.io.InputStream;
 17  
 import java.io.Reader;
 18  
 import java.math.BigDecimal;
 19  
 import java.net.URL;
 20  
 import java.sql.Array;
 21  
 import java.sql.Blob;
 22  
 import java.sql.Clob;
 23  
 import java.sql.Date;
 24  
 import java.sql.ParameterMetaData;
 25  
 import java.sql.PreparedStatement;
 26  
 import java.sql.Ref;
 27  
 import java.sql.ResultSet;
 28  
 import java.sql.ResultSetMetaData;
 29  
 import java.sql.SQLException;
 30  
 import java.sql.Time;
 31  
 import java.sql.Timestamp;
 32  
 import java.util.Calendar;
 33  
 
 34  
 import net.admin4j.deps.commons.lang3.Validate;
 35  
 import net.admin4j.jdbc.driver.SqlStatementTimerFactory;
 36  
 import net.admin4j.timer.TaskTimer;
 37  
 import net.admin4j.util.annotate.PackageRestrictions;
 38  
 
 39  
 /**
 40  
  * Wraps a JDBC V2.0 prepared statement so specifics can be reported to administrators.
 41  
  * @author D. Ashmore
 42  
  * @since 1.0
 43  
  */
 44  
 @PackageRestrictions({"net.admin4j","java","javax"})
 45  
 public abstract class PreparedStatementWrapper30Base extends StatementWrapper30Base implements
 46  
         PreparedStatement, SqlContext {
 47  
     
 48  
     private String sqlText;
 49  
     private StackTraceElement[] executionStack;
 50  
     
 51  
     public PreparedStatementWrapper30Base(ConnectionWrapper30Base connection,
 52  
             PreparedStatement statement) {
 53  180033
         super(connection, statement);
 54  180033
     }
 55  
     
 56  
     protected PreparedStatement getUnderlyingPreparedStatement() {
 57  60111
         return (PreparedStatement)this.getUnderlyingStatement();
 58  
     }
 59  
 
 60  
     public void addBatch() throws SQLException {
 61  6
         this.getUnderlyingPreparedStatement().addBatch();
 62  
 
 63  6
     }
 64  
 
 65  
     public void clearParameters() throws SQLException {
 66  6
         this.getUnderlyingPreparedStatement().clearParameters();
 67  
 
 68  6
     }
 69  
 
 70  
     public boolean execute() throws SQLException {
 71  6
         TaskTimer timer = null;
 72  
         try {
 73  6
             timer = SqlStatementTimerFactory.start(this.getSqlText(), 
 74  
                     this.getConnectionWrapper().getDriverContext(),
 75  
                     this.getExecutionStack());
 76  6
             return this.getUnderlyingPreparedStatement().execute();
 77  
         }
 78  
         finally {
 79  6
             if (timer != null) timer.stop();
 80  
         }
 81  
     }
 82  
 
 83  
     public ResultSet executeQuery() throws SQLException {
 84  120006
         TaskTimer timer = null;
 85  
         try {
 86  120006
             timer = SqlStatementTimerFactory.start(this.getSqlText(), 
 87  
                     this.getConnectionWrapper().getDriverContext(),
 88  
                     this.getExecutionStack());
 89  120006
             return this.getUnderlyingPreparedStatement().executeQuery();
 90  
         }
 91  
         finally {
 92  120006
             if (timer != null) timer.stop();
 93  
         }
 94  
     }
 95  
 
 96  
     public int executeUpdate() throws SQLException {
 97  60006
         TaskTimer timer = null;
 98  
         try {
 99  60006
             timer = SqlStatementTimerFactory.start(this.getSqlText(),
 100  
                     this.getConnectionWrapper().getDriverContext(),
 101  
                     this.getExecutionStack());
 102  60006
             return this.getUnderlyingPreparedStatement().executeUpdate();
 103  
         }
 104  
         finally {
 105  60006
             if (timer != null) timer.stop();
 106  
         }
 107  
     }
 108  
 
 109  
     public ResultSetMetaData getMetaData() throws SQLException {
 110  6
         return this.getUnderlyingPreparedStatement().getMetaData();
 111  
     }
 112  
 
 113  
     public ParameterMetaData getParameterMetaData() throws SQLException {
 114  6
         return this.getUnderlyingPreparedStatement().getParameterMetaData();
 115  
     }
 116  
 
 117  
     public void setArray(int parameterIndex, Array x) throws SQLException {
 118  6
         this.getUnderlyingPreparedStatement().setArray(parameterIndex, x);
 119  
 
 120  6
     }
 121  
 
 122  
     public void setAsciiStream(int parameterIndex, InputStream x, int length)
 123  
             throws SQLException {
 124  6
         this.getUnderlyingPreparedStatement().setAsciiStream(parameterIndex, x, length);
 125  
 
 126  6
     }
 127  
 
 128  
     public void setBigDecimal(int parameterIndex, BigDecimal x)
 129  
             throws SQLException {
 130  6
         this.getUnderlyingPreparedStatement().setBigDecimal(parameterIndex, x);
 131  
 
 132  6
     }
 133  
 
 134  
     public void setBinaryStream(int parameterIndex, InputStream x, int length)
 135  
             throws SQLException {
 136  6
         this.getUnderlyingPreparedStatement().setBinaryStream(parameterIndex, x, length);
 137  
 
 138  6
     }
 139  
 
 140  
     public void setBlob(int parameterIndex, Blob x) throws SQLException {
 141  6
         this.getUnderlyingPreparedStatement().setBlob(parameterIndex, x);
 142  
 
 143  6
     }
 144  
 
 145  
     public void setBoolean(int parameterIndex, boolean x) throws SQLException {
 146  6
         this.getUnderlyingPreparedStatement().setBoolean(parameterIndex, x);
 147  
 
 148  6
     }
 149  
 
 150  
     public void setByte(int parameterIndex, byte x) throws SQLException {
 151  6
         this.getUnderlyingPreparedStatement().setByte(parameterIndex, x);
 152  
 
 153  6
     }
 154  
 
 155  
     public void setBytes(int parameterIndex, byte[] x) throws SQLException {
 156  6
         this.getUnderlyingPreparedStatement().setBytes(parameterIndex, x);
 157  
 
 158  6
     }
 159  
 
 160  
     public void setCharacterStream(int parameterIndex, Reader reader, int length)
 161  
             throws SQLException {
 162  6
         this.getUnderlyingPreparedStatement().setCharacterStream(parameterIndex, reader, length);
 163  
 
 164  6
     }
 165  
 
 166  
     public void setClob(int parameterIndex, Clob x) throws SQLException {
 167  6
         this.getUnderlyingPreparedStatement().setClob(parameterIndex, x);
 168  
 
 169  6
     }
 170  
 
 171  
     public void setDate(int parameterIndex, Date x) throws SQLException {
 172  6
         this.getUnderlyingPreparedStatement().setDate(parameterIndex, x);
 173  
 
 174  6
     }
 175  
 
 176  
     public void setDate(int parameterIndex, Date x, Calendar cal)
 177  
             throws SQLException {
 178  6
         this.getUnderlyingPreparedStatement().setDate(parameterIndex, x, cal);
 179  
 
 180  6
     }
 181  
 
 182  
     public void setDouble(int parameterIndex, double x) throws SQLException {
 183  6
         this.getUnderlyingPreparedStatement().setDouble(parameterIndex, x);
 184  
 
 185  6
     }
 186  
 
 187  
     public void setFloat(int parameterIndex, float x) throws SQLException {
 188  6
         this.getUnderlyingPreparedStatement().setFloat(parameterIndex, x);
 189  
 
 190  6
     }
 191  
 
 192  
     public void setInt(int parameterIndex, int x) throws SQLException {
 193  60006
         this.getUnderlyingPreparedStatement().setInt(parameterIndex, x);
 194  
 
 195  60006
     }
 196  
 
 197  
     public void setLong(int parameterIndex, long x) throws SQLException {
 198  6
         this.getUnderlyingPreparedStatement().setLong(parameterIndex, x);
 199  
 
 200  6
     }
 201  
 
 202  
     public void setNull(int parameterIndex, int sqlType) throws SQLException {
 203  6
         this.getUnderlyingPreparedStatement().setNull(parameterIndex, sqlType);
 204  
 
 205  6
     }
 206  
 
 207  
     public void setNull(int parameterIndex, int sqlType, String typeName)
 208  
             throws SQLException {
 209  6
         this.getUnderlyingPreparedStatement().setNull(parameterIndex, sqlType, typeName);
 210  
 
 211  6
     }
 212  
 
 213  
     public void setObject(int parameterIndex, Object x) throws SQLException {
 214  6
         this.getUnderlyingPreparedStatement().setObject(parameterIndex, x);
 215  
 
 216  6
     }
 217  
 
 218  
     public void setObject(int parameterIndex, Object x, int targetSqlType)
 219  
             throws SQLException {
 220  6
         this.getUnderlyingPreparedStatement().setObject(parameterIndex, x, targetSqlType);
 221  
 
 222  6
     }
 223  
 
 224  
     public void setRef(int parameterIndex, Ref x) throws SQLException {
 225  6
         this.getUnderlyingPreparedStatement().setRef(parameterIndex, x);
 226  
 
 227  6
     }
 228  
 
 229  
     public void setShort(int parameterIndex, short x) throws SQLException {
 230  6
         this.getUnderlyingPreparedStatement().setShort(parameterIndex, x);
 231  
 
 232  6
     }
 233  
 
 234  
     public void setString(int parameterIndex, String x) throws SQLException {
 235  6
         this.getUnderlyingPreparedStatement().setString(parameterIndex, x);
 236  
 
 237  6
     }
 238  
 
 239  
     public void setTime(int parameterIndex, Time x) throws SQLException {
 240  6
         this.getUnderlyingPreparedStatement().setTime(parameterIndex, x);
 241  
 
 242  6
     }
 243  
 
 244  
     public void setTime(int parameterIndex, Time x, Calendar cal)
 245  
             throws SQLException {
 246  6
         this.getUnderlyingPreparedStatement().setTime(parameterIndex, x, cal);
 247  
 
 248  6
     }
 249  
 
 250  
     public void setTimestamp(int parameterIndex, Timestamp x)
 251  
             throws SQLException {
 252  6
         this.getUnderlyingPreparedStatement().setTimestamp(parameterIndex, x);
 253  
 
 254  6
     }
 255  
 
 256  
     public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal)
 257  
             throws SQLException {
 258  6
         this.getUnderlyingPreparedStatement().setTimestamp(parameterIndex, x, cal);
 259  
 
 260  6
     }
 261  
 
 262  
     public void setURL(int parameterIndex, URL x) throws SQLException {
 263  6
         this.getUnderlyingPreparedStatement().setURL(parameterIndex, x);
 264  
 
 265  6
     }
 266  
 
 267  
     @SuppressWarnings({ "deprecation" })
 268  
     public void setUnicodeStream(int parameterIndex, InputStream x, int length)
 269  
             throws SQLException {
 270  6
         this.getUnderlyingPreparedStatement().setUnicodeStream(parameterIndex, x, length);
 271  
 
 272  6
     }
 273  
     
 274  
     public void setObject(int parameterIndex, Object x, int targetSqlType,
 275  
             int scaleOrLength) throws SQLException {
 276  3
         this.getUnderlyingPreparedStatement().setObject(parameterIndex, x, targetSqlType, scaleOrLength);
 277  
 
 278  3
     }
 279  
 
 280  
     /* (non-Javadoc)
 281  
      * @see net.admin4j.jdbc.driver.sql.SqlContext#getSqlText()
 282  
      */
 283  
     public String getSqlText() {
 284  180018
         return sqlText;
 285  
     }
 286  
 
 287  
     /* (non-Javadoc)
 288  
      * @see net.admin4j.jdbc.driver.sql.SqlContext#setSqlText(java.lang.String)
 289  
      */
 290  
     public void setSqlText(String sqlText) {
 291  
         Validate.notEmpty(sqlText, "Null or blank sqlText not allowed.");
 292  180033
         this.sqlText = sqlText;        
 293  180033
     }
 294  
 
 295  
     /* (non-Javadoc)
 296  
      * @see net.admin4j.jdbc.driver.sql.SqlContext#getExecutionStack()
 297  
      */
 298  
     public StackTraceElement[] getExecutionStack() {
 299  180018
         return executionStack;
 300  
     }
 301  
 
 302  
     /* (non-Javadoc)
 303  
      * @see net.admin4j.jdbc.driver.sql.SqlContext#setExecutionStack(java.lang.StackTraceElement[])
 304  
      */
 305  
     public void setExecutionStack(StackTraceElement[] stack) {
 306  180033
         this.executionStack = stack;
 307  
         
 308  180033
     }
 309  
 
 310  
 }