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

Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 

Último (20)

Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 

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.