Search in sources :

Example 31 with DDLInfo

use of com.varsql.core.db.valueobject.ddl.DDLInfo 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)

Example 32 with DDLInfo

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

the class MssqlDDLScript method getIndexs.

@Override
public List<DDLInfo> getIndexs(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
    List<DDLInfo> reval = new ArrayList<DDLInfo>();
    DDLInfo ddlInfo;
    StringBuilder ddlStr;
    for (String name : objNmArr) {
        ddlInfo = new DDLInfo();
        ddlInfo.setName(name);
        dataParamInfo.setObjectName(name);
        ddlStr = new StringBuilder();
        List srcScriptList = sqlSesseion.selectList("indexScriptSource", dataParamInfo);
        Map indexMap;
        if (srcScriptList.size() > 0) {
            if (ddlOption.isAddDropClause()) {
                ddlStr.append("/* DROP INDEX " + dataParamInfo.getObjectName() + "; */").append(BlankConstants.NEW_LINE_TWO);
            }
            for (int i = 0; i < srcScriptList.size(); i++) {
                indexMap = (Map) srcScriptList.get(i);
                ddlStr.append(indexMap.get("SOURCES"));
            }
        }
        ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat(VarsqlFormatterUtil.addLastSemicolon(ddlStr, ddlOption), dbType));
        reval.add(ddlInfo);
    }
    return reval;
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) 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 33 with DDLInfo

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

the class MysqlDDLScript method getProcedures.

@Override
public List<DDLInfo> getProcedures(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
    logger.debug(" Procedure DDL Generation...");
    List<DDLInfo> reval = new ArrayList<DDLInfo>();
    DDLInfo ddlInfo;
    StringBuilder ddlStr;
    for (String name : objNmArr) {
        ddlInfo = new DDLInfo();
        ddlInfo.setName(name);
        ddlStr = new StringBuilder();
        dataParamInfo.setObjectName(name);
        ParamMap source = sqlSesseion.selectOne("procedureScript", dataParamInfo);
        ddlStr.append(source.getString("Create Procedure"));
        ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat(VarsqlFormatterUtil.addLastSemicolon(ddlStr, ddlOption), dbType));
        reval.add(ddlInfo);
    }
    return reval;
}
Also used : ParamMap(com.vartech.common.app.beans.ParamMap) SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) DDLInfo(com.varsql.core.db.valueobject.ddl.DDLInfo)

Example 34 with DDLInfo

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

the class MysqlDDLScript method getIndexs.

@Override
public List<DDLInfo> getIndexs(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
    List<DDLInfo> reval = new ArrayList<DDLInfo>();
    DDLInfo ddlInfo;
    for (String name : objNmArr) {
        ddlInfo = new DDLInfo();
        ddlInfo.setName(name);
        dataParamInfo.setObjectName(name);
        ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat("", dbType));
        reval.add(ddlInfo);
    }
    return reval;
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) DDLInfo(com.varsql.core.db.valueobject.ddl.DDLInfo)

Example 35 with DDLInfo

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

the class MysqlDDLScript method getViews.

@Override
public List<DDLInfo> getViews(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    StringBuilder ddlStr;
    SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
    List<DDLInfo> reval = new ArrayList<DDLInfo>();
    DDLInfo ddlInfo;
    for (String name : objNmArr) {
        ddlStr = new StringBuilder();
        ddlInfo = new DDLInfo();
        ddlInfo.setName(name);
        dataParamInfo.setObjectName(name);
        if (ddlOption.isAddDropClause()) {
            ddlStr.append("/* DROP ViEW " + dataParamInfo.getObjectName() + "; */").append(BlankConstants.NEW_LINE_TWO);
        }
        ParamMap source = sqlSesseion.selectOne("viewScript", dataParamInfo);
        ddlStr.append(source.getString("Create View"));
        ddlInfo.setCreateScript(VarsqlFormatterUtil.ddlFormat(VarsqlFormatterUtil.addLastSemicolon(ddlStr, ddlOption), dbType));
        reval.add(ddlInfo);
    }
    return reval;
}
Also used : ParamMap(com.vartech.common.app.beans.ParamMap) SqlSession(org.apache.ibatis.session.SqlSession) ArrayList(java.util.ArrayList) DDLInfo(com.varsql.core.db.valueobject.ddl.DDLInfo)

Aggregations

DDLInfo (com.varsql.core.db.valueobject.ddl.DDLInfo)62 ArrayList (java.util.ArrayList)61 SqlSession (org.apache.ibatis.session.SqlSession)60 ParamMap (com.vartech.common.app.beans.ParamMap)32 Map (java.util.Map)29 HashMap (java.util.HashMap)18 List (java.util.List)15 DataTypeImpl (com.varsql.core.db.meta.datatype.DataTypeImpl)4 DataTypeInfo (com.varsql.core.db.valueobject.DataTypeInfo)4 ProgressInfo (com.varsql.core.common.beans.ProgressInfo)1 VarsqlFileType (com.varsql.core.common.code.VarsqlFileType)1 BlankConstants (com.varsql.core.common.constants.BlankConstants)1 VarsqlConstants (com.varsql.core.common.constants.VarsqlConstants)1 SecurityUtil (com.varsql.core.common.util.SecurityUtil)1 SQLWriter (com.varsql.core.data.writer.SQLWriter)1 DBType (com.varsql.core.db.DBType)1 MetaControlBean (com.varsql.core.db.MetaControlBean)1 MetaControlFactory (com.varsql.core.db.MetaControlFactory)1 VarsqlReportConfig (com.varsql.core.db.report.VarsqlReportConfig)1 ObjectType (com.varsql.core.db.servicemenu.ObjectType)1