Search in sources :

Example 1 with DDLInfo

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

the class ExportServiceImpl method ddlExport.

/**
 * @Method Name  : tableDDLExport
 * @Method 설명 : 테이블 ddl 내보내기
 * @작성자   : ytkim
 * @작성일   : 2017. 8. 24.
 * @변경이력  :
 * @param preferencesInfo
 * @param req
 * @param res
 * @throws Exception
 */
public void ddlExport(PreferencesRequestDTO preferencesInfo, HttpServletRequest req, HttpServletResponse res) throws Exception {
    String jsonString = preferencesInfo.getPrefVal();
    logger.debug("ddlExport PreferencesInfo :{}", VartechUtils.reflectionToString(preferencesInfo));
    logger.debug("settingInfo :{}", jsonString);
    DataCommonVO settingInfo = VartechUtils.jsonStringToObject(jsonString, DataCommonVO.class);
    Map<String, List<Map>> exportInfo = (Map<String, List<Map>>) settingInfo.get("exportInfo");
    Iterator<String> iter = exportInfo.keySet().iterator();
    MetaControlBean dbMetaEnum = MetaControlFactory.getDbInstanceFactory(preferencesInfo.getDbType());
    StringBuilder allDDLScript = new StringBuilder();
    DDLCreateOption ddlOption = new DDLCreateOption();
    while (iter.hasNext()) {
        String objectName = iter.next();
        allDDLScript.append("--------- " + objectName + " start----------").append(BlankConstants.NEW_LINE_TWO);
        List<Map> objList = exportInfo.get(objectName);
        String[] objNmArr = Arrays.stream(objList.toArray(new HashMap[objList.size()])).map(tmp -> tmp.get("name")).toArray(String[]::new);
        preferencesInfo.setObjectType(ObjectType.getDBObjectType(objectName).name());
        List<DDLInfo> ddlList = dbMetaEnum.getDDLScript(ObjectType.getDBObjectType(objectName).getObjectTypeId(), preferencesInfo, ddlOption, objNmArr);
        for (DDLInfo ddlInfo : ddlList) {
            allDDLScript.append(ddlInfo.getCreateScript()).append(BlankConstants.NEW_LINE_TWO);
        }
        allDDLScript.append(BlankConstants.NEW_LINE).append("--------- // " + objectName + " end----------").append(BlankConstants.NEW_LINE_THREE);
    }
    String exportFileName = settingInfo.getString("exportName", "export-ddl");
    exportFileName += exportFileName.endsWith(".sql") ? "" : ".sql";
    VarsqlUtils.setResponseDownAttr(res, req, exportFileName);
    VarsqlUtils.textDownload(res.getOutputStream(), allDDLScript.toString());
}
Also used : ExportColumnInfo(com.varsql.core.sql.beans.ExportColumnInfo) Arrays(java.util.Arrays) MetaControlBean(com.varsql.core.db.MetaControlBean) DatabaseParamInfo(com.varsql.core.db.valueobject.DatabaseParamInfo) BufferedInputStream(java.io.BufferedInputStream) WriteMetadataInfo(com.vartech.common.io.writer.WriteMetadataInfo) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) VarsqlUtils(com.varsql.web.util.VarsqlUtils) ModelMap(org.springframework.ui.ModelMap) DatabaseInfo(com.varsql.core.db.valueobject.DatabaseInfo) ObjectType(com.varsql.core.db.servicemenu.ObjectType) DataCommonVO(com.varsql.web.common.beans.DataCommonVO) DownloadItemInfo(com.varsql.web.dto.DownloadItemInfo) Map(java.util.Map) SQLUtils(com.varsql.core.sql.util.SQLUtils) VarsqlReportConfig(com.varsql.core.db.report.VarsqlReportConfig) JSONWriter(com.vartech.common.io.writer.JSONWriter) XMLWriter(com.vartech.common.io.writer.XMLWriter) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) HttpSession(javax.servlet.http.HttpSession) DataDownloadInfo(com.varsql.web.dto.DataDownloadInfo) PreferencesConstants(com.varsql.web.constants.PreferencesConstants) ProgressInfo(com.varsql.core.common.beans.ProgressInfo) VarsqlFileType(com.varsql.core.common.code.VarsqlFileType) Collectors(java.util.stream.Collectors) CSVWriter(com.vartech.common.io.writer.CSVWriter) DDLCreateOption(com.varsql.core.db.valueobject.ddl.DDLCreateOption) List(java.util.List) ZipOutputStream(java.util.zip.ZipOutputStream) DDLInfo(com.varsql.core.db.valueobject.ddl.DDLInfo) FileInfoEntity(com.varsql.web.model.entity.app.FileInfoEntity) ExcelWriter(com.vartech.common.io.writer.ExcelWriter) IOUtils(com.vartech.common.utils.IOUtils) SQLWriter(com.varsql.core.data.writer.SQLWriter) ValidateUtils(com.varsql.web.util.ValidateUtils) HashMap(java.util.HashMap) ResponseResult(com.vartech.common.app.beans.ResponseResult) SQLExecuteResult(com.varsql.core.sql.executor.SQLExecuteResult) FileUtils(com.vartech.common.utils.FileUtils) BufferedOutputStream(java.io.BufferedOutputStream) SecurityUtil(com.varsql.core.common.util.SecurityUtil) VartechUtils(com.vartech.common.utils.VartechUtils) HttpServletRequest(javax.servlet.http.HttpServletRequest) UploadFileType(com.varsql.web.constants.UploadFileType) Charset(java.nio.charset.Charset) BlankConstants(com.varsql.core.common.constants.BlankConstants) AbstractWriter(com.vartech.common.io.writer.AbstractWriter) Service(org.springframework.stereotype.Service) LinkedList(java.util.LinkedList) HttpSessionConstants(com.varsql.web.constants.HttpSessionConstants) EnumMapperValue(com.vartech.common.app.beans.EnumMapperValue) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) FileServiceUtils(com.varsql.web.util.FileServiceUtils) StringUtils(com.vartech.common.utils.StringUtils) HttpServletResponse(javax.servlet.http.HttpServletResponse) VarsqlConstants(com.varsql.core.common.constants.VarsqlConstants) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) File(java.io.File) PreferencesRequestDTO(com.varsql.web.dto.user.PreferencesRequestDTO) SQLHandlerParameter(com.varsql.core.sql.executor.handler.SQLHandlerParameter) DBType(com.varsql.core.db.DBType) MetaControlFactory(com.varsql.core.db.MetaControlFactory) FileInfoEntityRepository(com.varsql.web.repository.user.FileInfoEntityRepository) SqlExecuteDTO(com.varsql.web.dto.sql.SqlExecuteDTO) SelectExecutor(com.varsql.core.sql.executor.SelectExecutor) AbstractSQLExecutorHandler(com.varsql.core.sql.executor.handler.AbstractSQLExecutorHandler) ExcelReport(com.vartech.common.excel.ExcelReport) HashMap(java.util.HashMap) DataCommonVO(com.varsql.web.common.beans.DataCommonVO) DDLInfo(com.varsql.core.db.valueobject.ddl.DDLInfo) List(java.util.List) LinkedList(java.util.LinkedList) MetaControlBean(com.varsql.core.db.MetaControlBean) ModelMap(org.springframework.ui.ModelMap) Map(java.util.Map) HashMap(java.util.HashMap) DDLCreateOption(com.varsql.core.db.valueobject.ddl.DDLCreateOption)

