use of com.varsql.core.common.beans.FileInfo in project varsql by varsqlinfo.
the class ConnectionInfoComponent method getConnectionInfo.
@Override
public ConnectionInfo getConnectionInfo(String connid) throws EncryptDecryptException {
logger.debug("create connection info : {}", connid);
ConnectionInfo connInfo = new ConnectionInfo();
ConnectionInfoDTO dto = dbConnectionEntityRepository.findByConnInfo(connid);
connInfo.setConnid(dto.getConnection().getVconnid());
connInfo.setAliasName(dto.getConnection().getVname());
connInfo.setType(dto.getProvider().getDbType().toLowerCase());
connInfo.setUsername(dto.getConnection().getVid());
String pw = dto.getConnection().getVpw();
connInfo.setPassword("");
if (!StringUtils.isBlank(pw)) {
connInfo.setPassword(DBPasswordCryptionFactory.getInstance().decrypt(pw));
}
connInfo.setPoolOptions(dto.getConnection().getVpoolopt());
connInfo.setConnectionOptions(dto.getConnection().getVconnopt());
connInfo.setMaxActive(NumberUtils.toInt(dto.getConnection().getMaxActive() + "", 10));
connInfo.setMinIdle(NumberUtils.toInt(dto.getConnection().getMinIdle() + "", 3));
connInfo.setConnectionTimeOut(NumberUtils.toInt(dto.getConnection().getTimeout() + "", 18000));
connInfo.setExportCount(NumberUtils.toInt(dto.getConnection().getExportcount() + "", 1000));
connInfo.setTestWhileIdle("Y".equals(dto.getConnection().getTestWhileIdle()));
String defaultDriverValidationQuery = ValidationProperty.getInstance().validationQuery(connInfo.getType());
String urlDirectYn = dto.getConnection().getUrlDirectYn();
if ("Y".equals(urlDirectYn)) {
connInfo.setUrl(dto.getConnection().getVurl());
} else {
connInfo.setUrl(VarsqlJdbcUtil.getJdbcUrl(dto.getDriver().getUrlFormat(), JdbcURLFormatParam.builder().serverIp(dto.getConnection().getVserverip()).port(Integer.parseInt(dto.getConnection().getVport() + "")).databaseName(dto.getConnection().getVdatabasename()).build()));
}
defaultDriverValidationQuery = StringUtils.isBlank(dto.getDriver().getValidationQuery()) ? defaultDriverValidationQuery : dto.getDriver().getValidationQuery();
String validation_query = dto.getProvider().getValidationQuery();
validation_query = StringUtils.isBlank(validation_query) ? defaultDriverValidationQuery : validation_query;
connInfo.setValidationQuery(validation_query);
List<FileInfo> driverFileInfos;
if (PathType.PATH.equals(PathType.getPathType(dto.getProvider().getPathType()))) {
try {
driverFileInfos = FileServiceUtils.getFileInfos(dto.getProvider().getDriverPath().split(";"));
} catch (IOException e) {
logger.error("driver load fail : " + dto.getProvider().getDriverPath());
driverFileInfos = null;
}
} else {
driverFileInfos = FileServiceUtils.getFileInfos(dbTypeDriverFileEntityRepository.findByFileContId(dto.getProvider().getDriverProviderId()));
}
JDBCDriverInfo jdbcDriverInfo = new JDBCDriverInfo(dto.getDriver().getDriverId(), dto.getDriver().getDbdriver());
jdbcDriverInfo.setDriverFiles(driverFileInfos);
connInfo.setJdbcDriverInfo(jdbcDriverInfo);
return connInfo;
}
use of com.varsql.core.common.beans.FileInfo in project varsql by varsqlinfo.
the class FileServiceUtils method getFileInfos.
/**
* @method : fileInfos
* @desc : file info 구하기
* @author : ytkim
* @date : 2022. 1. 15.
* @param FilePaths
* @return
* @throws IOException
*/
public static List<FileInfo> getFileInfos(String[] FilePaths) throws IOException {
List<FileInfo> driverJarFiles = new ArrayList<>();
for (String path : FilePaths) {
Resource resource = ResourceUtils.getResource(path);
if (resource != null) {
FileInfo fi = new FileInfo();
fi.setName(resource.getFile().getName());
fi.setPath(resource.getFile().getAbsolutePath());
fi.setExt(FileUtils.extension(resource.getFile().getName()));
driverJarFiles.add(fi);
} else {
throw new FileNotFoundException("file path not found : " + path);
}
}
return driverJarFiles;
}
use of com.varsql.core.common.beans.FileInfo in project varsql by varsqlinfo.
the class JdbcDriverLoader method getJdbcDriver.
private Driver getJdbcDriver(JDBCDriverInfo jdbcDriverInfo) throws IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
List<FileInfo> jdbcList = jdbcDriverInfo.getDriverFiles();
if (jdbcList != null && jdbcList.size() > 0) {
List<URL> urlList = new ArrayList<>();
for (FileInfo item : jdbcList) {
Resource resource = ResourceUtils.getResource(item.getPath());
if (resource != null)
urlList.add(resource.getURL());
}
if (urlList.size() > 0) {
URLClassLoader ucl = new URLClassLoader(urlList.<URL>toArray(new URL[0]));
Class<?> driverClass = Class.forName(jdbcDriverInfo.getDriverClass(), true, ucl);
try {
return (Driver) driverClass.getDeclaredConstructor().newInstance();
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) {
throw new JdbcDriverClassException(e);
}
// return (Driver) Class.forName(jdbcDriverInfo.getDriverClass(), true, ucl).newInstance();
}
}
return null;
}
use of com.varsql.core.common.beans.FileInfo 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.core.common.beans.FileInfo in project varsql by varsqlinfo.
the class SimpleConnectionInfoDao method getConnectionInfo.
@Override
public ConnectionInfo getConnectionInfo(String connid) {
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = ConnectionFactory.getInstance().getConnection();
StringBuffer querySb = new StringBuffer();
querySb.append(" select ");
querySb.append(" a.* ");
querySb.append(" , b.DRIVER_PROVIDER_ID, b.DRIVER_CLASS, b.VALIDATION_QUERY, b.DB_TYPE, b.PATH_TYPE, b.DRIVER_PATH ");
querySb.append(" , c.URL_FORMAT ");
querySb.append(" from ");
querySb.append(" VTCONNECTION a left outer join VTDBTYPE_DRIVER_PROVIDER b on a.VDRIVER = b.DRIVER_PROVIDER_ID ");
querySb.append(" left outer join VTDBTYPE_DRIVER_TYPE c on b.DRIVER_ID = c.DRIVER_ID ");
querySb.append(" where 1=1 ");
querySb.append(" and a.VCONNID = ? ");
pstmt = conn.prepareStatement(querySb.toString());
pstmt.setString(1, connid);
rs = pstmt.executeQuery();
if (rs == null)
throw new ConnectionFactoryException("not valid connection infomation :" + connid);
rs.next();
ConnectionInfo connInfo = new ConnectionInfo();
connInfo.setConnid(rs.getString("VCONNID"));
connInfo.setAliasName(rs.getString("VNAME"));
connInfo.setType(rs.getString("VTYPE").toLowerCase());
String urlDirectYn = rs.getString("URL_DIRECT_YN");
if ("Y".equals(urlDirectYn)) {
connInfo.setUrl(rs.getString("VURL"));
} else {
connInfo.setUrl(VarsqlJdbcUtil.getJdbcUrl(rs.getString("URL_FORMAT"), JdbcURLFormatParam.builder().serverIp(rs.getString("VSERVERIP")).port(Integer.parseInt(rs.getString("VPORT"))).databaseName(rs.getString("VDATABASENAME")).build()));
}
connInfo.setUsername(rs.getString("VID"));
if ("varsql".equals(connInfo.getConnid())) {
connInfo.setPassword(rs.getString("VPW"));
} else {
String str = rs.getString("VPW");
connInfo.setPassword("");
if (str != null && !"".equals(str))
connInfo.setPassword(DBPasswordCryptionFactory.getInstance().decrypt(rs.getString("VPW")));
}
connInfo.setPoolOptions(rs.getString("VPOOLOPT"));
connInfo.setConnectionOptions(rs.getString("VCONNOPT"));
connInfo.setMaxActive(NumberUtils.toInt(rs.getString("MAX_ACTIVE"), 10));
connInfo.setMinIdle(NumberUtils.toInt(rs.getString("MIN_IDLE"), 3));
connInfo.setConnectionTimeOut(NumberUtils.toInt(rs.getString("TIMEOUT"), 18000));
connInfo.setExportCount(NumberUtils.toInt(rs.getString("EXPORTCOUNT"), 1000));
connInfo.setTestWhileIdle("Y".equals(rs.getString("TEST_WHILE_IDLE")));
String conn_query = rs.getString("VQUERY");
String dbvalidation_query = rs.getString("VALIDATION_QUERY");
conn_query = (conn_query == null) ? "" : conn_query;
dbvalidation_query = (dbvalidation_query == null) ? "" : dbvalidation_query;
String validation_query = !"".equals(conn_query.trim()) ? conn_query : (!"".equals(dbvalidation_query.trim()) ? dbvalidation_query : ValidationProperty.getInstance().validationQuery(connInfo.getType()));
this.logger.debug("valication_query : {}", validation_query);
connInfo.setValidationQuery(validation_query);
String driverProviderId = rs.getString("DRIVER_PROVIDER_ID");
pstmt.close();
pstmt = conn.prepareStatement(" select FILE_NAME,FILE_PATH,FILE_EXT from VTDBTYPE_DRIVER_FILE where FILE_CONT_ID = ? ");
pstmt.setString(1, driverProviderId);
rs.close();
rs = pstmt.executeQuery();
if (rs == null) {
throw new ConnectionFactoryException("jdbc driver file not found :" + connid);
}
List<FileInfo> jarFileList = new ArrayList<>();
while (rs.next()) {
FileInfo fi = new FileInfo();
fi.setName(rs.getString("FILE_NAME"));
fi.setPath(Paths.get(VarsqlConstants.UPLOAD_PATH).toAbsolutePath().resolve(rs.getString("FILE_PATH")).normalize().toAbsolutePath().toString());
fi.setExt(rs.getString("FILE_EXT"));
jarFileList.add(fi);
}
JDBCDriverInfo jdbcDriverInfo = new JDBCDriverInfo(rs.getString("DRIVER_PROVIDER_ID"), rs.getString("DRIVER_CLASS"));
jdbcDriverInfo.setDriverFiles(jarFileList);
connInfo.setJdbcDriverInfo(jdbcDriverInfo);
return connInfo;
} catch (EncryptDecryptException e) {
this.logger.error("password decrypt error", e);
throw new ConnectionFactoryException("password decrypt error", e);
} catch (Exception e) {
this.logger.error("empty connection info", e);
throw new ConnectionFactoryException("empty connection info : [" + connid + "]", e);
} finally {
JdbcUtils.close(conn, pstmt, rs);
}
}
Aggregations