Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This in BootStrap.groovy
- class BootStrap {
- def dataService
- def init = { servletContext ->
- dataService.initBeans()
- }
- def destroy = {
- }
- }
- // Then this is the DataService
- class DataService implements ApplicationContextAware {
- ApplicationContext applicationContext
- boolean transactional = false
- // Get an Sql instance for a DataSource
- def getSql( species, version ) {
- Sql.newInstance( applicationContext.getBean( "${species}_${version}_db" ) )
- }
- // Register all BasicDataSource beans
- def initBeans() {
- Species.list().each { species ->
- species.versions.each { version ->
- registerBean( species, version )
- }
- }
- }
- // Register a single bean
- def registerBean( Species species, SpeciesVersion version ) {
- def bb = new grails.spring.BeanBuilder()
- bb.beans {
- "${species.internalName}_${version.name}_db"( BasicDataSource ) {
- driverClassName = "com.mysql.jdbc.Driver"
- url = "jdbc:mysql://localhost/${species.dbName}_${version.name}"
- username = "XXXXXXXXX"
- password = "XXXXXXXXX"
- }
- }
- bb.registerBeans( applicationContext )
- }
- }
Add Comment
Please, Sign In to add comment