SlideShare a Scribd company logo
JEST: REST on OpenJPA Pinaki Poddar, PhD Java Persistence Evangelist [email_address]
Agenda Introduction to JEST Integration of REST and OpenJPA Resource Representation URI Syntax Transaction JEST in Action Conclusion  Q&A
JEST: REST on OpenJPA JEST is RESTful interaction with OpenJPA Runtime http JDBC XML/JSON Java Object Graph
 
JEST: REST on OpenJPA Deploy-and-Play  No annotation on persistent classes No browser plug-in  No client knowledge of persistent schema KISS: Keep It Short and Simple
JEST: Primary Use Cases Access  persistent object graph by language-neutral, domain-agnostic clients or Web Services Visualize  OpenJPA runtime internals via Web Browser-based Admin console Transact  with  any  OpenJPA application from language-neutral clients  without  violating REST principles
REST:  RE presentational  S tate  T ransfer C0 C0 C1’ C1’ S1 S2 S1 renders C1 modifies C2 renders Response 1 Request 2 Request 1 Response 2 @  rest State Transition 1 2 3 4 5 6
REST Principles Identifiable Resource ( URI ) based,  not  API-based  Document-oriented Resource Representation  XML, JSON, … Stateless Server Standard Communication Protocol HTTP
Java Persistence API Persistence framework for Java Objects mapped to Relational database EntityManagerFactory EntityManager Persistence Unit Persistence Context Second-Tier Caches (optional) Relational Database User Application Data Cache META-INF/persistence.xml Java Object Graph
JPA is Model-View-Controller for Persistence View Control Model /** * A persistent entity **/ @Entity public class   Actor  { @Id private  String  name ; } /** * Find Actor by name **/ public  Actor   findByName( String   name )  { EntityManager em = …; return  em.find( Actor . class , name); } POJO sees uses updates modifies Java Persistence API Relational Database
JPA:  access-detach-merge programming model C0 C0 C1’ C1’ em1 em2 renders C1 modifies C2 renders State Transition SELECT … detach find merge commit UPDATE/INSERT/DELETE … 1 2 3 5 6 4
REST and JPA: brothers separated at birth? Stateless Server Detached Transaction Identifiable Resource Persistent Identity Coherent Representation Persistent Closure Self-descriptive JPA 2.0 Metamodel REST JPA
JEST Resource Perisistent Object Graph Customizable Coherent
Customizable, Persistent Closure A  persistence context  as a graph  managed entity  as vertex persistent relation  as edge Persistent Closure  of an entity  x  is defined as set of entities  C(x)={e}   such that  e  is  reachable  from  x  in graph-theoretic sense. Every entity is reachable to itself,  by definition .  Customization is ability to define what is  reachable  at runtime. x a c1 b c2 d C(x) = {x, a, b, c1, c2, d} C(x) = {x, a, b, d} could be customized to and its complete closure C(x) = {x, b} or An object graph…
Identifiable Resource: URI for persistent object? Actor  p1 = em1.find ( Actor . class , “ John ”); Actor  p2 = em2.find ( Actor . class , “ John ”); name :” John ” hash :  56789 p1 name :” John ” hash :  56789 p2 p1.equals(p2) p1.hashCode()  == p2.hashCode() p1 != p2 public   class   Actor  { @Id String   name ; } Persistent Identity carries the notion that both  p1  and  p2 refer to the same database record. EntityManager EntityManager … Robert … John ACTOR
Customizable, Persistent Closure: State of the art JEST response contains customizable, persistent closure  JPA provides preliminary semantics on  customized  closure,  statically OpenJPA   FetchPlan  already provides rich syntax and semantics to customize closure,  dynamically  . Future JPA specification   will enhance support on this area.  This feature had been the most sought after user requirement during JavaOne 2010.
OpenJPA Fetch Plan  @Entity @FetchGroups ({ @FetchGroup ( name =&quot; OnlyName &quot;,  attributes ={ @FetchAttribute ( name =&quot; firstName &quot;), @FetchAttribute ( name =&quot; lastName &quot;) }) }) public   class  Actor { @Id private  String  id ; private  String  firstName ; private  String  lastName ; private  Gender  gender ; private  Date  dob ; @OneToOne private  Actor  partner ; @OneToMany private  Set<Movie>  movies ; // getters and setters }
JEST Representation Theme Meta-meta-data driven as opposed to Domain-driven Content Customizable closure of persistent object graph  Reference Resolution Coherent,  not  Chatty Format XML and JSON  Thrift, Protobuf, Avro … (not right now, but tomorrow)
JPA Metamodel: Persistent Type System Class Type<X> ManagedType<X> BasicType<X> IdentifiableType<X> EmbeddableType<X> EntityType<X> MappedSuperclassType<X> package javax.persistence.metamodel package java.lang <X>: Type<X> represents Java class X
JPA Metamodel : Persistent Type System Field Attribute<X,Y> SingularAttribute<X,Y> PluralAttribute<X,C,E> ListAttribute<X,E> CollectionAttribute<X,E> SetAttribute<X> MapAttribute<X,K,V> package javax.persistence.metamodel package java.lang.reflect <X>: Attribute<X,Y> declared in Java class X <Y>: Attribute<X,Y> is of type Y  <C>: PluralAttribute<X,C,E> is of Java collection type C <E>: PluralAttribute<X,C,E> contains elements of type E
JPA Metamodel: Persistent Scope java.lang.Class java.lang.reflect.Field Metamodel ManagedType<X> Attribute<X,Y> java.lang.ClassLoader A classloader defines a scope for a set of Java classes A metamodel defines a scope for a set of managed persistent types package javax.persistence.metamodel
Meta-Meta-Data Driven Representation < Actor > < id > 1234 </ id > < firstName > John </ firstName > < lastName > Doe </ lastName > </ Actor > Domain Driven Representation Domain-variant Schema  < instance   id = “Actor-1234”   type =“Actor” > < id   name = “ id ”   type = “long” > 1234 </ id > < basic   name = “firstName”   type = “String” > John </ basic > < basic   name = “lastName”   type = “String” > Doe </ basic > </ instance > Model Driven Representation Domain-invariant Schema  JPA 2.0 MetaModel based XML Schema compliant jest-instances.xsd Common  Domain-based schema some-domain.xsd
JSON-based Representation in JEST JSON  does not support  cycles in graphs JEST  supports  cyclic object graph [ {  &quot;$id&quot; :  Actor-m2 ,  &quot;id&quot;: &quot;m2&quot;,  &quot;dob&quot;: &quot;Tue May 14 1940&quot;,  &quot;firstName&quot;: &quot;Robert&quot;,  &quot;lastName&quot;: &quot;De Niro&quot;,  &quot;gender&quot;: &quot;Male&quot;,  &quot;partner&quot;: {  &quot;$id&quot; :  Actor-f3 ,  &quot;id&quot;: &quot;f3&quot;,  &quot;dob&quot;: “Wed May 15 1960&quot;,  &quot;firstName&quot;: &quot;Jodie&quot;,  &quot;lastName&quot;: &quot;Foster&quot;,  &quot;gender&quot;: &quot;Female“, “ partner”: { “ $ref”  :  Actor-m2 }  }  }  ]  dummy  $id  field dummy  $ref  field resolved circular reference JSON by JEST
JEST URI Syntax identifies JPA  resources. maps to JPA  operation decorates JPA  operation JEST resolves argument strings to strong types, e.g. “ type=Actor ” to  Actor .class . scheme authority path query context action qualifiers arguments OpenJPAEntityManager  em = getPersistenceContext(); em.addFetchPlan(“ basic ”); Actor  a = em.find( Actor . class , “m1”); find plan=basic type=Actor ? jest / / & id=m1 http 8080 openjpa.com / : ://
JEST URI Examples find an Actor with primary key m1 using fetch plan ‘basic’ http :// openjpa.com:8080 / jest / find / plan = basic ? type = Actor & m1 Query for a single Actor by name John http :// openjpa.com:8080 / jest / query / single ? q = select p from Actor   p where   p.name=:n & n = John Get the metamodel http :// openjpa.com:8080 / jest / domain
JEST translates HTTP verbs to JPA operations GET HTTP POST PUT DELETE find() getMetamodel() createQuery().getResultList() getProperties() /find / query / domain / properties merge() persist() remove() JEST Action JPA Operation non-transactional transactional
JEST Deployment < web-app > < servlet > < servlet-name > demo </ servlet-name > < servlet-class > demo.SimpleApp </ servlet-class > </ servlet > < servlet-mapping > < servlet-name > demo </ servlet-name > < url-pattern > /* </ url-pattern > </ servlet-mapping > <!--   Deployment descriptor for JESTServlet.   --> < servlet > < servlet-name > jest </ servlet-name > < servlet-class > org.apache.openjpa.persistence.jest.JESTServlet </ servlet-class > < init-param > < param-name > persistence.unit </ param-name > < param-value > SimplePU </ param-value > </ init-param > </ servlet > < servlet-mapping > < servlet-name > jest </ servlet-name > < url-pattern > /jest/* </ url-pattern > </ servlet-mapping > </ web-app > Deployed as  HTTP Servlet within the  same  module scope Identifies the module by  persistence unit name
Deployment Modes for JEST Servlet JESTServlet emf Module X emf JESTServlet instantiates discovers instantiates or  injected primary mode auxiliary mode default
JEST Client: An afterthought JEST works from navigation bar of a web browser A JEST client is developed as an afterthought  for feature demonstration uses  dojo  JavaScript library Why dojo? everybody likes cool widgets validates JEST representation for XML/JSON with  dojo  parsers
 
 
 
 
 
Why JEST? Managed, persistent object graphs can not be  effectively  represented as REST resources  without  JPA knowledge JPA Metamodel  is the right basis for self-describing REST representation Detached transaction  support of JPA is the right model for stateless REST style server Internal states of OpenJPA runtime are useful information for administration console
JEST: JPA Detached Transaction C1 C1 C1’ C1’ S1 S2 S1 renders C1 modifies C2 renders A1 A1’ R1 Response 2 @  rest State Transition find() detach() represent() parse() merge() commit()
REST is successful in real world  Success has many friends… “ Amazon has both  SOAP  and  REST  interfaces to their web services, and  85%  of their usage is of the REST interface. ”   Jeff Barr, Web Services Evangelist @ Amazon Reference:  REST vs SOAP at Amazon
Does JEST pass the RESTness est? YES  Q5 . Can server transfer logic to clients? NO  Q4 . Can client determine the exact server endpoint? YES  Q3 . Does response describe their cacheability for the client? NO Q2 . Does server store client context between requests? YES Q1 . Are clients separated from servers by a uniform interface?
Does JEST pass Uniform Interface Test? YES Q9 . Are related resources accessible via received representation? YES Q8 . Does representation carry enough information to be processed by the client? YES Q7 . Can client manipulate received resource representation? YES Q6 . Does request identify a resource?
Why JEST? JEST explores  naturalness  between REST and JPA for language-neutral, schema-agnostic clients to access and transact with OpenJPA based applications JEST solves  representational issues  for managed, persistent object graph using  Metamodel Persistent Closure   Fetch Plan
How JEST can help your effort? Similar work such as JAX-RS will benefit from  model-driven, coherent  representation in JEST in XML and JSON JEST and Fetch Plan  will obviate extra annotations in persistent domain classes Dynamic customization of object graph  is a powerful, distinctive feature of OpenJPA      Explore JEST to your advantage.
Q&A In case, you are in SF on Feb 2011: http://www.sfjava.org/calendar/15592287/   JEST Documentation https://cwiki.apache.org/openjpa/jest.html

More Related Content

PPT
Spring overview
PDF
Significant Characteristics In Planets Manfred Thaller
PPTX
Semantic Parsing to Linked Data
ODP
What I Love About Ruby
PDF
Breaking The Monotony
PDF
Testing untestable code - ConFoo13
PDF
Getting started with the JNI
Spring overview
Significant Characteristics In Planets Manfred Thaller
Semantic Parsing to Linked Data
What I Love About Ruby
Breaking The Monotony
Testing untestable code - ConFoo13
Getting started with the JNI

What's hot (6)

PDF
Django - 次の一歩 gumiStudy#3
PDF
Introduction to web programming with JavaScript
PDF
Java Programming Guide Quick Reference
PDF
Testing untestable code - IPC12
ZIP
Object Oriented PHP5
Django - 次の一歩 gumiStudy#3
Introduction to web programming with JavaScript
Java Programming Guide Quick Reference
Testing untestable code - IPC12
Object Oriented PHP5
Ad

Viewers also liked (7)

PDF
Dropwizard at Yammer
PDF
Dropwizard Spring - the perfect Java REST server stack
PPTX
Use of computer software in airline
PDF
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
ODP
Microservice Architecture JavaCro 2015
PDF
Java application monitoring with Dropwizard Metrics and graphite
Dropwizard at Yammer
Dropwizard Spring - the perfect Java REST server stack
Use of computer software in airline
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
Microservice Architecture JavaCro 2015
Java application monitoring with Dropwizard Metrics and graphite
Ad

Similar to JEST: REST on OpenJPA (20)

PPT
Entity Persistence with JPA
PDF
Java persistence api 2.1
ODP
Working with jpa
PDF
Java Persistence API
PDF
Spring Boot Tutorial Part 2 (JPA&Hibernate) .pdf
PPTX
Jpa 2.1 Application Development
PPT
Java Persistence API (JPA) - A Brief Overview
PPT
Slice: OpenJPA for Distributed Persistence
PDF
Data access 2.0? Please welcome: Spring Data!
PPT
ORM Concepts and JPA 2.0 Specifications
PDF
PPT
test for jpa spring boot persistence hehe
PDF
Java Persistence 2.0
PPTX
Евгений Капинос "Advanced JPA (Java Persistent API)"
PPTX
WebLogic Developer Webcast 1: JPA 2.0
PPT
Al rihieli persistence
PPT
Jpa basics
PDF
Introduction to JPA and Hibernate including examples
PPT
PDF
Using the latest Java Persistence API 2 Features - Tech Days 2010 India
Entity Persistence with JPA
Java persistence api 2.1
Working with jpa
Java Persistence API
Spring Boot Tutorial Part 2 (JPA&Hibernate) .pdf
Jpa 2.1 Application Development
Java Persistence API (JPA) - A Brief Overview
Slice: OpenJPA for Distributed Persistence
Data access 2.0? Please welcome: Spring Data!
ORM Concepts and JPA 2.0 Specifications
test for jpa spring boot persistence hehe
Java Persistence 2.0
Евгений Капинос "Advanced JPA (Java Persistent API)"
WebLogic Developer Webcast 1: JPA 2.0
Al rihieli persistence
Jpa basics
Introduction to JPA and Hibernate including examples
Using the latest Java Persistence API 2 Features - Tech Days 2010 India

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Encapsulation theory and applications.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
Spectroscopy.pptx food analysis technology
PDF
Approach and Philosophy of On baking technology
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
Cloud computing and distributed systems.
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Empathic Computing: Creating Shared Understanding
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation theory and applications.pdf
Review of recent advances in non-invasive hemoglobin estimation
Dropbox Q2 2025 Financial Results & Investor Presentation
Spectroscopy.pptx food analysis technology
Approach and Philosophy of On baking technology
A comparative analysis of optical character recognition models for extracting...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Unlocking AI with Model Context Protocol (MCP)
Agricultural_Statistics_at_a_Glance_2022_0.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Cloud computing and distributed systems.
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Empathic Computing: Creating Shared Understanding
The Rise and Fall of 3GPP – Time for a Sabbatical?

JEST: REST on OpenJPA

  • 1. JEST: REST on OpenJPA Pinaki Poddar, PhD Java Persistence Evangelist [email_address]
  • 2. Agenda Introduction to JEST Integration of REST and OpenJPA Resource Representation URI Syntax Transaction JEST in Action Conclusion Q&A
  • 3. JEST: REST on OpenJPA JEST is RESTful interaction with OpenJPA Runtime http JDBC XML/JSON Java Object Graph
  • 4.  
  • 5. JEST: REST on OpenJPA Deploy-and-Play No annotation on persistent classes No browser plug-in No client knowledge of persistent schema KISS: Keep It Short and Simple
  • 6. JEST: Primary Use Cases Access persistent object graph by language-neutral, domain-agnostic clients or Web Services Visualize OpenJPA runtime internals via Web Browser-based Admin console Transact with any OpenJPA application from language-neutral clients without violating REST principles
  • 7. REST: RE presentational S tate T ransfer C0 C0 C1’ C1’ S1 S2 S1 renders C1 modifies C2 renders Response 1 Request 2 Request 1 Response 2 @ rest State Transition 1 2 3 4 5 6
  • 8. REST Principles Identifiable Resource ( URI ) based, not API-based Document-oriented Resource Representation XML, JSON, … Stateless Server Standard Communication Protocol HTTP
  • 9. Java Persistence API Persistence framework for Java Objects mapped to Relational database EntityManagerFactory EntityManager Persistence Unit Persistence Context Second-Tier Caches (optional) Relational Database User Application Data Cache META-INF/persistence.xml Java Object Graph
  • 10. JPA is Model-View-Controller for Persistence View Control Model /** * A persistent entity **/ @Entity public class Actor { @Id private String name ; } /** * Find Actor by name **/ public Actor findByName( String name ) { EntityManager em = …; return em.find( Actor . class , name); } POJO sees uses updates modifies Java Persistence API Relational Database
  • 11. JPA: access-detach-merge programming model C0 C0 C1’ C1’ em1 em2 renders C1 modifies C2 renders State Transition SELECT … detach find merge commit UPDATE/INSERT/DELETE … 1 2 3 5 6 4
  • 12. REST and JPA: brothers separated at birth? Stateless Server Detached Transaction Identifiable Resource Persistent Identity Coherent Representation Persistent Closure Self-descriptive JPA 2.0 Metamodel REST JPA
  • 13. JEST Resource Perisistent Object Graph Customizable Coherent
  • 14. Customizable, Persistent Closure A persistence context as a graph managed entity as vertex persistent relation as edge Persistent Closure of an entity x is defined as set of entities C(x)={e} such that e is reachable from x in graph-theoretic sense. Every entity is reachable to itself, by definition . Customization is ability to define what is reachable at runtime. x a c1 b c2 d C(x) = {x, a, b, c1, c2, d} C(x) = {x, a, b, d} could be customized to and its complete closure C(x) = {x, b} or An object graph…
  • 15. Identifiable Resource: URI for persistent object? Actor p1 = em1.find ( Actor . class , “ John ”); Actor p2 = em2.find ( Actor . class , “ John ”); name :” John ” hash : 56789 p1 name :” John ” hash : 56789 p2 p1.equals(p2) p1.hashCode() == p2.hashCode() p1 != p2 public class Actor { @Id String name ; } Persistent Identity carries the notion that both p1 and p2 refer to the same database record. EntityManager EntityManager … Robert … John ACTOR
  • 16. Customizable, Persistent Closure: State of the art JEST response contains customizable, persistent closure JPA provides preliminary semantics on customized closure, statically OpenJPA FetchPlan already provides rich syntax and semantics to customize closure, dynamically . Future JPA specification will enhance support on this area. This feature had been the most sought after user requirement during JavaOne 2010.
  • 17. OpenJPA Fetch Plan @Entity @FetchGroups ({ @FetchGroup ( name =&quot; OnlyName &quot;, attributes ={ @FetchAttribute ( name =&quot; firstName &quot;), @FetchAttribute ( name =&quot; lastName &quot;) }) }) public class Actor { @Id private String id ; private String firstName ; private String lastName ; private Gender gender ; private Date dob ; @OneToOne private Actor partner ; @OneToMany private Set<Movie> movies ; // getters and setters }
  • 18. JEST Representation Theme Meta-meta-data driven as opposed to Domain-driven Content Customizable closure of persistent object graph Reference Resolution Coherent, not Chatty Format XML and JSON Thrift, Protobuf, Avro … (not right now, but tomorrow)
  • 19. JPA Metamodel: Persistent Type System Class Type<X> ManagedType<X> BasicType<X> IdentifiableType<X> EmbeddableType<X> EntityType<X> MappedSuperclassType<X> package javax.persistence.metamodel package java.lang <X>: Type<X> represents Java class X
  • 20. JPA Metamodel : Persistent Type System Field Attribute<X,Y> SingularAttribute<X,Y> PluralAttribute<X,C,E> ListAttribute<X,E> CollectionAttribute<X,E> SetAttribute<X> MapAttribute<X,K,V> package javax.persistence.metamodel package java.lang.reflect <X>: Attribute<X,Y> declared in Java class X <Y>: Attribute<X,Y> is of type Y <C>: PluralAttribute<X,C,E> is of Java collection type C <E>: PluralAttribute<X,C,E> contains elements of type E
  • 21. JPA Metamodel: Persistent Scope java.lang.Class java.lang.reflect.Field Metamodel ManagedType<X> Attribute<X,Y> java.lang.ClassLoader A classloader defines a scope for a set of Java classes A metamodel defines a scope for a set of managed persistent types package javax.persistence.metamodel
  • 22. Meta-Meta-Data Driven Representation < Actor > < id > 1234 </ id > < firstName > John </ firstName > < lastName > Doe </ lastName > </ Actor > Domain Driven Representation Domain-variant Schema < instance id = “Actor-1234” type =“Actor” > < id name = “ id ” type = “long” > 1234 </ id > < basic name = “firstName” type = “String” > John </ basic > < basic name = “lastName” type = “String” > Doe </ basic > </ instance > Model Driven Representation Domain-invariant Schema JPA 2.0 MetaModel based XML Schema compliant jest-instances.xsd Common Domain-based schema some-domain.xsd
  • 23. JSON-based Representation in JEST JSON does not support cycles in graphs JEST supports cyclic object graph [ { &quot;$id&quot; : Actor-m2 , &quot;id&quot;: &quot;m2&quot;, &quot;dob&quot;: &quot;Tue May 14 1940&quot;, &quot;firstName&quot;: &quot;Robert&quot;, &quot;lastName&quot;: &quot;De Niro&quot;, &quot;gender&quot;: &quot;Male&quot;, &quot;partner&quot;: { &quot;$id&quot; : Actor-f3 , &quot;id&quot;: &quot;f3&quot;, &quot;dob&quot;: “Wed May 15 1960&quot;, &quot;firstName&quot;: &quot;Jodie&quot;, &quot;lastName&quot;: &quot;Foster&quot;, &quot;gender&quot;: &quot;Female“, “ partner”: { “ $ref” : Actor-m2 } } } ] dummy $id field dummy $ref field resolved circular reference JSON by JEST
  • 24. JEST URI Syntax identifies JPA resources. maps to JPA operation decorates JPA operation JEST resolves argument strings to strong types, e.g. “ type=Actor ” to Actor .class . scheme authority path query context action qualifiers arguments OpenJPAEntityManager em = getPersistenceContext(); em.addFetchPlan(“ basic ”); Actor a = em.find( Actor . class , “m1”); find plan=basic type=Actor ? jest / / & id=m1 http 8080 openjpa.com / : ://
  • 25. JEST URI Examples find an Actor with primary key m1 using fetch plan ‘basic’ http :// openjpa.com:8080 / jest / find / plan = basic ? type = Actor & m1 Query for a single Actor by name John http :// openjpa.com:8080 / jest / query / single ? q = select p from Actor p where p.name=:n & n = John Get the metamodel http :// openjpa.com:8080 / jest / domain
  • 26. JEST translates HTTP verbs to JPA operations GET HTTP POST PUT DELETE find() getMetamodel() createQuery().getResultList() getProperties() /find / query / domain / properties merge() persist() remove() JEST Action JPA Operation non-transactional transactional
  • 27. JEST Deployment < web-app > < servlet > < servlet-name > demo </ servlet-name > < servlet-class > demo.SimpleApp </ servlet-class > </ servlet > < servlet-mapping > < servlet-name > demo </ servlet-name > < url-pattern > /* </ url-pattern > </ servlet-mapping > <!-- Deployment descriptor for JESTServlet. --> < servlet > < servlet-name > jest </ servlet-name > < servlet-class > org.apache.openjpa.persistence.jest.JESTServlet </ servlet-class > < init-param > < param-name > persistence.unit </ param-name > < param-value > SimplePU </ param-value > </ init-param > </ servlet > < servlet-mapping > < servlet-name > jest </ servlet-name > < url-pattern > /jest/* </ url-pattern > </ servlet-mapping > </ web-app > Deployed as HTTP Servlet within the same module scope Identifies the module by persistence unit name
  • 28. Deployment Modes for JEST Servlet JESTServlet emf Module X emf JESTServlet instantiates discovers instantiates or injected primary mode auxiliary mode default
  • 29. JEST Client: An afterthought JEST works from navigation bar of a web browser A JEST client is developed as an afterthought for feature demonstration uses dojo JavaScript library Why dojo? everybody likes cool widgets validates JEST representation for XML/JSON with dojo parsers
  • 30.  
  • 31.  
  • 32.  
  • 33.  
  • 34.  
  • 35. Why JEST? Managed, persistent object graphs can not be effectively represented as REST resources without JPA knowledge JPA Metamodel is the right basis for self-describing REST representation Detached transaction support of JPA is the right model for stateless REST style server Internal states of OpenJPA runtime are useful information for administration console
  • 36. JEST: JPA Detached Transaction C1 C1 C1’ C1’ S1 S2 S1 renders C1 modifies C2 renders A1 A1’ R1 Response 2 @ rest State Transition find() detach() represent() parse() merge() commit()
  • 37. REST is successful in real world Success has many friends… “ Amazon has both SOAP and REST interfaces to their web services, and 85% of their usage is of the REST interface. ” Jeff Barr, Web Services Evangelist @ Amazon Reference: REST vs SOAP at Amazon
  • 38. Does JEST pass the RESTness est? YES Q5 . Can server transfer logic to clients? NO Q4 . Can client determine the exact server endpoint? YES Q3 . Does response describe their cacheability for the client? NO Q2 . Does server store client context between requests? YES Q1 . Are clients separated from servers by a uniform interface?
  • 39. Does JEST pass Uniform Interface Test? YES Q9 . Are related resources accessible via received representation? YES Q8 . Does representation carry enough information to be processed by the client? YES Q7 . Can client manipulate received resource representation? YES Q6 . Does request identify a resource?
  • 40. Why JEST? JEST explores naturalness between REST and JPA for language-neutral, schema-agnostic clients to access and transact with OpenJPA based applications JEST solves representational issues for managed, persistent object graph using Metamodel Persistent Closure Fetch Plan
  • 41. How JEST can help your effort? Similar work such as JAX-RS will benefit from model-driven, coherent representation in JEST in XML and JSON JEST and Fetch Plan will obviate extra annotations in persistent domain classes Dynamic customization of object graph is a powerful, distinctive feature of OpenJPA Explore JEST to your advantage.
  • 42. Q&A In case, you are in SF on Feb 2011: http://www.sfjava.org/calendar/15592287/ JEST Documentation https://cwiki.apache.org/openjpa/jest.html