Created
April 19, 2011 20:25
-
-
Save allnightlong/929543 to your computer and use it in GitHub Desktop.
Grails way to configure connection pool other than legacy dbcp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.jolbox.bonecp.BoneCPDataSource | |
import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH | |
import org.codehaus.groovy.grails.commons.ApplicationHolder as AH | |
import com.burtbeckwith.grails.plugin.datasources.DatasourcesBuilder | |
import grails.util.Environment | |
beans = { | |
def ds = CH.config.dataSource | |
def dsClosure = { bean -> | |
bean.destroyMethod = 'close' | |
username = ds.username | |
password = ds.password | |
jdbcUrl = ds.url | |
driverClass = ds.driverClassName | |
disableJMX = true | |
logStatementsEnabled = true | |
} | |
dataSource(BoneCPDataSource, dsClosure) | |
def environment = Environment.getCurrent().getName() | |
def dateSources = getDataSources().findAll {it.environments.contains(environment)} | |
dateSources.each { | |
ds = it | |
"dataSource_${ds.name}"(BoneCPDataSource, dsClosure) | |
} | |
} | |
//this code is from DatasourcesGrailsPlugin.loadConfig() | |
//yeah, I did have to dig in datasources plugin internals to avoid copy-past | |
private getDataSources() { | |
def script = AH.application.classLoader.loadClass('Datasources').newInstance() | |
script.run() | |
def datasources = script.datasources | |
datasources.delegate = new DatasourcesBuilder() | |
datasources() | |
datasources.delegate.dataSources | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Grails JIRA site no longer exists, the issue was migrated to GitHub, here it is:
grails/grails-core#7087