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 | |
} |
Sorry for delay, just noticed your comment.
It's based on grails 1.3.x line with datasources plugin.
I didn't test it on grails 2.x.
The whole story, behind this gist:
http://grails.1312388.n4.nabble.com/Get-rid-of-legacy-commons-dbcp-or-at-least-simplify-different-connection-pool-setup-td3461550.html
https://jira.grails.org/browse/GRAILS-7455
The Grails JIRA site no longer exists, the issue was migrated to GitHub, here it is:
grails/grails-core#7087
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi. Does this apply to Grails 1.X? Could I use this under Grails 2.3.6? Thanks!