Eclipse JPA - EclipseCon Europe 2012

Download Report

Transcript Eclipse JPA - EclipseCon Europe 2012

Eclipse JPA
Gordon Yorke
EclipseLink Architecture Committee Member,
EclipseLink Core Technical Lead,
JPA 2.0 Expert Group Member
[email protected]
© 2008 by Gordon Yorke made available under the EPL v1.0 | March 20, 2008 |
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
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
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
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
Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0
Java SE, Java EE, SCA, Spring, OSGi
JPA
MOXy
DBWS
SDO
EIS
Eclipse Persistence Services (EclipseLink)
JCA
JDBC
Relational
Databases
XML
Packaged Apps
Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0
Legacy Systems
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) …
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
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
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
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.
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
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
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 properties
 eclipselink.jdbc.driver, eclipselink.jdbc.connection-url
 Entities to check for annotations
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
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
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
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 …
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
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
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…
Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0
DEMO
• Extensions in action
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
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
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
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
Eclipse JPA | © 2008 by Gordon Yorke; made available under the EPL v1.0