List of usage examples for java.sql JDBCType valueOf
public static JDBCType valueOf(int type)
From source file:com.thinkbiganalytics.discovery.util.ParserHelper.java
/** * Derive data types//www.j a v a 2 s . 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()); } } } }
From source file:com.thinkbiganalytics.discovery.util.ParserHelper.java
public static String toNativeType(Integer dataType) { return JDBCType.valueOf(dataType).getName(); }
From source file:com.streamsets.pipeline.lib.jdbc.multithread.TableContextUtil.java
private static String createPartitionSizeValidationError(String colName, String partitionSize, int sqlType, String errorMsg) {//from w w w . j av a2s. c om return String.format("Partition size of %s is invalid for offset column %s (type %s): %s", partitionSize, colName, JDBCType.valueOf(sqlType).getName(), errorMsg); }
From source file:org.hswebframework.web.dao.mybatis.builder.EasyOrmSqlBuilder.java
protected RDBTableMetaData createMeta(String tableName, String resultMapId) { RDBDatabaseMetaData active = getActiveDatabase(); String cacheKey = tableName.concat("-").concat(resultMapId); Map<String, RDBTableMetaData> cache = metaCache.get(active); RDBTableMetaData cached = cache.get(cacheKey); if (cached != null) { return cached; }/* ww w . j av a2 s . c om*/ RDBTableMetaData rdbTableMetaData = new RDBTableMetaData(); ResultMap resultMaps = MybatisUtils.getResultMap(resultMapId); rdbTableMetaData.setName(tableName); rdbTableMetaData.setDatabaseMetaData(active); List<ResultMapping> resultMappings = new ArrayList<>(resultMaps.getResultMappings()); resultMappings.addAll(resultMaps.getIdResultMappings()); resultMappings.forEach(resultMapping -> { if (resultMapping.getNestedQueryId() == null) { RDBColumnMetaData column = new RDBColumnMetaData(); column.setJdbcType(JDBCType.valueOf(resultMapping.getJdbcType().name())); column.setName(resultMapping.getColumn()); if (!StringUtils.isNullOrEmpty(resultMapping.getProperty())) { column.setAlias(resultMapping.getProperty()); } column.setJavaType(resultMapping.getJavaType()); column.setProperty("resultMapping", resultMapping); ValueConverter dateConvert = new DateTimeConverter("yyyy-MM-dd HH:mm:ss", column.getJavaType()) { @Override public Object getData(Object value) { if (value instanceof Number) { return new Date(((Number) value).longValue()); } return super.getData(value); } }; if (column.getJdbcType() == JDBCType.DATE) { column.setValueConverter(dateConvert); } else if (column.getJdbcType() == JDBCType.TIMESTAMP) { column.setValueConverter(dateConvert); } else if (column.getJdbcType() == JDBCType.NUMERIC) { column.setValueConverter(new NumberValueConverter(column.getJavaType())); } rdbTableMetaData.addColumn(column); } }); cache.put(cacheKey, rdbTableMetaData); if (useJpa) { Class type = entityFactory == null ? resultMaps.getType() : entityFactory.getInstanceType(resultMaps.getType()); RDBTableMetaData parseResult = JpaAnnotationParser.parseMetaDataFromEntity(type); if (parseResult != null) { for (RDBColumnMetaData columnMetaData : parseResult.getColumns()) { if (rdbTableMetaData.findColumn(columnMetaData.getName()) == null) { columnMetaData = columnMetaData.clone(); columnMetaData.setProperty("fromJpa", true); rdbTableMetaData.addColumn(columnMetaData); } } } } return rdbTableMetaData; }
From source file:org.silverpeas.components.mydb.web.MyDBWebController.java
private void throwInvalidValueType(final String name, final int expectedType) { throw new IllegalArgumentException(getMultilang().getString("mydb.error.invalidValue") + ". " + name + ": " + JDBCType.valueOf(expectedType).getName()); }