Search in sources :

Example 1 with ConnectionInfo

use of com.varsql.core.connection.beans.ConnectionInfo 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;
}
Also used : FileInfo(com.varsql.core.common.beans.FileInfo) ConnectionInfo(com.varsql.core.connection.beans.ConnectionInfo) IOException(java.io.IOException) JDBCDriverInfo(com.varsql.core.connection.beans.JDBCDriverInfo)

Example 2 with ConnectionInfo

use of com.varsql.core.connection.beans.ConnectionInfo in project varsql by varsqlinfo.

the class ConnectionFactory method getConnection.

@Override
public synchronized Connection getConnection() throws ConnectionFactoryException {
    if (initFlag == false) {
        ConnectionInfo baseConInfo = new ConnectionInfo();
        try {
            BeanUtils.copyProperties(baseConInfo, Configuration.getInstance().getVarsqlDB());
            baseConInfo.setMaxActive(10);
            baseConInfo.setMinIdle(2);
            createPool(baseConInfo);
        } catch (IllegalAccessException | InvocationTargetException e) {
            logger.error("vsql connection pool error : {} ", e.getMessage(), e);
        } catch (SQLException e) {
            logger.error("vsql connection pool error : {} ", e.getMessage(), e);
        }
        initFlag = true;
    }
    return getConnection("varsql");
}
Also used : SQLException(java.sql.SQLException) ConnectionInfo(com.varsql.core.connection.beans.ConnectionInfo) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with ConnectionInfo

use of com.varsql.core.connection.beans.ConnectionInfo in project varsql by varsqlinfo.

the class JPAConfigurer method initialize.

@PostConstruct
public void initialize() {
    ConnectionInfo ci = Configuration.getInstance().getVarsqlDB();
    DriverManagerDataSource dataSource = new DriverManagerDataSource();
    dataSource.setDriverClassName(ci.getJdbcDriverInfo().getDriverClass());
    dataSource.setUrl(ci.getUrl());
    dataSource.setUsername(ci.getUsername());
    dataSource.setPassword(ci.getPassword());
    logger.debug("=================datasourceconfig info====================");
    logger.debug(" driver : {}", ci.getJdbcDriverInfo().getDriverClass());
    logger.debug(" url : {}", ci.getUrl());
    logger.debug(" username", ci.getUsername());
    logger.debug("=================datasourceconfig info====================");
    mainDataSource = dataSource;
}
Also used : DriverManagerDataSource(org.springframework.jdbc.datasource.DriverManagerDataSource) ConnectionInfo(com.varsql.core.connection.beans.ConnectionInfo) PostConstruct(javax.annotation.PostConstruct)

Example 4 with ConnectionInfo

use of com.varsql.core.connection.beans.ConnectionInfo in project varsql by varsqlinfo.

the class ConnectionFactory method createConnectionInfo.

/**
 * @Method Name  : createConnectionInfo
 * @Method 설명 : connection info 생성.
 * @작성일   : 2018. 2. 13.
 * @작성자   : ytkim
 * @변경이력  :
 * @param connid
 * @return
 * @throws Exception
 */
private synchronized ConnectionInfo createConnectionInfo(String connid) throws ConnectionFactoryException {
    try {
        ConnectionInfo connInfo = connectionInfoDao.getConnectionInfo(connid);
        getPoolBean().createDataSource(connInfo);
        this.connectionConfig.put(connid, connInfo);
        return connInfo;
    } catch (Exception e) {
        this.logger.error("empty connection info", e);
        throw new ConnectionFactoryException("empty connection info : [" + connid + "]", e);
    }
}
Also used : ConnectionInfo(com.varsql.core.connection.beans.ConnectionInfo) ConnectionFactoryException(com.varsql.core.exception.ConnectionFactoryException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SQLException(java.sql.SQLException) ConnectionFactoryException(com.varsql.core.exception.ConnectionFactoryException)

Example 5 with ConnectionInfo

use of com.varsql.core.connection.beans.ConnectionInfo in project varsql by varsqlinfo.

the class BaseExecutorTest method testUpdate.

// @Test
// @Ignore
void testUpdate() {
    ConnectionInfo connInfo = getBaseConnection();
    try {
        DatabaseInfo di = getDatabaseInfo(connInfo);
        SqlStatementInfo sqi = new SqlStatementInfo();
        sqi.setSchema("PUBLIC");
        sqi.setConuid(connInfo.getConnid(), TEST_CON_UID, di);
        SQLExecutor baseExecutor = new SqlUpdateExecutor();
        sqi.setSqlParam("{}");
        String insertQuery = getResourceContent("/db/importdata/insertdata.sql");
        sqi.setSql(insertQuery);
        SQLExecuteResult ser = baseExecutor.execute(sqi, new AbstractSQLExecutorHandler() {

            @Override
            public boolean handle(SQLHandlerParameter handleParam) {
                return true;
            }
        });
        System.out.println("testUpdate ser.getTotalCount(): " + ser.getTotalCount());
        System.out.println("testUpdate ser.getResult(): " + ser.getResult());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SqlStatementInfo(com.varsql.core.db.valueobject.SqlStatementInfo) AbstractSQLExecutorHandler(com.varsql.core.sql.executor.handler.AbstractSQLExecutorHandler) DatabaseInfo(com.varsql.core.db.valueobject.DatabaseInfo) SQLHandlerParameter(com.varsql.core.sql.executor.handler.SQLHandlerParameter) ConnectionInfo(com.varsql.core.connection.beans.ConnectionInfo) IOException(java.io.IOException)

Aggregations

ConnectionInfo (com.varsql.core.connection.beans.ConnectionInfo)9 JDBCDriverInfo (com.varsql.core.connection.beans.JDBCDriverInfo)3 DatabaseInfo (com.varsql.core.db.valueobject.DatabaseInfo)3 IOException (java.io.IOException)3 FileInfo (com.varsql.core.common.beans.FileInfo)2 SqlStatementInfo (com.varsql.core.db.valueobject.SqlStatementInfo)2 ConnectionFactoryException (com.varsql.core.exception.ConnectionFactoryException)2 AbstractSQLExecutorHandler (com.varsql.core.sql.executor.handler.AbstractSQLExecutorHandler)2 SQLHandlerParameter (com.varsql.core.sql.executor.handler.SQLHandlerParameter)2 BaseTest (com.varsql.core.test.BaseTest)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 SQLException (java.sql.SQLException)2 Test (org.junit.jupiter.api.Test)2 SQLWriter (com.varsql.core.data.writer.SQLWriter)1 DatabaseParamInfo (com.varsql.core.db.valueobject.DatabaseParamInfo)1 TableInfo (com.varsql.core.db.valueobject.TableInfo)1 EncryptDecryptException (com.vartech.common.crypto.EncryptDecryptException)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 Connection (java.sql.Connection)1