Example 2 with DDLInfo

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

the class DDLScriptImpl method getIndexs.

/**
 * @Method Name  : getIndex
 * @Method 설명 : index ddl
 * @Method override : @see com.varsql.core.db.ddl.script.DDLScript#getIndex(com.varsql.core.db.valueobject.DatabaseParamInfo, java.lang.String[])
 * @작성자   : ytkim
 * @작성일   : 2015. 6. 18.
 * @변경이력  :
 * @param dataParamInfo
 * @param objNm
 * @return
 * @throws Exception
 */
@Override
public List<DDLInfo> getIndexs(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    StringBuilder ddlStrBuf;
    List<DDLInfo> reval = new ArrayList<DDLInfo>();
    DDLInfo ddlInfo;
    SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
    for (String viewNm : objNmArr) {
        ddlInfo = new DDLInfo();
        ddlInfo.setName(viewNm);
        ddlStrBuf = new StringBuilder();
        dataParamInfo.setObjectName(viewNm);
        if (ddlOption.isAddDropClause()) {
            ddlStrBuf.append("/* DROP INDEX " + dataParamInfo.getObjectName() + "; */").append(BlankConstants.NEW_LINE_TWO);
        }
        List<String> srcProcList = sqlSesseion.selectList("indexScript", dataParamInfo);
        for (int j = 0; j < srcProcList.size(); j++) {
            ddlStrBuf.append(srcProcList.get(j));
        }
        ddlStrBuf.append(ddlOption.isAddLastSemicolon() ? ";" : "").append(BlankConstants.NEW_LINE_TWO);
        ddlInfo.setCreateScript(ddlStrBuf.toString());
        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 3 with DDLInfo

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

the class DDLScriptImpl method getFunctions.

/**
 * @Method Name  : getFunction
 * @Method 설명 : function ddl
 * @Method override : @see com.varsql.core.db.ddl.script.DDLScript#getFunction(com.varsql.core.db.valueobject.DatabaseParamInfo, java.lang.String[])
 * @작성자   : ytkim
 * @작성일   : 2015. 6. 18.
 * @변경이력  :
 * @param dataParamInfo
 * @param objNm
 * @return
 * @throws Exception
 */
@Override
public List<DDLInfo> getFunctions(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    StringBuilder ddlStrBuf;
    List<DDLInfo> reval = new ArrayList<DDLInfo>();
    DDLInfo ddlInfo;
    SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
    for (String objNm : objNmArr) {
        ddlInfo = new DDLInfo();
        ddlInfo.setName(objNm);
        ddlStrBuf = new StringBuilder();
        dataParamInfo.setObjectName(objNm);
        if (ddlOption.isAddDropClause()) {
            ddlStrBuf.append("/* DROP FUNCTION " + objNm + "; */").append(BlankConstants.NEW_LINE_TWO);
        }
        List<String> srcProcList = sqlSesseion.selectList("functionScript", dataParamInfo);
        for (int j = 0; j < srcProcList.size(); j++) {
            ddlStrBuf.append(srcProcList.get(j));
        }
        ddlStrBuf.append(ddlOption.isAddLastSemicolon() ? ";" : "").append(BlankConstants.NEW_LINE_TWO);
        ddlInfo.setCreateScript(ddlStrBuf.toString());
        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 4 with DDLInfo

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

the class DDLScriptImpl method getSequences.

/**
 * @Method Name  : getSequence
 * @Method 설명 : sequence ddl
 * @Method override : @see com.varsql.core.db.ddl.script.DDLScript#getSequence(com.varsql.core.db.valueobject.DatabaseParamInfo, java.lang.String[])
 * @작성자   : ytkim
 * @작성일   : 2015. 6. 18.
 * @변경이력  :
 * @param dataParamInfo
 * @param objNm
 * @return
 * @throws Exception
 */
@Override
public List<DDLInfo> getSequences(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    StringBuilder ddlStrBuf;
    List<DDLInfo> reval = new ArrayList<DDLInfo>();
    DDLInfo ddlInfo;
    SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
    for (String objNm : objNmArr) {
        ddlInfo = new DDLInfo();
        ddlInfo.setName(objNm);
        ddlStrBuf = new StringBuilder();
        dataParamInfo.setObjectName(objNm);
        if (ddlOption.isAddDropClause()) {
            ddlStrBuf.append("/* DROP SEQUENCE " + objNm + "; */").append(BlankConstants.NEW_LINE_TWO);
        }
        Map param = sqlSesseion.selectOne("sequenceScript", dataParamInfo);
        param.put("schema", dataParamInfo.getSchema());
        param.put("ddlOption", ddlOption);
        ddlStrBuf.append(SQLTemplateFactory.getInstance().sqlRender(DBType.OTHER, SQLTemplateCode.SEQUENCE.create, param));
        ddlStrBuf.append(ddlOption.isAddLastSemicolon() ? ";" : "").append(BlankConstants.NEW_LINE_TWO);
        ddlInfo.setCreateScript(ddlStrBuf.toString());
        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) Map(java.util.Map)

Example 5 with DDLInfo

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

the class DDLScriptImpl method getTriggers.

/**
 * @Method Name  : getTrigger
 * @Method 설명 : trigger ddl
 * @Method override : @see com.varsql.core.db.ddl.script.DDLScript#getTrigger(com.varsql.core.db.valueobject.DatabaseParamInfo, java.lang.String[])
 * @작성자   : ytkim
 * @작성일   : 2015. 6. 18.
 * @변경이력  :
 * @param dataParamInfo
 * @param objNm
 * @return
 * @throws Exception
 */
@Override
public List<DDLInfo> getTriggers(DatabaseParamInfo dataParamInfo, DDLCreateOption ddlOption, String... objNmArr) throws Exception {
    StringBuilder ddlStrBuf;
    List<DDLInfo> reval = new ArrayList<DDLInfo>();
    DDLInfo ddlInfo;
    SqlSession sqlSesseion = SQLManager.getInstance().sqlSessionTemplate(dataParamInfo.getVconnid());
    for (String objNm : objNmArr) {
        ddlInfo = new DDLInfo();
        ddlInfo.setName(objNm);
        ddlStrBuf = new StringBuilder();
        dataParamInfo.setObjectName(objNm);
        if (ddlOption.isAddDropClause()) {
            ddlStrBuf.append("/* DROP TRIGGER " + objNm + "; */").append(BlankConstants.NEW_LINE_TWO);
        }
        List<String> srcProcList = sqlSesseion.selectList("triggerScript", dataParamInfo);
        for (int j = 0; j < srcProcList.size(); j++) {
            ddlStrBuf.append(srcProcList.get(j));
        }
        ddlStrBuf.append(ddlOption.isAddLastSemicolon() ? ";" : "").append(BlankConstants.NEW_LINE_TWO);
        ddlInfo.setCreateScript(ddlStrBuf.toString());
        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)

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