Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 365619 - Integrate with properties from Config Admin service
Summary: Integrate with properties from Config Admin service
Status: RESOLVED FIXED
Alias: None
Product: Gemini.JPA
Classification: RT
Component: Core (show other bugs)
Version: 1.0.0   Edit
Hardware: PC Windows 7
: P3 enhancement (vote)
Target Milestone: 1.1.0 M2   Edit
Assignee: Michael Keith CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-05 10:47 EST by Michael Keith CLA
Modified: 2013-01-07 12:12 EST (History)
4 users (show)

See Also:


Attachments
Simple bundle to get PU properties from the ConfigAdmin (10.07 KB, application/java-archive)
2012-06-29 12:35 EDT, Thomas Gillet CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Keith CLA 2011-12-05 10:47:09 EST
Some people would like to decouple the persistence configuration from the persistence unit bundle by storing some or all of the persistence properties in the config admin service. It would be nice to have an integration such that a given pid was specified in the persistence descriptor and Gemini JPA looked up the given config and incremented the descriptor with additional properties found there. Only then would it proceed to register the services, etc.
Comment 1 Cristiano Gaviao CLA 2012-03-05 16:22:10 EST
I'm one of those that want this feature. 
But in my opinion it would be valid only if the punit created using the CM properties were considered a PUnit complete, where EMF and Datasource lifecycles would be tracked...
Comment 2 Cristiano Gaviao CLA 2012-03-22 15:19:20 EDT
Mike, 
what is the name of PID ?
it will be a factory one ? 
what properties should be handled ?
Comment 3 Michael Keith CLA 2012-06-18 15:04:16 EDT
(In reply to comment #2)
> Mike, 
> what is the name of PID ?
> it will be a factory one ? 
> what properties should be handled ?

How about gemini.jpa.<unit-name> ?

Any properties in the config would override the same ones in the persistence descriptor, but would be overriden by properties passed in at runtime in the createEntityManagerFactory method on the builder. Make sense?
Comment 4 Thomas Gillet CLA 2012-06-29 12:34:38 EDT
I wrote something similar when Gemini first came out, so I post it here. Could give some ideas, or can be used as is before this enhancement is closed.

It's a quite simple bundle.
For each EMFB service found in the registry, a new EMF service is created and published in the registry as well.
Properties comes from the config admin (the PID is the bundle symbolic name, so "jpa.emfcreator").
Nothing is done if an EMF already exists so complete and incomplete units can be safely used together.

Only one set of properties can be provided, but it can be easily extended.
The advantage is that this bundle should work with any OSGi JPA implementation (no dependency on Gemini).

Sources are included.
Comment 5 Thomas Gillet CLA 2012-06-29 12:35:49 EDT
Created attachment 218098 [details]
Simple bundle to get PU properties from the ConfigAdmin
Comment 6 Cristiano Gaviao CLA 2012-07-03 09:27:55 EDT
After some experiments, I think that one good approach would be to implement ManagedServiceFactory, possibly in EclipseLinkOSGiProvider or PersistenceBundleExtender or in a new specific one. 

The managed service should be started at EclipseLinkOSGiProvider start() method.

That would given us the possibility to setup/modify a PU even without read any xml.
Comment 7 Michael Keith CLA 2012-08-29 15:08:27 EDT
Added the ability to create either an "incremental configuration" to specify persistence unit properties (such as driver props, etc), or a basic "standalone configuration" that contains enough information necessary to create a persistence unit without any XML descriptor in the persistence bundle.
Comment 8 Christoph Laeubrich CLA 2013-01-03 05:28:29 EST
(In reply to comment #7)
> "standalone configuration"
For some reason I can't ge the stand alone cfg working, I use the following config:
[ gemini.jpa.punit-1357206819390-0, location: initial@reference:file:../eclipse/gemini-jpa-1.1.0.RELEASE/org.eclipse.gemini.jpa_1.1.0.RELEASE.jar/ ]
 eclipselink.target-database = org.eclipse.persistence.platform.database.H2Platform
 eclipselink.weaving = false
 gemini.jpa.punit.bsn = my.bundle.name
 gemini.jpa.punit.classes = class1,class2,class3
 gemini.jpa.punit.excludeUnlistedClasses = true
 gemini.jpa.punit.name = company.db.0
 gemini.jpa.punit.refresh = false
 javax.persistence.jdbc.driver = org.h2.Driver
 javax.persistence.jdbc.password = somepassword
 javax.persistence.jdbc.url = jdbc:h2:/database
 javax.persistence.jdbc.user = someuser
 service.factoryPid = gemini.jpa.punit
 service.pid = gemini.jpa.punit-1357206819390-0

(this is a debug dump from the config admin service)

As you can see the configuration is bound to the gemini bundle, no error/warning occurs, but no EMF or EMFB is registered.

BTW: I would suggest to support for property gemini.jpa.punit.classes either a commaseparated string or an array of strings.
Comment 9 Michael Keith CLA 2013-01-07 12:12:56 EST
Laeubi,

Please enter issues as a separate bug. This one describes a feature enhancement and is completed/closed.

Thanks,
-Mike