View Javadoc
1   /*
2    * Copyright (C) 2016 uwe
3    *
4    * This program is free software: you can redistribute it and/or modify
5    * it under the terms of the GNU General Public License as published by
6    * the Free Software Foundation, either version 3 of the License, or
7    * (at your option) any later version.
8    *
9    * This program is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   * GNU General Public License for more details.
13   *
14   * You should have received a copy of the GNU General Public License
15   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16   */
17  package org.sw4j.tool.annotation.jpa.generator.liquibase.common;
18  
19  import javax.annotation.Nonnull;
20  
21  /**
22   * This class contains utility methods to convert the datatypes from Java to SQL.
23   *
24   * @author Uwe Plonus
25   */
26  public final class DataTypeUtils {
27  
28      /**
29       * Hide the default constructor of this utility class.
30       */
31      private DataTypeUtils() { }
32  
33      /**
34       * Create the java.sql.Types type for the given Java datatype.
35       *
36       * @param javaDataType the Java datatype to convert.
37       * @return the created java.sql.Types datatype created.
38       */
39      public static String createSqlDataType(@Nonnull final String javaDataType) {
40          if ("boolean".equals(javaDataType) || "java.lang.Boolean".equals(javaDataType)) {
41              return "java.sql.Types.BOOLEAN";
42          } else if ("byte".equals(javaDataType) || "java.lang.Byte".equals(javaDataType)) {
43              return "java.sql.Types.TINYINT";
44          } else if ("short".equals(javaDataType) || "java.lang.Short".equals(javaDataType)) {
45              return "java.sql.Types.SMALLINT";
46          } else if ("int".equals(javaDataType) || "java.lang.Integer".equals(javaDataType)) {
47              return "java.sql.Types.INTEGER";
48          } else if ("long".equals(javaDataType) || "java.lang.Long".equals(javaDataType)) {
49              return "java.sql.Types.BIGINT";
50          } else {
51              return "java.sql.Types.BINARY";
52          }
53      }
54  
55  }