NoSuchColumnException.java

  1. /*
  2.  *
  3.  * The DbUnit Database Testing Framework
  4.  * Copyright (C)2002-2004, DbUnit.org
  5.  *
  6.  * This library is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU Lesser General Public
  8.  * License as published by the Free Software Foundation; either
  9.  * version 2.1 of the License, or (at your option) any later version.
  10.  *
  11.  * This library is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14.  * Lesser General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Lesser General Public
  17.  * License along with this library; if not, write to the Free Software
  18.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  *
  20.  */

  21. package org.dbunit.dataset;


  22. /**
  23.  * Thrown to indicate that a database column has been accessed that does not
  24.  * exist.
  25.  *
  26.  * @author Manuel Laflamme
  27.  * @version $Revision$
  28.  * @since Feb 17, 2002
  29.  */
  30. public class NoSuchColumnException extends DataSetException
  31. {
  32.     /**
  33.      * @deprecated since 2.3.0. Prefer constructor taking a table/columnName as argument
  34.      */
  35.     public NoSuchColumnException()
  36.     {
  37.     }
  38.    
  39.     /**
  40.      * @deprecated since 2.3.0. Prefer constructor taking a table/columnName as argument
  41.      */
  42.     public NoSuchColumnException(String msg)
  43.     {
  44.         super(msg);
  45.     }

  46.     /**
  47.      * Creates an exception using the given table name + column name
  48.      * @param tableName table in which the column was not found. Can be null
  49.      * @param columnName the column that was not found
  50.      * @since 2.3.0
  51.      */
  52.     public NoSuchColumnException(String tableName, String columnName)
  53.     {
  54.         this(tableName, columnName, null);
  55.     }

  56.     /**
  57.      * Creates an exception using the given table name + column name
  58.      * @param tableName table in which the column was not found. Can be null
  59.      * @param columnName the column that was not found
  60.      * @param msg Additional message to append to the exception text
  61.      * @since 2.3.0
  62.      */
  63.     public NoSuchColumnException(String tableName, String columnName, String msg)
  64.     {
  65.         super(buildText(tableName, columnName, msg));
  66.     }

  67.     /**
  68.      * @param msg
  69.      * @param e
  70.      * @deprecated since 2.3.0. Prefer constructor taking a table/columnName as argument
  71.      */
  72.     public NoSuchColumnException(String msg, Throwable e)
  73.     {
  74.         super(msg, e);
  75.     }

  76.     /**
  77.      * @param e
  78.      * @deprecated since 2.3.0. Prefer constructor taking a table/columnName as argument
  79.      */
  80.     public NoSuchColumnException(Throwable e)
  81.     {
  82.         super(e);
  83.     }
  84.    
  85.    
  86.     private static String buildText(String tableName, String columnName, String message) {
  87.         final StringBuilder sb = new StringBuilder();
  88.         if(tableName != null){
  89.             sb.append(tableName).append(".");
  90.         }
  91.         sb.append(columnName);
  92.         if(message != null) {
  93.             sb.append(" - ").append(message);
  94.         }
  95.         return sb.toString();
  96.     }

  97. }