Example usage for java.sql JDBCType getName

List of usage examples for java.sql JDBCType getName

Introduction

In this page you can find the example usage for java.sql JDBCType getName.

Prototype

public String getName() 

Source Link

Usage

From source file:com.thinkbiganalytics.discovery.util.ParserHelper.java

/**
 * Derive data types//from   ww  w  .j  a v  a  2s.  c  o  m
 *
 * @param type   the target database platform
 * @param fields the fields
 */
public static void deriveDataTypes(TableSchemaType type, List<? extends Field> fields) {
    for (Field field : fields) {
        if (StringUtils.isEmpty(field.getDerivedDataType())) {
            JDBCType jdbcType = JDBCType.VARCHAR;
            try {
                if (!StringUtils.isEmpty(field.getNativeDataType())) {
                    jdbcType = JDBCType.valueOf(field.getNativeDataType());
                } else {
                    jdbcType = deriveJDBCDataType(field.getSampleValues());
                }
            } catch (IllegalArgumentException e) {
                log.warn("Unable to convert data type [?] will be converted to VARCHAR",
                        field.getNativeDataType());
            }

            switch (type) {
            case HIVE:
                String hiveType = sqlTypeToHiveType(jdbcType);
                field.setDerivedDataType(hiveType);
                field.setDataTypeDescriptor(hiveTypeToDescriptor(hiveType));
                break;
            case RDBMS:
                field.setDerivedDataType(jdbcType.getName());
            }
        }
    }
}