Search in sources :

Example 1 with DataTypeInfo

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

the class TableInfoHandler method handleResult.

@Override
public void handleResult(ResultContext<? extends ParamMap> paramResultContext) {
    ParamMap rowData = paramResultContext.getResultObject();
    String tblName = rowData.getString(MetaColumnConstants.TABLE_NAME);
    if (!tblName.equals(beforeTableName)) {
        if (useTableIndex) {
            currentTableInfo = this.tableInfoList.get(this.tableIndexInfo.get(tblName));
            currentTableInfo.setColList(new ArrayList<ColumnInfo>());
            currentTableInfo.setRemarks(StringUtils.nullToString(currentTableInfo.getRemarks(), ""));
        } else {
            currentTableInfo = new TableInfo();
            currentTableInfo.setName(tblName);
            currentTableInfo.setColList(new ArrayList<ColumnInfo>());
            currentTableInfo.setRemarks(rowData.getString(MetaColumnConstants.REMARKS, ""));
            tableInfoList.add(currentTableInfo);
        }
    }
    ColumnInfo column = new ColumnInfo();
    String cName = rowData.getString(MetaColumnConstants.COLUMN_NAME);
    String columnSize = rowData.getString(MetaColumnConstants.COLUMN_SIZE);
    String degitsLen = rowData.getString(MetaColumnConstants.DECIMAL_DIGITS);
    String dataType = rowData.getString(MetaColumnConstants.DATA_TYPE);
    DataTypeInfo dataTypeInfo = dataTypeImpl.getDataType(dataType);
    column.setName(cName);
    column.setDataType(dataType);
    Object lenInfoObj = rowData.get(MetaColumnConstants.COLUMN_SIZE);
    if (lenInfoObj != null) {
        if (lenInfoObj instanceof Integer) {
            column.setLength(Integer.parseInt(lenInfoObj + ""));
        } else {
            column.setLength(new BigDecimal(lenInfoObj + ""));
        }
    }
    column.setDefaultVal(rowData.getString(MetaColumnConstants.COLUMN_DEF));
    column.setNullable(rowData.getString(MetaColumnConstants.IS_NULLABLE));
    column.setTypeName(dataTypeInfo.getDataTypeName());
    String typeAndLength = rowData.getString(MetaColumnConstants.TYPE_NAME_SIZE, "");
    if ("".equals(typeAndLength)) {
        column.setTypeAndLength(DbMetaUtils.getTypeName(dataTypeInfo, column, dataTypeInfo.getDataTypeName(), columnSize, degitsLen));
    } else {
        column.setTypeAndLength(typeAndLength);
    }
    column.setComment(rowData.getString(MetaColumnConstants.COMMENT, ""));
    column.setConstraints(rowData.getString(MetaColumnConstants.CONSTRAINTS, ""));
    currentTableInfo.addColInfo(column);
    beforeTableName = tblName;
}
Also used : DataTypeInfo(com.varsql.core.db.valueobject.DataTypeInfo) ParamMap(com.vartech.common.app.beans.ParamMap) ColumnInfo(com.varsql.core.db.valueobject.ColumnInfo) TableInfo(com.varsql.core.db.valueobject.TableInfo) BigDecimal(java.math.BigDecimal)

Example 2 with DataTypeInfo

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

the class DBMetaHandlerImpl 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 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.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(), 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 3 with DataTypeInfo

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

the class MssqlDDLScript 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((String) 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 4 with DataTypeInfo

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

the class TiberoDBMetaHandler 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 5 with DataTypeInfo

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

the class DDLScriptImpl method getTables.

/**
 * @Method Name  : getTable
 * @Method 설명 : table ddl
 * @Method override : @see com.varsql.core.db.ddl.script.DDLScript#getTable(com.varsql.core.db.valueobject.DatabaseParamInfo, java.lang.String[])
 * @작성자   : ytkim
 * @작성일   : 2015. 6. 18.
 * @변경이력  :
 * @param dataParamInfo
 * @param objNm
 * @return
 * @throws Exception
 */
public List<DDLInfo> getTables(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    List<TableInfo> tableInfoList = dbInstanceFactory.getDBObjectMeta(ObjectType.TABLE.getObjectTypeId(), dataParamInfo, objNmArr);
    StringBuilder ddlStrBuf;
    List<DDLInfo> reval = new ArrayList<DDLInfo>();
    DDLInfo ddlInfo;
    for (TableInfo tableInfo : tableInfoList) {
        String name = tableInfo.getName();
        dataParamInfo.setObjectName(name);
        ddlInfo = new DDLInfo();
        ddlInfo.setName(name);
        ddlStrBuf = new StringBuilder();
        if (ddlOption.isAddDropClause()) {
            ddlStrBuf.append("/* DROP TABLE " + name + " CASCADE CONSTRAINT; */ ").append(BlankConstants.NEW_LINE_TWO);
        }
        List<ColumnInfo> columnList = tableInfo.getColList();
        ddlStrBuf.append("CREATE TABLE " + name + "(").append(BlankConstants.NEW_LINE);
        DataTypeInfo dataTypeInfo;
        ColumnInfo columnInfo;
        for (int i = 0; i < columnList.size(); i++) {
            columnInfo = columnList.get(i);
            dataTypeInfo = dbInstanceFactory.getDataTypeImpl().getDataType(columnInfo.getDataType());
            ddlStrBuf.append(BlankConstants.TAB);
            if (i > 0) {
                ddlStrBuf.append(",");
            }
            ddlStrBuf.append(columnInfo.getName()).append(" ");
            ddlStrBuf.append(columnInfo.getTypeAndLength());
            ddlStrBuf.append(getDefaultValue(columnInfo.getDefaultVal(), dataTypeInfo));
            ddlStrBuf.append(getNotNullValue(columnInfo.getNullable()));
            ddlStrBuf.append(BlankConstants.NEW_LINE);
        }
        List<Map> keyInfo = getTablePrimaryKeyInfo(dataParamInfo, name);
        if (keyInfo.size() > 0) {
            Map source;
            ddlStrBuf.append(BlankConstants.TAB).append(",CONSTRAINT ").append(keyInfo.get(0).get(MetaColumnConstants.PK_NAME)).append(" PRIMARY KEY  ( ");
            for (int i = 0; i < keyInfo.size(); i++) {
                source = keyInfo.get(i);
                ddlStrBuf.append(i == 0 ? "" : ", ").append(source.get(MetaColumnConstants.COLUMN_NAME));
            }
            ddlStrBuf.append(")").append(BlankConstants.NEW_LINE);
        }
        ddlStrBuf.append(")").append(ddlOption.isAddLastSemicolon() ? ";" : "").append(BlankConstants.NEW_LINE_TWO);
        ddlInfo.setCreateScript(ddlStrBuf.toString());
        reval.add(ddlInfo);
    }
    return reval;
}
Also used : DataTypeInfo(com.varsql.core.db.valueobject.DataTypeInfo) ArrayList(java.util.ArrayList) ColumnInfo(com.varsql.core.db.valueobject.ColumnInfo) DDLInfo(com.varsql.core.db.valueobject.ddl.DDLInfo) TableInfo(com.varsql.core.db.valueobject.TableInfo) HashMap(java.util.HashMap) 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