Search in sources :

Example 1 with DBTypeDriverProviderEntity

use of com.varsql.web.model.entity.db.DBTypeDriverProviderEntity in project varsql by varsqlinfo.

the class AdminDbMgmtServiceImpl method connectionCheck.

/**
 * @Method Name  : connectionCheck
 * @Method 설명 : 커넥션 체크.
 * @작성자   : ytkim
 * @작성일   : 2018. 1. 22.
 * @변경이력  :
 * @param vtConnection
 * @return
 * @throws EncryptDecryptException
 */
public ResponseResult connectionCheck(DBConnectionRequestDTO vtConnection) throws EncryptDecryptException {
    ResponseResult resultObject = new ResponseResult();
    this.dbConnectionModelRepository.findByConnInfo(vtConnection.getVconnid());
    logger.debug("connection check object param :  {}", VartechUtils.reflectionToString(vtConnection));
    String username = vtConnection.getVid();
    DBConnectionEntity dbInfo = this.dbConnectionModelRepository.findOne(DBConnectionSpec.detailInfo(vtConnection.getVconnid())).orElseThrow(NullPointerException::new);
    DBTypeDriverProviderEntity driverProviderEntity = dbInfo.getDbTypeDriverProvider();
    String url = vtConnection.getVurl();
    String defaultDriverValidationQuery = ValidationProperty.getInstance().validationQuery(driverProviderEntity.getDbType());
    if (!"Y".equals(driverProviderEntity.getDirectYn())) {
        DBTypeDriverEntity dbDriverModel = this.dbTypeDriverModelRepository.findByDriverId(driverProviderEntity.getDriverId());
        if (!"Y".equals(vtConnection.getUrlDirectYn())) {
            url = VarsqlJdbcUtil.getJdbcUrl(dbDriverModel.getUrlFormat(), JdbcURLFormatParam.builder().serverIp(vtConnection.getVserverip()).port(vtConnection.getVport()).databaseName(vtConnection.getVdatabasename()).build());
        }
        defaultDriverValidationQuery = StringUtils.isBlank(dbDriverModel.getValidationQuery()) ? defaultDriverValidationQuery : dbDriverModel.getValidationQuery();
    }
    logger.debug("connection check url :  {}", url);
    String validation_query = driverProviderEntity.getValidationQuery();
    validation_query = StringUtils.isBlank(validation_query) ? defaultDriverValidationQuery : validation_query;
    String failMessage = "";
    PreparedStatement pstmt = null;
    Connection connChk = null;
    VarsqlAppCode resultCode = VarsqlAppCode.SUCCESS;
    try {
        String pwd = vtConnection.getVpw();
        if (pwd == null || "".equals(pwd))
            pwd = dbInfo.getVpw();
        pwd = (pwd == null) ? "" : pwd;
        pwd = DBPasswordCryptionFactory.getInstance().decrypt(pwd);
        Properties p = new Properties();
        p.setProperty("user", username);
        p.setProperty("password", pwd);
        List<FileInfo> driverJarFiles;
        if (PathType.PATH.equals(PathType.getPathType(driverProviderEntity.getPathType()))) {
            driverJarFiles = FileServiceUtils.getFileInfos(driverProviderEntity.getDriverPath().split(";"));
        } else {
            driverJarFiles = FileServiceUtils.getFileInfos(dbTypeDriverFileEntityRepository.findByFileContId(driverProviderEntity.getDriverProviderId()));
        }
        JDBCDriverInfo jdbcDriverInfo = new JDBCDriverInfo(dbInfo.getDbTypeDriverProvider().getDriverProviderId(), dbInfo.getDbTypeDriverProvider().getDriverClass());
        jdbcDriverInfo.setDriverFiles(driverJarFiles);
        Driver dbDriver = JdbcDriverLoader.checkDriver(jdbcDriverInfo);
        connChk = dbDriver.connect(url, p);
        pstmt = connChk.prepareStatement(validation_query);
        pstmt.executeQuery();
        connChk.close();
    } catch (EncryptDecryptException e) {
        resultCode = VarsqlAppCode.ERROR;
        failMessage = "password decrypt error : " + e.getMessage();
        logger.error(getClass().getName(), (Throwable) e);
    } catch (ClassNotFoundException e) {
        resultCode = VarsqlAppCode.ERROR;
        failMessage = e.getMessage();
        logger.error("url :{}", url);
        logger.error(getClass().getName(), e);
    } catch (Exception e) {
        resultCode = VarsqlAppCode.ERROR;
        failMessage = e.getMessage();
        logger.error(getClass().getName(), e);
    } finally {
        JdbcUtils.close(connChk, pstmt, null);
    }
    resultObject.setResultCode(resultCode);
    resultObject.setMessage(failMessage);
    return resultObject;
}
Also used : DBTypeDriverProviderEntity(com.varsql.web.model.entity.db.DBTypeDriverProviderEntity) Connection(java.sql.Connection) Driver(java.sql.Driver) DBTypeDriverEntity(com.varsql.web.model.entity.db.DBTypeDriverEntity) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties) EncryptDecryptException(com.vartech.common.crypto.EncryptDecryptException) InvocationTargetException(java.lang.reflect.InvocationTargetException) BeansException(org.springframework.beans.BeansException) FileInfo(com.varsql.core.common.beans.FileInfo) ResponseResult(com.vartech.common.app.beans.ResponseResult) DBConnectionEntity(com.varsql.web.model.entity.db.DBConnectionEntity) JDBCDriverInfo(com.varsql.core.connection.beans.JDBCDriverInfo) EncryptDecryptException(com.vartech.common.crypto.EncryptDecryptException) VarsqlAppCode(com.varsql.core.common.code.VarsqlAppCode)

