Guest User

Untitled

a guest
May 1st, 2018
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. // This in BootStrap.groovy
  2.  
  3. class BootStrap {
  4. def dataService
  5.  
  6. def init = { servletContext ->
  7. dataService.initBeans()
  8. }
  9. def destroy = {
  10. }
  11. }
  12.  
  13. // Then this is the DataService
  14.  
  15. class DataService implements ApplicationContextAware {
  16. ApplicationContext applicationContext
  17.  
  18. boolean transactional = false
  19.  
  20. // Get an Sql instance for a DataSource
  21. def getSql( species, version ) {
  22. Sql.newInstance( applicationContext.getBean( "${species}_${version}_db" ) )
  23. }
  24.  
  25. // Register all BasicDataSource beans
  26. def initBeans() {
  27. Species.list().each { species ->
  28. species.versions.each { version ->
  29. registerBean( species, version )
  30. }
  31. }
  32. }
  33.  
  34. // Register a single bean
  35. def registerBean( Species species, SpeciesVersion version ) {
  36. def bb = new grails.spring.BeanBuilder()
  37. bb.beans {
  38. "${species.internalName}_${version.name}_db"( BasicDataSource ) {
  39. driverClassName = "com.mysql.jdbc.Driver"
  40. url = "jdbc:mysql://localhost/${species.dbName}_${version.name}"
  41. username = "XXXXXXXXX"
  42. password = "XXXXXXXXX"
  43. }
  44. }
  45. bb.registerBeans( applicationContext )
  46. }
  47. }
Add Comment
Please, Sign In to add comment