eclipse jpa

26
© 2008 by Gordon Yorke made available under the EPL v1.0 | March 20, 2008 | Eclipse JPA Gordon Yorke EclipseLink Architecture Committee Member, EclipseLink Core Technical Lead, JPA 2.0 Expert Group Member [email protected]

Upload: junior

Post on 03-Feb-2016

63 views

Category:

Documents


1 download

DESCRIPTION

Eclipse JPA. Gordon Yorke EclipseLink Architecture Committee Member, EclipseLink Core Technical Lead, JPA 2.0 Expert Group Member [email protected]. What you will learn. Eclipse Persistence Services Project (EclipseLink) Components Focus on EclipseLink JPA - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Eclipse JPA

© 2008 by Gordon Yorke made available under the EPL v1.0 | March 20, 2008 |

Eclipse JPA

Gordon YorkeEclipseLink Architecture Committee Member,EclipseLink Core Technical Lead,JPA 2.0 Expert Group [email protected]

Page 2: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

What you will learn

• Eclipse Persistence Services Project (EclipseLink) Components

• Focus on EclipseLink JPA Constructing a Persistence Unit Developing with Dali Deployments

Java SE, Java EE

Usage for RCP EclipseLink Extensions

Page 3: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

Eclipse Persistence Services

• Eclipse runtime project Nicknamed “EclipseLink” Currently Incubating in Technology Project

Page 4: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

What is EclipseLink

• Based upon product with 12 years of commercial usage • First comprehensive open source persistence solution

EclipseLink JPA: Object-Relational EclipseLink MOXy: Object-XML EclipseLink SDO: Service Data Objects EclipseLink EIS: Non-Relational using JCA EclipseLink DBWS: Database Web Services

Page 5: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

EclipseLink…

• Shared infrastructure• Easily share the same domain model with multiple persistence

technologies• Leverage metadata for multiple services• Providing enterprise data access and manipulation services to the

Eclipse Ecosystem

Page 6: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

JDBC

Eclipse Persistence Services (EclipseLink)

JPA MOXy SDO DBWS EIS

Java SE, Java EE, SCA, Spring, OSGi

Legacy SystemsXML

Packaged Apps

JCA

RelationalDatabases

Page 7: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

Why EclipseLink JPA

• JPA 1.0 compliant implementation• JPA 2.0 in development• Any JDBC/SQL compliant database

Database specific support for Oracle, Derby, MySQL, SQLServer, PostgreSQL and more.

• Extensible and pluggable• Key infrastructure:

Query Framework, Mapping, …

• many valuable advanced features Caching, locking, dynamic enhancement (weaving) …

Page 8: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

The JPA Specification

• Simple configuration by exception• Extensive use of annotations• XML configuration available

Page 9: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

ORM

• Mappings @Embeddables

multiple objects but data in same table @Basic/@Id

Simple types mapping to single columns (ie. int, String) @Lob

Binary based data (ie. Images) @OneToOne, @ManyToOne

References to single target object. @OneToMany, @ManyToMany

Collections and Maps

• Class Inheritance All classes in single table Extended fields in separate tables

Page 10: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

EntityManager

• Contains the lifecycle APIs for the Entities persist(), remove(), merge()

• Contains management APIs for local transactions getTransaction().begin(), getTransation().rollback();

• Contains management APIs for Persistence Context clear()

• Source for Queries createQuery(), createNativeQuery(), find(), refresh()

• Optimistic database locking lock()

• Central interface point for JPA

Page 11: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

Persistence Context

• Set of objects tracked for changes by Persistence Provider• Objects enter Persistence Context through EntityManager APIs • Has two life expectancies

transactional – entities are no longer tracked at end of transaction extended – entities are tracked for life of Persistence Context unless

cleared.

• Persistence Context ≈ EntityManager Except transactional PC will be propagated to multiple EMs within

Container Managed environment

• Changes will be written at end of transaction or on ‘flush’ call.

Page 12: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

Queries

• Dynamic or statically defined (named queries)• Criteria using JP QL (object based query language)• Native SQL support (when required)• Named parameters bound at execution time• Pagination and ability to restrict size of result• Single/multiple-entity results, data projections• Bulk update and delete operation on an entity• Standard hooks for vendor-specific hints

Page 13: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

How to use it

• Create Entities and Map Simple POJOs annotations or XML Database can be pre-existing Generate table definitions later

• Package into Persistence Unit Lots of options

Easiest into .jar OSGi bundle support in development

