Search in sources :

Example 1 with VarsqlRuntimeException

use of com.varsql.core.exception.VarsqlRuntimeException in project varsql by varsqlinfo.

the class SQLManager method setSQLMapper.

public void setSQLMapper(ConnectionInfo connInfo, Object obj) {
    try {
        if (!(obj instanceof ConnectionFactory || obj instanceof SQLManager)) {
            logger.error("SQLManager setSQLMapper access denied object {}", obj);
            throw new VarsqlRuntimeException(VarsqlAppCode.EC_DB_POOL, "SQLManager setSQLMapper access denied object " + obj);
        }
        SqlSessionFactory sqlSessionFactory = sqlSessionFactory(connInfo).getObject();
        try (Connection connChk = sqlSessionFactory.openSession().getConnection()) {
            JdbcUtils.close(connChk);
        }
        sqlSessionFactoryMap.put(connInfo.getConnid(), sqlSessionFactory);
        sqlSessionMap.put(connInfo.getConnid(), new SqlSessionTemplate(sqlSessionFactory));
    } catch (Exception e) {
        logger.error("connection info :  {} ", VartechReflectionUtils.reflectionToString(connInfo));
        logger.error("SQLManager :{} ", e.getMessage(), e);
        throw new ConnectionException("getSqlSession IOException " + e.getMessage(), e);
    }
}
Also used : ConnectionFactory(com.varsql.core.connection.ConnectionFactory) SqlSessionTemplate(org.mybatis.spring.SqlSessionTemplate) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Connection(java.sql.Connection) VarsqlRuntimeException(com.varsql.core.exception.VarsqlRuntimeException) VarsqlRuntimeException(com.varsql.core.exception.VarsqlRuntimeException) SQLException(java.sql.SQLException) IOException(java.io.IOException) ConnectionFactoryException(com.varsql.core.exception.ConnectionFactoryException) ConnectionException(com.varsql.core.exception.ConnectionException) ConnectionException(com.varsql.core.exception.ConnectionException)

Example 2 with VarsqlRuntimeException

use of com.varsql.core.exception.VarsqlRuntimeException in project varsql by varsqlinfo.

the class FileUploadService method uploadFiles.

public List<FileInfoEntity> uploadFiles(UploadFileType fileType, List<MultipartFile> files, String fileContId, String contGroupId, String fieldName, boolean addExtensionSuffix, boolean fileInfoSaveFlag) {
    List<FileInfoEntity> fileInfos = new ArrayList<FileInfoEntity>();
    files.forEach(file -> {
        if (!(file.getSize() <= 0 && "blob".equals(file.getOriginalFilename()))) {
            try {
                FileInfoEntity fileInfo = saveFile(fileType, file, fileContId, addExtensionSuffix);
                fileInfo.setFileContId(fileContId);
                fileInfo.setFileFieldName(fieldName);
                fileInfo.setContGroupId(contGroupId);
                fileInfos.add(fileInfo);
            } catch (IllegalStateException | IOException e) {
                logger.error("file upload exception : {}", e.getMessage(), e);
                throw new VarsqlRuntimeException(VarsqlAppCode.COMM_FILE_UPLOAD_ERROR, "file upload error", e);
            }
        }
    });
    if (fileInfoSaveFlag) {
        fileInfoEntityRepository.saveAll(fileInfos);
    }
    return fileInfos;
}
Also used : ArrayList(java.util.ArrayList) FileInfoEntity(com.varsql.web.model.entity.app.FileInfoEntity) IOException(java.io.IOException) VarsqlRuntimeException(com.varsql.core.exception.VarsqlRuntimeException)

Example 3 with VarsqlRuntimeException

use of com.varsql.core.exception.VarsqlRuntimeException in project varsql by varsqlinfo.

the class SQLTemplateFactory method sqlRender.

/**
 * @Method Name  : sqlRender
 * @Method 설명 : query render
 * @작성일   : 2018. 6. 12.
 * @작성자   : ytkim
 * @변경이력  :
 * @param dbVender
 * @param templateId
 * @param param
 * @return
 */
