Search in sources :

Example 1 with DBConnectionEntity

use of com.varsql.web.model.entity.db.DBConnectionEntity 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 2 with DBConnectionEntity

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

the class AdminDbMgmtServiceImpl method viewVtConntionPwInfo.

/**
 * @method  : viewVtConntionPwInfo
 * @desc : view db password
 * @author   : ytkim
 * @date   : 2020. 7. 4.
 * @param vconnid
 * @return ResponseResult
 */
public ResponseResult viewVtConntionPwInfo(String vconnid, String userPw) {
    ResponseResult resultObject = new ResponseResult();
    if (!userService.passwordCheck(SecurityUtil.loginName(), userPw)) {
        resultObject.setResultCode(RequestResultCode.ERROR);
        resultObject.setMessage("password not valid");
        return resultObject;
    }
    DBConnectionEntity dbInfo = dbConnectionModelRepository.findOne(DBConnectionSpec.detailInfo(vconnid)).orElseThrow(NullPointerException::new);
    try {
        resultObject.setItemOne(DBPasswordCryptionFactory.getInstance().decrypt(dbInfo.getVpw()));
    } catch (EncryptDecryptException e) {
        resultObject.setItemOne("password decrypt error");
    }
    return resultObject;
}
Also used : ResponseResult(com.vartech.common.app.beans.ResponseResult) DBConnectionEntity(com.varsql.web.model.entity.db.DBConnectionEntity) EncryptDecryptException(com.vartech.common.crypto.EncryptDecryptException)

Example 3 with DBConnectionEntity

use of com.varsql.web.model.entity.db.DBConnectionEntity 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 4 with DBConnectionEntity

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

the class DBConnectionModelRepositoryTest method testSave.

@Test
void testSave() {
    DBConnectionEntity modelData = dbConnectionModelRepository.save(DBConnectionEntity.builder().vname("testdb").vserverip("123.123.123.1").vport(12312).vdatabasename("varsql").vurl("jdbc:h2:file:E://varsql").vdriver("004").vid("varsql").vpw("").urlDirectYn("Y").vdbversion(ConvertUtils.longValueOf("1")).vdbschema("PUBLIC").useYn("Y").basetableYn("N").schemaViewYn("N").lazyloadYn("Y").maxActive(50).minIdle(10).timeout(3000).exportcount(3000).maxSelectCount(10000).build());
    DBConnectionEntity modelData2 = dbConnectionModelRepository.findOne(DBConnectionSpec.detailInfo(modelData.getVconnid())).get();
    assertNotNull(modelData.getVconnid());
    assertEquals(modelData.getVname(), modelData2.getVname());
    assertEquals(modelData.getVurl(), modelData2.getVurl());
}
Also used : DBConnectionEntity(com.varsql.web.model.entity.db.DBConnectionEntity) Test(org.junit.jupiter.api.Test)

Example 5 with DBConnectionEntity

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

the class AdminDbMgmtServiceImpl method deleteVtconnectionInfo.

/**
 * @method  : deleteVtconnectionInfo
 * @desc : db 정보 삭제 처리.
 * @author   : ytkim
 * @date   : 2020. 4. 20.
 * @param vconnid
 * @return
 */
@Transactional(value = ResourceConfigConstants.APP_TRANSMANAGER, rollbackFor = Exception.class)
public boolean deleteVtconnectionInfo(String vconnid) {
    DBConnectionEntity dbInfo = dbConnectionModelRepository.findOne(DBConnectionSpec.detailInfo(vconnid)).orElseThrow(NullPointerException::new);
    dbInfo.setDelYn(true);
    dbConnectionModelRepository.save(dbInfo);
    dbGroupMappingDbEntityRepository.deleteByVconnid(vconnid);
    dbManagerRepository.deleteByVconnid(vconnid);
    try {
        ConnectionFactory.getInstance().poolShutdown(vconnid);
    } catch (Exception e) {
        logger.error("deleteVtconnectionInfo vconnid :  {}", vconnid, e);
    } finally {
        CacheUtils.removeObjectCache(cacheManager, vconnid);
    }
    return true;
}
Also used : DBConnectionEntity(com.varsql.web.model.entity.db.DBConnectionEntity) EncryptDecryptException(com.vartech.common.crypto.EncryptDecryptException) InvocationTargetException(java.lang.reflect.InvocationTargetException) BeansException(org.springframework.beans.BeansException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

DBConnectionEntity (com.varsql.web.model.entity.db.DBConnectionEntity)8 ResponseResult (com.vartech.common.app.beans.ResponseResult)5 EncryptDecryptException (com.vartech.common.crypto.EncryptDecryptException)3 MetaControlBean (com.varsql.core.db.MetaControlBean)2 DBTypeDriverEntity (com.varsql.web.model.entity.db.DBTypeDriverEntity)2 DBTypeDriverProviderEntity (com.varsql.web.model.entity.db.DBTypeDriverProviderEntity)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 BeansException (org.springframework.beans.BeansException)2 FileInfo (com.varsql.core.common.beans.FileInfo)1 VarsqlAppCode (com.varsql.core.common.code.VarsqlAppCode)1 JDBCDriverInfo (com.varsql.core.connection.beans.JDBCDriverInfo)1 BaseObjectInfo (com.varsql.core.db.valueobject.BaseObjectInfo)1 DatabaseParamInfo (com.varsql.core.db.valueobject.DatabaseParamInfo)1 DDLCreateOption (com.varsql.core.db.valueobject.ddl.DDLCreateOption)1 Connection (java.sql.Connection)1 Driver (java.sql.Driver)1 PreparedStatement (java.sql.PreparedStatement)1 Properties (java.util.Properties)1 Test (org.junit.jupiter.api.Test)1 Transactional (org.springframework.transaction.annotation.Transactional)1