Last updated by admin 2 years ago
grails install-plugin jdbc-pool
Last updated by domurtag 2 months ago
Replaces default Grails Commons DBCP Pool with Tomcat JDBC Pool (
http://people.apache.org/~fhanik/jdbc-pool/).
Compatible with built-in dataSource plugin and the datasources plugin.
There is only
a couple of lines of code in the plugin.
The plugin just replaces the bean's class name with "org.apache.tomcat.jdbc.pool.DataSource" for beans having the class "org.apache.commons.dbcp.BasicDataSource" (this is done in doWithSpring which is called before the Spring context is running). Tomcat JDBC Pool is properties compatible with Commons DBCP.
Information about Tomcat JDBC Pool (cannot find public home page for it):
Tomcat JBDC Pool comes with SpringSource tcServer:
Plugin History
- 02/2012 1.0.9.3 - Changes: (contribution by Donal Murtagh)
- Upgraded JDBC commons pool lib to latest version 1.0.9.3
- Changed plugin version to match that of lib
- Upgraded to Grails 2.0.1
Last updated by lhotari 1 year ago
Question: How does the jdbc-pool plugin replace Commons DBCP?
jdbc-pool plugin uses a clever trick to replace Commons DBCP:
def doWithSpring = {
springConfig.beanNames.each { beanName ->
if(beanName.startsWith('dataSource')) {
def beanconf=springConfig.getBeanConfig(beanName)
if(beanconf.beanDefinition.beanClassName=='org.apache.commons.dbcp.BasicDataSource') {
beanconf.beanDefinition.beanClassName='org.apache.tomcat.jdbc.pool.DataSource'
}
}
} }(http://svn.codehaus.org/grails-plugins/grails-jdbc-pool/trunk/JdbcPoolGrailsPlugin.groovy)
Question: Do I have to download Tomcat JDBC Pool jars manually?
No, The latest version of jdbc-pool plugin defines a dependency :
dependencies {
runtime 'org.apache.tomcat:com.springsource.org.apache.tomcat.jdbc:1.0.8.5'
}(gets it from SpringSource's EBR repository, using ebr() in repositories closure: http://svn.codehaus.org/grails-plugins/grails-jdbc-pool/trunk/grails-app/conf/BuildConfig.groovy)
Question: How can I enable a JMX MBean for Tomcat JDBC Pool?
I've enabled the JMX MBean for Tomcat JDBC Pool by adding these beans to resources.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="grailsApplicationName" class="java.lang.String">
<constructor-arg><value>#{T(grails.util.Metadata).getCurrent().applicationName}</value></constructor-arg>
</bean> <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="true"/>
</bean> <bean id="mbeanExporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="JDBC:type=pool,application=#{grailsApplicationName}">
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject">
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="targetObject" ref="dataSourceUnproxied"/>
<property name="targetMethod" value="getPool"/>
</bean>
</property>
<property name="targetMethod" value="getJmxPool"/>
</bean>
</entry>
</map>
</property>
<property name="server" ref="mbeanServer"/>
</bean>
</beans>
Last updated by admin 2 years ago