View Javadoc

    1   /*
    2    * joey-gen and its relative products are published under the terms
    3    * of the Apache Software License.
    4    *
    5    * Created on 2004/10/27 2:44:46
    6    */
    7   package org.asyrinx.joey.gen.command.rdb2java.standard;
    8
    9   import java.util.HashMap;
    10  import java.util.Map;
    11
    12  import org.asyrinx.joey.gen.command.rdb2java.TypeMappingStrategy;
    13  import org.asyrinx.joey.gen.model.java.Type;
    14  import org.asyrinx.joey.gen.model.java.classes.JavaLangClass;
    15  import org.asyrinx.joey.gen.model.java.classes.JavaUtilClass;
    16  import org.asyrinx.joey.gen.model.java.classes.PrimitiveType;
    17  import org.asyrinx.joey.gen.model.rdb.Column;
    18
    19  /***
    20   * @author takeshi
    21   */
    22  public class BasicTypeMapping implements TypeMappingStrategy {
    23
    24      private final Map typeMap;
    25
    26      /***
    27       *
    28       */
    29      public BasicTypeMapping() {
    30          super();
    31          typeMap = initialize();
    32      }
    33
    34      /*
    35       * (non-Javadoc)
    36       *
    37       * @see org.asyrinx.joey.gen.command.rdb2java.standard.TypeMappingStrategy#toJavaType(org.asyrinx.joey.gen.model.rdb.Column)
    38       */
    39      public Type toJavaType(Column column) {
    40          if ("CHAR".equals(column.getType()) && (column.getSizeAsInt() > 1))
    41              return JavaLangClass.STRING;
    42          else
    43              return (Type) typeMap.get(column.getType());
    44      }
    45
    46      /*
    47       * (non-Javadoc)
    48       *
    49       * @see org.asyrinx.joey.gen.command.rdb2java.standard.TypeMappingStrategy#toJavaType(java.lang.String)
    50       */
    51      public Type toJavaType(String jdbcTypeName) {
    52          return (Type) typeMap.get(jdbcTypeName);
    53      }
    54
    55      /*
    56       * @see java.sql.Types
    57       */
    58      //public final static int BIT = -7;
    59      //public final static int TINYINT = -6;
    60      //public final static int SMALLINT = 5;
    61      //public final static int INTEGER = 4;
    62      //public final static int BIGINT = -5;
    63      //public final static int FLOAT = 6;
    64      //public final static int REAL = 7;
    65      //public final static int DOUBLE = 8;
    66      //public final static int NUMERIC = 2;
    67      //public final static int DECIMAL = 3;
    68      //public final static int CHAR = 1;
    69      //public final static int VARCHAR = 12;
    70      //public final static int LONGVARCHAR = -1;
    71      //public final static int DATE = 91;
    72      //public final static int TIME = 92;
    73      //public final static int TIMESTAMP = 93;
    74      //public final static int BINARY = -2;
    75      //public final static int VARBINARY = -3;
    76      //public final static int LONGVARBINARY = -4;
    77      //public final static int NULL = 0;
    78      //public final static int OTHER = 1111;
    79      //public final static int JAVA_OBJECT = 2000;
    80      //public final static int DISTINCT = 2001;
    81      //public final static int STRUCT = 2002;
    82      //public final static int ARRAY = 2003;
    83      //public final static int BLOB = 2004;
    84      //public final static int CLOB = 2005;
    85      //public final static int REF = 2006;
    86      //public final static int DATALINK = 70;
    87      //public final static int BOOLEAN = 16;
    88      /***
    89       * @param jdbcTypeName
    90       * @param type
    91       */
    92      private static void add(Map dest, String jdbcTypeName, Type type) {
    93          dest.put(jdbcTypeName, type);
    94      }
    95
    96      /***
    97       *
    98       */
    99      private static Map initialize() {
    100         final Map result = new HashMap();
    101         add(result, "BIT", PrimitiveType.BOOLEAN);
    102         add(result, "TINYINT", PrimitiveType.BYTE);
    103         add(result, "SMALLINT", PrimitiveType.SHORT);
    104         add(result, "INTEGER", PrimitiveType.INT);
    105         add(result, "BIGINT", PrimitiveType.LONG);
    106         add(result, "FLOAT", PrimitiveType.FLOAT);
    107         add(result, "REAL", PrimitiveType.DOUBLE);
    108         add(result, "DOUBLE", PrimitiveType.DOUBLE);
    109         add(result, "NUMERIC", PrimitiveType.INT);
    110         add(result, "DECIMAL", PrimitiveType.DOUBLE);
    111         add(result, "CHAR", PrimitiveType.CHAR);
    112         add(result, "VARCHAR", JavaLangClass.STRING);
    113         add(result, "LONGVARCHAR", JavaLangClass.STRING);
    114         add(result, "DATE", JavaUtilClass.DATE);
    115         add(result, "TIME", JavaUtilClass.DATE);
    116         add(result, "TIMESTAMP", JavaUtilClass.DATE);
    117         add(result, "CLOB", JavaLangClass.STRING);
    118         add(result, "BOOLEAN", PrimitiveType.BOOLEAN);
    119         return result;
    120     }
    121
    122 }