SlideShare una empresa de Scribd logo
1 de 42
JEST: REST on OpenJPA Pinaki Poddar, PhD Java Persistence Evangelist [email_address]
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JEST: REST on OpenJPA JEST is RESTful interaction with OpenJPA Runtime http JDBC XML/JSON Java Object Graph
 
JEST: REST on OpenJPA ,[object Object],[object Object],[object Object],[object Object],KISS: Keep It Short and Simple
JEST: Primary Use Cases ,[object Object],[object Object],[object Object]
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 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Java Persistence API ,[object Object],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 ,[object Object],[object Object],[object Object]
Customizable, Persistent Closure ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],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  ,[object Object],[object Object],[object Object],[object Object]
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 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
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  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
JSON-based Representation in JEST ,[object Object],[object Object],[ {  &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 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
 
 
 
 
 
Why JEST? ,[object Object],[object Object],[object Object],[object Object]
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? ,[object Object],[object Object],[object Object],[object Object],[object Object]
How JEST can help your effort? ,[object Object],[object Object],[object Object]
Q&A ,[object Object],[object Object],[object Object],https://cwiki.apache.org/openjpa/jest.html

Más contenido relacionado

La actualidad más candente

La actualidad más candente (6)

Django - 次の一歩 gumiStudy#3
Django - 次の一歩 gumiStudy#3Django - 次の一歩 gumiStudy#3
Django - 次の一歩 gumiStudy#3
 
Introduction to web programming with JavaScript
Introduction to web programming with JavaScriptIntroduction to web programming with JavaScript
Introduction to web programming with JavaScript
 
Java Programming Guide Quick Reference
Java Programming Guide Quick ReferenceJava Programming Guide Quick Reference
Java Programming Guide Quick Reference
 
Testing untestable code - IPC12
Testing untestable code - IPC12Testing untestable code - IPC12
Testing untestable code - IPC12
 
AMIS definer invoker rights
AMIS definer invoker rightsAMIS definer invoker rights
AMIS definer invoker rights
 
Object Oriented PHP5
Object Oriented PHP5Object Oriented PHP5
Object Oriented PHP5
 

Destacado

Dropwizard at Yammer
Dropwizard at YammerDropwizard at Yammer
Dropwizard at YammerJamie Furness
 
Dropwizard Spring - the perfect Java REST server stack
Dropwizard Spring - the perfect Java REST server stackDropwizard Spring - the perfect Java REST server stack
Dropwizard Spring - the perfect Java REST server stackJacek Furmankiewicz
 
Use of computer software in airline
Use of computer software in airlineUse of computer software in airline
Use of computer software in airlinesaurav rawat
 
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016
Get Hip with JHipster: Spring Boot + AngularJS + Bootstrap - DOSUG February 2016Matt Raible
 
Microservice Architecture JavaCro 2015
Microservice Architecture JavaCro 2015Microservice Architecture JavaCro 2015
Microservice Architecture JavaCro 2015Nenad Pecanac
 
Java application monitoring with Dropwizard Metrics and graphite
Java application monitoring with Dropwizard Metrics and graphite Java application monitoring with Dropwizard Metrics and graphite
Java application monitoring with Dropwizard Metrics and graphite Roberto Franchini
 

Destacado (7)

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

Similar a JEST: REST on OpenJPA

Slice: OpenJPA for Distributed Persistence
Slice: OpenJPA for Distributed PersistenceSlice: OpenJPA for Distributed Persistence
Slice: OpenJPA for Distributed PersistencePinaki Poddar
 
Using DAOs without implementing them
Using DAOs without implementing themUsing DAOs without implementing them
Using DAOs without implementing thembenfante
 
Entity Persistence with JPA
Entity Persistence with JPAEntity Persistence with JPA
Entity Persistence with JPASubin Sugunan
 
2008.07.17 발표
2008.07.17 발표2008.07.17 발표
2008.07.17 발표Sunjoo Park
 
Intro To Hibernate
Intro To HibernateIntro To Hibernate
Intro To HibernateAmit Himani
 
JSUG - TU Wien Castor Project by Lukas Lang
JSUG - TU Wien Castor Project by Lukas LangJSUG - TU Wien Castor Project by Lukas Lang
JSUG - TU Wien Castor Project by Lukas LangChristoph Pickl
 
Architecting Web Services
Architecting Web ServicesArchitecting Web Services
Architecting Web ServicesLorna Mitchell
 
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...Baruch Sadogursky
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesJohn Brunswick
 
Developing web apps using Java and the Play framework
Developing web apps using Java and the Play frameworkDeveloping web apps using Java and the Play framework
Developing web apps using Java and the Play frameworkVictor Porof
 
The java server pages
The java server pagesThe java server pages
The java server pagesAtul Saurabh
 

Similar a JEST: REST on OpenJPA (20)

Slice: OpenJPA for Distributed Persistence
Slice: OpenJPA for Distributed PersistenceSlice: OpenJPA for Distributed Persistence
Slice: OpenJPA for Distributed Persistence
 
Using DAOs without implementing them
Using DAOs without implementing themUsing DAOs without implementing them
Using DAOs without implementing them
 
Jsp
JspJsp
Jsp
 
Os Leonard
Os LeonardOs Leonard
Os Leonard
 
Entity Persistence with JPA
Entity Persistence with JPAEntity Persistence with JPA
Entity Persistence with JPA
 
2008.07.17 발표
2008.07.17 발표2008.07.17 발표
2008.07.17 발표
 
Intro To Hibernate
Intro To HibernateIntro To Hibernate
Intro To Hibernate
 
REST dojo Comet
REST dojo CometREST dojo Comet
REST dojo Comet
 
JSUG - TU Wien Castor Project by Lukas Lang
JSUG - TU Wien Castor Project by Lukas LangJSUG - TU Wien Castor Project by Lukas Lang
JSUG - TU Wien Castor Project by Lukas Lang
 
Architecting Web Services
Architecting Web ServicesArchitecting Web Services
Architecting Web Services
 
Apache Persistence Layers
Apache Persistence LayersApache Persistence Layers
Apache Persistence Layers
 
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
Persisting Your Objects In The Database World @ AlphaCSP Professional OSS Con...
 
JavaEE Spring Seam
JavaEE Spring SeamJavaEE Spring Seam
JavaEE Spring Seam
 
I Feel Pretty
I Feel PrettyI Feel Pretty
I Feel Pretty
 
Boston Computing Review - Java Server Pages
Boston Computing Review - Java Server PagesBoston Computing Review - Java Server Pages
Boston Computing Review - Java Server Pages
 
Struts2
Struts2Struts2
Struts2
 
Developing web apps using Java and the Play framework
Developing web apps using Java and the Play frameworkDeveloping web apps using Java and the Play framework
Developing web apps using Java and the Play framework
 
The java server pages
The java server pagesThe java server pages
The java server pages
 
Javascript2839
Javascript2839Javascript2839
Javascript2839
 
Json
JsonJson
Json
 

Último

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Último (20)

Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

JEST: REST on OpenJPA

  • 1. JEST: REST on OpenJPA Pinaki Poddar, PhD Java Persistence Evangelist [email_address]
  • 2.
  • 3. JEST: REST on OpenJPA JEST is RESTful interaction with OpenJPA Runtime http JDBC XML/JSON Java Object Graph
  • 4.  
  • 5.
  • 6.
  • 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.
  • 9.
  • 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.
  • 14.
  • 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.
  • 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.
  • 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.
  • 23.
  • 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.
  • 30.  
  • 31.  
  • 32.  
  • 33.  
  • 34.  
  • 35.
  • 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.
  • 41.
  • 42.