Post on 19-May-2015
description
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.
2 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
3 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
The Evolution of Java Persistence
Shaun Smith
shaun.smith@oracle.com
@shaunMsmith
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
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
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
7 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
MULTITENANCY
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.
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
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
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
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 {
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 {
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
15 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
DEMO-MULTITENANCY
16 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
DOMAIN MODEL EXTENSIONS
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>
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’
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>
20 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
DEMO DOMAIN MODEL EXTENSIONS
21 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
JPA-RS
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
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
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
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;
}
...
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);
}
...
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/...
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
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
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
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
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
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
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
35 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
JAX-RS DEMO
41 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
NOSQL PERSISTENCE
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
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”)
44 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
Example MongoDB Mapped Entity
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();
46 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
Polyglot Persistence
• Relationships can span databases—and technologies!
Order Discount
47 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
NOSQL DEMO
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
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
50 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.