Example 2 with DBTypeDriverProviderEntity

use of com.varsql.web.model.entity.db.DBTypeDriverProviderEntity in project varsql by varsqlinfo.

the class AdminDbMgmtServiceImpl method jdbcProviderList.

public ResponseResult jdbcProviderList(SearchParameter searchParameter) {
    Sort sort = Sort.by(Sort.Direction.ASC, DBTypeDriverProviderEntity.DB_TYPE).and(Sort.by(Sort.Direction.ASC, DBTypeDriverProviderEntity.PROVIDER_NAME));
    List<DBTypeDriverProviderEntity> result = dbTypeDriverProviderRepository.findAll(DBTypeDriverProviderSpec.searchField(searchParameter), sort);
    List<DBTypeDriverProviderResponseDTO> list = result.stream().map(item -> {
        DBTypeDriverProviderResponseDTO dto = new DBTypeDriverProviderResponseDTO();
        dto.setDbType(item.getDbType());
        dto.setProviderName(item.getProviderName());
        dto.setDriverProviderId(item.getDriverProviderId());
        dto.setDriverId(item.getDriverId());
        dto.setDirectYn(item.getDirectYn());
        return dto;
    }).collect(Collectors.toList());
    return VarsqlUtils.getResponseResultItemList(list);
}
Also used : Arrays(java.util.Arrays) Connection(java.sql.Connection) PropertyUtils(org.apache.commons.beanutils.PropertyUtils) DBConnectionRequestDTO(com.varsql.web.dto.db.DBConnectionRequestDTO) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) VarsqlUtils(com.varsql.web.util.VarsqlUtils) BeanWrapperImpl(org.springframework.beans.BeanWrapperImpl) DBTypeEntity(com.varsql.web.model.entity.db.DBTypeEntity) DBTypeDriverProviderSpec(com.varsql.web.repository.spec.DBTypeDriverProviderSpec) VarsqlJdbcUtil(com.varsql.core.common.util.VarsqlJdbcUtil) Map(java.util.Map) ConnectionFactory(com.varsql.core.connection.ConnectionFactory) EncryptDecryptException(com.vartech.common.crypto.EncryptDecryptException) SearchParameter(com.vartech.common.app.beans.SearchParameter) Sort(org.springframework.data.domain.Sort) DBTypeEntityRepository(com.varsql.web.repository.db.DBTypeEntityRepository) DBTypeDriverProviderRepository(com.varsql.web.repository.db.DBTypeDriverProviderRepository) JdbcURLFormatParam(com.varsql.core.connection.beans.JdbcURLFormatParam) RequestResultCode(com.vartech.common.constants.RequestResultCode) DBConnectionEntityRepository(com.varsql.web.repository.db.DBConnectionEntityRepository) Set(java.util.Set) ValidationProperty(com.varsql.core.configuration.prop.ValidationProperty) PreparedStatement(java.sql.PreparedStatement) Page(org.springframework.data.domain.Page) Collectors(java.util.stream.Collectors) DBTypeDriverEntity(com.varsql.web.model.entity.db.DBTypeDriverEntity) InvocationTargetException(java.lang.reflect.InvocationTargetException) List(java.util.List) PathType(com.varsql.core.common.constants.PathType) UserService(com.varsql.web.security.UserService) DBTypeDriverEntityRepository(com.varsql.web.repository.db.DBTypeDriverEntityRepository) DBManagerEntityRepository(com.varsql.web.repository.db.DBManagerEntityRepository) JDBCDriverInfo(com.varsql.core.connection.beans.JDBCDriverInfo) BeanUtils(org.springframework.beans.BeanUtils) JdbcDriverLoader(com.varsql.core.common.util.JdbcDriverLoader) ResourceConfigConstants(com.varsql.web.constants.ResourceConfigConstants) JdbcUtils(com.varsql.core.sql.util.JdbcUtils) BeanWrapper(org.springframework.beans.BeanWrapper) HashMap(java.util.HashMap) DBTypeDriverProviderEntity(com.varsql.web.model.entity.db.DBTypeDriverProviderEntity) ResponseResult(com.vartech.common.app.beans.ResponseResult) SecurityUtil(com.varsql.core.common.util.SecurityUtil) HashSet(java.util.HashSet) VartechUtils(com.vartech.common.utils.VartechUtils) CacheManager(org.springframework.cache.CacheManager) Service(org.springframework.stereotype.Service) Qualifier(org.springframework.beans.factory.annotation.Qualifier) DBConnectionMapper(com.varsql.web.model.mapper.db.DBConnectionMapper) FileInfo(com.varsql.core.common.beans.FileInfo) DBConnectionDetailMapper(com.varsql.web.model.mapper.db.DBConnectionDetailMapper) Properties(java.util.Properties) Logger(org.slf4j.Logger) AbstractService(com.varsql.web.common.service.AbstractService) FileServiceUtils(com.varsql.web.util.FileServiceUtils) DBPasswordCryptionFactory(com.varsql.core.crypto.DBPasswordCryptionFactory) StringUtils(com.vartech.common.utils.StringUtils) DBTypeDriverFileEntityRepository(com.varsql.web.repository.db.DBTypeDriverFileEntityRepository) BeansException(org.springframework.beans.BeansException) DBConnectionEntity(com.varsql.web.model.entity.db.DBConnectionEntity) Driver(java.sql.Driver) VarsqlBeanUtils(com.varsql.web.util.VarsqlBeanUtils) DBGroupMappingDbEntityRepository(com.varsql.web.repository.db.DBGroupMappingDbEntityRepository) VarsqlAppCode(com.varsql.core.common.code.VarsqlAppCode) DBTypeDriverProviderResponseDTO(com.varsql.web.dto.db.DBTypeDriverProviderResponseDTO) CacheUtils(com.varsql.web.common.cache.CacheUtils) DBConnectionSpec(com.varsql.web.repository.spec.DBConnectionSpec) Transactional(org.springframework.transaction.annotation.Transactional) DBTypeDriverProviderResponseDTO(com.varsql.web.dto.db.DBTypeDriverProviderResponseDTO) DBTypeDriverProviderEntity(com.varsql.web.model.entity.db.DBTypeDriverProviderEntity) Sort(org.springframework.data.domain.Sort)

