2

Could you please explain to me how to add a standalone c3pO or DBCP connection pool to my toplink-based JPA project?

I have a persistence.xml file, and everytime I want to query the database, I'm doing this:

EntityManagerFactory emf = this.getEntityManagerFactory();

// Surely using persistence.xml to set up the factory

EntityManager em = emf.createEntityManager(); ...

Where do I build the bridge between my external connection pool manager and Toplink? Any ideas or links are welcomed.

Regards, Jean

skaffman
  • 398,947
  • 96
  • 818
  • 769
Jean N.T.
  • 73
  • 1
  • 5

2 Answers2

0

I don't use Toplink so I didn't test this but, my understanding of various resources found over the net is that you'll need to provide an implementation of SessionCustomizer. In this implementation, use the JNDIConnector class to give a DataSource object (c3p0 implements the DataSource API) using the setDataSource(javax.sql.DataSource) method.

Adapt the sample from Working with a non JTA DataSource in Toplink Essentials.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • I really don't understand what to do. So blurry page for a beginner. Nevertheless, I created a SessionCustomizer class apart. Here is my customize() method: public void customize(Session session) throws Exception{ DataSource ds = DataSources.unpooledDataSource("myServerURL", "login", "pwd"); DataSource pooled = DataSources.pooledDataSource(ds); JNDIConnector conn = (JNDIConnector)session.getLogin().getConnector(); conn.setDataSource(pooled); conn.setLookupType(JNDIConnector.STRING_LOOKUP); } – Jean N.T. Apr 14 '10 at 10:25
  • @Jean Well, the problem is that I'm not using Toplink, that it is incredibly hard to find resources or even pointer to the documentation and, most important part, that I'm not even sure of what you're using exactly (is it Toplink Essentials?). Can you first confirm this? – Pascal Thivent Apr 14 '10 at 20:01
0

I really don't understand what to do. So blurry page for a beginner. Nevertheless, I have created a SessionCustomizer class apart. Here is my customize() method, using c3p0:

public void customize(Session session) throws Exception{ 
DataSource ds = DataSources.unpooledDataSource("myServerURL", "login", "pwd"); 
DataSource pooled = DataSources.pooledDataSource(ds); 
JNDIConnector conn = (JNDIConnector)session.getLogin().getConnector(); 
conn.setDataSource(pooled); 
conn.setLookupType(JNDIConnector.STRING_LOOKUP); 
}

I don't even think it's correct. I'm putting my connection infos in clear in code, really weird.

Secondly, in persistence.xml example from the link, they have put:

<non-jta-data-source>java:comp/env/jdbc/DefaultDS</non-jta-data-source>
   <class>sample.MyEntity</class>
   <properties>
     <property name="toplink.session.customizer" value="es.claro.commons.ds.DataSourceSessionCustomizer"/>
   </properties>

What should I put in mine, particularly for "non-jta-data-source" tag? Is there a way to put connection informations in that xml instead of in code?

Help.

Jean N.T.
  • 73
  • 1
  • 5