Grails with commons-dbcp2 connection pool datasource -
Grails with commons-dbcp2 connection pool datasource -
background: have 2 projects
a: spring based java project
b: grails project gui
i have 2 questions related:
how can utilize org.apache.commons.dbcp2.basicdatasource in grails project instead of default apache tomcat datasource? there limitation org.apache.tomcat.jdbc.pool.datasource , allows 1 initsql string. want run 2 init sql statements ["set schema", "set role"], possible dbcp2 because takes connectioninitsqls list. tried combine 2 sql statements semicolon tomcat datasource gave validation error.
is possible extend datasource parent bean? want extend grails datasource abstract bean defined in java project, thought reuse mutual datasource properties.
i haven't seen performance comparing between particular pool , tomcat pool, guess you'll trading in ferrari plays 1 radio station jalopy plays two. look @ comparisons of tomcat vs others - it's faster. if don't much traffic maybe won't big deal.
performance issues aside, it's easy register own datasource
- create bean in grails-app/conf/spring/resources.groovy
right name , yours override 1 configured grails. true of spring beans; if register new bean name of 1 configured before grails or plugin, yours wins. , set properties needed:
import org.apache.commons.dbcp2.basicdatasource beans = { datasource(basicdatasource) { url = '${datasource.url}' driverclassname = '${datasource.driverclassname}' username = '${datasource.username}' password = '${datasource.password}' // other valid setters - see source or // javadocs what's available } }
note must utilize single quotes when referring config.groovy
variables (the values datasource.groovy
merged main config under "datasource" key) because trigger's spring property placeholder handling, replace specified keys lookups in scheme properties, properties files, , in grails, config. if utilize double quotes become gstrings , evaluated , cause exception.
that's not plenty though - in add-on big pool performance downgrade, give valid connection pool eliminate 2 cool features grails adds. datasource
bean if don't customize 2 proxies wrapping real datasource
. 1 org.springframework.jdbc.datasource.lazyconnectiondatasourceproxy
avoids cost of configuring connection @ origin of transaction when no updates occur. configures connection
proxy caches method invocations (setautocommit(false)
, setting isolation level, readonly, timeout, etc.) , when actual update, applies values real connection , uses that. if don't updates, you'l save time, not big savings add together on busy site. other org.springframework.jdbc.datasource.transactionawaredatasourceproxy
ensures during transaction or hibernate session, if go datasource
connection, 1 beingness used already, you'll able see active updates, read uncommitted changes, etc.
so there 3 datasource beans, , you'd register 1 above name datasourceunproxied
, , others via references:
datasourceunproxied(basicdatasource) { url = ... ... } datasourcelazy(lazyconnectiondatasourceproxy, ref('datasourceunproxied')) datasource(transactionawaredatasourceproxy, ref('datasourcelazy'))
even when related, should inquire 1 question per question. i'll reply sec pointer code. if there multiple datasources, , 3 beans per datasource, you'd end lot of redundant code , config, datasourcegrailsplugin
create abstract parent bean definition mutual properties , builds real beans that; can see in code.
grails apache-commons-dbcp
Comments
Post a Comment