Polyglot Persistence with
OSGi
Combining relational databases
and NoSQL MongoDB with
EclipseLink
OSGi Community Event
Ludw...
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/Compo...
SQL Persistence Unit
• Plain JPA PU jar
• PU‘s must use same transaction strategy
<persistence-unit name="persistence-test...
NoSQL Persistence Unit

• EclipseLink NoSQL support for
– MongoDB
– OracleNoSQL

• Configure like SQL PU
<persistence-unit...
MongoDB Configuration
• Tell the PU it uses MongoDB
<property name="eclipselink.target-database"
value="org.eclipse.persis...
Mapping NoSQL Entities
• Add @NoSQL Annotation
@Entity
@NoSql(dataFormat = DataFormatType.MAPPED)
public class BMIRecord {...
Composite Persistence Unit
• Defines visible PU name
<persistence-unit name="persistence-composite" transactiontype="RESOU...
Composite PU MANIFEST:
Embedded-Artifacts:
medisite.eclipsecon.pu-sql-0.0.1.jar,
medisite.eclipsecon.pu-nosql-0.0.1.jar
Ex...
Summary
• No JTA transactions
• No referential integrity between DBs
• Not all Eclipselink features are supported:
Persist...
Further Information
• http://wiki.eclipse.org/EclipseLink/UserGui
de/JPA/Advanced_JPA_Development/Co
mposite_Persistence_U...
Questions ?

More on OSGi, Persistence and Cloud:
Tomorrow 11:15
TRESOR: The modular cloud - Building a domain specific
cl...
Upcoming SlideShare
Loading in...5
×

Polyglot Persistence with OSGi - Alexander Grzesik

932

Published on

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

Lightning Talk

ABSTRACT
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.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
932
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Polyglot Persistence with OSGi - Alexander Grzesik

  1. 1. Polyglot Persistence with OSGi Combining relational databases and NoSQL MongoDB with EclipseLink OSGi Community Event Ludwigsburg Eclipsecon 2013 Alexander Grzesik
  2. 2. Polyglot Persistence http://martinfowler.com/bliki/PolyglotPersistence.html
  3. 3. EclipseLink composite persistence unit Since 2.3 NoSQL SQL From: http://wiki.eclipse.org/EclipseLink/Examples/JPA/Composite Eclipsecon 2013 Polyglot Persistence with OSGi
  4. 4. 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
  5. 5. 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
  6. 6. 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
  7. 7. 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
  8. 8. 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
  9. 9. 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
  10. 10. 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
  11. 11. 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
  12. 12. 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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×