Polyglot Persistence with OSGi - Alexander Grzesik
Upcoming SlideShare
Loading in...5

Polyglot Persistence with OSGi - Alexander Grzesik



OSGi Community Event 2013 (http://www.osgi.org/CommunityEvent2013/Schedule) ...

OSGi Community Event 2013 (http://www.osgi.org/CommunityEvent2013/Schedule)

Lightning Talk

This Lightning talk shows an example how to use use an EclipseLink composite Persistence Unit in an OSGi Bundle to seamless combine a Relational Database and NoSQL MongoDB. Furthermore it gives some best practice how to use a JPA Persistence Unit with Blueprint.



Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

Polyglot Persistence with OSGi - Alexander Grzesik Polyglot Persistence with OSGi - Alexander Grzesik Presentation Transcript

  • Polyglot Persistence with OSGi Combining relational databases and NoSQL MongoDB with EclipseLink OSGi Community Event Ludwigsburg Eclipsecon 2013 Alexander Grzesik
  • Polyglot Persistence http://martinfowler.com/bliki/PolyglotPersistence.html
  • EclipseLink composite persistence unit Since 2.3 NoSQL SQL From: http://wiki.eclipse.org/EclipseLink/Examples/JPA/Composite Eclipsecon 2013 Polyglot Persistence with OSGi
  • SQL Persistence Unit • Plain JPA PU jar • PU‘s must use same transaction strategy <persistence-unit name="persistence-test-sql" transaction-type="RESOURCE_LOCAL"> <non-jta-data-source>jdbc/test</non-jta-data-source> • Class Mappings <class>medisite.eclipsecon.entities.sql.BMIUser</class> • Member PU setting <property name="eclipselink.composite-unit.member" value="true"/> • PU specific settings <property name="eclipselink.target-database" value="POSTGRESQL"/> … Eclipsecon 2013 Polyglot Persistence with OSGi
  • NoSQL Persistence Unit • EclipseLink NoSQL support for – MongoDB – OracleNoSQL • Configure like SQL PU <persistence-unit name="persistence-test-nosql" transaction-type="RESOURCE_LOCAL"> <class>medisite.eclipsecon.entities.nosql.BMIRecord</class> … <property name="eclipselink.composite-unit.member" value="true"/> Eclipsecon 2013 Polyglot Persistence with OSGi
  • MongoDB Configuration • Tell the PU it uses MongoDB <property name="eclipselink.target-database" value="org.eclipse.persistence.nosql.adapters.mongo. MongoPlatform"/> <property name="eclipselink.nosql.connection-spec" value="org.eclipse.persistence.nosql.adapters.mongo. MongoConnectionSpec"/> • Configure Connection <property name="eclipselink.nosql.property.mongo.host" value="localhost"/> <property name="eclipselink.nosql.property.mongo.port“ value="27017"/> <property name="eclipselink.nosql.property.mongo.db“ value="test"/> Eclipsecon 2013 Polyglot Persistence with OSGi
  • Mapping NoSQL Entities • Add @NoSQL Annotation @Entity @NoSql(dataFormat = DataFormatType.MAPPED) public class BMIRecord { @Basic private String name; @ElementCollection private List<BMIResult> bmiResults; @OneToOne() private BMIUser user; • Embeded entity @Embeddable @NoSql(dataFormat = DataFormatType.MAPPED) public class BMIResult { … Eclipsecon 2013 Polyglot Persistence with OSGi
  • Composite Persistence Unit • Defines visible PU name <persistence-unit name="persistence-composite" transactiontype="RESOURCE_LOCAL"> • Included Member PUs <jar-file>medisite.eclipsecon.pu-nosql-0.0.1.jar</jar-file> <jar-file>medisite.eclipsecon.pu-sql-0.0.1.jar</jar-file> • Composite PU setting <property name="eclipselink.composite-unit" value="true"/> • Settings for all PUs <property name="eclipselink.logging.level" value="FINEST"/> <property name="eclipselink.target-server" value="SunAS9"/> Eclipsecon 2013 Polyglot Persistence with OSGi
  • Composite PU MANIFEST: Embedded-Artifacts: medisite.eclipsecon.pu-sql-0.0.1.jar, medisite.eclipsecon.pu-nosql-0.0.1.jar Export-Package: medisite.eclipsecon.entities.sql;uses:="javax.persistence";versi on="0.0.1", medisite.eclipsecon.entities.nosql; uses:="org.eclipse.persistence.nosql.annotations,javax.persisten ce,medisite.eclipsecon.entities.sql";version="0.0.1" Import-Package: javax.persistence;version="[2.1,3)", org.eclipse.persistence.jpa;version="[2.5,3)", org.eclipse.persistence.nosql.adapters.mongo;version="[2.5,3)", org.eclipse.persistence.nosql.annotations;version="[2.5,3)", org.eclipse.persistence.platform.server.sunas;version="[2.5,3)", com.mongodb,… JPA-PersistenceUnits: persistence-test Meta-Persistence: META-INF/persistence.xml Eclipsecon 2013 Polyglot Persistence with OSGi
  • Summary • No JTA transactions • No referential integrity between DBs • Not all Eclipselink features are supported: Persistence Unit Properties for Composite Pus • Transparent combination of different databases • Use JPA API • Works as OSGi persistence bundle • Blueprint integration via Aries JPA Eclipsecon 2013 Polyglot Persistence with OSGi
  • Further Information • http://wiki.eclipse.org/EclipseLink/UserGui de/JPA/Advanced_JPA_Development/Co mposite_Persistence_Units • http://wiki.eclipse.org/EclipseLink/Example s/PolyglotPersistence • Contact me: mailto:alexander.grzesik@medisite.de Eclipsecon 2013 Polyglot Persistence with OSGi
  • Questions ? More on OSGi, Persistence and Cloud: Tomorrow 11:15 TRESOR: The modular cloud - Building a domain specific cloud platform with OSGi Eclipsecon 2013 Polyglot Persistence with OSGi