the evolution of java persistence in eclipselink: shaun smith

45
1 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. 1 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. The following is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracles products remains at the sole discretion of Oracle.

Upload: jaxconf

Post on 19-May-2015

1.191 views

Category:

Technology


0 download

DESCRIPTION

Data access today isn’t just about reading and writing from relational databases anymore. It’s also about mapping your objects to XML and to JSON for use in RESTful web services. It’s about being able to persist your objects in NoSQL databases and being able to cache them in data grids so you can scale out your application to hundreds of servers. The EclipseLink project is well known as an object-relational mapping framework and as the JPA 2.0 reference implementation in Java EE 6, but it is evolving to provide a comprehensive set of data services for Java developers building enterprise and cloud applications in Java EE, Java SE, and in OSGi. In this session we’ll dive into these new services and see how to build modern enterprise Java applications leveraging EclipseLink both in the back end for data persistence and on the front end to build RESTful services that support HTML5 clients.

TRANSCRIPT

Page 1: The Evolution of Java Persistence in EclipseLink: Shaun Smith

1 Copyright © 2011, Oracle and/or its affiliates. All rights reserved. 1 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

The following is intended to outline our general product direction. It is

intended for information purposes only, and may not be incorporated

into any contract. It is not a commitment to deliver any material, code,

or functionality, and should not be relied upon in making purchasing

decisions. The development, release, and timing of any features or

functionality described for Oracle’s products remains at the sole

discretion of Oracle.

Page 2: The Evolution of Java Persistence in EclipseLink: Shaun Smith

2 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Page 3: The Evolution of Java Persistence in EclipseLink: Shaun Smith

3 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

The Evolution of Java Persistence

Shaun Smith

[email protected]

@shaunMsmith

Page 4: The Evolution of Java Persistence in EclipseLink: Shaun Smith

4 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Software Evolution

• Computing architecture is constantly evolving:

Mainframe, client/server, web/thin client, mobile/apps, ...

• Current technologies with increasing adoption include:

– Cloud computing

– HTML 5

– NoSQL databases

• Java EE 7 is evolving to address many of these new

requirements

Page 5: The Evolution of Java Persistence in EclipseLink: Shaun Smith

5 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Evolutionary Pressures on Persistence

• Shared Services & Consolidation

– Multitenancy

• Mobile Clients

– JPA-RS

• Scaling/Elastic Capacity

– Data Partitioning

– NoSQL/Big Data/Fast Data

– Grid Caching

Page 6: The Evolution of Java Persistence in EclipseLink: Shaun Smith

6 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

EclipseLink Project

• Open Source Eclipse Project

– Founded with contribution of Oracle TopLink to Eclipse

Foundation

• Object-Relational: Java Persistence API (JPA)

– JPA 1.0 part of EJB 3.0 standard (JSR 220)

– JPA 2.0 standardized in JSR 317

– EclipseLink is JPA 2.0 & 2.1 Reference Implementation

• Object-XML: Java Architecture for XML Binding (JAXB)

– JAXB 2.2 Certified Implementation

Page 7: The Evolution of Java Persistence in EclipseLink: Shaun Smith

7 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

MULTITENANCY

Page 8: The Evolution of Java Persistence in EclipseLink: Shaun Smith

8 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Multitenancy

Wikipedia http://en.wikipedia.org/wiki/Multitenancy

• Multitenancy refers to a principle in software architecture

where a single instance of the software runs on a server,

serving multiple client organizations (tenants).

• Multitenancy is contrasted with a multi-instance

architecture where separate software instances (or

hardware systems) are set up for different client

organizations.

Page 9: The Evolution of Java Persistence in EclipseLink: Shaun Smith

9 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Application Development and the Cloud

• Past

– Single Tenant or non-Tenant Applications

– Dedicated application instance and database

• Today..Tomorrow

– Support multiple tenants

– Support extensibility (custom fields per tenant)

– Support various deployment architectures

• Dedicated or shared application instances

• Dedicated or shared databases

Page 10: The Evolution of Java Persistence in EclipseLink: Shaun Smith

10 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Multitenant Topologies

Application

Dedicated Shared

Da

tab

as

e

Dedicated

Shared

1 2 3

T1 T2 T3 T1 T2 T3

1 2 3

3

T1 T2 T3

2 1

T1 T2 T3

3 2 1

Note: Single application deployed to support various MT architectures

Page 11: The Evolution of Java Persistence in EclipseLink: Shaun Smith

11 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Multitenant Topologies

Application

Dedicated Shared

Da

tab

as

e

Dedicated

Shared

1 2 3

T1 T2 T3 T1 T2 T3

1 2 3

3

T1 T2 T3

2 1

T1 T2 T3

3 2 1

Note: Single application deployed to support various MT architectures

Page 12: The Evolution of Java Persistence in EclipseLink: Shaun Smith

12 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

In the beginning…

• Application dedicated for single tenant

• All rows available to all queries

PLAYER

ID VERSION F_NAME L_NAME LEAGUE

1 1 John Doe HTHL

