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;
}
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;
}
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;
}
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());
}
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;
}
Aggregations