Coverage Report - org.apache.tapestry.contrib.jdbc.SimpleStatement
 
Classes in this File Line Coverage Branch Coverage Complexity
SimpleStatement
0%
0/27
0%
0/4
1.25
 
 1  
 // Copyright 2004, 2005 The Apache Software Foundation
 2  
 //
 3  
 // Licensed under the Apache License, Version 2.0 (the "License");
 4  
 // you may not use this file except in compliance with the License.
 5  
 // You may obtain a copy of the License at
 6  
 //
 7  
 //     http://www.apache.org/licenses/LICENSE-2.0
 8  
 //
 9  
 // Unless required by applicable law or agreed to in writing, software
 10  
 // distributed under the License is distributed on an "AS IS" BASIS,
 11  
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12  
 // See the License for the specific language governing permissions and
 13  
 // limitations under the License.
 14  
 
 15  
 package org.apache.tapestry.contrib.jdbc;
 16  
 
 17  
 import java.sql.Connection;
 18  
 import java.sql.ResultSet;
 19  
 import java.sql.SQLException;
 20  
 import java.sql.Statement;
 21  
 
 22  
 import org.apache.commons.logging.Log;
 23  
 import org.apache.commons.logging.LogFactory;
 24  
 
 25  
 /**
 26  
  *  A wrapper around {@link Statement}.
 27  
  *
 28  
  *  @author Howard Lewis Ship
 29  
  *
 30  
  **/
 31  
 
 32  
 public class SimpleStatement implements IStatement
 33  
 {
 34  0
     private static final Log LOG = LogFactory.getLog(SimpleStatement.class);
 35  
 
 36  
     private String _sql;
 37  
     private Statement _statement;
 38  
 
 39  
     public SimpleStatement(String SQL, Connection connection) throws SQLException
 40  0
     {
 41  0
         _sql = SQL;
 42  0
         _statement = connection.createStatement();
 43  0
     }
 44  
 
 45  
     public SimpleStatement(String SQL, Connection connection, int resultSetType, int resultSetConcurrency)
 46  
         throws SQLException
 47  0
     {
 48  0
         _sql = SQL;
 49  0
         _statement = connection.createStatement(resultSetType, resultSetConcurrency);
 50  0
     }
 51  
 
 52  
     /**
 53  
      * Returns the SQL associated with this statement.
 54  
      *
 55  
      **/
 56  
 
 57  
     public String getSQL()
 58  
     {
 59  0
         return _sql;
 60  
     }
 61  
 
 62  
     /**
 63  
      *  Returns the underlying {@link Statement}.
 64  
      *
 65  
      **/
 66  
 
 67  
     public Statement getStatement()
 68  
     {
 69  0
         return _statement;
 70  
     }
 71  
 
 72  
     /**
 73  
      *  Closes the underlying statement, and nulls the reference to it.
 74  
      *
 75  
      **/
 76  
 
 77  
     public void close() throws SQLException
 78  
     {
 79  0
         _statement.close();
 80  
 
 81  0
         _statement = null;
 82  0
         _sql = null;
 83  0
     }
 84  
 
 85  
     /**
 86  
      *  Executes the statement as a query, returning a {@link ResultSet}.
 87  
      *
 88  
      **/
 89  
 
 90  
     public ResultSet executeQuery() throws SQLException
 91  
     {
 92  0
         if (LOG.isDebugEnabled())
 93  0
             LOG.debug("Executing query: " + this);
 94  
 
 95  0
         return _statement.executeQuery(_sql);
 96  
     }
 97  
 
 98  
     /**
 99  
      *  Executes the statement as an update, returning the number of rows
 100  
      *  affected.
 101  
      *
 102  
      **/
 103  
 
 104  
     public int executeUpdate() throws SQLException
 105  
     {
 106  0
         if (LOG.isDebugEnabled())
 107  0
             LOG.debug("Executing update: " + this);
 108  
 
 109  0
         return _statement.executeUpdate(_sql);
 110  
     }
 111  
 
 112  
     public String toString()
 113  
     {
 114  
         StringBuffer buffer;
 115  
 
 116  0
         buffer = new StringBuffer("SimpleStatement@");
 117  0
         buffer.append(Integer.toHexString(hashCode()));
 118  
 
 119  0
         buffer.append("[SQL=<\n");
 120  0
         buffer.append(_sql);
 121  0
         buffer.append("\n>]");
 122  
 
 123  0
         return buffer.toString();
 124  
     }
 125  
 
 126  
 }