Guest User

Untitled

a guest
Jan 5th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. @Component
  2. public class DDLReviewDao {
  3.  
  4. @Autowired
  5. @Qualifier("devbJdbc")
  6. private JdbcTemplate jdbcTemplate;
  7.  
  8. public static final Logger logger = LogManager.getLogger(DDLReviewDao.class);
  9.  
  10. public List<DDLObject> getDDLReviewData(DDLQuery ddlQuery) {
  11.  
  12. String selectSql = MacroGenerator.generateMacro(ddlQuery);
  13. List<DDLObject> ddlObject = jdbcTemplate.query(selectSql, new DDLMapper());
  14. logger.info(ddlObject);
  15. return ddlObject;
  16. }
  17.  
  18. }
  19.  
  20. @Configuration
  21. class DevbConfig {
  22.  
  23. @Bean(name = "devbDataSource")
  24. DataSource devbDataSource() {
  25. try {
  26. return new SimpleDriverDataSource(DriverManager.getDriver("jdbc:..."), "jdbc:...", "username", "password");
  27. } catch (SQLException e) {
  28. throw new RuntimeException(e);
  29. }
  30. }
  31.  
  32. @Bean(name = "devbJdbc")
  33. JdbcTemplate devbJdbc(@Qualifier("devbDataSource") DataSource dataSource) {
  34. return new JdbcTemplate(dataSource);
  35. }
  36.  
  37. }
  38.  
  39. public static void doReleaseConnection(Connection con, DataSource dataSource) throws SQLException {
  40. if (con == null) {
  41. return;
  42. }
  43. if (dataSource != null) {
  44. ConnectionHolder conHolder = (ConnectionHolder) TransactionSynchronizationManager.getResource(dataSource);
  45. if (conHolder != null && connectionEquals(conHolder, con)) {
  46. // It's the transactional Connection: Don't close it.
  47. conHolder.released();
  48. return;
  49. }
  50. }
  51. logger.debug("Returning JDBC Connection to DataSource");
  52. doCloseConnection(con, dataSource);
  53. }
  54.  
  55. public static void doCloseConnection(Connection con, DataSource dataSource) throws SQLException {
  56. if (!(dataSource instanceof SmartDataSource) || ((SmartDataSource) dataSource).shouldClose(con)) {
  57. con.close();
  58. }
  59. }
Add Comment
Please, Sign In to add comment