Search in sources :

Example 1 with DbType

use of com.ctrip.platform.dal.daogen.enums.DbType in project dal by ctripcorp.

the class CsharpGivenSqlResultSetExtractor method extractData.

@Override
public List<AbstractParameterHost> extractData(ResultSet rs) throws SQLException {
    List<AbstractParameterHost> hosts = new ArrayList<>();
    if (rs == null) {
        return hosts;
    }
    ResultSetMetaData metaData = rs.getMetaData();
    int count = metaData.getColumnCount();
    for (int i = 1; i <= count; i++) {
        CSharpParameterHost host = new CSharpParameterHost();
        String columnName = metaData.getColumnLabel(i);
        host.setName(columnName);
        String typeName = metaData.getColumnTypeName(i);
        boolean isUnsigned = DbUtils.isColumnUnsigned(typeName);
        int dataType = metaData.getColumnType(i);
        int length = metaData.getColumnDisplaySize(i);
        // 特殊处理
        DbType dbType = DbUtils.getDotNetDbType(typeName, dataType, length, isUnsigned, dbCategory);
        host.setDbType(dbType);
        String type = DbType.getCSharpType(host.getDbType());
        host.setType(type);
        host.setIdentity(false);
        host.setNullable(metaData.isNullable(i) == 1 ? true : false);
        host.setPrimary(false);
        host.setLength(length);
        host.setValueType(Consts.CSharpValueTypes.contains(host.getType()));
        hosts.add(host);
    }
    return hosts;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) AbstractParameterHost(com.ctrip.platform.dal.daogen.host.AbstractParameterHost) ArrayList(java.util.ArrayList) DbType(com.ctrip.platform.dal.daogen.enums.DbType)

Example 2 with DbType

use of com.ctrip.platform.dal.daogen.enums.DbType in project dal by ctripcorp.

the class CsharpColumnNameResultSetExtractor method extract.

@Override
public List<AbstractParameterHost> extract(ResultSet rs) throws SQLException {
    List<AbstractParameterHost> allColumns = new ArrayList<>();
    if (rs == null) {
        return allColumns;
    }
    Map<String, String> columnComment;
    try {
        columnComment = DbUtils.getSqlserverColumnComment(allInOneName, tableName);
    } catch (Exception e) {
        throw new SQLException(e.getMessage(), e);
    }
    while (rs.next()) {
        CSharpParameterHost host = new CSharpParameterHost();
        String columnName = rs.getString(COLUMN_NAME);
        host.setName(columnName);
        String typeName = rs.getString(TYPE_NAME);
        boolean isUnsigned = DbUtils.isColumnUnsigned(typeName);
        int dataType = rs.getInt(DATA_TYPE);
        host.setDataType(dataType);
        int length = rs.getInt(COLUMN_SIZE);
        // 特殊处理
        DbType dbType = DbUtils.getDotNetDbType(typeName, dataType, length, isUnsigned, dbCategory);
        host.setDbType(dbType);
        String remark = rs.getString(REMARKS);
        if (remark == null) {
            String description = columnComment.get(columnName.toLowerCase());
            remark = description == null ? "" : description;
        }
        host.setComment(remark.replace("\n", " "));
        String type = DbType.getCSharpType(host.getDbType());
        host.setType(type);
        host.setIdentity(rs.getString(IS_AUTOINCREMENT).equalsIgnoreCase("YES"));
        host.setNullable(rs.getShort(NULLABLE) == DatabaseMetaData.columnNullable);
        host.setValueType(Consts.CSharpValueTypes.contains(host.getType()));
        // 仅获取String类型的长度
        if ("string".equalsIgnoreCase(host.getType()))
            host.setLength(length);
        host.setDefaultValue(rs.getString(COLUMN_DEF));
        host.setDbCategory(dbCategory);
        allColumns.add(host);
    }
    return allColumns;
}
Also used : AbstractParameterHost(com.ctrip.platform.dal.daogen.host.AbstractParameterHost) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) DbType(com.ctrip.platform.dal.daogen.enums.DbType)

Example 3 with DbType

use of com.ctrip.platform.dal.daogen.enums.DbType in project dal by ctripcorp.

the class CsharpColumnNameResultSetExtractor method extractData.