Example 3 with DBTypeDriverProviderEntity

use of com.varsql.web.model.entity.db.DBTypeDriverProviderEntity in project varsql by varsqlinfo.

the class AdminDbMgmtServiceImpl method saveVtconnectionInfo.

/**
 * @Method Name  : insertVtconnectionInfo
 * @Method 설명 : 정보 저장
 * @작성자   : ytkim
 * @작성일   : 2018. 1. 22.
 * @변경이력  :
 * @param vtConnection
 * @return
 * @throws NoSuchMethodException
 * @throws InvocationTargetException
 * @throws IllegalAccessException
 * @throws BeansException
 */
public ResponseResult saveVtconnectionInfo(DBConnectionRequestDTO vtConnection) throws BeansException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    ResponseResult resultObject = new ResponseResult();
    vtConnection.setUserId(SecurityUtil.userViewId());
    DBTypeDriverProviderEntity driverProviderEntity = dbTypeDriverProviderRepository.findByDriverProviderId(vtConnection.getVdriver());
    DBTypeDriverEntity dbDriverModel = this.dbTypeDriverModelRepository.findByDriverId(driverProviderEntity.getDriverId());
    String schemeType = dbDriverModel.getSchemaType();
    if ("user".equals(schemeType)) {
        vtConnection.setVdbschema(vtConnection.getVid().toUpperCase());
    } else if ("orginUser".equals(schemeType)) {
        vtConnection.setVdbschema(vtConnection.getVid());
    } else if ("db".equals(schemeType)) {
        vtConnection.setVdbschema(vtConnection.getVdatabasename());
    } else {
        vtConnection.setVdbschema(schemeType);
    }
    DBConnectionEntity reqEntity = vtConnection.toEntity();
    DBConnectionEntity saveEntity = null;
    DBConnectionEntity currentEntity = null;
    boolean updateFlag = false;
    if (reqEntity.getVconnid() != null) {
        currentEntity = this.dbConnectionModelRepository.findByVconnid(reqEntity.getVconnid());
        if (currentEntity != null) {
            saveEntity = new DBConnectionEntity();
            BeanUtils.copyProperties(currentEntity, saveEntity);
            updateFlag = true;
            copyNonNullProperties(reqEntity, saveEntity, new String[] { "vpw" });
        }
    }
    if (!updateFlag)
        saveEntity = reqEntity;
    if (vtConnection.isPasswordChange())
        saveEntity.setVpw(vtConnection.getVpw());
    logger.debug("saveVtconnectionInfo object param :  {}", VartechUtils.reflectionToString(saveEntity));
    this.dbConnectionModelRepository.save(saveEntity);
    if (updateFlag)
        if (!reqEntity.getVdbschema().equalsIgnoreCase(currentEntity.getVdbschema())) {
            CacheUtils.removeObjectCache(this.cacheManager, currentEntity);
        } else if (!reqEntity.getVdatabasename().equalsIgnoreCase(currentEntity.getVdatabasename())) {
            CacheUtils.removeObjectCache(this.cacheManager, currentEntity);
        } else if ("Y".equals(reqEntity.getUrlDirectYn()) && !reqEntity.getVurl().equals(currentEntity.getVurl())) {
            CacheUtils.removeObjectCache(this.cacheManager, currentEntity);
        } else if (!reqEntity.getVserverip().equals(currentEntity.getVserverip()) || reqEntity.getVport() != currentEntity.getVport()) {
            CacheUtils.removeObjectCache(this.cacheManager, currentEntity);
        }
    resultObject.setItemOne(Integer.valueOf(1));
    return resultObject;
}
Also used : DBTypeDriverProviderEntity(com.varsql.web.model.entity.db.DBTypeDriverProviderEntity) ResponseResult(com.vartech.common.app.beans.ResponseResult) DBConnectionEntity(com.varsql.web.model.entity.db.DBConnectionEntity) DBTypeDriverEntity(com.varsql.web.model.entity.db.DBTypeDriverEntity)

