LowerCaseTableMetaData.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. import org.slf4j.Logger;
  23. import org.slf4j.LoggerFactory;


  24. /**
  25.  * Specialized ITableMetaData implementation that convert the table name and
  26.  * column names to lower case. Used in DbUnit own test suite to verify that
  27.  * operations are case insensitive.
  28.  *
  29.  * @author Manuel Laflamme
  30.  * @version $Revision$
  31.  * @since Feb 14, 2003
  32.  */
  33. public class LowerCaseTableMetaData extends AbstractTableMetaData
  34. {

  35.     /**
  36.      * Logger for this class
  37.      */
  38.     private static final Logger logger = LoggerFactory.getLogger(LowerCaseTableMetaData.class);

  39.     private final String _tableName;
  40.     private final Column[] _columns;
  41.     private final Column[] _primaryKeys;

  42.     public LowerCaseTableMetaData(String tableName, Column[] columns)
  43.             //throws DataSetException
  44.     {
  45.         this(tableName, columns, new Column[0]);
  46.     }

  47.     public LowerCaseTableMetaData(String tableName, Column[] columns,
  48.             String[] primaryKeys) //throws DataSetException
  49.     {
  50.         this(tableName, columns, Columns.getColumns(primaryKeys, columns) );
  51.     }

  52.     public LowerCaseTableMetaData(ITableMetaData metaData) throws DataSetException
  53.     {
  54.         this(metaData.getTableName(), metaData.getColumns(),
  55.                 metaData.getPrimaryKeys());
  56.     }

  57.     public LowerCaseTableMetaData(String tableName, Column[] columns,
  58.             Column[] primaryKeys) //throws DataSetException
  59.     {
  60.         _tableName = tableName.toLowerCase();
  61.         _columns = createLowerColumns(columns);
  62.         _primaryKeys = createLowerColumns(primaryKeys);
  63.     }

  64.     private Column[] createLowerColumns(Column[] columns)
  65.     {
  66.         logger.debug("createLowerColumns(columns={}) - start", columns);

  67.         Column[] lowerColumns = new Column[columns.length];
  68.         for (int i = 0; i < columns.length; i++)
  69.         {
  70.             lowerColumns[i] = createLowerColumn(columns[i]);
  71.         }

  72.         return lowerColumns;
  73.     }

  74.     private Column createLowerColumn(Column column)
  75.     {
  76.         logger.debug("createLowerColumn(column={}) - start", column);

  77.         return new Column(
  78.                 column.getColumnName().toLowerCase(),
  79.                 column.getDataType(),
  80.                 column.getSqlTypeName(),
  81.                 column.getNullable(),
  82.                 column.getDefaultValue());
  83.     }

  84.     ////////////////////////////////////////////////////////////////////////////
  85.     // ITableMetaData interface

  86.     public String getTableName()
  87.     {
  88.         return _tableName;
  89.     }

  90.     public Column[] getColumns()
  91.     {
  92.         return _columns;
  93.     }

  94.     public Column[] getPrimaryKeys()
  95.     {
  96.         return _primaryKeys;
  97.     }
  98. }