001: /*
002: *
003: * The DbUnit Database Testing Framework
004: * Copyright (C)2002-2004, DbUnit.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or (at your option) any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: */
021:
022: package org.dbunit.dataset;
023:
024: import org.slf4j.Logger;
025: import org.slf4j.LoggerFactory;
026:
027: /**
028: * Specialized ITableMetaData implementation that convert the table name and
029: * column names to lower case. Used in DbUnit own test suite to verify that
030: * operations are case insensitive.
031: *
032: * @author Manuel Laflamme
033: * @version $Revision: 554 $
034: * @since Feb 14, 2003
035: */
036: public class LowerCaseTableMetaData extends AbstractTableMetaData {
037:
038: /**
039: * Logger for this class
040: */
041: private static final Logger logger = LoggerFactory
042: .getLogger(LowerCaseTableMetaData.class);
043:
044: private final String _tableName;
045: private final Column[] _columns;
046: private final Column[] _primaryKeys;
047:
048: public LowerCaseTableMetaData(String tableName, Column[] columns)
049: //throws DataSetException
050: {
051: this (tableName, columns, new Column[0]);
052: }
053:
054: public LowerCaseTableMetaData(String tableName, Column[] columns,
055: String[] primaryKeys) //throws DataSetException
056: {
057: this (tableName, columns, getPrimaryKeys(columns, primaryKeys));
058: }
059:
060: public LowerCaseTableMetaData(ITableMetaData metaData)
061: throws DataSetException {
062: this (metaData.getTableName(), metaData.getColumns(), metaData
063: .getPrimaryKeys());
064: }
065:
066: public LowerCaseTableMetaData(String tableName, Column[] columns,
067: Column[] primaryKeys) //throws DataSetException
068: {
069: _tableName = tableName.toLowerCase();
070: _columns = createLowerColumns(columns);
071: _primaryKeys = createLowerColumns(primaryKeys);
072: }
073:
074: private Column[] createLowerColumns(Column[] columns) {
075: logger.debug("createLowerColumns(columns=" + columns
076: + ") - start");
077:
078: Column[] lowerColumns = new Column[columns.length];
079: for (int i = 0; i < columns.length; i++) {
080: lowerColumns[i] = createLowerColumn(columns[i]);
081: }
082:
083: return lowerColumns;
084: }
085:
086: private Column createLowerColumn(Column column) {
087: logger
088: .debug("createLowerColumn(column=" + column
089: + ") - start");
090:
091: return new Column(column.getColumnName().toLowerCase(), column
092: .getDataType(), column.getSqlTypeName(), column
093: .getNullable());
094: }
095:
096: ////////////////////////////////////////////////////////////////////////////
097: // ITableMetaData interface
098:
099: public String getTableName() {
100: logger.debug("getTableName() - start");
101:
102: return _tableName;
103: }
104:
105: public Column[] getColumns() {
106: logger.debug("getColumns() - start");
107:
108: return _columns;
109: }
110:
111: public Column[] getPrimaryKeys() {
112: logger.debug("getPrimaryKeys() - start");
113:
114: return _primaryKeys;
115: }
116: }
|