Search in sources :

Example 6 with DataTypeInfo

use of com.varsql.core.db.valueobject.DataTypeInfo in project varsql by varsqlinfo.

the class MysqlDBMetaHandler method getColumnInfo.

/**
 * @Method Name  : getColumnInfo
 * @Method 설명 : 컬럼 정보 얻기.
 * @작성자   : ytkim
 * @작성일   : 2017. 11. 20.
 * @변경이력  :
 * @param rs
 * @param dataTypeImpl
 * @param keyColumn
 * @return
 * @throws SQLException
 */
@Override
public ColumnInfo getColumnInfo(ResultSet rs, DataTypeImpl dataTypeImpl, Set keyColumn, Map colComment) throws SQLException {
    ColumnInfo column = new ColumnInfo();
    String cName = rs.getString(MetaColumnConstants.COLUMN_NAME);
    String dataType = rs.getString(MetaColumnConstants.DATA_TYPE);
    String degitsLen = StringUtils.nullToString(rs.getString(MetaColumnConstants.DECIMAL_DIGITS));
    String columnSize = rs.getString(MetaColumnConstants.COLUMN_SIZE);
    DataTypeInfo dataTypeInfo = dataTypeImpl.getDataType(dataType);
    column.setName(cName);
    column.setDataType(dataType);
    column.setLength(rs.getBigDecimal(MetaColumnConstants.COLUMN_SIZE));
    column.setDefaultVal(StringUtils.nullToString(rs.getString(MetaColumnConstants.COLUMN_DEF)));
    column.setNullable(StringUtils.nullToString(rs.getString(MetaColumnConstants.IS_NULLABLE)));
    column.setAutoincrement("");
    column.setTypeName(dataTypeInfo.getDataTypeName());
    column.setTypeAndLength(DbMetaUtils.getTypeName(dataTypeInfo, column, dataTypeInfo.getDataTypeName(), columnSize, degitsLen));
    if (colComment != null) {
        column.setComment(StringUtils.nullToString(colComment.get(cName) != null ? (String) colComment.get(cName) : rs.getString(MetaColumnConstants.REMARKS)));
    }
    if (keyColumn != null) {
        column.setConstraints(keyColumn.contains(cName) ? "PK" : "");
    }
    return column;
}
Also used : DataTypeInfo(com.varsql.core.db.valueobject.DataTypeInfo) ColumnInfo(com.varsql.core.db.valueobject.ColumnInfo)

Example 7 with DataTypeInfo

use of com.varsql.core.db.valueobject.DataTypeInfo in project varsql by varsqlinfo.

the class OracleDBMetaHandler method getColumnInfo.

@Override
public ColumnInfo getColumnInfo(ResultSet rs, DataTypeImpl dataTypeImpl, Set keyColumn, Map colComment) throws SQLException {
    ColumnInfo column = new ColumnInfo();
    String cName = rs.getString(MetaColumnConstants.COLUMN_NAME);
    String degitsLen = StringUtils.nullToString(rs.getString(MetaColumnConstants.DECIMAL_DIGITS));
    String dataType = rs.getString(MetaColumnConstants.DATA_TYPE);
    DataTypeInfo dataTypeInfo = dataTypeImpl.getDataType(dataType);
    column.setName(cName);
    column.setDataType(dataType);
    column.setLength(rs.getInt(MetaColumnConstants.COLUMN_SIZE));
    column.setDefaultVal(StringUtils.nullToString(rs.getString(MetaColumnConstants.COLUMN_DEF)));
    column.setNullable(StringUtils.nullToString(rs.getString(MetaColumnConstants.IS_NULLABLE)));
    column.setAutoincrement("");
    column.setTypeName(dataTypeInfo.getDataTypeName());
    column.setTypeAndLength(DbMetaUtils.getTypeName(dataTypeInfo, column, dataTypeInfo.getDataTypeName(), degitsLen));
    if (colComment != null) {
        column.setComment(StringUtils.nullToString(colComment.get(cName) != null ? (String) colComment.get(cName) : rs.getString(MetaColumnConstants.REMARKS)));
    }
    column.setConstraints(keyColumn.contains(cName) ? "PK" : "");
    return column;
}
Also used : DataTypeInfo(com.varsql.core.db.valueobject.DataTypeInfo) ColumnInfo(com.varsql.core.db.valueobject.ColumnInfo)

