osgi persistence with eclipselink

22
<Insert Picture Here> OSGi Persistence Shaun Smith

Upload: shaun-smith

Post on 19-May-2015

10.112 views

Category:

Economy & Finance


0 download

DESCRIPTION

A presentation on the use of EclipseLink as a JPA, JAXB, or SDO persistence provider in OSGi. Equinox specific extensions for JPA byte code weaving are also described.

TRANSCRIPT

Page 1: OSGi Persistence With EclipseLink

<Insert Picture Here>

OSGi PersistenceShaun Smith

Page 2: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 2

OSGi Persistence

• A core need for any enterprise Java application is persistence, e.g.:• Data maintained in a relational database• XML data maintained in files or exchanged with other

systems

• Persistence frameworks and standards designed for Java SE and EE are not typically OSGi compatible

• EclipseLink provides a set of high performance and scalable Java persistence services for OSGi

Page 3: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 3

Java Persistence: The Problem Space

Customer

id: intname: StringcreditRating: int

CUST

ID NAME C_RATING

<customer id=“…”> <name>…</name> …</contact-info></customer>

Relational

XML

Java

Page 4: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 4

Java Persistence Standards

• Object-Relational: Java Persistence API (JPA)• JPA 1.0 part of EJB 3.0 standard (JSR 220)• JPA 2.0 independent standard (JSR 317)

• Object-XML: Java Architecture for XML Binding (JAXB)• JAXB 2.x standardized in JSR 222

• Object-XML: Service Data Objects• SDO 2.1.1 standardized in JSR 235

Page 5: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 5

DBWSDBWS

SDOSDO

EISEIS

MOXyMOXy

JPAJPA

XML Data Legacy SystemsDatabases

Java SEJava SE Java EEJava EE OSGiOSGi SpringSpring

EclipseLink Architecture

Page 6: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 6

EclipseLink Background

• EclipseLink • Official name "Eclipse Persistence Services Project"• Founding Eclipse Runtime Project member

• Lead by Oracle• Founded upon contribution of full TopLink source• Code base with 12 years of commercial usage • First comprehensive open source persistence solution

Page 7: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 7

EclipseLink Distributions

• Eclipse• Oracle

• TopLink 11g• WebLogic Server

• Sun GlassFish v3 (SunAS)• Replaces TopLink Essentials (JPA

2.0 Reference Implementation)

• Spring Source• Spring Framework• Spring OSGi Bundle Repository

• JOnAS Application Server 5.1

Page 8: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 8

EclipseLink JPA

• JPA 1.0 compliant implementation • Delivering the JPA 2.0 Reference Implementation• Java EE, Java SE, Web, Spring, and OSGi• Any JDBC/SQL compliant database• Extensible and pluggable• Schema generation• Key infrastructure:

• Caching, Locking, Query Framework, Mapping, …

• … plus many valuable advanced features

Page 9: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 9

EclipseLink MOXy

• Provides complete Object-XML mapping• Allows developers to work with XML as objects• Efficiently produce and consume XML

• Supports Object-XML binding standard - JAXB • Provides external mapping file for complete control on

how objects are mapped

XML Datadomainmodel

Page 10: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 10

EclipseLink SDO

• SDO 2.1 provides the ability to:• Generate Java SDO classes (static SDOs) from an XML

Schema.• Generate SDO Types and Properties at runtime from an XML

Schema to create dynamic SDOs.• Generate an XML schema that corresponds to the types and

properties of an SDO model.• This allows XML payloads in, for example, web services to

include the schema that they conform to making the payload contents fully self describing.

• Capture and marshal to XML the set of changes made to an SDO object graph in an SDO Change Summary.

Page 11: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 11

EclipseLink OSGi Packaging

• EclipseLink is available as a set of OSGi bundles:• JPA

• org.eclipse.persistence.jpa—JPA implementation• org.eclipse.persistence.antlr—JPQL parsing• org.eclipse.persistence.asm—Byte code weaving

• MOXy JAXB• org.eclipse.persistence.moxy—OXM/JAXB implementation

