Search in sources :

Example 6 with MetaControlBean

use of com.varsql.core.db.MetaControlBean in project varsql by varsqlinfo.

the class ExportServiceImpl method selectExportDbObjectInfo.

/**
 * @Method Name  : selectExportDbObjectInfo
 * @Method 설명 : db object info
 * @작성자   : ytkim
 * @작성일   : 2018. 8. 29.
 * @변경이력  :
 * @param preferencesInfo
 * @param mode
 * @param model
 * @return
 * @throws Exception
 */
public ResponseResult selectExportDbObjectInfo(DatabaseParamInfo databaseParam) throws Exception {
    MetaControlBean dbMetaEnum = MetaControlFactory.getDbInstanceFactory(databaseParam.getDbType());
    Map customParam = databaseParam.getCustom();
    String ddlObjInfo = String.valueOf(customParam.get("ddlObjInfo"));
    String[] objArr = ddlObjInfo.split(",");
    ResponseResult result = new ResponseResult();
    for (int i = 0; i < objArr.length; i++) {
        String mode = objArr[i];
        result.addCustoms(mode, dbMetaEnum.getDBObjectList(ObjectType.getDBObjectType(mode).getObjectTypeId(), databaseParam));
    }
    return result;
}
Also used : ResponseResult(com.vartech.common.app.beans.ResponseResult) MetaControlBean(com.varsql.core.db.MetaControlBean) ModelMap(org.springframework.ui.ModelMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 7 with MetaControlBean

use of com.varsql.core.db.MetaControlBean 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 8 with MetaControlBean

use of com.varsql.core.db.MetaControlBean in project varsql by varsqlinfo.

the class ExportServiceImpl method selectExportConfigInfo.

/**
 * @Method Name  : selectConfigInfo
 * @Method 설명 : table export Info
 * @작성자   : ytkim
 * @작성일   : 2017. 11. 22.
 * @변경이력  :
 * @param preferencesInfo
 * @param model
 * @throws Exception
 */
public void selectExportConfigInfo(PreferencesRequestDTO preferencesInfo, ModelMap model) throws Exception {
    MetaControlBean dbMetaEnum = MetaControlFactory.getDbInstanceFactory(preferencesInfo.getDbType());
    model.addAttribute("userSettingInfo", preferencesServiceImpl.selectPreferencesInfo(preferencesInfo, true));
    model.addAttribute("columnInfo", Arrays.stream(VarsqlReportConfig.TABLE_COLUMN.values()).map(EnumMapperValue::new).collect(Collectors.toList()));
    if (SecurityUtil.isSchemaView(preferencesInfo)) {
        model.addAttribute("schemaList", dbMetaEnum.getSchemas(preferencesInfo));
    } else {
        model.addAttribute("schemaInfo", "");
    }
}
Also used : EnumMapperValue(com.vartech.common.app.beans.EnumMapperValue) MetaControlBean(com.varsql.core.db.MetaControlBean)

Example 9 with MetaControlBean

use of com.varsql.core.db.MetaControlBean in project varsql by varsqlinfo.

the class DbDiffServiceImpl method objectTypeList.

/**
 * @Method Name  : objectTypeList
 * @Method 설명 : db object type list (table , view 등등)
 * @작성자   : ytkim
 * @작성일   : 2019. 1. 2.
 * @변경이력  :
 * @param vconnid
 * @return
 * @throws SQLException
 */
public ResponseResult objectTypeList(String vconnid) throws SQLException {
    ResponseResult resultObject = new ResponseResult();
    DBConnectionEntity vtConnRVO = dbConnectionEntityRepository.findByVconnid(vconnid);
    if (vtConnRVO == null) {
        resultObject.setResultCode(RequestResultCode.ERROR);
        resultObject.setItemList(null);
    } else {
        MetaControlBean dbMetaEnum = MetaControlFactory.getDbInstanceFactory(vtConnRVO.getDbTypeDriverProvider().getDbType());
        resultObject.setItemList(dbMetaEnum.getServiceMenu());
        resultObject.addCustoms("schemaInfo", dbMetaEnum.getSchemas(getDatabaseParamInfo(vtConnRVO)));
    }
    return resultObject;
}
Also used : ResponseResult(com.vartech.common.app.beans.ResponseResult) DBConnectionEntity(com.varsql.web.model.entity.db.DBConnectionEntity) MetaControlBean(com.varsql.core.db.MetaControlBean)

Example 10 with MetaControlBean

use of com.varsql.core.db.MetaControlBean in project varsql by varsqlinfo.

the class DatabaseServiceImpl method dbInfo.

/**
 * @Method Name  : dbInfo
 * @Method 설명 : db 정보
 * @작성자   : ytkim
 * @작성일   : 2018. 10. 8.
 * @변경이력  :
 * @param databaseParamInfo
 * @return
 */
public ResponseResult dbInfo(DatabaseParamInfo databaseParamInfo) {
    MetaControlBean dbMetaEnum = MetaControlFactory.getDbInstanceFactory(databaseParamInfo.getDbType());
    ResponseResult result = new ResponseResult();
    try {
        result.setItemList(dbMetaEnum.getDBInfo(databaseParamInfo));
    } catch (Exception e) {
        logger.error("createDDL : ", e);
    }
    return result;
}
Also used : ResponseResult(com.vartech.common.app.beans.ResponseResult) MetaControlBean(com.varsql.core.db.MetaControlBean) SQLException(java.sql.SQLException) DBMetadataException(com.varsql.core.exception.DBMetadataException)

Aggregations

MetaControlBean (com.varsql.core.db.MetaControlBean)12 ResponseResult (com.vartech.common.app.beans.ResponseResult)10 DBMetadataException (com.varsql.core.exception.DBMetadataException)4 SQLException (java.sql.SQLException)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 DatabaseInfo (com.varsql.core.db.valueobject.DatabaseInfo)2 DatabaseParamInfo (com.varsql.core.db.valueobject.DatabaseParamInfo)2 DDLCreateOption (com.varsql.core.db.valueobject.ddl.DDLCreateOption)2 DBConnectionEntity (com.varsql.web.model.entity.db.DBConnectionEntity)2 EnumMapperValue (com.vartech.common.app.beans.EnumMapperValue)2 ModelMap (org.springframework.ui.ModelMap)2 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 MetaControlFactory (com.varsql.core.db.MetaControlFactory)1