| %line | %branch | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| ca.spaz.sql.SQLDelete |
|
|
| 1 | /* |
|
| 2 | * Created on 18-Apr-2005 |
|
| 3 | */ |
|
| 4 | package ca.spaz.sql; |
|
| 5 | ||
| 6 | import java.sql.*; |
|
| 7 | ||
| 8 | import org.apache.log4j.Logger; |
|
| 9 | ||
| 10 | /** |
|
| 11 | * Conveniently produces simple SQL DELETE statements |
|
| 12 | * |
|
| 13 | * @author Aaron Davidson |
|
| 14 | */ |
|
| 15 | public class SQLDelete extends SQLSelectableStatement { |
|
| 16 | /** |
|
| 17 | * Logger for this class |
|
| 18 | */ |
|
| 19 | 0 | private static final Logger logger = Logger.getLogger(SQLDelete.class); |
| 20 | ||
| 21 | /** |
|
| 22 | * Create a new SQLUpdate command for the given table |
|
| 23 | * @param tableName the name of the table to update on |
|
| 24 | */ |
|
| 25 | public SQLDelete(String tableName) { |
|
| 26 | 0 | super(tableName, true, false, class="keyword">true); |
| 27 | 0 | } |
| 28 | ||
| 29 | /** |
|
| 30 | * Overrides execute() and calls executeUpdate() |
|
| 31 | */ |
|
| 32 | protected void doExecute(Connection con) throws SQLException { |
|
| 33 | 0 | Statement stmt = con.createStatement(); |
| 34 | 0 | String query = this.getQueryString(); |
| 35 | 0 | if (logger.isDebugEnabled()) { |
| 36 | 0 | logger.debug("executeQuery() - Statement to be executed: " + query); |
| 37 | } |
|
| 38 | ||
| 39 | 0 | stmt.execute(query); |
| 40 | 0 | } |
| 41 | ||
| 42 | /** |
|
| 43 | * Generate the SQL string for an DELETE command. |
|
| 44 | */ |
|
| 45 | protected String getQueryString() { |
|
| 46 | 0 | StringBuffer sb = new StringBuffer(); |
| 47 | 0 | sb.append("DELETE FROM "); |
| 48 | 0 | sb.append(getTableName()); |
| 49 | 0 | sb.append(getWhere()); |
| 50 | 0 | return sb.toString(); |
| 51 | } |
|
| 52 | } |
| This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |