Example usage for java.sql JDBCType DATE

List of usage examples for java.sql JDBCType DATE

Introduction

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

Prototype

JDBCType DATE

To view the source code for java.sql JDBCType DATE.

Click Source Link

Document

Identifies the generic SQL type DATE .

Usage

From source file:com.microsoft.sqlserver.testframework.DBTable.java

/**
 * /*  w w  w  . ja v  a 2 s  .co  m*/
 * @param colNum
 * @return <code>true</code> if value can be passed as String for the column
 */
boolean passDataAsString(int colNum) {
    return (JDBCType.CHAR == getColumn(colNum).getJdbctype()
            || JDBCType.VARCHAR == getColumn(colNum).getJdbctype()
            || JDBCType.NCHAR == getColumn(colNum).getJdbctype()
            || JDBCType.NVARCHAR == getColumn(colNum).getJdbctype()
            || JDBCType.TIMESTAMP == getColumn(colNum).getJdbctype()
            || JDBCType.DATE == getColumn(colNum).getJdbctype()
            || JDBCType.TIME == getColumn(colNum).getJdbctype()
            || JDBCType.LONGVARCHAR == getColumn(colNum).getJdbctype()
            || JDBCType.LONGNVARCHAR == getColumn(colNum).getJdbctype());
}

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 w w  w. j a v  a  2  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;
}