H2DataTypeFactory.java

  1. /*
  2.  *
  3.  * The DbUnit Database Testing Framework
  4.  * Copyright (C)2008, 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.h2;

  22. import java.util.Arrays;
  23. import java.util.Collection;

  24. import org.dbunit.dataset.datatype.DataType;
  25. import org.dbunit.dataset.datatype.DataTypeException;
  26. import org.dbunit.dataset.datatype.DefaultDataTypeFactory;
  27. import org.slf4j.Logger;
  28. import org.slf4j.LoggerFactory;

  29. /**
  30.  * Specialized factory that recognizes H2 data types.
  31.  *
  32.  * @author Felipe Leme
  33.  * @author Last changed by: $Author$
  34.  * @version $Revision$ $Date$
  35.  * @since 2.2.1
  36.  */
  37. public class H2DataTypeFactory extends DefaultDataTypeFactory
  38. {
  39.     /**
  40.      * Logger for this class
  41.      */
  42.     private static final Logger logger = LoggerFactory.getLogger(H2DataTypeFactory.class);
  43.     /**
  44.      * Database product names supported.
  45.      */
  46.     private static final Collection DATABASE_PRODUCTS = Arrays.asList(new String[] {"h2"});

  47.     /**
  48.      * @see org.dbunit.dataset.datatype.IDbProductRelatable#getValidDbProducts()
  49.      */
  50.     @Override
  51.     public Collection getValidDbProducts()
  52.     {
  53.         return DATABASE_PRODUCTS;
  54.     }

  55.     @Override
  56.     public DataType createDataType(int sqlType, String sqlTypeName) throws DataTypeException
  57.     {
  58.         if(logger.isDebugEnabled())
  59.         {
  60.             logger.debug("createDataType(sqlType={}, sqlTypeName={}) - start", String.valueOf(sqlType), sqlTypeName);
  61.         }

  62.         if (sqlTypeName.equals("BOOLEAN"))
  63.         {
  64.             return DataType.BOOLEAN;
  65.         } else if ("UUID".equals(sqlTypeName))
  66.         {
  67.             return DataType.NVARCHAR;
  68.         }

  69.         return super.createDataType(sqlType, sqlTypeName);
  70.     }
  71. }