Example 8 with DataTypeInfo

use of com.varsql.core.db.valueobject.DataTypeInfo in project varsql by varsqlinfo.

the class OracleDDLScript method getTables.

@Override
public List<DDLInfo> getTables(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    SqlSession client = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
    List<DDLInfo> reval = new ArrayList<DDLInfo>();
    DDLInfo ddlInfo;
    StringBuilder ddlStr;
    for (String name : objNmArr) {
        ddlStr = new StringBuilder();
        ddlInfo = new DDLInfo();
        ddlInfo.setName(name);
        dataParamInfo.setObjectName(name);
        if (ddlOption.isAddDropClause()) {
            ddlStr.append("/* DROP TABLE " + name + "; */").append(BlankConstants.NEW_LINE_TWO);
        }
        List<ParamMap> srcList = client.selectList("tableScript", dataParamInfo);
        ddlStr.append("CREATE TABLE " + name + "(\n");
        String dataType = "";
        dataParamInfo.setObjectName(name);
        DataTypeImpl dataTypeImpl = dbInstanceFactory.getDataTypeImpl();
        ParamMap source;
        for (int i = 0; i < srcList.size(); i++) {
            source = srcList.get(i);
            dataType = String.valueOf(source.get("DATA_TYPE"));
            DataTypeInfo dataTypeInfo = dataTypeImpl.getDataType(dataType);
            ddlStr.append("\t");
            if (i > 0) {
                ddlStr.append(",");
            }
            ddlStr.append(source.get(MetaColumnConstants.COLUMN_NAME)).append(" ");
            ddlStr.append(DbMetaUtils.getTypeName(dataTypeInfo, null, dataTypeInfo.getDataTypeName(), source.getString(MetaColumnConstants.COLUMN_SIZE), source.getString(MetaColumnConstants.DECIMAL_DIGITS)));
            ddlStr.append(getDefaultValue(source.getString("DATA_DEFAULT"), dataTypeInfo, true));
            ddlStr.append(getNotNullValue(source.getString(MetaColumnConstants.NULLABLE)));
            ddlStr.append(BlankConstants.NEW_LINE);
        }
        List srcPkList = client.selectList("tableScriptPk", dataParamInfo);
        Map pkMap;
        for (int i = 0; i < srcPkList.size(); i++) {
            pkMap = (HashMap) srcPkList.get(i);
            if (i == 0)
                ddlStr.append(BlankConstants.TAB).append(",CONSTRAINT ").append(pkMap.get("CONSTRAINT_NAME")).append(" PRIMARY KEY ( ").append(pkMap.get("COLUMN_NAME"));
            else {
                ddlStr.append(", " + pkMap.get("COLUMN_NAME"));
            }
            if (i == srcPkList.size() - 1) {
                ddlStr.append(")").append(BlankConstants.NEW_LINE);
            }
        }
        ddlStr.append(");").append(BlankConstants.NEW_LINE_TWO);
        List srcCommentList = client.selectList("tableScriptComments", dataParamInfo);
        for (int i = 0; i < srcCommentList.size(); i++) {
            ddlStr.append(srcCommentList.get(i)).append(BlankConstants.NEW_LINE);
        }
        if (srcCommentList.size() > 0) {
            ddlStr.append(BlankConstants.NEW_LINE);
        }
        ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat(ddlStr.toString(), dbType));
        reval.add(ddlInfo);
    }
    return reval;
}
Also used : DataTypeInfo(com.varsql.core.db.valueobject.DataTypeInfo) ParamMap(com.vartech.common.app.beans.ParamMap) SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) DataTypeImpl(com.varsql.core.db.meta.datatype.DataTypeImpl) DDLInfo(com.varsql.core.db.valueobject.ddl.DDLInfo) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) ParamMap(com.vartech.common.app.beans.ParamMap) Map(java.util.Map)

Example 9 with DataTypeInfo

use of com.varsql.core.db.valueobject.DataTypeInfo in project varsql by varsqlinfo.

the class TiberoDDLScript method getTables.

