Page 1
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
2 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
Page 3
3 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
The Evolution of Java Persistence
Shaun Smith
[email protected]
@shaunMsmith
Page 4
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
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
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
7 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
MULTITENANCY
Page 8
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
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
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
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
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
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
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
15 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
DEMO-MULTITENANCY
Page 16
16 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
DOMAIN MODEL EXTENSIONS
Page 17
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
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
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
20 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
DEMO DOMAIN MODEL EXTENSIONS
Page 21
21 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
JPA-RS
Page 22
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
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
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
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
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
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
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
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
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
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
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
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
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
35 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
JAX-RS DEMO
Page 36
41 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
NOSQL PERSISTENCE
Page 37
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
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
44 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
Example MongoDB Mapped Entity
Page 40
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
46 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
Polyglot Persistence
• Relationships can span databases—and technologies!
Order Discount
Page 42
47 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
NOSQL DEMO
Page 43
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
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
50 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.