Search in sources :

Example 1 with DateTimeOffset

use of microsoft.sql.DateTimeOffset in project dal by ctripcorp.

the class JavaColumnNameResultSetExtractor method extractData.

@Override
public List<AbstractParameterHost> extractData(ResultSet rs) throws SQLException {
    List<AbstractParameterHost> allColumns = new ArrayList<>();
    Map<String, Integer> columnSqlType = DbUtils.getColumnSqlType(allInOneName, tableName);
    Map<String, Class<?>> typeMapper = DbUtils.getSqlType2JavaTypeMaper(allInOneName, tableName);
    Map<String, String> columnComment;
    try {
        columnComment = DbUtils.getSqlserverColumnComment(allInOneName, tableName);
    } catch (Exception e) {
        throw new SQLException(e.getMessage(), e);
    }
    if (columnSqlType != null && columnSqlType.size() > 0) {
        while (rs.next()) {
            JavaParameterHost host = new JavaParameterHost();
            String typeName = rs.getString(TYPE_NAME);
            String columnName = rs.getString(COLUMN_NAME);
            host.setName(columnName);
            host.setSqlType(columnSqlType.get(host.getName()));
            Class<?> javaClass = null;
            if (null != typeMapper && typeMapper.containsKey(host.getName())) {
                javaClass = typeMapper.get(host.getName());
            } else {
                javaClass = Consts.jdbcSqlTypeToJavaClass.get(host.getSqlType());
            }
            if (null == javaClass) {
                if (null != typeName && typeName.equalsIgnoreCase("sql_variant")) {
                    log.fatal(String.format("The sql_variant is not support by java.[%s, %s, %s, %s, %s]", host.getName(), allInOneName, tableName, host.getSqlType(), javaClass));
                    return null;
                } else if (null != typeName && typeName.equalsIgnoreCase("datetimeoffset")) {
                    javaClass = DateTimeOffset.class;
                } else {
                    log.fatal(String.format("The java type cant be mapped.[%s, %s, %s, %s, %s]", host.getName(), allInOneName, tableName, host.getSqlType(), javaClass));
                    return null;
                }
            }
            host.setJavaClass(javaClass);
            host.setIndex(rs.getInt(ORDINAL_POSITION));
            host.setIdentity(rs.getString(IS_AUTOINCREMENT).equalsIgnoreCase("YES"));
            String remarks = rs.getString(REMARKS);
            if (remarks == null) {
                String description = columnComment.get(columnName.toLowerCase());
                remarks = description == null ? "" : description;
            }
            host.setComment(remarks.replace("\n", " "));
            host.setDefaultValue(rs.getString(COLUMN_DEF));
            host.setDbCategory(dbCategory);
            int dataType = rs.getInt(DATA_TYPE);
            host.setDataType(dataType);
            allColumns.add(host);
        }
    }
    return allColumns;
}
Also used : AbstractParameterHost(com.ctrip.platform.dal.daogen.host.AbstractParameterHost) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DateTimeOffset(microsoft.sql.DateTimeOffset) SQLException(java.sql.SQLException)

Aggregations

AbstractParameterHost (com.ctrip.platform.dal.daogen.host.AbstractParameterHost)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 DateTimeOffset (microsoft.sql.DateTimeOffset)1