java - EclipseLink JPA 2.1 User supplied connection -
i use eclipselink jpa engine. using subclass of java.sql.connection , know if can force eclipselink use connection. set connection object programmatically.
something like
myconnection conn = new myconnection(jdbc_url, usr, pwd); entitymanagerfactory factory = persistence.createentitymanagerfactory(conn);
you can set custom connection programatically using following code:
map properties = new hashmap(); // configure internal eclipselink connection pool properties.put(jdbc_driver, "oracle.jdbc.oracledriver"); properties.put(jdbc_url, "jdbc:oracle:thin:@localhost:1521:orcl"); properties.put(jdbc_user, "user-name"); properties.put(jdbc_password, "password"); persistence.createentitymanagerfactory("unit-name", properties);
i found answer here after quick google search:
http://eclipse.1072660.n5.nabble.com/defining-persistence-xml-programatically-td2536.html
i dont believe there way force eclipselink connect using java.sql.connection
; not out of box @ least. make simple utility method pass in said connection , build properties map described above.
public map convertconnectiontoproperties(connection conn) { // mapping return themap; }
if take @ this link see
persistence.java
createentitymanagerfactory(string persistenceunitname) createentitymanagerfactory(string persistenceunitname, map properties)
that can take parameters. put; asking isn't possible without taking connection object , adjust return complies createentitymanagerfactory
can take in.
class myconnection { // code here public map converttomap() { // mapping return themap; } public string getpersistenceunitname() { return "some-name"; } }
and utilize this:
myconnection conn = new myconnection(jdbc_url, usr, pwd); entitymanagerfactory factory = persistence.createentitymanagerfactory(conn.getpersistenceunitname(), conn.converttomap());
Comments
Post a Comment