Search in sources :

Example 1 with SqlFileEntity

use of com.varsql.web.model.entity.sql.SqlFileEntity in project varsql by varsqlinfo.

the class SQLFileServiceImpl method saveAllSql.

/**
 * @Method Name  : saveAllQuery
 * @Method 설명 : sql 파일 모두저장.
 * @작성자   : ytkim
 * @작성일   : 2018. 11. 26.
 * @변경이력  :
 * @param sqlParamInfo
 * @return
 */
@Transactional(value = ResourceConfigConstants.APP_TRANSMANAGER, rollbackFor = Throwable.class)
public ResponseResult saveAllSql(SqlFileRequestDTO sqlParamInfo) {
    Map<String, Object> customParam = (Map<String, Object>) sqlParamInfo.getCustom();
    String sqlIdStr = String.valueOf(customParam.get("sqlIdArr"));
    String[] sqlIdArr = sqlIdStr.split(";");
    SqlFileEntity sfe;
    List<SqlFileEntity> sqlFileInfos = new ArrayList<>();
    for (int i = 0; i < sqlIdArr.length; i++) {
        String sqlId = sqlIdArr[i];
        sfe = sqlFileEntityRepository.findOne(SqlFileSpec.detailSqlFile(sqlParamInfo.getVconnid(), sqlId)).orElse(null);
        if (sfe == null)
            continue;
        sfe.setSqlId(sqlId);
        sfe.setSqlParam(String.valueOf(customParam.get(sqlId + "_param")));
        sfe.setSqlCont(String.valueOf(customParam.get(sqlId)));
        sfe.setEditorCursor(String.valueOf(customParam.get(sqlId + "_cursor")));
        sqlFileInfos.add(sfe);
    }
    sqlFileEntityRepository.saveAll(sqlFileInfos);
    return VarsqlUtils.getResponseResultItemOne(1);
}
Also used : SqlFileEntity(com.varsql.web.model.entity.sql.SqlFileEntity) ArrayList(java.util.ArrayList) Map(java.util.Map) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with SqlFileEntity

use of com.varsql.web.model.entity.sql.SqlFileEntity in project varsql by varsqlinfo.

the class SQLFileServiceImpl method saveSql.

/**
 * 쿼리 저장.
 * @param sqlFileRequestDTO
 */
