View Javadoc
1   /*
2    *
3    * The DbUnit Database Testing Framework
4    * Copyright (C)2002-2009, 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.ext.mckoi;
22  
23  import org.dbunit.dataset.datatype.DataType;
24  import org.dbunit.dataset.datatype.DataTypeException;
25  import org.dbunit.dataset.datatype.DefaultDataTypeFactory;
26  import org.slf4j.Logger;
27  import org.slf4j.LoggerFactory;
28  
29  import java.sql.Types;
30  import java.util.Arrays;
31  import java.util.Collection;
32  
33  /**
34   * MckoiDataTypeFactory - This class is for the DBUnit data type factory for Mckoi database
35   * 
36   * @author Luigi Talamona (luigitalamona AT users.sourceforge.net)
37   * @author Last changed by: $Author$
38   * @version $Revision$ $Date$
39   * @since 2.4.8
40   */
41  public class MckoiDataTypeFactory extends DefaultDataTypeFactory {
42  
43      /**
44       * Logger for this class
45       */
46      private static final Logger logger = LoggerFactory.getLogger(MckoiDataTypeFactory.class);
47  
48  
49      /**
50       * Database product names supported.
51       */
52      private static final Collection DATABASE_PRODUCTS = Arrays.asList(new String[] {"Mckoi"});
53  
54      /**
55       * @see org.dbunit.dataset.datatype.IDbProductRelatable#getValidDbProducts()
56       */
57      public Collection getValidDbProducts()
58      {
59        return DATABASE_PRODUCTS;
60      }
61  
62  
63      public DataType createDataType(int sqlType, String sqlTypeName) throws DataTypeException {
64          DataType retValue = super.createDataType(sqlType, sqlTypeName);
65  
66          if (logger.isDebugEnabled()) {
67              logger.debug("createDataType(sqlType={}, sqlTypeName={}) - start", String.valueOf(sqlType), sqlTypeName);
68          }
69  
70          retValue = (sqlTypeName.equals("BOOLEAN"))? DataType.BOOLEAN: retValue;
71          retValue = (sqlTypeName.equals("CHAR"))? DataType.CHAR: retValue;
72          retValue = (sqlTypeName.equals("CHARACTER"))? DataType.CHAR: retValue;
73  
74          retValue = (sqlTypeName.equals("VARCHAR"))? DataType.VARCHAR: retValue;
75          retValue = (sqlTypeName.equals("LONGVARCHAR"))? DataType.LONGVARCHAR: retValue;
76          retValue = (sqlTypeName.equals("CHARACTER VARYING"))? DataType.VARCHAR: retValue;
77          retValue = (sqlTypeName.equals("LONG CHARACTER VARYING"))? DataType.VARCHAR: retValue;
78          retValue = (sqlTypeName.equals("TEXT"))? DataType.VARCHAR: retValue;
79          retValue = (sqlTypeName.equals("STRING"))? DataType.VARCHAR: retValue;
80  
81          retValue = (sqlTypeName.equals("CLOB"))? DataType.CLOB: retValue;
82          retValue = (sqlTypeName.equals("TINYINT"))? DataType.TINYINT: retValue;
83          retValue = (sqlTypeName.equals("SMALLINT"))? DataType.SMALLINT: retValue;
84          retValue = (sqlTypeName.equals("INTEGER"))? DataType.INTEGER: retValue;
85          retValue = (sqlTypeName.equals("INT"))? DataType.INTEGER: retValue;
86  
87          retValue = (sqlTypeName.equals("BIGINT"))? DataType.BIGINT: retValue;
88          retValue = (sqlTypeName.equals("FLOAT"))? DataType.FLOAT: retValue;
89          retValue = (sqlTypeName.equals("DOUBLE"))? DataType.DOUBLE: retValue;
90          retValue = (sqlTypeName.equals("REAL"))? DataType.REAL: retValue;
91          retValue = (sqlTypeName.equals("NUMERIC"))? DataType.NUMERIC: retValue;
92          retValue = (sqlTypeName.equals("DECIMAL"))? DataType.DECIMAL: retValue;
93          retValue = (sqlTypeName.equals("DATE"))? DataType.DATE: retValue;
94          retValue = (sqlTypeName.equals("TIME"))? DataType.TIME: retValue;
95          retValue = (sqlTypeName.equals("TIMESTAMP"))? DataType.TIMESTAMP: retValue;
96  
97          retValue = (sqlTypeName.equals("BINARY"))? DataType.BINARY: retValue;
98          retValue = (sqlTypeName.equals("VARBINARY"))? DataType.VARBINARY: retValue;
99          retValue = (sqlTypeName.equals("LONGVARBINARY"))? DataType.LONGVARBINARY: retValue;
100         retValue = (sqlTypeName.equals("BLOB"))? DataType.BLOB: retValue;
101         retValue = (sqlTypeName.equals("JAVA_OBJECT"))? DataType.forSqlType(Types.JAVA_OBJECT): retValue;
102         return retValue;
103     }
104 }
105 
106 
107