• SDO• org.eclipse.persistence.sdo—SDO implementation

• Core (used by all persistence services)• org.eclipse.persistence.core—shared infrastructure

Page 12: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 12

OSGi Persistence Goal

• Support usage of standard APIs• javax.persistence.Persistence.createEntityManagerFactory(..)• javax.xml.bind.JAXBContext.newInstance(..)• commonj.sdo.HelperProvider

• Support modular packaging• E.g., domain model bundle(s), meta-data bundle, provider

bundles

• Decouple application from provider• Use JPA resolution to find suitable provider• Use JPA standard <provider> tag in persistence.xml to

identify specific provider—no provider specific require-bundle or import-package

Page 13: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 13

OSGi Persistence Challenges

• JPA• javax.persistence.Persistence SPI scans classpath for providers

• Provider needs access to domain model classes and application resources

• Needs access to JDBC driver (addressed by RFC 122)

• JAXB• Spec SPI does not support registration of providers

• Provider needs access to domain model classes and application resources

• Spec supports passing domain model classloader

• SDO• Spec hardwires provider class and package—doesn't support

multiple providers.

Page 14: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 14

JPA—Bootstrap Problem

• Persistence finds providers by loading all javax.persistence.spi.PersistenceProvider.xml files on classpath—but in OSGi it can’t see any.

javax.persistence

Eclipselink JPA

PersistenceProvider.xml

Persistence

requires

Page 15: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 15

JPA—Service Based Solution

• OSGi aware javax.persistence bundle that allows providers to register a persistence provider service.

• When a provider bundle is started it registers with javax.peristence

• When javax.persistence.Persistence is asked for a persistence unit it can ask registered providers to supply it.

javax.persistence

PersistenceProvider

register Providers

Eclipselink JPA

Page 16: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 16

JPA—Resource Access Problem

• EclipseLink’s Persistence Provider can’t see persistence.xml, orm.xml, or Entities in PU bundle. Eclipselink

JPA

persistenceunit bundle

persistence.xmlorm.xml,…

Page 17: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 17

JPA—Extender Pattern Solution

• EclipseLink JPA uses extender pattern to identify persistence unit bundles.

• EclipseLink keeps track of what persistence units are associated with what bundles (and what classloaders)

persistenceunit bundle

persistence.xmlorm.xml,…

bundle event

OSGi

Eclipselink JPA

Page 18: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 18

Demo

Page 19: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 19

EclipseLink Weaving Support

• Uses (ASM) to introduce additional functionality into the ‘POJO’ domain classes

• Used for • M:1 and 1:1 lazy fetching

• Fetch Groups

• Change Tracking

• State Caching

• Use is Optional (used by default when possible)• Static weaving also supported

• Weaving of .class files before deployment

• Dynamic weaving supported in Equinox through Adaptor Hook framework

Page 20: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 20

More Problems and Solutions

• JAXB OSGi • Support usage of standard APIs

javax.xml.bind.JAXBContext.newInstance(..)• Support modular packaging

E.g., domain model bundle(s), meta-data bundle, provider No dependency on specific provider

• JAXB SPI, unlike JPA, does not have a provider resolution mechanism that is OSGi friendly

• Application must explicitly depend on specific provider

• SDO OSGi Support usage of standard commonj.sdo.HelperProvider

• Application must use provider specific HelperProvider

Page 21: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 21

Future Plans and Goals

• Investigate further bundle splitting• As required by usage scenarios

• Participate on development of OSGi RFC 143 JPA Integration• Weaving• Container vs. non-container API• JPA packaging configurations

• Participate on JAXB and SDO expert groups to better support OSGi

• Usability• Documentation and Examples

Page 22: OSGi Persistence With EclipseLink

OSGi Persistence with EclipseLink | © 2009 Oracle; made available under the EPL v1.0 22

Summary

• OSGi presents challenges when trying to use many frameworks built for Java SE/EE environments.

• Before you commit to a framework you must evaluate whether it is OSGi friendly.

• EclipseLink is the only comprehensive persistence framework shipping with support for OSGi!