@Override
public List<DDLInfo> getTables(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    SqlSession client = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
    List<DDLInfo> reval = new ArrayList<DDLInfo>();
    DDLInfo ddlInfo;
    StringBuilder ddlStr;
    for (String name : objNmArr) {
        ddlStr = new StringBuilder();
        ddlInfo = new DDLInfo();
        ddlInfo.setName(name);
        dataParamInfo.setObjectName(name);
        if (ddlOption.isAddDropClause()) {
            ddlStr.append("/* DROP TABLE " + name + "; */").append(BlankConstants.NEW_LINE_TWO);
        }
        List<ParamMap> srcList = client.selectList("tableScript", dataParamInfo);
        ddlStr.append("CREATE TABLE " + name + "(\n");
        String dataType = "";
        dataParamInfo.setObjectName(name);
        DataTypeImpl dataTypeImpl = dbInstanceFactory.getDataTypeImpl();
        ParamMap source;
        for (int i = 0; i < srcList.size(); i++) {
            source = srcList.get(i);
            dataType = String.valueOf(source.get("DATA_TYPE"));
            DataTypeInfo dataTypeInfo = dataTypeImpl.getDataType(dataType);
            ddlStr.append("\t");
            if (i > 0) {
                ddlStr.append(",");
            }
            ddlStr.append(source.get(MetaColumnConstants.COLUMN_NAME)).append(" ");
            ddlStr.append(DbMetaUtils.getTypeName(dataTypeInfo, null, dataTypeInfo.getDataTypeName(), source.getString(MetaColumnConstants.COLUMN_SIZE), source.getString(MetaColumnConstants.DECIMAL_DIGITS)));
            ddlStr.append(getDefaultValue(source.getString("DATA_DEFAULT"), dataTypeInfo, true));
            ddlStr.append(getNotNullValue(source.getString("NULLABLE")));
            ddlStr.append(BlankConstants.NEW_LINE);
        }
        List srcPkList = client.selectList("tableScriptPk", dataParamInfo);
        Map pkMap;
        for (int i = 0; i < srcPkList.size(); i++) {
            pkMap = (HashMap) srcPkList.get(i);
            if (i == 0)
                ddlStr.append(BlankConstants.TAB).append(",CONSTRAINT ").append(pkMap.get("CONSTRAINT_NAME")).append(" PRIMARY KEY ( ").append(pkMap.get("COLUMN_NAME"));
            else {
                ddlStr.append(", " + pkMap.get("COLUMN_NAME"));
            }
            if (i == srcPkList.size() - 1) {
                ddlStr.append(")").append(BlankConstants.NEW_LINE);
            }
        }
        ddlStr.append(");").append(BlankConstants.NEW_LINE_TWO);
        List srcCommentList = client.selectList("tableScriptComments", dataParamInfo);
        for (int i = 0; i < srcCommentList.size(); i++) {
            ddlStr.append(srcCommentList.get(i)).append(BlankConstants.NEW_LINE);
        }
        if (srcCommentList.size() > 0) {
            ddlStr.append(BlankConstants.NEW_LINE);
        }
        ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat(ddlStr.toString(), dbType));
        reval.add(ddlInfo);
    }
    return reval;
}
Also used : DataTypeInfo(com.varsql.core.db.valueobject.DataTypeInfo) ParamMap(com.vartech.common.app.beans.ParamMap) SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) DataTypeImpl(com.varsql.core.db.meta.datatype.DataTypeImpl) DDLInfo(com.varsql.core.db.valueobject.ddl.DDLInfo) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) ParamMap(com.vartech.common.app.beans.ParamMap) Map(java.util.Map)

Aggregations

DataTypeInfo (com.varsql.core.db.valueobject.DataTypeInfo)9 ColumnInfo (com.varsql.core.db.valueobject.ColumnInfo)6 DDLInfo (com.varsql.core.db.valueobject.ddl.DDLInfo)4 ParamMap (com.vartech.common.app.beans.ParamMap)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 DataTypeImpl (com.varsql.core.db.meta.datatype.DataTypeImpl)3 List (java.util.List)3 SqlSession (org.apache.ibatis.session.SqlSession)3 TableInfo (com.varsql.core.db.valueobject.TableInfo)2 BigDecimal (java.math.BigDecimal)1