Tribune

Home » Liferay Portal » English » 3. Development

Vista Combinata Vista Piatta Vista ad Albero
Discussioni [ Precedente | Successivo ]
toggle
Jack Bakker
get connection from c3p0
6 settembre 2012 19.04
Risposta

Jack Bakker

Punteggio: Liferay Master

Messaggi: 559

Data di Iscrizione: 3 gennaio 2010

Messaggi recenti

any way to get a connection from c3p0 from in a portlet ?
Christianto Sahat
RE: get connection from c3p0
6 settembre 2012 20.10
Risposta

Christianto Sahat

Punteggio: Regular Member

Messaggi: 175

Data di Iscrizione: 24 settembre 2007

Messaggi recenti

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 settembre 2012 6.30
Risposta

Jack Bakker

Punteggio: Liferay Master

Messaggi: 559

Data di Iscrizione: 3 gennaio 2010

Messaggi recenti

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

humble thanks
Jack Bakker
RE: get connection from c3p0
7 settembre 2012 6.41
Risposta

Jack Bakker

Punteggio: Liferay Master

Messaggi: 559

Data di Iscrizione: 3 gennaio 2010

Messaggi recenti

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 settembre 2012 8.18
Risposta

Jack Bakker

Punteggio: Liferay Master

Messaggi: 559

Data di Iscrizione: 3 gennaio 2010

Messaggi recenti

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 settembre 2012 10.59
Risposta

David H Nebinger

Punteggio: Liferay Legend

Messaggi: 6682

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

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 settembre 2012 9.09
Risposta

Jack Bakker

Punteggio: Liferay Master

Messaggi: 559

Data di Iscrizione: 3 gennaio 2010

Messaggi recenti

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 settembre 2012 10.03
Risposta

David H Nebinger

Punteggio: Liferay Legend

Messaggi: 6682

Data di Iscrizione: 1 settembre 2006

Messaggi recenti

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.