<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Free practice test , mock test, driving test, interview questions &#187; Sharing C3p pool</title>
	<atom:link href="http://www.skill-guru.com/blog/tag/sharing-c3p-pool/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.skill-guru.com/blog</link>
	<description>Find free mock and practice test, create and sell tests</description>
	<lastBuildDate>Mon, 16 Jan 2012 16:53:10 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Spring Application and Jforum Integration – Sharing same c3p pool</title>
		<link>http://www.skill-guru.com/blog/2009/08/03/spring-application-and-jforum-integration-%e2%80%93-sharing-same-c3p-pool/</link>
		<comments>http://www.skill-guru.com/blog/2009/08/03/spring-application-and-jforum-integration-%e2%80%93-sharing-same-c3p-pool/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 17:23:35 +0000</pubDate>
		<dc:creator>smitha</dc:creator>
				<category><![CDATA[Programming / tutorials]]></category>
		<category><![CDATA[c3p pool configuration]]></category>
		<category><![CDATA[JForum integration]]></category>
		<category><![CDATA[Sharing C3p pool]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.skill-guru.com/blog/?p=242</guid>
		<description><![CDATA[Sharing C3p pool, c3p pool configuration,JForum integration]]></description>
			<content:encoded><![CDATA[<p>I hope you have gone through my previous blog about Jforum integration. There I have explained integration of Jforum into a spring / jsf application.</p>
<p>After integration the main problem was the database connectivity. My spring application was using a c3p pool datasource and the Jforum was also creating c3p pool and datasources to connect to db. As I had all tables (both Jforum and my application tables) in same db, it was not appropriate to have 2 pools for same db by same application.</p>
<p><span id="more-242"></span></p>
<p>I had following in my spring’s applicationContext.xml file:</p>
<p><strong> </strong><strong>&lt;bean id=&#8221;dataSource&#8221; destroy-method=&#8221;close&#8221;&gt;</strong></p>
<p><strong>&lt;property name=&#8221;driverClass&#8221; value=&#8221;${db.driverClass}&#8221;/&gt;</strong></p>
<p><strong>&lt;property name=&#8221;jdbcUrl&#8221; value=&#8221;${db.url}&#8221;/&gt;</strong></p>
<p><strong>&lt;property name=&#8221;user&#8221; value=&#8221;${db.username}&#8221;/&gt;</strong></p>
<p><strong>&lt;property name=&#8221;password&#8221; value=&#8221;${db.password}&#8221;/&gt;</strong></p>
<p><strong>&lt;property name=&#8221;minPoolSize&#8221; value=&#8221;2&#8243;/&gt;</strong></p>
<p><strong>&lt;property name=&#8221;maxPoolSize&#8221; value=&#8221;10&#8243;/&gt;</strong></p>
<p><strong>&lt;property name=&#8221;breakAfterAcquireFailure&#8221; value=&#8221;false&#8221;/&gt;</strong></p>
<p><strong>&lt;property name=&#8221;acquireRetryAttempts&#8221; value=&#8221;3&#8243;/&gt;</strong></p>
<p><strong>&lt;property name=&#8221;idleConnectionTestPeriod&#8221; value=&#8221;300&#8243;/&gt;</strong></p>
<p><strong>&lt;/bean&gt;</strong></p>
<p>Spring initializes this pool when application loads. The JForum uses <strong>com.jforum.C3P0PooledConnection</strong>class to create pool for mysql db. It has <strong>init()</strong> method which create the pool and initiates <strong>ComboPooledDataSource </strong>intstance. JForum then uses it throughout the life cycle.</p>
<p>My goal was to make JForum to use spring initiated pool.</p>
<p>It can be done as follows:</p>
<p>Create a class implementing <strong>ApplicationContextAware interface</strong>.</p>
<p>As below:</p>
<p><strong>import org.springframework.beans.BeansException;</strong></p>
<p><strong>import org.springframework.context.ApplicationContext;</strong></p>
<p><strong>import org.springframework.context.ApplicationContextAware;</strong></p>
<p><strong>public class SpringApplicationContext implements ApplicationContextAware {</strong></p>
<p><strong>private static ApplicationContext <em>CONTEXT</em>;</strong></p>
<p><strong>public void setApplicationContext(ApplicationContext context) throws BeansException {</strong></p>
<p><strong><em>CONTEXT</em> = context;</strong></p>
<p><strong></strong></p>
<p><strong>public static Object getBean(String beanName) {</strong></p>
<p><strong>return <em>CONTEXT</em>.getBean(beanName);</strong></p>
<p><strong>}</strong></p>
<p><strong>}</strong></p>
<p>Using this, we should be able to get the spring managed beans, which spring initializes during startup.   Calling <strong>getBean()</strong> method and sending it bean id as argument, we can get the spring managed instance.</p>
<p>And now replace the <strong>init()</strong> method of <strong>net.jforum. C3P0PooledConnection</strong> like below:</p>
<p><strong>public void init() throws Exception</strong></p>
<p><strong>{ </strong></p>
<p><strong>ds =(ComboPooledDataSource)  SpringApplicationContext.<em>getBean</em>(&#8220;dataSource&#8221;);</strong></p>
<p><strong>System.<em>out</em>.println(&#8220;datasource ==&gt;&#8221;+ds); </strong></p>
<p><strong>}</strong></p>
<p>That’s it. You are done. Now JSF uses the spring’s c3p pool.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.skill-guru.com/blog/2009/08/03/spring-application-and-jforum-integration-%e2%80%93-sharing-same-c3p-pool/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

