Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Component
- public class DDLReviewDao {
- @Autowired
- @Qualifier("devbJdbc")
- private JdbcTemplate jdbcTemplate;
- public static final Logger logger = LogManager.getLogger(DDLReviewDao.class);
- public List<DDLObject> getDDLReviewData(DDLQuery ddlQuery) {
- String selectSql = MacroGenerator.generateMacro(ddlQuery);
- List<DDLObject> ddlObject = jdbcTemplate.query(selectSql, new DDLMapper());
- logger.info(ddlObject);
- return ddlObject;
- }
- }
- @Configuration
- class DevbConfig {
- @Bean(name = "devbDataSource")
- DataSource devbDataSource() {
- try {
- return new SimpleDriverDataSource(DriverManager.getDriver("jdbc:..."), "jdbc:...", "username", "password");
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- }
- @Bean(name = "devbJdbc")
- JdbcTemplate devbJdbc(@Qualifier("devbDataSource") DataSource dataSource) {
- return new JdbcTemplate(dataSource);
- }
- }
- public static void doReleaseConnection(Connection con, DataSource dataSource) throws SQLException {
- if (con == null) {
- return;
- }
- if (dataSource != null) {
- ConnectionHolder conHolder = (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource);
- if (conHolder != null && connectionEquals(conHolder, con)) {
- // It's the transactional Connection: Don't close it.
- conHolder.released();
- return;
- }
- }
- logger.debug("Returning JDBC Connection to DataSource");
- doCloseConnection(con, dataSource);
- }
- public static void doCloseConnection(Connection con, DataSource dataSource) throws SQLException {
- if (!(dataSource instanceof SmartDataSource) || ((SmartDataSource) dataSource).shouldClose(con)) {
- con.close();
- }
- }
Add Comment
Please, Sign In to add comment