Search in sources :

Example 41 with DDLInfo

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

the class OracleDDLScript method getProcedures.

@Override
public List<DDLInfo> getProcedures(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    logger.debug(" Procedure DDL Generation...");
    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);
        ddlStr = new StringBuilder();
        dataParamInfo.setObjectName(name);
        String objType = sqlSesseion.selectOne("sourceObjectType", dataParamInfo);
        List srcScriptList = null;
        if (StringUtils.contains(objType, "PROCEDURE")) {
            if (ddlOption.isAddDropClause()) {
                ddlStr.append("/* DROP PROCEDURE " + dataParamInfo.getObjectName() + "; */").append(BlankConstants.NEW_LINE_TWO);
            }
            ddlStr.append("CREATE OR REPLACE ");
            srcScriptList = sqlSesseion.selectList("objectScriptSource", dataParamInfo);
            for (int i = 0; i < srcScriptList.size(); i++) {
                ddlStr.append(srcScriptList.get(i));
            }
        } else if (StringUtils.contains(objType, "PACKAGE")) {
            if (ddlOption.isAddDropClause()) {
                ddlStr.append(BlankConstants.NEW_LINE).append("/* DROP PACKAGE BODY " + name + "; */").append(BlankConstants.NEW_LINE_TWO);
                ;
                ddlStr.append("/* DROP PACKAGE " + name + "; */").append(BlankConstants.NEW_LINE_TWO);
            }
            dataParamInfo.setObjectType("PACKAGE");
            ddlStr.append("CREATE OR REPLACE ");
            srcScriptList = sqlSesseion.selectList("objectScriptSource", dataParamInfo);
            for (int i = 0; i < srcScriptList.size(); i++) {
                ddlStr.append(srcScriptList.get(i));
            }
            dataParamInfo.setObjectType("PACKAGE BODY");
            ddlStr.append("/ \n\n ");
            ddlStr.append("CREATE OR REPLACE ");
            srcScriptList = sqlSesseion.selectList("objectScriptSource", dataParamInfo);
            for (int i = 0; i < srcScriptList.size(); i++) {
                ddlStr.append(srcScriptList.get(i));
            }
        }
        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)

Example 42 with DDLInfo

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

the class OracleDDLScript method getTriggers.

/**
 * @Method Name  : getTrigger
 * @Method 설명 : trigger ddl
 * @Method override : @see com.varsql.core.db.ddl.script.DDLScriptImpl#getTrigger(com.varsql.core.db.valueobject.DatabaseParamInfo, java.lang.String[])
 * @작성자   : ytkim
 * @작성일   : 2018. 9. 19.
 * @변경이력  :
 * @param dataParamInfo
 * @param objNmArr
 * @return
 * @throws Exception
 */
@Override
public List<DDLInfo> getTriggers(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    logger.debug("Trigger DDL Generation...");
    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);
        ddlStr = new StringBuilder();
        dataParamInfo.setObjectName(name);
        if (ddlOption.isAddDropClause()) {
            ddlStr.append("/* DROP TRIGGER " + dataParamInfo.getObjectName() + "; */").append(BlankConstants.NEW_LINE_TWO);
        }
        ddlStr.append("CREATE OR REPLACE ");
        List scrList = sqlSesseion.selectList("objectScriptSource", dataParamInfo);
        for (int i = 0; i < scrList.size(); i++) {
            ddlStr.append(scrList.get(i));
        }
        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)

Example 43 with DDLInfo

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

the class CubridDDLScript 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("CREATE OR REPLACE VIEW ").append(name).append(" AS ").append(BlankConstants.NEW_LINE_TWO);
        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)

Example 44 with DDLInfo

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

the class CubridDDLScript 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("indexScript", dataParamInfo);
        Map indexMap;
        if (ddlOption.isAddDropClause()) {
            if (srcScriptList.size() > 0) {
                indexMap = (Map) srcScriptList.get(0);
                ddlStr.append("/* DROP INDEX " + dataParamInfo.getObjectName() + " ON ").append(indexMap.get("TABLE_NAME")).append("; */").append(BlankConstants.NEW_LINE_TWO);
            }
        }
        ddlStr.append("CREATE ");
        if (srcScriptList.size() > 0) {
            indexMap = (Map) srcScriptList.get(0);
            if ("UQ".equals(indexMap.get("INDEX_TYPE")))
                ddlStr.append(" UNIQUE INDEX ");
            else {
                ddlStr.append(" INDEX ");
            }
            ddlStr.append(indexMap.get("INDEX_NAME") + " ON ");
            ddlStr.append(indexMap.get("TABLE_NAME") + "\n ( ");
            for (int i = 0; i < srcScriptList.size(); i++) {
                indexMap = (Map) srcScriptList.get(i);
                ddlStr.append(i > 0 ? ", " : "");
                ddlStr.append(indexMap.get("COLUMN_NAME"));
                ddlStr.append(" ").append(indexMap.get("ASC_OR_DESC"));
            }
            ddlStr.append(")").append(BlankConstants.NEW_LINE);
        }
        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) ParamMap(com.vartech.common.app.beans.ParamMap) Map(java.util.Map)

Example 45 with DDLInfo

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

the class PostgresqlDDLScript method getProcedures.

@Override
public List<DDLInfo> getProcedures(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    logger.debug(" Procedure DDL Generation... ");
    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);
        ddlStr = new StringBuilder();
        dataParamInfo.setObjectName(name);
        if (ddlOption.isAddDropClause()) {
            ddlStr.append("/* DROP PROCEDURE " + dataParamInfo.getObjectName() + "; */").append(BlankConstants.NEW_LINE_TWO);
        }
        Map scriptInfo = sqlSesseion.selectOne("procedureScript", dataParamInfo);
        ddlStr.append(scriptInfo.get(MetaColumnConstants.CREATE_SOURCE));
        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) HashMap(java.util.HashMap) ParamMap(com.vartech.common.app.beans.ParamMap) Map(java.util.Map)

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