Guest User

Untitled

a guest
Nov 28th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. <jdbc:embedded-database id="dataSource">
  2. <jdbc:script location="classpath:schema.sql"/>
  3. <jdbc:script location="classpath:test-data.sql"/>
  4. </jdbc:embedded-database>
  5.  
  6. @Service
  7. public class DbCleanup {
  8. @Resource
  9. private DataSource ds;
  10.  
  11. @PreDestroy
  12. public cleanUpDb() {
  13. //do your cleanup with DB
  14. }
  15. }
  16.  
  17. package com.obecto.fixtures;
  18.  
  19. public interface Fixture {
  20.  
  21. void prepare();
  22.  
  23. }
  24.  
  25. package com.avaco2.fixtures;
  26.  
  27. import java.util.logging.Logger;
  28.  
  29. import org.apache.commons.dbcp.BasicDataSource;
  30. import org.springframework.beans.factory.annotation.Autowired;
  31. import org.springframework.core.io.ClassPathResource;
  32. import org.springframework.core.io.Resource;
  33. import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
  34. import org.springframework.stereotype.Component;
  35. import org.springframework.test.jdbc.SimpleJdbcTestUtils;
  36.  
  37. import com.obecto.fixtures.Fixture;
  38.  
  39. @Component(value="logEventsSQLFixture")
  40. public class LogEventsSQLFixture implements Fixture {
  41. private static String IMPORT_SQL = "import-LogEvents.sql";
  42. private static Logger LOG = Logger.getLogger(LogEventsSQLFixture.class.getName());
  43.  
  44. @Autowired
  45. private BasicDataSource dataSource;
  46.  
  47. @Override
  48. public void prepare() {
  49. SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(dataSource);
  50. Resource sqlScript = new ClassPathResource(IMPORT_SQL);
  51. try {
  52. SimpleJdbcTestUtils.executeSqlScript(jdbcTemplate, sqlScript, true);
  53. } catch (Exception e) {
  54. LOG.severe("Cannot import " + IMPORT_SQL);
  55. }
  56.  
  57. }
  58.  
  59. }
Add Comment
Please, Sign In to add comment