List of usage examples for java.sql JDBCType NUMERIC
JDBCType NUMERIC
To view the source code for java.sql JDBCType NUMERIC.
Click Source Link
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; }//from ww w . j a v 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; }