How to use connection pooling in portlet?

thumbnail
Priyanka Dhingra, modified 12 Years ago. Liferay Master Posts: 501 Join Date: 12/20/11 Recent Posts
How does liferay service builder supports connection pooling?
If it does not, How can we define for the custom portlet.
thumbnail
Mika Koivisto, modified 12 Years ago. Liferay Legend Posts: 1519 Join Date: 8/7/06 Recent Posts
By default it uses Liferay's connection pool. You don't need to do anything special for that to work.
thumbnail
Priyanka Dhingra, modified 12 Years ago. Liferay Master Posts: 501 Join Date: 12/20/11 Recent Posts
How can we then increase or decrease the pool size?
or any other modifications, if required?
thumbnail
Jitendra Rajput, modified 12 Years ago. Liferay Master Posts: 875 Join Date: 1/7/11 Recent Posts
Liferay by default comes with c3po as default provider . But you can change it to DBCP or other check below properties in portal-ext.

 #
    # Liferay can use C3PO, DBCP, or Tomcat for connection pooling. See
    # com.liferay.portal.dao.jdbc.util.DataSourceFactoryBean for the actual
    # implementation. It is important to understand the strengths and weaknesses
    # of each provider so that you can choose the best one that fits your
    # deployment scenario. Provider specific properties can also be passed along
    # directly to the provider. For example, the property
    # "jdbc.default.acquireIncrement" is read by C3PO, and the property
    # "jdbc.default.maxActive" is read by DBCP.
    #
    # The default provider is C3PO.
    #

    jdbc.default.liferay.pool.provider=c3po
    #jdbc.default.liferay.pool.provider=dbcp
    #jdbc.default.liferay.pool.provider=tomcat


Default pool size and other details you can get it from below properties




 #
    # The following properties will be read by C3PO if Liferay is configured to
    # use C3PO in the property "jdbc.default.liferay.pool.provider". See
    # http://www.mchange.com/projects/c3p0/index.html#configuration for a list
    # of additional fields used by C3PO for configuring database connections.
    #
    jdbc.default.acquireIncrement=5
    jdbc.default.acquireRetryAttempts=3
    jdbc.default.acquireRetryDelay=1000
    jdbc.default.connectionCustomizerClassName=com.liferay.portal.dao.jdbc.pool.c3p0.PortalConnectionCustomizer
    jdbc.default.idleConnectionTestPeriod=60
    jdbc.default.maxIdleTime=3600
    jdbc.default.maxPoolSize=100
    jdbc.default.minPoolSize=10
    jdbc.default.numHelperThreads=10
    #jdbc.default.transactionIsolation=1


Note : This is for entire portal not specific to any portlet
thumbnail
Priyanka Dhingra, modified 12 Years ago. Liferay Master Posts: 501 Join Date: 12/20/11 Recent Posts
I have a requirement where my portlet uses a different database and liferay tables are ata different database. So, I configured the database for my portlet by adding ext-spring.xml and then putting the data-source name in my service builder..

Now I have to implement connection pooling for the database referred by the portlet. So, What should be done?
thumbnail
Jitendra Rajput, modified 12 Years ago. Liferay Master Posts: 875 Join Date: 1/7/11 Recent Posts
See if this thread can help you ..!!
thumbnail
Priyanka Dhingra, modified 12 Years ago. Liferay Master Posts: 501 Join Date: 12/20/11 Recent Posts
Thanks for the link..
but it will be great if someone can share a solution that can do connection pooling using ext-spring.xml
thumbnail
Kan Zhang, modified 12 Years ago. Junior Member Posts: 68 Join Date: 12/1/10 Recent Posts
Priyanka Dhingra:
Thanks for the link..
but it will be great if someone can share a solution that can do connection pooling using ext-spring.xml



Are you using the approach mentioned in here?: http://www.liferay.com/web/sten.martinez/blog/-/blogs/using-a-legacy-db-with-service-builder

If yes, then you should have a jndi name for your "legacy db" in ext-spring.xml similar to this:

<bean id="trainingDataSourceTarget" class="com.liferay.portal.spring.jndi.JndiObjectFactoryBean" lazy-init="true">
    <property name="jndiName">
        <value>jdbc/legacyDB</value>
    </property>
</bean>


And in ${your.portlet.name}/docroot/META-INF/context.xml, you can define your jndiName. When you define your jndi name you will be configuring your connection pool:

<context antijarlocking="true" antiresourcelocking="true">
    <resource name="jdbc/legacyDB" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="" password="" driverClassName="net.sourceforge.jtds.jdbc.Driver" url="jdbc:jtds:sqlserver://servername/databasename;domain=domainname" />
</context>


Don't forget, in your ${your.portlet.name}/docroot/WEB-INF/web.xml, you need to reference your jndiName:

<resource-ref>
    <res-ref-name>jdbc/legacyDB</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>
thumbnail
Priyanka Dhingra, modified 12 Years ago. Liferay Master Posts: 501 Join Date: 12/20/11 Recent Posts
Thanks this is what I was looking for.
But there is a problem, Whenever I deploy my code the {my-portlet}/META-INF/context.xml is blank after deployment, with just the following code in it
<context antiJARLocking="true" antiResourceLocking="true" />

becoz of which i get nullPointerexception because there is no entry.

If I replace this file manually in the server, then it works fine.