Coverage report

  %line %branch
org.apache.torque.engine.database.model.TypeMap
92% 
92% 

 1  
 package org.apache.torque.engine.database.model;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import java.sql.Types;
 23  
 import java.util.Hashtable;
 24  
 import java.util.Iterator;
 25  
 
 26  
 import org.apache.commons.logging.Log;
 27  
 import org.apache.commons.logging.LogFactory;
 28  
 
 29  
 // I don't know if the peer system deals
 30  
 // with the recommended mappings.
 31  
 //
 32  
 //import java.sql.Date;
 33  
 //import java.sql.Time;
 34  
 //import java.sql.Timestamp;
 35  
 
 36  
 /**
 37  
  * A class that maps JDBC types to their corresponding
 38  
  * Java object types, and Java native types. Used
 39  
  * by Column.java to perform object/native mappings.
 40  
  *
 41  
  * These are the official SQL type to Java type mappings.
 42  
  * These don't quite correspond to the way the peer
 43  
  * system works so we'll have to make some adjustments.
 44  
  * <pre>
 45  
  * -------------------------------------------------------
 46  
  * SQL Type      | Java Type            | Peer Type
 47  
  * -------------------------------------------------------
 48  
  * CHAR          | String               | String
 49  
  * VARCHAR       | String               | String
 50  
  * LONGVARCHAR   | String               | String
 51  
  * NUMERIC       | java.math.BigDecimal | java.math.BigDecimal
 52  
  * DECIMAL       | java.math.BigDecimal | java.math.BigDecimal
 53  
  * BIT           | boolean OR Boolean   | Boolean
 54  
  * TINYINT       | byte OR Byte         | Byte
 55  
  * SMALLINT      | short OR Short       | Short
 56  
  * INTEGER       | int OR Integer       | Integer
 57  
  * BIGINT        | long OR Long         | Long
 58  
  * REAL          | float OR Float       | Float
 59  
  * FLOAT         | double OR Double     | Double
 60  
  * DOUBLE        | double OR Double     | Double
 61  
  * BINARY        | byte[]               | ?
 62  
  * VARBINARY     | byte[]               | ?
 63  
  * LONGVARBINARY | byte[]               | ?
 64  
  * DATE          | java.sql.Date        | java.util.Date
 65  
  * TIME          | java.sql.Time        | java.util.Date
 66  
  * TIMESTAMP     | java.sql.Timestamp   | java.util.Date
 67  
  *
 68  
  * -------------------------------------------------------
 69  
  * A couple variations have been introduced to cover cases
 70  
  * that may arise, but are not covered above
 71  
  * BOOLEANCHAR   | boolean OR Boolean   | String
 72  
  * BOOLEANINT    | boolean OR Boolean   | Integer
 73  
  * </pre>
 74  
  *
 75  
  * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
 76  
  * @author <a href="mailto:mpoeschl@marmot.at>Martin Poeschl</a>
 77  
  * @version $Id: TypeMap.java 473814 2006-11-11 22:30:30Z tv $
 78  
  */
 79  0
 public class TypeMap
 80  
 {
 81  
     /** Logging class from commons.logging */
 82  204
     private static Log log = LogFactory.getLog(Column.class);
 83  
 
 84  102
     private static final SchemaType[] TEXT_TYPES =
 85  
     {
 86  
         SchemaType.CHAR, SchemaType.VARCHAR, SchemaType.LONGVARCHAR,
 87  
         SchemaType.CLOB, SchemaType.DATE, SchemaType.TIME,
 88  
         SchemaType.TIMESTAMP, SchemaType.BOOLEANCHAR
 89  
     };
 90  
 
 91  
     public static final String CHAR_OBJECT_TYPE = "\"\"";
 92  
     public static final String VARCHAR_OBJECT_TYPE = "\"\"";
 93  
     public static final String LONGVARCHAR_OBJECT_TYPE = "\"\"";
 94  
     public static final String CLOB_OBJECT_TYPE = "\"\"";
 95  
     public static final String NUMERIC_OBJECT_TYPE = "new BigDecimal((double) 0)";
 96  
     public static final String DECIMAL_OBJECT_TYPE = "new BigDecimal((double) 0)";
 97  
     public static final String BIT_OBJECT_TYPE = "new Boolean(true)";
 98  
     public static final String TINYINT_OBJECT_TYPE = "new Byte((byte)0)";
 99  
     public static final String SMALLINT_OBJECT_TYPE = "new Short((short)0)";
 100  
     public static final String INTEGER_OBJECT_TYPE = "new Integer(0)";
 101  
     public static final String BIGINT_OBJECT_TYPE = "new Long(0)";
 102  
     public static final String REAL_OBJECT_TYPE = "new Float(0)";
 103  
     public static final String FLOAT_OBJECT_TYPE = "new Double(0)";
 104  
     public static final String DOUBLE_OBJECT_TYPE = "new Double(0)";
 105  
     public static final String BINARY_OBJECT_TYPE = "new Object()"; //?
 106  
     public static final String VARBINARY_OBJECT_TYPE = "new Object()"; //?
 107  
     public static final String LONGVARBINARY_OBJECT_TYPE = "new Object()"; //?
 108  
     public static final String BLOB_OBJECT_TYPE = "new Object()"; //?
 109  
     public static final String DATE_OBJECT_TYPE = "new Date()";
 110  
     public static final String TIME_OBJECT_TYPE = "new Date()";
 111  
     public static final String TIMESTAMP_OBJECT_TYPE = "new Date()";
 112  
     public static final String BOOLEANCHAR_OBJECT_TYPE = "\"\"";
 113  
     public static final String BOOLEANINT_OBJECT_TYPE = "new Integer(0)";
 114  
 
 115  
     public static final String CHAR_NATIVE_TYPE = "String";
 116  
     public static final String VARCHAR_NATIVE_TYPE = "String";
 117  
     public static final String LONGVARCHAR_NATIVE_TYPE = "String";
 118  
     public static final String CLOB_NATIVE_TYPE = "String";
 119  
     public static final String NUMERIC_NATIVE_TYPE = "BigDecimal";
 120  
     public static final String DECIMAL_NATIVE_TYPE = "BigDecimal";
 121  
     public static final String BIT_NATIVE_TYPE = "boolean";
 122  
     public static final String TINYINT_NATIVE_TYPE = "byte";
 123  
     public static final String SMALLINT_NATIVE_TYPE = "short";
 124  
     public static final String INTEGER_NATIVE_TYPE = "int";
 125  
     public static final String BIGINT_NATIVE_TYPE = "long";
 126  
     public static final String REAL_NATIVE_TYPE = "float";
 127  
     public static final String FLOAT_NATIVE_TYPE = "double";
 128  
     public static final String DOUBLE_NATIVE_TYPE = "double";
 129  
     public static final String BINARY_NATIVE_TYPE = "byte[]";
 130  
     public static final String VARBINARY_NATIVE_TYPE = "byte[]";
 131  
     public static final String LONGVARBINARY_NATIVE_TYPE = "byte[]";
 132  
     public static final String BLOB_NATIVE_TYPE = "byte[]";
 133  
     public static final String DATE_NATIVE_TYPE = "Date";
 134  
     public static final String TIME_NATIVE_TYPE = "Date";
 135  
     public static final String TIMESTAMP_NATIVE_TYPE = "Date";
 136  
     public static final String BOOLEANCHAR_NATIVE_TYPE = "boolean";
 137  
     public static final String BOOLEANINT_NATIVE_TYPE = "boolean";
 138  
 
 139  
     public static final String BIT_NATIVE_OBJECT_TYPE = "Boolean";
 140  
     public static final String TINYINT_NATIVE_OBJECT_TYPE = "Byte";
 141  
     public static final String SMALLINT_NATIVE_OBJECT_TYPE = "Short";
 142  
     public static final String INTEGER_NATIVE_OBJECT_TYPE = "Integer";
 143  
     public static final String BIGINT_NATIVE_OBJECT_TYPE = "Long";
 144  
     public static final String REAL_NATIVE_OBJECT_TYPE = "Float";
 145  
     public static final String FLOAT_NATIVE_OBJECT_TYPE = "Double";
 146  
     public static final String DOUBLE_NATIVE_OBJECT_TYPE = "Double";
 147  
     public static final String BOOLEANCHAR_NATIVE_OBJECT_TYPE = "Boolean";
 148  
     public static final String BOOLEANINT_NATIVE_OBJECT_TYPE = "Boolean";
 149  
 
 150  
     public static final String CHAR_VILLAGE_METHOD = "asString()";
 151  
     public static final String VARCHAR_VILLAGE_METHOD = "asString()";
 152  
     public static final String LONGVARCHAR_VILLAGE_METHOD = "asString()";
 153  
     public static final String CLOB_VILLAGE_METHOD = "asString()";
 154  
     public static final String NUMERIC_VILLAGE_METHOD = "asBigDecimal()";
 155  
     public static final String DECIMAL_VILLAGE_METHOD = "asBigDecimal()";
 156  
     public static final String BIT_VILLAGE_METHOD = "asBoolean()";
 157  
     public static final String TINYINT_VILLAGE_METHOD = "asByte()";
 158  
     public static final String SMALLINT_VILLAGE_METHOD = "asShort()";
 159  
     public static final String INTEGER_VILLAGE_METHOD = "asInt()";
 160  
     public static final String BIGINT_VILLAGE_METHOD = "asLong()";
 161  
     public static final String REAL_VILLAGE_METHOD = "asFloat()";
 162  
     public static final String FLOAT_VILLAGE_METHOD = "asDouble()";
 163  
     public static final String DOUBLE_VILLAGE_METHOD = "asDouble()";
 164  
     public static final String BINARY_VILLAGE_METHOD = "asBytes()";
 165  
     public static final String VARBINARY_VILLAGE_METHOD = "asBytes()";
 166  
     public static final String LONGVARBINARY_VILLAGE_METHOD = "asBytes()";
 167  
     public static final String BLOB_VILLAGE_METHOD = "asBytes()";
 168  
     public static final String DATE_VILLAGE_METHOD = "asUtilDate()";
 169  
     public static final String TIME_VILLAGE_METHOD = "asUtilDate()";
 170  
     public static final String TIMESTAMP_VILLAGE_METHOD = "asUtilDate()";
 171  
     public static final String BOOLEANCHAR_VILLAGE_METHOD = "asBoolean()";
 172  
     public static final String BOOLEANINT_VILLAGE_METHOD = "asBoolean()";
 173  
 
 174  
     public static final String BIT_VILLAGE_OBJECT_METHOD = "asBooleanObj()";
 175  
     public static final String TINYINT_VILLAGE_OBJECT_METHOD = "asByteObj()";
 176  
     public static final String SMALLINT_VILLAGE_OBJECT_METHOD = "asShortObj()";
 177  
     public static final String INTEGER_VILLAGE_OBJECT_METHOD = "asIntegerObj()";
 178  
     public static final String BIGINT_VILLAGE_OBJECT_METHOD = "asLongObj()";
 179  
     public static final String REAL_VILLAGE_OBJECT_METHOD = "asFloatObj()";
 180  
     public static final String FLOAT_VILLAGE_OBJECT_METHOD = "asDoubleObj()";
 181  
     public static final String DOUBLE_VILLAGE_OBJECT_METHOD = "asDoubleObj()";
 182  
     public static final String BOOLEANCHAR_VILLAGE_OBJECT_METHOD = "asBooleanObj()";
 183  
     public static final String BOOLEANINT_VILLAGE_OBJECT_METHOD = "asBooleanObj()";
 184  
 
 185  
     public static final String CHAR_PP_METHOD = "getString(ppKey)";
 186  
     public static final String VARCHAR_PP_METHOD = "getString(ppKey)";
 187  
     public static final String LONGVARCHAR_PP_METHOD = "getString(ppKey)";
 188  
     public static final String NUMERIC_PP_METHOD = "getBigDecimal(ppKey)";
 189  
     public static final String DECIMAL_PP_METHOD = "getBigDecimal(ppKey)";
 190  
     public static final String BIT_PP_METHOD = "getBoolean(ppKey)";
 191  
     public static final String TINYINT_PP_METHOD = "getByte(ppKey)";
 192  
     public static final String SMALLINT_PP_METHOD = "getShort(ppKey)";
 193  
     public static final String INTEGER_PP_METHOD = "getInt(ppKey)";
 194  
     public static final String BIGINT_PP_METHOD = "getLong(ppKey)";
 195  
     public static final String REAL_PP_METHOD = "getFloat(ppKey)";
 196  
     public static final String FLOAT_PP_METHOD = "getDouble(ppKey)";
 197  
     public static final String DOUBLE_PP_METHOD = "getDouble(ppKey)";
 198  
     public static final String BINARY_PP_METHOD = "getBytes(ppKey)";
 199  
     public static final String VARBINARY_PP_METHOD = "getBytes(ppKey)";
 200  
     public static final String LONGVARBINARY_PP_METHOD = "getBytes(ppKey)";
 201  
     public static final String DATE_PP_METHOD = "getDate(ppKey)";
 202  
     public static final String TIME_PP_METHOD = "getDate(ppKey)";
 203  
     public static final String TIMESTAMP_PP_METHOD = "getDate(ppKey)";
 204  
     public static final String BOOLEANCHAR_PP_METHOD = "getBoolean(ppKey)";
 205  
     public static final String BOOLEANINT_PP_METHOD = "getBoolean(ppKey)";
 206  
 
 207  102
     private static Hashtable jdbcToJavaObjectMap = null;
 208  102
     private static Hashtable jdbcToJavaNativeMap = null;
 209  102
     private static Hashtable jdbcToJavaNativeObjectMap = null;
 210  102
     private static Hashtable jdbcToVillageMethodMap = null;
 211  102
     private static Hashtable jdbcToVillageObjectMethodMap = null;
 212  102
     private static Hashtable jdbcToPPMethodMap = null;
 213  102
     private static Hashtable torqueTypeToJdbcTypeMap = null;
 214  102
     private static Hashtable jdbcToTorqueTypeMap = null;
 215  102
     private static boolean isInitialized = false;
 216  
 
 217  
     /**
 218  
      * Initializes the SQL to Java map so that it
 219  
      * can be used by client code.
 220  
      */
 221  
     public static synchronized void initialize()
 222  
     {
 223  17
         if (!isInitialized)
 224  
         {
 225  
             // Create JDBC -> Java object mappings.
 226  17
             jdbcToJavaObjectMap = new Hashtable();
 227  
 
 228  17
             jdbcToJavaObjectMap.put(SchemaType.CHAR, CHAR_OBJECT_TYPE);
 229  17
             jdbcToJavaObjectMap.put(SchemaType.VARCHAR, VARCHAR_OBJECT_TYPE);
 230  17
             jdbcToJavaObjectMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_OBJECT_TYPE);
 231  17
             jdbcToJavaObjectMap.put(SchemaType.CLOB, CLOB_OBJECT_TYPE);
 232  17
             jdbcToJavaObjectMap.put(SchemaType.NUMERIC, NUMERIC_OBJECT_TYPE);
 233  17
             jdbcToJavaObjectMap.put(SchemaType.DECIMAL, DECIMAL_OBJECT_TYPE);
 234  17
             jdbcToJavaObjectMap.put(SchemaType.BIT, BIT_OBJECT_TYPE);
 235  17
             jdbcToJavaObjectMap.put(SchemaType.TINYINT, TINYINT_OBJECT_TYPE);
 236  17
             jdbcToJavaObjectMap.put(SchemaType.SMALLINT, SMALLINT_OBJECT_TYPE);
 237  17
             jdbcToJavaObjectMap.put(SchemaType.INTEGER, INTEGER_OBJECT_TYPE);
 238  17
             jdbcToJavaObjectMap.put(SchemaType.BIGINT, BIGINT_OBJECT_TYPE);
 239  17
             jdbcToJavaObjectMap.put(SchemaType.REAL, REAL_OBJECT_TYPE);
 240  17
             jdbcToJavaObjectMap.put(SchemaType.FLOAT, FLOAT_OBJECT_TYPE);
 241  17
             jdbcToJavaObjectMap.put(SchemaType.DOUBLE, DOUBLE_OBJECT_TYPE);
 242  17
             jdbcToJavaObjectMap.put(SchemaType.BINARY, BINARY_OBJECT_TYPE);
 243  17
             jdbcToJavaObjectMap.put(SchemaType.VARBINARY, VARBINARY_OBJECT_TYPE);
 244  17
             jdbcToJavaObjectMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_OBJECT_TYPE);
 245  17
             jdbcToJavaObjectMap.put(SchemaType.BLOB, BLOB_OBJECT_TYPE);
 246  17
             jdbcToJavaObjectMap.put(SchemaType.DATE, DATE_OBJECT_TYPE);
 247  17
             jdbcToJavaObjectMap.put(SchemaType.TIME, TIME_OBJECT_TYPE);
 248  17
             jdbcToJavaObjectMap.put(SchemaType.TIMESTAMP, TIMESTAMP_OBJECT_TYPE);
 249  17
             jdbcToJavaObjectMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_OBJECT_TYPE);
 250  17
             jdbcToJavaObjectMap.put(SchemaType.BOOLEANINT, BOOLEANINT_OBJECT_TYPE);
 251  
 
 252  
             // Create JDBC -> native Java type mappings.
 253  17
             jdbcToJavaNativeMap = new Hashtable();
 254  
 
 255  17
             jdbcToJavaNativeMap.put(SchemaType.CHAR, CHAR_NATIVE_TYPE);
 256  17
             jdbcToJavaNativeMap.put(SchemaType.VARCHAR, VARCHAR_NATIVE_TYPE);
 257  17
             jdbcToJavaNativeMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_NATIVE_TYPE);
 258  17
             jdbcToJavaNativeMap.put(SchemaType.CLOB, CLOB_NATIVE_TYPE);
 259  17
             jdbcToJavaNativeMap.put(SchemaType.NUMERIC, NUMERIC_NATIVE_TYPE);
 260  17
             jdbcToJavaNativeMap.put(SchemaType.DECIMAL, DECIMAL_NATIVE_TYPE);
 261  17
             jdbcToJavaNativeMap.put(SchemaType.BIT, BIT_NATIVE_TYPE);
 262  17
             jdbcToJavaNativeMap.put(SchemaType.TINYINT, TINYINT_NATIVE_TYPE);
 263  17
             jdbcToJavaNativeMap.put(SchemaType.SMALLINT, SMALLINT_NATIVE_TYPE);
 264  17
             jdbcToJavaNativeMap.put(SchemaType.INTEGER, INTEGER_NATIVE_TYPE);
 265  17
             jdbcToJavaNativeMap.put(SchemaType.BIGINT, BIGINT_NATIVE_TYPE);
 266  17
             jdbcToJavaNativeMap.put(SchemaType.REAL, REAL_NATIVE_TYPE);
 267  17
             jdbcToJavaNativeMap.put(SchemaType.FLOAT, FLOAT_NATIVE_TYPE);
 268  17
             jdbcToJavaNativeMap.put(SchemaType.DOUBLE, DOUBLE_NATIVE_TYPE);
 269  17
             jdbcToJavaNativeMap.put(SchemaType.BINARY, BINARY_NATIVE_TYPE);
 270  17
             jdbcToJavaNativeMap.put(SchemaType.VARBINARY, VARBINARY_NATIVE_TYPE);
 271  17
             jdbcToJavaNativeMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_NATIVE_TYPE);
 272  17
             jdbcToJavaNativeMap.put(SchemaType.BLOB, BLOB_NATIVE_TYPE);
 273  17
             jdbcToJavaNativeMap.put(SchemaType.DATE, DATE_NATIVE_TYPE);
 274  17
             jdbcToJavaNativeMap.put(SchemaType.TIME, TIME_NATIVE_TYPE);
 275  17
             jdbcToJavaNativeMap.put(SchemaType.TIMESTAMP, TIMESTAMP_NATIVE_TYPE);
 276  17
             jdbcToJavaNativeMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_NATIVE_TYPE);
 277  17
             jdbcToJavaNativeMap.put(SchemaType.BOOLEANINT, BOOLEANINT_NATIVE_TYPE);
 278  
 
 279  17
             jdbcToJavaNativeObjectMap = new Hashtable();
 280  17
             jdbcToJavaNativeObjectMap.put(SchemaType.BIT, BIT_NATIVE_OBJECT_TYPE);
 281  17
             jdbcToJavaNativeObjectMap.put(SchemaType.TINYINT, TINYINT_NATIVE_OBJECT_TYPE);
 282  17
             jdbcToJavaNativeObjectMap.put(SchemaType.SMALLINT, SMALLINT_NATIVE_OBJECT_TYPE);
 283  17
             jdbcToJavaNativeObjectMap.put(SchemaType.INTEGER, INTEGER_NATIVE_OBJECT_TYPE);
 284  17
             jdbcToJavaNativeObjectMap.put(SchemaType.BIGINT, BIGINT_NATIVE_OBJECT_TYPE);
 285  17
             jdbcToJavaNativeObjectMap.put(SchemaType.REAL, REAL_NATIVE_OBJECT_TYPE);
 286  17
             jdbcToJavaNativeObjectMap.put(SchemaType.FLOAT, FLOAT_NATIVE_OBJECT_TYPE);
 287  17
             jdbcToJavaNativeObjectMap.put(SchemaType.DOUBLE, DOUBLE_NATIVE_OBJECT_TYPE);
 288  17
             jdbcToJavaNativeObjectMap.put(SchemaType.BOOLEANCHAR,
 289  
                                           BOOLEANCHAR_NATIVE_OBJECT_TYPE);
 290  17
             jdbcToJavaNativeObjectMap.put(SchemaType.BOOLEANINT,
 291  
                                           BOOLEANINT_NATIVE_OBJECT_TYPE);
 292  
 
 293  
             // Create JDBC -> Village asX() mappings.
 294  17
             jdbcToVillageMethodMap = new Hashtable();
 295  
 
 296  17
             jdbcToVillageMethodMap.put(SchemaType.CHAR, CHAR_VILLAGE_METHOD);
 297  17
             jdbcToVillageMethodMap.put(SchemaType.VARCHAR, VARCHAR_VILLAGE_METHOD);
 298  17
             jdbcToVillageMethodMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_VILLAGE_METHOD);
 299  17
             jdbcToVillageMethodMap.put(SchemaType.CLOB, CLOB_VILLAGE_METHOD);
 300  17
             jdbcToVillageMethodMap.put(SchemaType.NUMERIC, NUMERIC_VILLAGE_METHOD);
 301  17
             jdbcToVillageMethodMap.put(SchemaType.DECIMAL, DECIMAL_VILLAGE_METHOD);
 302  17
             jdbcToVillageMethodMap.put(SchemaType.BIT, BIT_VILLAGE_METHOD);
 303  17
             jdbcToVillageMethodMap.put(SchemaType.TINYINT, TINYINT_VILLAGE_METHOD);
 304  17
             jdbcToVillageMethodMap.put(SchemaType.SMALLINT, SMALLINT_VILLAGE_METHOD);
 305  17
             jdbcToVillageMethodMap.put(SchemaType.INTEGER, INTEGER_VILLAGE_METHOD);
 306  17
             jdbcToVillageMethodMap.put(SchemaType.BIGINT, BIGINT_VILLAGE_METHOD);
 307  17
             jdbcToVillageMethodMap.put(SchemaType.REAL, REAL_VILLAGE_METHOD);
 308  17
             jdbcToVillageMethodMap.put(SchemaType.FLOAT, FLOAT_VILLAGE_METHOD);
 309  17
             jdbcToVillageMethodMap.put(SchemaType.DOUBLE, DOUBLE_VILLAGE_METHOD);
 310  17
             jdbcToVillageMethodMap.put(SchemaType.BINARY, BINARY_VILLAGE_METHOD);
 311  17
             jdbcToVillageMethodMap.put(SchemaType.VARBINARY, VARBINARY_VILLAGE_METHOD);
 312  17
             jdbcToVillageMethodMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_VILLAGE_METHOD);
 313  17
             jdbcToVillageMethodMap.put(SchemaType.BLOB, BLOB_VILLAGE_METHOD);
 314  17
             jdbcToVillageMethodMap.put(SchemaType.DATE, DATE_VILLAGE_METHOD);
 315  17
             jdbcToVillageMethodMap.put(SchemaType.TIME, TIME_VILLAGE_METHOD);
 316  17
             jdbcToVillageMethodMap.put(SchemaType.TIMESTAMP, TIMESTAMP_VILLAGE_METHOD);
 317  17
             jdbcToVillageMethodMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_VILLAGE_METHOD);
 318  17
             jdbcToVillageMethodMap.put(SchemaType.BOOLEANINT, BOOLEANINT_VILLAGE_METHOD);
 319  
 
 320  
 
 321  17
             jdbcToVillageObjectMethodMap = new Hashtable();
 322  17
             jdbcToVillageObjectMethodMap.put(SchemaType.BIT, BIT_VILLAGE_OBJECT_METHOD);
 323  17
             jdbcToVillageObjectMethodMap.put(SchemaType.TINYINT,
 324  
                                              TINYINT_VILLAGE_OBJECT_METHOD);
 325  17
             jdbcToVillageObjectMethodMap.put(SchemaType.SMALLINT,
 326  
                                              SMALLINT_VILLAGE_OBJECT_METHOD);
 327  17
             jdbcToVillageObjectMethodMap.put(SchemaType.INTEGER,
 328  
                                              INTEGER_VILLAGE_OBJECT_METHOD);
 329  17
             jdbcToVillageObjectMethodMap.put(SchemaType.BIGINT,
 330  
                                              BIGINT_VILLAGE_OBJECT_METHOD);
 331  17
             jdbcToVillageObjectMethodMap.put(SchemaType.REAL, REAL_VILLAGE_OBJECT_METHOD);
 332  17
             jdbcToVillageObjectMethodMap.put(SchemaType.FLOAT, FLOAT_VILLAGE_OBJECT_METHOD);
 333  17
             jdbcToVillageObjectMethodMap.put(SchemaType.DOUBLE,
 334  
                                              DOUBLE_VILLAGE_OBJECT_METHOD);
 335  17
             jdbcToVillageObjectMethodMap.put(SchemaType.BOOLEANCHAR,
 336  
                                              BOOLEANCHAR_VILLAGE_OBJECT_METHOD);
 337  17
             jdbcToVillageObjectMethodMap.put(SchemaType.BOOLEANINT,
 338  
                                              BOOLEANINT_VILLAGE_OBJECT_METHOD);
 339  
 
 340  
             // Create JDBC -> ParameterParser getX() mappings.
 341  17
             jdbcToPPMethodMap = new Hashtable();
 342  
 
 343  17
             jdbcToPPMethodMap.put(SchemaType.CHAR, CHAR_PP_METHOD);
 344  17
             jdbcToPPMethodMap.put(SchemaType.VARCHAR, VARCHAR_PP_METHOD);
 345  17
             jdbcToPPMethodMap.put(SchemaType.LONGVARCHAR, LONGVARCHAR_PP_METHOD);
 346  17
             jdbcToPPMethodMap.put(SchemaType.NUMERIC, NUMERIC_PP_METHOD);
 347  17
             jdbcToPPMethodMap.put(SchemaType.DECIMAL, DECIMAL_PP_METHOD);
 348  17
             jdbcToPPMethodMap.put(SchemaType.BIT, BIT_PP_METHOD);
 349  17
             jdbcToPPMethodMap.put(SchemaType.TINYINT, TINYINT_PP_METHOD);
 350  17
             jdbcToPPMethodMap.put(SchemaType.SMALLINT, SMALLINT_PP_METHOD);
 351  17
             jdbcToPPMethodMap.put(SchemaType.INTEGER, INTEGER_PP_METHOD);
 352  17
             jdbcToPPMethodMap.put(SchemaType.BIGINT, BIGINT_PP_METHOD);
 353  17
             jdbcToPPMethodMap.put(SchemaType.REAL, REAL_PP_METHOD);
 354  17
             jdbcToPPMethodMap.put(SchemaType.FLOAT, FLOAT_PP_METHOD);
 355  17
             jdbcToPPMethodMap.put(SchemaType.DOUBLE, DOUBLE_PP_METHOD);
 356  17
             jdbcToPPMethodMap.put(SchemaType.BINARY, BINARY_PP_METHOD);
 357  17
             jdbcToPPMethodMap.put(SchemaType.VARBINARY, VARBINARY_PP_METHOD);
 358  17
             jdbcToPPMethodMap.put(SchemaType.LONGVARBINARY, LONGVARBINARY_PP_METHOD);
 359  17
             jdbcToPPMethodMap.put(SchemaType.DATE, DATE_PP_METHOD);
 360  17
             jdbcToPPMethodMap.put(SchemaType.TIME, TIME_PP_METHOD);
 361  17
             jdbcToPPMethodMap.put(SchemaType.TIMESTAMP, TIMESTAMP_PP_METHOD);
 362  17
             jdbcToPPMethodMap.put(SchemaType.BOOLEANCHAR, BOOLEANCHAR_PP_METHOD);
 363  17
             jdbcToPPMethodMap.put(SchemaType.BOOLEANINT, BOOLEANINT_PP_METHOD);
 364  
 
 365  
             // Create JDBC -> Java object mappings.
 366  17
             torqueTypeToJdbcTypeMap = new Hashtable();
 367  
 
 368  17
             Iterator iter = SchemaType.iterator();
 369  527
             while (iter.hasNext())
 370  
             {
 371  510
                 SchemaType type = (SchemaType) iter.next();
 372  510
                 torqueTypeToJdbcTypeMap.put(type, type);
 373  510
             }
 374  17
             torqueTypeToJdbcTypeMap.put(SchemaType.BOOLEANCHAR, SchemaType.CHAR);
 375  17
             torqueTypeToJdbcTypeMap.put(SchemaType.BOOLEANINT, SchemaType.INTEGER);
 376  
 
 377  
             // Create JDBC type code to torque type map.
 378  17
             jdbcToTorqueTypeMap = new Hashtable();
 379  
 
 380  17
             jdbcToTorqueTypeMap.put(new Integer(Types.CHAR), SchemaType.CHAR);
 381  17
             jdbcToTorqueTypeMap.put(new Integer(Types.VARCHAR), SchemaType.VARCHAR);
 382  17
             jdbcToTorqueTypeMap.put(new Integer(Types.LONGVARCHAR), SchemaType.LONGVARCHAR);
 383  17
             jdbcToTorqueTypeMap.put(new Integer(Types.CLOB), SchemaType.CLOB);
 384  17
             jdbcToTorqueTypeMap.put(new Integer(Types.NUMERIC), SchemaType.NUMERIC);
 385  17
             jdbcToTorqueTypeMap.put(new Integer(Types.DECIMAL), SchemaType.DECIMAL);
 386  17
             jdbcToTorqueTypeMap.put(new Integer(Types.BIT), SchemaType.BIT);
 387  17
             jdbcToTorqueTypeMap.put(new Integer(Types.TINYINT), SchemaType.TINYINT);
 388  17
             jdbcToTorqueTypeMap.put(new Integer(Types.SMALLINT), SchemaType.SMALLINT);
 389  17
             jdbcToTorqueTypeMap.put(new Integer(Types.INTEGER), SchemaType.INTEGER);
 390  17
             jdbcToTorqueTypeMap.put(new Integer(Types.BIGINT), SchemaType.BIGINT);
 391  17
             jdbcToTorqueTypeMap.put(new Integer(Types.REAL), SchemaType.REAL);
 392  17
             jdbcToTorqueTypeMap.put(new Integer(Types.FLOAT), SchemaType.FLOAT);
 393  17
             jdbcToTorqueTypeMap.put(new Integer(Types.DOUBLE), SchemaType.DOUBLE);
 394  17
             jdbcToTorqueTypeMap.put(new Integer(Types.BINARY), SchemaType.BINARY);
 395  17
             jdbcToTorqueTypeMap.put(new Integer(Types.VARBINARY), SchemaType.VARBINARY);
 396  17
             jdbcToTorqueTypeMap.put(new Integer(Types.LONGVARBINARY), SchemaType.LONGVARBINARY);
 397  17
             jdbcToTorqueTypeMap.put(new Integer(Types.BLOB), SchemaType.BLOB);
 398  17
             jdbcToTorqueTypeMap.put(new Integer(Types.DATE), SchemaType.DATE);
 399  17
             jdbcToTorqueTypeMap.put(new Integer(Types.TIME), SchemaType.TIME);
 400  17
             jdbcToTorqueTypeMap.put(new Integer(Types.TIMESTAMP), SchemaType.TIMESTAMP);
 401  
 
 402  17
             isInitialized = true;
 403  
         }
 404  17
     }
 405  
 
 406  
     /**
 407  
      * Report whether this object has been initialized.
 408  
      *
 409  
      * @return true if this object has been initialized
 410  
      */
 411  
     public static boolean isInitialized()
 412  
     {
 413  0
         return isInitialized;
 414  
     }
 415  
 
 416  
     /**
 417  
      * Return a Java object which corresponds to the
 418  
      * JDBC type provided. Use in MapBuilder generation.
 419  
      *
 420  
      * @param jdbcType the JDBC type
 421  
      * @return name of the Object
 422  
      */
 423  
     public static String getJavaObject(SchemaType jdbcType)
 424  
     {
 425  
         // Make sure the we are initialized.
 426  17
         if (!isInitialized)
 427  
         {
 428  17
             initialize();
 429  
         }
 430  17
         return (String) jdbcToJavaObjectMap.get(jdbcType);
 431  
     }
 432  
 
 433  
     /**
 434  
      * Return native java type which corresponds to the
 435  
      * JDBC type provided. Use in the base object class generation.
 436  
      *
 437  
      * @param jdbcType the JDBC type
 438  
      * @return name of the native java type
 439  
      */
 440  
     public static String getJavaNative(SchemaType jdbcType)
 441  
     {
 442  
         // Make sure the we are initialized.
 443  17
         if (!isInitialized)
 444  
         {
 445  0
             initialize();
 446  
         }
 447  17
         return (String) jdbcToJavaNativeMap.get(jdbcType);
 448  
     }
 449  
 
 450  
     /**
 451  
      * Return native java type which corresponds to the
 452  
      * JDBC type provided. Use in the base object class generation.
 453  
      *
 454  
      * @param jdbcType the JDBC type
 455  
      * @return name of the Object
 456  
      */
 457  
     public static String getJavaNativeObject(SchemaType jdbcType)
 458  
     {
 459  
         // Make sure the we are initialized.
 460  17
         if (!isInitialized)
 461  
         {
 462  0
             initialize();
 463  
         }
 464  17
         String s = (String) jdbcToJavaNativeObjectMap.get(jdbcType);
 465  17
         if (s == null)
 466  
         {
 467  0
             s = (String) jdbcToJavaNativeMap.get(jdbcType);
 468  
         }
 469  17
         return s;
 470  
     }
 471  
 
 472  
     /**
 473  
      * Return Village asX() method which corresponds to the
 474  
      * JDBC type provided. Use in the Peer class generation.
 475  
      *
 476  
      * @param jdbcType the JDBC type
 477  
      * @return name of the Village asX() method
 478  
      */
 479  
     public static String getVillageMethod(SchemaType jdbcType)
 480  
     {
 481  
         // Make sure the we are initialized.
 482  17
         if (!isInitialized)
 483  
         {
 484  0
             initialize();
 485  
         }
 486  17
         return (String) jdbcToVillageMethodMap.get(jdbcType);
 487  
     }
 488  
 
 489  
     /**
 490  
      * Return Village asX() method which corresponds to the
 491  
      * JDBC type provided. Use in the Peer class generation.
 492  
      *
 493  
      * @param jdbcType the JDBC type
 494  
      * @return name of the Village asX() method
 495  
      */
 496  
     public static String getVillageObjectMethod(SchemaType jdbcType)
 497  
     {
 498  
         // Make sure the we are initialized.
 499  17
         if (!isInitialized)
 500  
         {
 501  0
             initialize();
 502  
         }
 503  17
         String s = (String) jdbcToVillageObjectMethodMap.get(jdbcType);
 504  17
         if (s == null)
 505  
         {
 506  0
             s = (String) jdbcToVillageMethodMap.get(jdbcType);
 507  
         }
 508  17
         return s;
 509  
     }
 510  
 
 511  
     /**
 512  
      * Return ParameterParser getX() method which corresponds to the
 513  
      * JDBC type provided. Use in the Object class generation.
 514  
      *
 515  
      * @param jdbcType the JDBC type
 516  
      * @return name of the ParameterParser getX() method
 517  
      */
 518  
     public static String getPPMethod(SchemaType jdbcType)
 519  
     {
 520  
         // Make sure the we are initialized.
 521  17
         if (!isInitialized)
 522  
         {
 523  0
             initialize();
 524  
         }
 525  17
         return (String) jdbcToPPMethodMap.get(jdbcType);
 526  
     }
 527  
 
 528  
     /**
 529  
      * Returns the correct jdbc type for torque added types
 530  
      *
 531  
      * @param type the torque added type
 532  
      * @return name of the the correct jdbc type
 533  
      * @deprecated the type conversion is handled by the platform package
 534  
      *             (since torque 3.2)
 535  
      */
 536  
     public static SchemaType getJdbcType(SchemaType type)
 537  
     {
 538  
         // Make sure the we are initialized.
 539  0
         if (!isInitialized)
 540  
         {
 541  0
             initialize();
 542  
         }
 543  0
         return (SchemaType) torqueTypeToJdbcTypeMap.get(type);
 544  
     }
 545  
 
 546  
     /**
 547  
      * Returns Torque type constant corresponding to JDBC type code.
 548  
      * Used by the Torque JDBC task.
 549  
      *
 550  
      * @param sqlType the SQL type
 551  
      * @return Torque type constant
 552  
      */
 553  
     public static SchemaType getTorqueType(Integer sqlType)
 554  
     {
 555  
         // Make sure the we are initialized.
 556  34
         if (!isInitialized)
 557  
         {
 558  0
             initialize();
 559  
         }
 560  34
         SchemaType st = (SchemaType) jdbcToTorqueTypeMap.get(sqlType);
 561  34
         if (st == null)
 562  
         {
 563  0
             st = SchemaType.VARCHAR;
 564  0
             log.warn("SchemaType for JdbcType '" + sqlType
 565  
                     + "' is not defined: Defaulting to '" + st + '\'');
 566  
         }
 567  34
         return st;
 568  
     }
 569  
 
 570  
     /**
 571  
      * Returns true if the type is boolean in the java
 572  
      * object and a numeric (1 or 0) in the db.
 573  
      *
 574  
      * @param type The type to check.
 575  
      * @return true if the type is BOOLEANINT
 576  
      */
 577  
     public static boolean isBooleanInt(SchemaType type)
 578  
     {
 579  34
         return SchemaType.BOOLEANINT.equals(type);
 580  
     }
 581  
 
 582  
     /**
 583  
      * Returns true if the type is boolean in the
 584  
      * java object and a String "Y" or "N" in the db.
 585  
      *
 586  
      * @param type The type to check.
 587  
      * @return true if the type is BOOLEANCHAR
 588  
      */
 589  
     public static boolean isBooleanChar(SchemaType type)
 590  
     {
 591  34
         return SchemaType.BOOLEANCHAR.equals(type);
 592  
     }
 593  
 
 594  
     /**
 595  
      * Returns true if the type is boolean in the
 596  
      * java object and a Bit "1" or "0" in the db.
 597  
      *
 598  
      * @param type The type to check.
 599  
      * @return true if the type is BIT
 600  
      */
 601  
     public static boolean isBit(SchemaType type)
 602  
     {
 603  0
         return SchemaType.BIT.equals(type);
 604  
     }
 605  
 
 606  
     /**
 607  
      * Returns true if values for the type need to be quoted.
 608  
      *
 609  
      * @param type The type to check.
 610  
      * @return true if values for the type need to be quoted.
 611  
      */
 612  
     public static final boolean isTextType(SchemaType type)
 613  
     {
 614  1700
         for (int i = 0; i < TEXT_TYPES.length; i++)
 615  
         {
 616  1513
             if (type.equals(TEXT_TYPES[i]))
 617  
             {
 618  17
                 return true;
 619  
             }
 620  
         }
 621  
 
 622  
         // If we get this far, there were no matches.
 623  187
         return false;
 624  
     }
 625  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.