Vista combinada Visión Plana Vista de árbol
Discusiones [ Anterior | Siguiente ]
toggle
Jack Bakker
get connection from c3p0
6 de septiembre de 2012 19:04
Respuesta

Jack Bakker

Ranking: Liferay Master

Mensajes: 604

Fecha de incorporación: 3 de enero de 2010

Mensajes recientes

any way to get a connection from c3p0 from in a portlet ?
Christianto Sahat
RE: get connection from c3p0
6 de septiembre de 2012 20:10
Respuesta

Christianto Sahat

Ranking: Regular Member

Mensajes: 175

Fecha de incorporación: 24 de septiembre de 2007

Mensajes recientes

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() ?
Jack Bakker
RE: get connection from c3p0
7 de septiembre de 2012 6:30
Respuesta

Jack Bakker

Ranking: Liferay Master

Mensajes: 604

Fecha de incorporación: 3 de enero de 2010

Mensajes recientes

how the heck did I miss that after all these years...

humble thanks
Jack Bakker
RE: get connection from c3p0
7 de septiembre de 2012 6:41
Respuesta

Jack Bakker

Ranking: Liferay Master

Mensajes: 604

Fecha de incorporación: 3 de enero de 2010

Mensajes recientes

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 ?
Jack Bakker
RE: get connection from c3p0
7 de septiembre de 2012 8:18
Respuesta

Jack Bakker

Ranking: Liferay Master

Mensajes: 604

Fecha de incorporación: 3 de enero de 2010

Mensajes recientes

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 ?
David H Nebinger
RE: get connection from c3p0
7 de septiembre de 2012 10:59
Respuesta

David H Nebinger

Ranking: Liferay Legend

Mensajes: 7027

Fecha de incorporación: 1 de septiembre de 2006

Mensajes recientes

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...
Jack Bakker
RE: get connection from c3p0
8 de septiembre de 2012 9:09
Respuesta

Jack Bakker

Ranking: Liferay Master

Mensajes: 604

Fecha de incorporación: 3 de enero de 2010

Mensajes recientes

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
David H Nebinger
RE: get connection from c3p0
8 de septiembre de 2012 10:03
Respuesta

David H Nebinger

Ranking: Liferay Legend

Mensajes: 7027

Fecha de incorporación: 1 de septiembre de 2006

Mensajes recientes

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.