use of com.varsql.web.model.entity.sql.SqlFileTabEntity 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;
}
Aggregations