Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package esame;
  7.  
  8. import javax.annotation.PostConstruct;
  9. import javax.annotation.PreDestroy;
  10. import javax.annotation.sql.DataSourceDefinition;
  11. import javax.ejb.Singleton;
  12. import javax.ejb.Startup;
  13. import javax.inject.Inject;
  14.  
  15. /**
  16. *
  17. * @author Desi
  18. */
  19. @Singleton
  20. @Startup
  21. @DataSourceDefinition(
  22. user = "app",
  23. password = "app",
  24. databaseName = "EsameDB",
  25. className = "org.apache.derby.jdbc.EmbeddedDataSource",
  26. name = "java:global/jdbc/EsameDS",
  27. properties = {"connectionAttributes=;create=true"}
  28. )
  29. public class DatabasePopulator {
  30. @Inject
  31. private ViaggioEJB vejb;
  32. private Viaggio v1,v2,v3;
  33. @PostConstruct
  34. public void CreateDB(){
  35. v1 = new Viaggio("c1", "d1", 1, 1, 1, 1);
  36. v1 = new Viaggio("c2", "d2", 2, 2, 2, 2);
  37. v1 = new Viaggio("c3", "d3", 3, 3, 3, 3);
  38. vejb.create(v1);
  39. vejb.create(v2);
  40. vejb.create(v3);
  41. }
  42.  
  43. @PreDestroy
  44. public void ClearDB(){
  45. vejb.remove(v1);
  46. vejb.remove(v2);
  47. vejb.remove(v3);
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement