View Javadoc
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  
22  package org.dbunit.dataset;
23  
24  import org.slf4j.Logger;
25  import org.slf4j.LoggerFactory;
26  
27  
28  /**
29   * Specialized ITableMetaData implementation that convert the table name and
30   * column names to lower case. Used in DbUnit own test suite to verify that
31   * operations are case insensitive.
32   *
33   * @author Manuel Laflamme
34   * @version $Revision$
35   * @since Feb 14, 2003
36   */
37  public class LowerCaseTableMetaData extends AbstractTableMetaData
38  {
39  
40      /**
41       * Logger for this class
42       */
43      private static final Logger logger = LoggerFactory.getLogger(LowerCaseTableMetaData.class);
44  
45      private final String _tableName;
46      private final Column[] _columns;
47      private final Column[] _primaryKeys;
48  
49      public LowerCaseTableMetaData(String tableName, Column[] columns)
50              //throws DataSetException
51      {
52          this(tableName, columns, new Column[0]);
53      }
54  
55      public LowerCaseTableMetaData(String tableName, Column[] columns,
56              String[] primaryKeys) //throws DataSetException
57      {
58          this(tableName, columns, Columns.getColumns(primaryKeys, columns) );
59      }
60  
61      public LowerCaseTableMetaData(ITableMetaData metaData) throws DataSetException
62      {
63          this(metaData.getTableName(), metaData.getColumns(),
64                  metaData.getPrimaryKeys());
65      }
66  
67      public LowerCaseTableMetaData(String tableName, Column[] columns,
68              Column[] primaryKeys) //throws DataSetException
69      {
70          _tableName = tableName.toLowerCase();
71          _columns = createLowerColumns(columns);
72          _primaryKeys = createLowerColumns(primaryKeys);
73      }
74  
75      private Column[] createLowerColumns(Column[] columns)
76      {
77          logger.debug("createLowerColumns(columns={}) - start", columns);
78  
79          Column[] lowerColumns = new Column[columns.length];
80          for (int i = 0; i < columns.length; i++)
81          {
82              lowerColumns[i] = createLowerColumn(columns[i]);
83          }
84  
85          return lowerColumns;
86      }
87  
88      private Column createLowerColumn(Column column)
89      {
90          logger.debug("createLowerColumn(column={}) - start", column);
91  
92          return new Column(
93                  column.getColumnName().toLowerCase(),
94                  column.getDataType(),
95                  column.getSqlTypeName(),
96                  column.getNullable(),
97                  column.getDefaultValue());
98      }
99  
100     ////////////////////////////////////////////////////////////////////////////
101     // ITableMetaData interface
102 
103     public String getTableName()
104     {
105         return _tableName;
106     }
107 
108     public Column[] getColumns()
109     {
110         return _columns;
111     }
112 
113     public Column[] getPrimaryKeys()
114     {
115         return _primaryKeys;
116     }
117 }