|
|||||||||||||||||||
| 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 | |||||||||||||||
| Parameter.java | - | 100% | 100% | 100% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* Copyright (C) 2003, Marco Jansen / Contrado Technologies (http://www.contrado.nl)
|
|
| 3 |
*
|
|
| 4 |
* This program is free software; you can redistribute it and/or
|
|
| 5 |
* modify it under the terms of the GNU General Public License as
|
|
| 6 |
* published by the Free Software Foundation; either version 2 of the
|
|
| 7 |
* License, or (at your option) any later version.
|
|
| 8 |
*
|
|
| 9 |
* This program is distributed in the hope that it will be useful, but
|
|
| 10 |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
| 12 |
* General Public License for more details.
|
|
| 13 |
*/
|
|
| 14 |
package net.sourceforge.anttestsetgen;
|
|
| 15 |
|
|
| 16 |
import org.apache.tools.ant.BuildException;
|
|
| 17 |
import org.apache.tools.ant.Project;
|
|
| 18 |
import org.apache.tools.ant.Task;
|
|
| 19 |
|
|
| 20 |
import java.sql.ResultSet;
|
|
| 21 |
import java.sql.SQLException;
|
|
| 22 |
|
|
| 23 |
/**
|
|
| 24 |
* A Parameter of a Validation subtask.
|
|
| 25 |
* <p/>
|
|
| 26 |
* A Parameter consists of a name and a column. The column relates to a column in the resultset of the SQL-Query.
|
|
| 27 |
* Both the name and the column are required.
|
|
| 28 |
*
|
|
| 29 |
* @author <a href="mailto:m.c.jansen.spam at planet.nl">Marco Jansen (Contrado Technologies)</a>
|
|
| 30 |
* @version $Id: Parameter.java,v 1.3 2004/01/04 15:00:18 mcjansen Exp $
|
|
| 31 |
*/
|
|
| 32 |
public class Parameter extends Task { |
|
| 33 |
|
|
| 34 |
/** The name of the parameter. */
|
|
| 35 |
private String name;
|
|
| 36 |
|
|
| 37 |
/** The column in the database that is related to this parameter. */
|
|
| 38 |
private String column;
|
|
| 39 |
|
|
| 40 |
/**
|
|
| 41 |
* Set the name of the parameter.
|
|
| 42 |
*
|
|
| 43 |
* @param name The name of the parameter
|
|
| 44 |
* @see #getName
|
|
| 45 |
*/
|
|
| 46 | 18 |
public void setName(String name) { |
| 47 | 18 |
this.name = name;
|
| 48 |
} |
|
| 49 |
|
|
| 50 |
/**
|
|
| 51 |
* Retrieve the name of the parameter.
|
|
| 52 |
*
|
|
| 53 |
* @return The name of the Parameter
|
|
| 54 |
* @throws org.apache.tools.ant.BuildException
|
|
| 55 |
* In case the name was not set.
|
|
| 56 |
* @see #setName
|
|
| 57 |
*/
|
|
| 58 | 278 |
public String getName() throws BuildException { |
| 59 | 278 |
return AntTestSetGenUtil.requiredCheck("name", name); |
| 60 |
} |
|
| 61 |
|
|
| 62 |
/**
|
|
| 63 |
* Set the column of the parameter. The column relates to a column in the resultset of the SQL-query.
|
|
| 64 |
*
|
|
| 65 |
* @param column The column of the parameter.
|
|
| 66 |
* @see #getColumn
|
|
| 67 |
*/
|
|
| 68 | 18 |
public void setColumn(String column) { |
| 69 | 18 |
this.column = column;
|
| 70 |
} |
|
| 71 |
|
|
| 72 |
/**
|
|
| 73 |
* Retrieve the column of the parameter.
|
|
| 74 |
*
|
|
| 75 |
* @return The column of the parameter
|
|
| 76 |
* @throws org.apache.tools.ant.BuildException
|
|
| 77 |
* In case the column was not set.
|
|
| 78 |
* @see #setColumn
|
|
| 79 |
*/
|
|
| 80 | 148 |
public String getColumn() throws BuildException { |
| 81 | 148 |
return AntTestSetGenUtil.requiredCheck("column", column); |
| 82 |
} |
|
| 83 |
|
|
| 84 |
/**
|
|
| 85 |
* Retrieve the database value of the parameter
|
|
| 86 |
* <p/>
|
|
| 87 |
* The value is retrieved based on the supplied resulset.
|
|
| 88 |
*
|
|
| 89 |
* @param resultSet A resultset with the current row that contains the column
|
|
| 90 |
* @return The value of the attribute in the database
|
|
| 91 |
* @throws org.apache.tools.ant.BuildException
|
|
| 92 |
* In case the column was not found in the resultset.
|
|
| 93 |
*/
|
|
| 94 | 144 |
public String getDatabaseValue(ResultSet resultSet) throws BuildException { |
| 95 |
|
|
| 96 | 144 |
try {
|
| 97 | 144 |
return resultSet.getString(getColumn());
|
| 98 |
} catch (SQLException e) {
|
|
| 99 | 2 |
log("Error loading column " + getColumn() + " from result test: " + e.getMessage(), Project.MSG_ERR); |
| 100 | 2 |
throw new BuildException("Column " + getColumn() + " not found"); |
| 101 |
} |
|
| 102 |
} |
|
| 103 |
|
|
| 104 |
} |
|
| 105 |
|
|
||||||||||