Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 335983 - Need to configure Gemini JPA with a data source.
Summary: Need to configure Gemini JPA with a data source.
Status: RESOLVED FIXED
Alias: None
Product: Gemini.JPA
Classification: RT
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 1.0.0 RC1   Edit
Assignee: Michael Keith CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-02-01 11:18 EST by Adrian Goerler CLA
Modified: 2011-06-10 13:35 EDT (History)
2 users (show)

See Also:
adrian.goerler: iplog+


Attachments
patch proposal (6.82 KB, patch)
2011-05-26 02:32 EDT, Eduard Bartsch CLA
adrian.goerler: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adrian Goerler CLA 2011-02-01 11:18:40 EST
Gemini JPA allows to configure an EMF using JDBC connection properties only. in some cases, however, it wouldbe preferable to pass in a preconfigured data source. 

I am suggesting to accept a data source using the standardized property 

javax.persistence.nonJtaDataSource.

E.g. 

DataSource dataSource = ...
EntityManagerFactoryBuilder emfBuilder = ...

Properties props = new Properties();
props.put("javax.persistence.nonJtaDataSource", dataSource);
[...]

EntityManagerFactory emf = emfBuilder.createEntityManagerFactory(props);


(A challenge could be to correctly track the life cylce of the data source).
Comment 1 Adrian Goerler CLA 2011-05-25 03:10:20 EDT
I actually don't believe any longer that Gemini JPA would need to track the life cycle of a data source handed in to the EMFBuilder.createEMF method (as proposed above):

The JPA Service Specification (OSGi Enterprise 4.2) Demands that the life cycle of the data source factory must be tracked for EMFs registered for complete persistence units (ยง127.4.7). But in the case of the EMFBuilder.createEMF method beeing used, the persistence unit would be incomplete and the hence Gemini JPA would not need to track the data source factory. 

So tracking the life cycle of the data source and hence of the EMF created by the EMFBuilder.createEMF methd would we the task of the caller of this method.
Comment 2 Eduard Bartsch CLA 2011-05-26 02:32:50 EDT
Created attachment 196630 [details]
patch proposal

I have created a patch that implements Adrian's proposal and also includes the test for this case.
Comment 3 Adrian Goerler CLA 2011-05-26 02:45:11 EDT
Hoping to see this in 1.0.
Comment 4 Michael Keith CLA 2011-05-27 16:19:53 EDT
Sure, as long as people are okay with the caveats to this feature:

The usual JDBC prop checking that EMFBuilder does against successive createEMF calls is not going to happen if no properties are passed in. This means that one could potentially make a first call and pass in a data source, then make a second call and pass in an entirely differently configured data source and the second call will appear to work even though it is using the first data source. (This case is supposed to fail.)

The reverse may also be true (although much less likely), that if the properties exist and do not equal each other the second call will fail even though the data sources passed in were exactly the same on both calls. (One could easily argue that this should be an error in any case.)

The data source tracking is entirely up to the caller since the caller is assuming the responsibility of obtaining and passing it in. The flip side is that there is no graceful way for Gemini JPA to stop providing the EMF service should the data source go away, since it has no way to discover or determine its disappearance.

In any case, thanks for the suggestions. I have merged in some changes, including the attached contribution.
Comment 5 Michael Keith CLA 2011-06-10 13:34:38 EDT
Added in RC2
Comment 6 Michael Keith CLA 2011-06-10 13:35:59 EDT
Marking as fixed