@Override
public List<AbstractParameterHost> extractData(ResultSet rs) throws SQLException {
    List<AbstractParameterHost> allColumns = new ArrayList<>();
    if (rs == null) {
        return allColumns;
    }
    Map<String, String> columnComment;
    try {
        columnComment = DbUtils.getSqlserverColumnComment(allInOneName, tableName);
    } catch (Exception e) {
        throw new SQLException(e.getMessage(), e);
    }
    while (rs.next()) {
        CSharpParameterHost host = new CSharpParameterHost();
        String columnName = rs.getString(COLUMN_NAME);
        host.setName(columnName);
        String typeName = rs.getString(TYPE_NAME);
        boolean isUnsigned = DbUtils.isColumnUnsigned(typeName);
        int dataType = rs.getInt(DATA_TYPE);
        host.setDataType(dataType);
        int length = rs.getInt(COLUMN_SIZE);
        // 特殊处理
        DbType dbType = DbUtils.getDotNetDbType(typeName, dataType, length, isUnsigned, dbCategory);
        host.setDbType(dbType);
        String remark = rs.getString(REMARKS);
        if (remark == null) {
            String description = columnComment.get(columnName.toLowerCase());
            remark = description == null ? "" : description;
        }
        host.setComment(remark.replace("\n", " "));
        String type = DbType.getCSharpType(host.getDbType());
        host.setType(type);
        host.setIdentity(rs.getString(IS_AUTOINCREMENT).equalsIgnoreCase("YES"));
        host.setNullable(rs.getShort(NULLABLE) == DatabaseMetaData.columnNullable);
        host.setValueType(Consts.CSharpValueTypes.contains(host.getType()));
        // 仅获取String类型的长度
        if ("string".equalsIgnoreCase(host.getType()))
            host.setLength(length);
        host.setDefaultValue(rs.getString(COLUMN_DEF));
        host.setDbCategory(dbCategory);
        allColumns.add(host);
    }
    return allColumns;
}
Also used : AbstractParameterHost(com.ctrip.platform.dal.daogen.host.AbstractParameterHost) SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) DbType(com.ctrip.platform.dal.daogen.enums.DbType)

Example 4 with DbType

use of com.ctrip.platform.dal.daogen.enums.DbType in project dal by ctripcorp.

the class CsharpSpParamResultSetExtractor method extractData.

@Override
public List<AbstractParameterHost> extractData(ResultSet rs) throws SQLException {
    List<AbstractParameterHost> parameters = new ArrayList<>();
    while (rs.next()) {
        int paramMode = rs.getShort("COLUMN_TYPE");
        if (!DbUtils.validMode.contains(paramMode)) {
            continue;
        }
        CSharpParameterHost host = new CSharpParameterHost();
        DbType dbType = DbUtils.getDotNetDbType(rs.getString("TYPE_NAME"), rs.getInt("DATA_TYPE"), rs.getInt("LENGTH"), false, null);
        host.setDbType(dbType);
        host.setNullable(rs.getShort("NULLABLE") == DatabaseMetaData.columnNullable);
        if (paramMode == DatabaseMetaData.procedureColumnIn) {
            host.setDirection(ParameterDirection.Input);
        } else if (paramMode == DatabaseMetaData.procedureColumnInOut) {
            host.setDirection(ParameterDirection.InputOutput);
        } else {
            host.setDirection(ParameterDirection.Output);
        }
        host.setName(rs.getString("COLUMN_NAME"));
        host.setType(DbType.getCSharpType(host.getDbType()));
        host.setNullable(rs.getShort("NULLABLE") == DatabaseMetaData.columnNullable);
        if (host.getType() == null) {
            host.setType("string");
            host.setDbType(DbType.AnsiString);
        }
        parameters.add(host);
    }
    return parameters;
}
Also used : AbstractParameterHost(com.ctrip.platform.dal.daogen.host.AbstractParameterHost) ArrayList(java.util.ArrayList) DbType(com.ctrip.platform.dal.daogen.enums.DbType)

Example 5 with DbType

use of com.ctrip.platform.dal.daogen.enums.DbType in project dal by ctripcorp.

the class CsharpGivenSqlResultSetExtractor method extract.

@Override
public List<AbstractParameterHost> extract(ResultSet rs) throws SQLException {
    List<AbstractParameterHost> hosts = new ArrayList<>();
    if (rs == null) {
        return hosts;
    }
    ResultSetMetaData metaData = rs.getMetaData();
    int count = metaData.getColumnCount();
    for (int i = 1; i <= count; i++) {
        CSharpParameterHost host = new CSharpParameterHost();
        String columnName = metaData.getColumnLabel(i);
        host.setName(columnName);
        String typeName = metaData.getColumnTypeName(i);
        boolean isUnsigned = DbUtils.isColumnUnsigned(typeName);
        int dataType = metaData.getColumnType(i);
        int length = metaData.getColumnDisplaySize(i);
        // 特殊处理
        DbType dbType = DbUtils.getDotNetDbType(typeName, dataType, length, isUnsigned, dbCategory);
        host.setDbType(dbType);
        String type = DbType.getCSharpType(host.getDbType());
        host.setType(type);
        host.setIdentity(false);
        host.setNullable(metaData.isNullable(i) == 1 ? true : false);
        host.setPrimary(false);
        host.setLength(length);
        host.setValueType(Consts.CSharpValueTypes.contains(host.getType()));
        hosts.add(host);
    }
    return hosts;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) AbstractParameterHost(com.ctrip.platform.dal.daogen.host.AbstractParameterHost) ArrayList(java.util.ArrayList) DbType(com.ctrip.platform.dal.daogen.enums.DbType)

Aggregations

DbType (com.ctrip.platform.dal.daogen.enums.DbType)6 AbstractParameterHost (com.ctrip.platform.dal.daogen.host.AbstractParameterHost)6 ArrayList (java.util.ArrayList)6 ResultSetMetaData (java.sql.ResultSetMetaData)2 SQLException (java.sql.SQLException)2