2 3 Jane Doe OSL

@Entity

public class Player {

Page 13: The Evolution of Java Persistence in EclipseLink: Shaun Smith

13 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Multitenant: SINGLE_TABLE

• Simple configuration: Annotation or XML

• Flexible tenant identifier support

• EclipseLink augments generated SQL

PLAYER

ID VERSION F_NAME L_NAME LEAGUE

1 1 John Doe HTHL

2 3 Jane Doe OSL

@Entity

@Multitenant(SINGLE_TABLE)

@TenantDiscriminatorColumn(name=“league-id”, columnName=“LEAGUE”)

public class Player {

Page 14: The Evolution of Java Persistence in EclipseLink: Shaun Smith

14 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Multitenant: TENANT_PER_TABLE

• Simple configuration: Annotation or XML

• EclipseLink queries table based on tentant identifier

@Entity

@Multitenant(TABLE_PER_TENANT)

public class Player {

HTHL.PLAYER

ID VERSION F_NAME L_NAME

1 1 John Doe

OSL.PLAYER

ID VERSION F_NAME L_NAME

2 3 Jane Doe

Page 15: The Evolution of Java Persistence in EclipseLink: Shaun Smith

15 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

DEMO-MULTITENANCY

Page 16: The Evolution of Java Persistence in EclipseLink: Shaun Smith

16 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

DOMAIN MODEL EXTENSIONS

Page 17: The Evolution of Java Persistence in EclipseLink: Shaun Smith

17 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Domain Model Extensions

• Storage and querying of extended properties

– Application developer enables extensions in entity

– Schema created with extension columns/table(s)

– Application Admin stores extension definitions

– Application instances made aware of extension definitions

– Application users make use of extensions

Employee

id

firstName

lastName

name

value

extensions *

Map<String, Object>

Page 18: The Evolution of Java Persistence in EclipseLink: Shaun Smith

18 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Flex Extensions @VirtualAccessMethods

public class Player{

… @Transient

private Map<String, Object> attributes;

public <T> T get(String attributeName) {

return (T) this.attributes.get(attributeName);

}

public Object set(String attributeName, Object value) {

return this.attributes.put(attributeName, value);

}

PLAYER

ID F_NAME L_NAME FLEX_1 FLEX_2

1 John Doe ‘R’ ’22’

2 Jane Smith ‘NONE’

Page 19: The Evolution of Java Persistence in EclipseLink: Shaun Smith

19 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Virtual Access Mappings <entity class="example.mysports.model.Player">

<attributes>

<basic name="penaltyMinutes" access="VIRTUAL"

attribute-type="java.lang.Integer">

<column name="flex_1"/>

</basic>

<basic name="position" access="VIRTUAL"

attribute-type="java.lang.String">

<column name="flex_2"/>

</basic>

</attributes>

</entity>

Page 20: The Evolution of Java Persistence in EclipseLink: Shaun Smith

20 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

DEMO DOMAIN MODEL EXTENSIONS

Page 21: The Evolution of Java Persistence in EclipseLink: Shaun Smith

21 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

JPA-RS

Page 22: The Evolution of Java Persistence in EclipseLink: Shaun Smith

22 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Project Avatar

HTML 5 browser

HTML & Java

hybrid application

Java application Java EE Cloud

JSON over

WebSocket/

Server Send

Events

Complete Solution for Dynamic Rich Clients

Page 23: The Evolution of Java Persistence in EclipseLink: Shaun Smith

23 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

JPA-RS: Building Block of Project Avatar

• Exposes JPA mapped entities over REST via JAX-RS

• Provides REST operations for persistence unit

• Content-Type and Accept-based content negotiation

– XML or JSON

• Client

– HTML5 with JavaScript (primary focus)

– JavaFX

REST JPA

GET, HEAD Find, Named Query, Meta-model

PUT, POST Persist, Merge

DELETE Remove

Page 24: The Evolution of Java Persistence in EclipseLink: Shaun Smith

24 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

JPA/JAX-RS: Current Programming Model

JAX-RS

JPA

Shop Persistence Unit

Customer Product Order

GET http://…/order/4

Page 25: The Evolution of Java Persistence in EclipseLink: Shaun Smith

25 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

JAX-RS with JPA Example – GET Invoice

public class InvoiceService {...

public Invoice read(int id) {

return null;

}

...

Page 26: The Evolution of Java Persistence in EclipseLink: Shaun Smith

26 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

JAX-RS with JPA Example – GET Invoice

@Stateless

public class InvoiceService {...

public Invoice read(int id) {

return entityManager.find(Invoice.class, id);

}

...

Page 27: The Evolution of Java Persistence in EclipseLink: Shaun Smith

27 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

JAX-RS with JPA Example – GET Invoice

@Path("/invoice")

@Stateless

public class InvoiceService {...

public Invoice read(int id) {

return entityManager.find(Invoice.class, id);

}

... http://[machine]:[port]/[web-context]/invoice/...

Page 28: The Evolution of Java Persistence in EclipseLink: Shaun Smith

28 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

JAX-RS with JPA Example – GET Invoice

@Path("/invoice")

@Stateless

public class InvoiceService {...

@GET

@Path("{id}")

public Invoice read(@PathParam("id") int id) {

return entityManager.find(Invoice.class, id);

}

... GET http://[machine]:[port]/[web-context]/invoice/4

Page 29: The Evolution of Java Persistence in EclipseLink: Shaun Smith

29 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

JAX-RS with JPA Example – GET Invoice

@Path("/invoice")

@Stateless

public class InvoiceService {...

@GET

@Path("{id}")

@Produces({"application/xml", "application/json"})

public Invoice read(@PathParam("id") int id) {

return entityManager.find(Invoice.class, id);

}

... Accept: application/json GET http://[machine]:[port]/[web-context]/invoice/4

Page 30: The Evolution of Java Persistence in EclipseLink: Shaun Smith

30 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

JPA-RS: Thin Server Architecture

JPA-RS

Shop PU

JPA

GET http://…/<pu-name>/<entity>/4

… PU

Page 31: The Evolution of Java Persistence in EclipseLink: Shaun Smith

31 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

JPA-RS: Building Block of Project Avatar

• Persistence Unit Operations

– /<root-uri>/<pu-name>/entity

– /<root-uri>/<pu-name>/query

– /<root-uri>/<pu-name>/metadata

• Supports invocation of @NamedQueries via HTTP

• Server-caching – EclipseLink clustered cache

• Dynamic Persistence also supported

– Entities defined via metadata – no Java classes required

– Enables persistence for HTML5/JavaScript apps

Page 32: The Evolution of Java Persistence in EclipseLink: Shaun Smith

32 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Client with Server Development

Client

Developer

Data Server

JPA-RS

config

Server

Developer

Java EE

dev

Client

HTML5

JavaScript

Native dev

Page 33: The Evolution of Java Persistence in EclipseLink: Shaun Smith

33 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

MySports – Java EE

ORACLE CONFIDENTIAL - INTERNAL

ONLY

Clients

Server

HTTP/S

MySports

JDBC JSF EJB JPA

Data

Page 34: The Evolution of Java Persistence in EclipseLink: Shaun Smith

34 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

MySports – JPA-RS Enabled

ORACLE CONFIDENTIAL - INTERNAL

ONLY

Clients Data

Server

MySports

JSF

EJB JPA JPA-

RS

HTTP/S JDBC

Page 35: The Evolution of Java Persistence in EclipseLink: Shaun Smith

35 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

JAX-RS DEMO

Page 36: The Evolution of Java Persistence in EclipseLink: Shaun Smith

41 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

NOSQL PERSISTENCE

Page 37: The Evolution of Java Persistence in EclipseLink: Shaun Smith

42 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

NoSQL Databases

• NoSQL (i.e., non-relational) database are increasingly

popular

• No standards

• Differing APIs and feature sets

• Some offer query language/API—some not

Page 38: The Evolution of Java Persistence in EclipseLink: Shaun Smith

43 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

EclipseLink NoSQL

• Support JPA access to NoSQL databases

– Leverage non-relational database support for JCA (and JDBC

when available)

• Define annotations and XML to identify NoSQL stored

entities (e.g., @NoSQL)

• Support JPQL subset for each

– Key principal: leverage what’s available

• Initial support for MongoDB and Oracle NoSQL.

• Support mixing relational and non-relational data in

single composite persistence unit (“polyglot persistence”)

Page 39: The Evolution of Java Persistence in EclipseLink: Shaun Smith

44 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Example MongoDB Mapped Entity

Page 40: The Evolution of Java Persistence in EclipseLink: Shaun Smith

45 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

MongoDB Query Examples

JPQL Queries:

Select o from Order o where o.totalCost > 1000

Select o from Order o where o.description like 'Pinball%‘

Select o from Order o join o.orderLines l where l.cost > :cost

Native Queries:

query = em.createNativeQuery("db.ORDER.findOne({\"_id\":\"" + oid + "\"})",

Order.class);

Order order = (Order)query.getSingleResult();

Page 41: The Evolution of Java Persistence in EclipseLink: Shaun Smith

46 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Polyglot Persistence

• Relationships can span databases—and technologies!

Order Discount

Page 42: The Evolution of Java Persistence in EclipseLink: Shaun Smith

47 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

NOSQL DEMO

Page 43: The Evolution of Java Persistence in EclipseLink: Shaun Smith

48 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Summary

• Java is evolving—and EclipseLink is evolving too!

– Tenant Isolation/Multitenancy

– JSON Binding

– JPA-RS

– NoSQL

– Polyglot Persistence

• EclipseLink is the center of innovation in Java

persistence

Page 44: The Evolution of Java Persistence in EclipseLink: Shaun Smith

49 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.

Provide Feedback, Get Involved!

User forums and lists at http://eclipse.org/eclipselink

Q & A

Page 45: The Evolution of Java Persistence in EclipseLink: Shaun Smith

50 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.