Example 4 with DBTypeDriverProviderEntity

use of com.varsql.web.model.entity.db.DBTypeDriverProviderEntity in project varsql by varsqlinfo.

the class DriverProvierMgmtServiceImpl method deleteInfo.

@Transactional(value = "transactionManager", rollbackFor = { Exception.class })
public ResponseResult deleteInfo(String driverProviderId) {
    logger.debug("delete jdbc provider id : {}", driverProviderId);
    ResponseResult resultObject = new ResponseResult();
    DBTypeDriverProviderEntity entity = dbTypeDriverProviderRepository.findByDriverProviderId(driverProviderId);
    if (entity == null) {
        logger.debug("delete driver id not found : {}", driverProviderId);
        resultObject.setResultCode(RequestResultCode.NOT_FOUND);
        resultObject.setMessage("db jdbc provider not found : " + driverProviderId);
        return resultObject;
    }
    dbTypeDriverProviderRepository.delete(entity);
    resultObject.setItemOne(1);
    return resultObject;
}
Also used : DBTypeDriverProviderEntity(com.varsql.web.model.entity.db.DBTypeDriverProviderEntity) ResponseResult(com.vartech.common.app.beans.ResponseResult) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with DBTypeDriverProviderEntity

use of com.varsql.web.model.entity.db.DBTypeDriverProviderEntity in project varsql by varsqlinfo.