public String sqlRender(DBType dbType, SQLTemplateEnum code, Map param) {
    String dbVender = dbType.getDbVenderName();
    String templateId = code.getTemplateId();
    Template template = getDDLTemplate(dbVender, templateId);
    if (template == null) {
        throw new VarsqlRuntimeException(VarsqlAppCode.EC_TEMPLATE_CONFIGURATION, new StringBuilder().append("sqlRender template ").append("dbVender : [").append(dbVender).append("] templateId : [").append(templateId).append("] template : [").append(template).append("]").toString());
    }
    try {
        return template.apply(param);
    } catch (IOException e) {
        logger.error("sqlRender IOException : {} ", e.getMessage(), e);
    }
    return "";
}
Also used : IOException(java.io.IOException) VarsqlRuntimeException(com.varsql.core.exception.VarsqlRuntimeException) Template(com.github.jknack.handlebars.Template)

Example 4 with VarsqlRuntimeException

use of com.varsql.core.exception.VarsqlRuntimeException in project varsql by varsqlinfo.

the class DriverProvierMgmtServiceImpl method uploadDriverFiles.

private List<DBTypeDriverFileEntity> uploadDriverFiles(List<MultipartFile> files, String fileContId) {
    final UploadFileType fileType = UploadFileType.JDBC_DIRVER;
    List<DBTypeDriverFileEntity> fileInfos = new ArrayList<DBTypeDriverFileEntity>();
    files.forEach(file -> {
        if (!(file.getSize() <= 0 && "blob".equals(file.getOriginalFilename()))) {
            try {
                String filePath = FileServiceUtils.getSaveRelativePath(fileType, fileContId);
                // 파일 원본명
                String fileName = FileUtils.normalize(file.getOriginalFilename());
                // 파일 확장자 구하기
                String extension = FileUtils.extension(fileName);
                String fileId = VartechUtils.generateUUID();
                if (fileType.isOrginFileName()) {
                    filePath = FileUtils.pathConcat(filePath, fileName);
                } else {
                    filePath = FileUtils.pathConcat(filePath, String.format("%s.%s", fileId, extension));
                }
                Path createFilePath = FileServiceUtils.getPath(filePath);
                file.transferTo(createFilePath);
                fileInfos.add(DBTypeDriverFileEntity.builder().fileDiv(fileType.getDiv()).fileId(fileId).fileName(fileName).fileSize(file.getSize()).fileExt(extension).fileContId(fileContId).filePath(filePath).build());
            } catch (IllegalStateException | IOException e) {
                logger.error("file upload exception : {}", e.getMessage(), e);
                throw new VarsqlRuntimeException(VarsqlAppCode.COMM_FILE_UPLOAD_ERROR, "file upload error", e);
            }
        }
    });
    dbTypeDriverFileEntityRepository.saveAll(fileInfos);
    return fileInfos;
}
Also used : Path(java.nio.file.Path) UploadFileType(com.varsql.web.constants.UploadFileType) DBTypeDriverFileEntity(com.varsql.web.model.entity.db.DBTypeDriverFileEntity) ArrayList(java.util.ArrayList) IOException(java.io.IOException) VarsqlRuntimeException(com.varsql.core.exception.VarsqlRuntimeException)

Aggregations

VarsqlRuntimeException (com.varsql.core.exception.VarsqlRuntimeException)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)2 Template (com.github.jknack.handlebars.Template)1 ConnectionFactory (com.varsql.core.connection.ConnectionFactory)1 ConnectionException (com.varsql.core.exception.ConnectionException)1 ConnectionFactoryException (com.varsql.core.exception.ConnectionFactoryException)1 UploadFileType (com.varsql.web.constants.UploadFileType)1 FileInfoEntity (com.varsql.web.model.entity.app.FileInfoEntity)1 DBTypeDriverFileEntity (com.varsql.web.model.entity.db.DBTypeDriverFileEntity)1 Path (java.nio.file.Path)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)1 SqlSessionTemplate (org.mybatis.spring.SqlSessionTemplate)1