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