the class DriverProvierMgmtServiceImpl method saveInfo.

@Transactional(transactionManager = ResourceConfigConstants.APP_TRANSMANAGER, rollbackFor = Throwable.class)
public ResponseResult saveInfo(DBTypeDriverProviderRequestDTO dto) throws BeansException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    ResponseResult resultObject = new ResponseResult();
    String driverProviderId = dto.getDriverProviderId();
    DBTypeDriverProviderEntity entity;
    if (StringUtils.isBlank(driverProviderId)) {
        entity = dto.toEntity();
    } else {
        entity = dbTypeDriverProviderRepository.findByDriverProviderId(driverProviderId);
        if (entity == null) {
            logger.debug("update jdbc provider info : {}", dto);
            resultObject.setResultCode(RequestResultCode.NOT_FOUND);
            resultObject.setMessage("db jdbc provider not found : " + driverProviderId);
            return resultObject;
        }
        entity.setProviderName(dto.getProviderName());
        entity.setDriverId(dto.getDriverId());
        entity.setDbType(dto.getDbType());
        entity.setDriverClass(dto.getDriverClass());
        entity.setDriverDesc(dto.getDriverDesc());
        entity.setValidationQuery(dto.getValidationQuery());
        entity.setDirectYn(dto.getDirectYn());
        entity.setPathType(dto.getPathType());
        entity.setDriverPath(dto.getDriverPath());
        String fileIds = dto.getRemoveFileIds();
        if (!StringUtils.isBlank(fileIds)) {
            dbTypeDriverFileEntityRepository.deleteByIdInQuery(Arrays.asList(fileIds.split(",")).stream().map(item -> {
                return item;
            }).collect(Collectors.toList()));
        }
    }
    entity = dbTypeDriverProviderRepository.save(entity);
    if (dto.getFile() != null && dto.getFile().size() > 0) {
        uploadDriverFiles(dto.getFile(), entity.getDriverProviderId());
    }
    return VarsqlUtils.getResponseResultItemOne(1);
}
Also used : DBTypeDriverProviderEntity(com.varsql.web.model.entity.db.DBTypeDriverProviderEntity) ResponseResult(com.vartech.common.app.beans.ResponseResult) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

DBTypeDriverProviderEntity (com.varsql.web.model.entity.db.DBTypeDriverProviderEntity)8 ResponseResult (com.vartech.common.app.beans.ResponseResult)8 FileInfo (com.varsql.core.common.beans.FileInfo)4 JDBCDriverInfo (com.varsql.core.connection.beans.JDBCDriverInfo)4 DBTypeDriverEntity (com.varsql.web.model.entity.db.DBTypeDriverEntity)4 EncryptDecryptException (com.vartech.common.crypto.EncryptDecryptException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 BeansException (org.springframework.beans.BeansException)4 VarsqlAppCode (com.varsql.core.common.code.VarsqlAppCode)3 DBTypeDriverProviderResponseDTO (com.varsql.web.dto.db.DBTypeDriverProviderResponseDTO)3 DBConnectionEntity (com.varsql.web.model.entity.db.DBConnectionEntity)3 Transactional (org.springframework.transaction.annotation.Transactional)3 PathType (com.varsql.core.common.constants.PathType)2 JdbcDriverLoader (com.varsql.core.common.util.JdbcDriverLoader)2 VarsqlRuntimeException (com.varsql.core.exception.VarsqlRuntimeException)2 AbstractService (com.varsql.web.common.service.AbstractService)2 ResourceConfigConstants (com.varsql.web.constants.ResourceConfigConstants)2 DBTypeDriverEntityRepository (com.varsql.web.repository.db.DBTypeDriverEntityRepository)2 DBTypeDriverFileEntityRepository (com.varsql.web.repository.db.DBTypeDriverFileEntityRepository)2 DBTypeDriverProviderRepository (com.varsql.web.repository.db.DBTypeDriverProviderRepository)2