@Transactional(value = ResourceConfigConstants.APP_TRANSMANAGER, rollbackFor = Throwable.class)
public ResponseResult saveSql(SqlFileRequestDTO sqlFileRequestDTO) {
    ResponseResult result = new ResponseResult();
    String mode = String.valueOf(sqlFileRequestDTO.getCustom().get("mode"));
    SqlFileEntity sqlFileInfo = sqlFileRequestDTO.toEntity();
    if ("newfile".equals(mode)) {
        sqlFileTabEntityRepository.updateSqlFileTabDisable(sqlFileRequestDTO.getVconnid(), sqlFileRequestDTO.getViewid(), sqlFileRequestDTO.getSqlId());
        sqlFileInfo = sqlFileEntityRepository.save(sqlFileInfo);
    } else if ("moveTab".equals(mode)) {
        SqlFileTabEntity moveFileTabInfo = sqlFileTabEntityRepository.findByVconnidAndViewidAndSqlId(sqlFileRequestDTO.getVconnid(), sqlFileRequestDTO.getViewid(), sqlFileRequestDTO.getSqlId());
        // 이동전 앞에 sqlid 파일 업데이트.
        sqlFileTabEntityRepository.updatePrevIdByPrevId(sqlFileRequestDTO.getVconnid(), sqlFileRequestDTO.getViewid(), sqlFileRequestDTO.getSqlId(), moveFileTabInfo.getPrevSqlId());
        if (StringUtils.isBlank(sqlFileRequestDTO.getPrevSqlId())) {
            sqlFileTabEntityRepository.updatePrevIdBySqlId(sqlFileRequestDTO.getVconnid(), sqlFileRequestDTO.getViewid(), sqlFileRequestDTO.getFirstSqlId(), sqlFileRequestDTO.getSqlId());
        } else {
            // 이동 할 위치 이전  sqlid 업데이트
            sqlFileTabEntityRepository.updatePrevIdByPrevId(sqlFileRequestDTO.getVconnid(), sqlFileRequestDTO.getViewid(), sqlFileRequestDTO.getPrevSqlId(), sqlFileRequestDTO.getSqlId());
        }
        moveFileTabInfo.setViewYn(true);
        moveFileTabInfo.setPrevSqlId(sqlFileRequestDTO.getPrevSqlId());
        sqlFileTabEntityRepository.save(moveFileTabInfo);
    } else {
        if ("addTab".equals(mode)) {
            sqlFileTabEntityRepository.updateSqlFileTabDisable(sqlFileRequestDTO.getVconnid(), sqlFileRequestDTO.getViewid(), sqlFileRequestDTO.getSqlId());
            SqlFileTabEntity sqlFileTabEntity = SqlFileTabEntity.builder().vconnid(sqlFileRequestDTO.getVconnid()).viewid(sqlFileRequestDTO.getViewid()).sqlId(sqlFileRequestDTO.getSqlId()).prevSqlId(sqlFileRequestDTO.getPrevSqlId()).viewYn(true).build();
            sqlFileTabEntity = sqlFileTabEntityRepository.save(sqlFileTabEntity);
        } else if (mode.startsWith("delTab")) {
            deleteSqlFileTabInfo(sqlFileRequestDTO, mode);
        } else if ("viewTab".equals(mode)) {
            sqlFileTabEntityRepository.updateSqlFileTabDisable(sqlFileRequestDTO.getVconnid(), sqlFileRequestDTO.getViewid(), sqlFileRequestDTO.getSqlId());
            sqlFileTabEntityRepository.updateSqlFileTabEnable(sqlFileRequestDTO.getVconnid(), sqlFileRequestDTO.getViewid(), sqlFileRequestDTO.getSqlId());
        } else {
            sqlFileInfo = sqlFileEntityRepository.findOne(SqlFileSpec.detailSqlFile(sqlFileRequestDTO.getVconnid(), sqlFileRequestDTO.getSqlId())).orElse(null);
            if (sqlFileInfo != null) {
                if (sqlFileRequestDTO.getSqlCont() != null)
                    sqlFileInfo.setSqlCont(sqlFileRequestDTO.getSqlCont());
                if (sqlFileRequestDTO.getSqlParam() != null)
                    sqlFileInfo.setSqlParam(sqlFileRequestDTO.getSqlParam());
                if (sqlFileRequestDTO.getSqlTitle() != null)
                    sqlFileInfo.setSqlTitle(sqlFileRequestDTO.getSqlTitle());
                if (sqlFileRequestDTO.getEditorCursor() != null)
                    sqlFileInfo.setEditorCursor(sqlFileRequestDTO.getEditorCursor());
                sqlFileInfo = sqlFileEntityRepository.save(sqlFileInfo);
            }
            if ("query_del".equals(mode)) {
                deleteSqlFileTabInfo(sqlFileRequestDTO);
            }
        }
    }
    if (sqlFileInfo != null)
        sqlFileRequestDTO.setSqlId(sqlFileInfo.getSqlId());
    result.setItemOne(sqlFileRequestDTO);
    return result;
}
Also used : SqlFileEntity(com.varsql.web.model.entity.sql.SqlFileEntity) ResponseResult(com.vartech.common.app.beans.ResponseResult) SqlFileTabEntity(com.varsql.web.model.entity.sql.SqlFileTabEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with SqlFileEntity

use of com.varsql.web.model.entity.sql.SqlFileEntity in project varsql by varsqlinfo.

the class UserPreferencesSqlFileServiceImpl method sqlFileList.

/**
 * @Method Name  : sqlFileList
 * @Method 설명 :sql file list
 * @작성자   : ytkim
 * @작성일   : 2019. 10. 31.
 * @변경이력  :
 * @param searchParameter
 * @return
 */
public ResponseResult sqlFileList(String vconnid, SearchParameter searchParameter) {
    Page<SqlFileEntity> result = null;
    if (vconnid != null && !"".equals(vconnid) && !"ALL".equals(vconnid)) {
        result = sqlFileEntityRepository.findAll(SqlFileSpec.findVconnSqlFileNameOrCont(vconnid, searchParameter.getKeyword()), VarsqlUtils.convertSearchInfoToPage(searchParameter));
    } else {
        result = sqlFileEntityRepository.findAll(SqlFileSpec.findSqlFileNameOrCont(searchParameter.getKeyword()), VarsqlUtils.convertSearchInfoToPage(searchParameter));
    }
    return VarsqlUtils.getResponseResult(result.getContent().stream().map(item -> {
        SqlFileResponseDTO resultItem = SqlFileMapper.INSTANCE.toDto(item);
        resultItem.setVname(item.getConnInfo().getVname());
        return resultItem;
    }).collect(Collectors.toList()), result.getTotalElements(), searchParameter);
}
Also used : SqlFileEntity(com.varsql.web.model.entity.sql.SqlFileEntity) SqlFileResponseDTO(com.varsql.web.dto.sql.SqlFileResponseDTO)

Aggregations

SqlFileEntity (com.varsql.web.model.entity.sql.SqlFileEntity)3 Transactional (org.springframework.transaction.annotation.Transactional)2 SqlFileResponseDTO (com.varsql.web.dto.sql.SqlFileResponseDTO)1 SqlFileTabEntity (com.varsql.web.model.entity.sql.SqlFileTabEntity)1 ResponseResult (com.vartech.common.app.beans.ResponseResult)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1