Search in sources :

Example 1 with ConnectionFactory

use of com.varsql.core.connection.ConnectionFactory in project varsql by varsqlinfo.

the class SQLManager method setSQLMapper.

public void setSQLMapper(ConnectionInfo connInfo, Object obj) {
    try {
        if (!(obj instanceof ConnectionFactory || obj instanceof SQLManager)) {
            logger.error("SQLManager setSQLMapper access denied object {}", obj);
            throw new VarsqlRuntimeException(VarsqlAppCode.EC_DB_POOL, "SQLManager setSQLMapper access denied object " + obj);
        }
        SqlSessionFactory sqlSessionFactory = sqlSessionFactory(connInfo).getObject();
        try (Connection connChk = sqlSessionFactory.openSession().getConnection()) {
            JdbcUtils.close(connChk);
        }
        sqlSessionFactoryMap.put(connInfo.getConnid(), sqlSessionFactory);
        sqlSessionMap.put(connInfo.getConnid(), new SqlSessionTemplate(sqlSessionFactory));
    } catch (Exception e) {
        logger.error("connection info :  {} ", VartechReflectionUtils.reflectionToString(connInfo));
        logger.error("SQLManager :{} ", e.getMessage(), e);
        throw new ConnectionException("getSqlSession IOException " + e.getMessage(), e);
    }
}
Also used : ConnectionFactory(com.varsql.core.connection.ConnectionFactory) SqlSessionTemplate(org.mybatis.spring.SqlSessionTemplate) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Connection(java.sql.Connection) VarsqlRuntimeException(com.varsql.core.exception.VarsqlRuntimeException) VarsqlRuntimeException(com.varsql.core.exception.VarsqlRuntimeException) SQLException(java.sql.SQLException) IOException(java.io.IOException) ConnectionFactoryException(com.varsql.core.exception.ConnectionFactoryException) ConnectionException(com.varsql.core.exception.ConnectionException) ConnectionException(com.varsql.core.exception.ConnectionException)

Aggregations

ConnectionFactory (com.varsql.core.connection.ConnectionFactory)1 ConnectionException (com.varsql.core.exception.ConnectionException)1 ConnectionFactoryException (com.varsql.core.exception.ConnectionFactoryException)1 VarsqlRuntimeException (com.varsql.core.exception.VarsqlRuntimeException)1 IOException (java.io.IOException)1 Connection (java.sql.Connection)1 SQLException (java.sql.SQLException)1 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)1 SqlSessionTemplate (org.mybatis.spring.SqlSessionTemplate)1