Fórumok

get connection from c3p0

thumbnail
Jack Bakker, módosítva 11 év-val korábban

get connection from c3p0

Liferay Master Bejegyzések: 978 Csatlakozás dátuma: 2010.01.03. Legújabb bejegyzések
any way to get a connection from c3p0 from in a portlet ?
thumbnail
Christianto Sahat, módosítva 11 év-val korábban

RE: get connection from c3p0

Regular Member Bejegyzések: 179 Csatlakozás dátuma: 2007.09.25. Legújabb bejegyzések
Jack Bakker:
any way to get a connection from c3p0 from in a portlet ?


Do you mean to get connection from Liferay's data source ?

How about :
InfrastructureUtil.getDataSource() ?
thumbnail
Jack Bakker, módosítva 11 év-val korábban

RE: get connection from c3p0

Liferay Master Bejegyzések: 978 Csatlakozás dátuma: 2010.01.03. Legújabb bejegyzések
how the heck did I miss that after all these years...

humble thanks
thumbnail
Jack Bakker, módosítva 11 év-val korábban

RE: get connection from c3p0

Liferay Master Bejegyzések: 978 Csatlakozás dátuma: 2010.01.03. Legújabb bejegyzések
InfrastructureUtil.getDataSource() does well to grab a connection from lportal db

however, my need here currently is to get a connection from a 2nd datasource (to another non-lportal database) where I have that 2nd datasource defined in META-INF/ext-spring in a 'services' project

ideas ?
thumbnail
Jack Bakker, módosítva 11 év-val korábban

RE: get connection from c3p0

Liferay Master Bejegyzések: 978 Csatlakozás dátuma: 2010.01.03. Legújabb bejegyzések
what I just did (and it seems to work) was:

I added to one of my *entityNameHere*LocalServiceImpl a new method:

public DataSource getDataSource(){
return *entityNameHere*Persistence.getDataSource();
}

then after regen of services, I call from in the portlet:

DataSource ds = *entityNameHere*LocalServiceUtil.getDataSource()

and then get a connection from the datasource ; I am using this to get connections for a JasperReports solution

is this safe, acceptable ?
thumbnail
David H Nebinger, módosítva 11 év-val korábban

RE: get connection from c3p0

Liferay Legend Bejegyzések: 14914 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
May work within the same portlet (so you're not crossing class loader boundaries), but I doubt it would work for other plugins.

You may want to take a look at the wiki. I think there was a recent wiki page update for using liferay SB code in a jasper report as a datasource...
thumbnail
Jack Bakker, módosítva 11 év-val korábban

RE: get connection from c3p0

Liferay Master Bejegyzések: 978 Csatlakozás dátuma: 2010.01.03. Legújabb bejegyzések
perhaps it is this one you are referring to

http://www.liferay.com/community/wiki/-/wiki/Main/How+to+Use+LiferayServiceBuilderClasses+in+JasperReports+and+IReport

wiki offers a useful approach for a JRBeanCollectionDataSource

in my case I have reports that also use implementations of the JRDataSource and others that require a sql.DataSource and some reports that use both at same time.

So far I am using the below to get a sql.DataSource which works

Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
DataSource ds = (DataSource) envCtx.lookup("jdbc/jasperConn");

but I want to use a connection pool c3p0 and config the pool through portal-ext.properties like we do for the lportal db
thumbnail
David H Nebinger, módosítva 11 év-val korábban

RE: get connection from c3p0

Liferay Legend Bejegyzések: 14914 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
I believe you can define your c3p0-wrapped datasource when defining in JNDI. Would give you c3p0 w/o worrying about portal-ext.properties setup...

The problem w/ the portal-ext.properties approach is that the portal really isn't going to create and/or manage your connection if you define it there. Properties would be available, but unless the Liferay core knew to create that datasource (like it does for lportal), it wouldn't get created nor used.