• Dali Tooling for mapping and packaging persistence unit

Page 14: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

The Persistence Unit .jar

• Domain model POJOs with or without annotations Each entity must be designated as such and must have a PK

defined.

• META-INF/persistence.xml Deployment configuration

Optional xml based mapping config (META-INF/orm.xml)Can override annotations or provide full mapping config

Datasource name or JDBC connection propertieseclipselink.jdbc.driver, eclipselink.jdbc.connection-url

Entities to check for annotations

Page 15: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

Java SE vs Java EE

• Java SE deployment Application managed EntityManagers

Local transactions Persistence Context always ‘extended’

Java SE bootstrapping APIs -javaagent jvm argument for dynamic weaving

• Java EE Container managed EntityManager

PersistenceContext JTA transaction scoped or ‘extended’ @PersisteneContext annotation for injection

Application Managed EntityManager PersistenceContext always extended JTA though ‘joinTransaction’ APIs

Dynamic weaving automatic

Page 16: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

Inside Eclipse Rich Client

• Referenced library or OSGI OSGi EclipseLink bundles in development

http://wiki.eclipse.org/EclipseLink/Development/OSGi_Proof_of_Concept

• Application managed EntityManagers Local transactions Persistence Context always ‘extended’

• Java SE bootstrapping APIs• Static weaving

Page 17: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

Demo

• Persistence Enable a Rich Client through bundles Tools,

Dali EclipseLink

Troubleshooting Check that the Persistence Unit Bundle is included in your launch Dali sets Persistence Unit name to project name by default make

sure it matches the name in ComicsModel.java

Page 18: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

EclipseLink JPA Extensions

• Weaving Lazy loading all non PK fields Performance options - change tracking, batch writing, batch reading

• Mappings @BasicMap, @BasicCollection, @PrivateOwned, @JoinFetch @Converter, @TypeConverter, @ObjectTypeConverter

• @NamedStoredProcedureQuery IN/OUT/INOUT parameters, multiple cursor results

• Extensions supported through annotations and XML • Query hints

refreshing, locking, parameter binding, database platform hints …

Page 19: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

Extensions - Locking

• Data Locking policies Optimistic: Numeric, Timestamp, All fields, Selected fields,

Changed field Pessimistic

Page 20: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

Extensions - Entity Caching

• Entity caching L2 shared across transactions/users Coordination in a clustered deployment

• Application specific configuration Caching: per Entity or per Persistence Unit

eclipselink.cache.shared(default|<entity>)

Cache Type and Size: Weak, Soft-Weak, Full, None* eclipselink.cache.type(default|<entity>)

Expiration/Invalidation Time to live, Time of day, API

Coordination (cluster-messaging) Messaging: JMS, RMI, RMI-IIOP, … Mode: SYNC, SYNC+NEW, INVALIDATE, NONE

Page 21: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

Performance and Tuning

• Highly configurable and tunable Principle: minimize and optimize database calls Enable application specific tuning

• Flexibility allows efficient business models and relational schemas to be used

• Leverages underlying performance tuning features Java, JDBC and the underlying database technology Batch Reading, Batch Writing, Joined Reading, etc…

Page 22: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

DEMO

• Extensions in action

Page 23: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

EclipseLink in the Eclipse Ecosystem

• Provide an Eclipse persistence solution easily consumable by any project

Storage of metadata in RDBMS, XML, EIS XML Messaging infrastructure

• Eclipse Projects Dali JPA Tooling Project Teneo to use EclipseLink for EMF model persistence Maya for storage of deployment configuration SOA Project for EclipseLink SDO

Page 24: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

Where are we going?

• Delivery of 1.0M5-incubation milestone • 1.0 Release Planed for June 2008• Specifications: JPA2.0, JAXB 2.0, SDO 2.1• OSGi packaging and usage examples• Database Web Services (DBWS)• Data Access Service (DAS) - SDO with JPA

Page 25: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

How can you get involved?

• Users The 1.0M5-incubation milestone is now available Try it out and provide feedback File bug reports and feature requests

• Contributors Contribute to roadmap discussions Bug fixes

• Committers Very interested in growing committer base

Page 26: Eclipse JPA

Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0

More Information

• www.eclipse.org/eclipselink• Newsgroup: eclipse.technology.eclipselink• Wiki: wiki.eclipse.org/EclipseLink• Mailing Lists:

[email protected] [email protected]

• Blogs Committer Team blog: eclipselink.blogspot.com