Here you can find the source of getClassForSqlType(String sqlType, Class extends java.util.Date> dateTimeClass)
Parameter | Description |
---|---|
sqlType | the SQL type |
dateTimeClass | the preferred date class (java.util.Date or java.sql.Timestamp) |
static Class<?> getClassForSqlType(String sqlType, Class<? extends java.util.Date> dateTimeClass)
//package com.java2s; /*/*from w w w . j a v a2 s. c o m*/ * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, * and the EPL 1.0 (http://h2database.com/html/license.html). * Initial Developer: James Moger */ import java.util.HashMap; import java.util.Map; public class Main { /** * The list of supported data types. It is used by the runtime mapping for * CREATE statements. */ private static final Map<Class<?>, String> SUPPORTED_TYPES = new HashMap<Class<?>, String>(); /** * Convert SQL type aliases to the list of supported types. * This map is used by generation and validation. */ private static final Map<String, String> SQL_TYPES = new HashMap<String, String>(); /** * Returns the Java class for a given SQL type. * * @param sqlType the SQL type * @param dateTimeClass the preferred date class (java.util.Date or * java.sql.Timestamp) * @return Class of type */ static Class<?> getClassForSqlType(String sqlType, Class<? extends java.util.Date> dateTimeClass) { sqlType = sqlType.toUpperCase(); // TODO dropping "UNSIGNED" or parts like that could be trouble sqlType = sqlType.split(" ")[0].trim(); if (SQL_TYPES.containsKey(sqlType)) { // convert the sqlType to a standard type sqlType = SQL_TYPES.get(sqlType); } Class<?> mappedClass = null; for (Class<?> clazz : SUPPORTED_TYPES.keySet()) { if (SUPPORTED_TYPES.get(clazz).equalsIgnoreCase(sqlType)) { mappedClass = clazz; break; } } if (mappedClass != null) { if (mappedClass.equals(java.util.Date.class) || mappedClass.equals(java.sql.Timestamp.class)) { return dateTimeClass; } return mappedClass; } return null; } }