Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
How to use connection pooling in portlet?
How does liferay service builder supports connection pooling?
If it does not, How can we define for the custom portlet.
If it does not, How can we define for the custom portlet.
By default it uses Liferay's connection pool. You don't need to do anything special for that to work.
How can we then increase or decrease the pool size?
or any other modifications, if required?
or any other modifications, if required?
Liferay by default comes with c3po as default provider . But you can change it to DBCP or other check below properties in portal-ext.
Default pool size and other details you can get it from below properties
#
# 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=tomcatDefault 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
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?
Now I have to implement connection pooling for the database referred by the portlet. So, What should be done?
Thanks for the link..
but it will be great if someone can share a solution that can do connection pooling using ext-spring.xml
but it will be great if someone can share a solution that can do connection pooling using ext-spring.xml
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>
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
becoz of which i get nullPointerexception because there is no entry.
If I replace this file manually in the server, then it works fine.
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.