rice krad data layer jpa design eric westfall july 2013

Download Rice KRAD Data Layer JPA Design Eric Westfall July 2013

If you can't read please download the document

Upload: colin-page

Post on 24-Dec-2015

224 views

Category:

Documents


5 download

TRANSCRIPT

  • Slide 1
  • rice KRAD Data Layer JPA Design Eric Westfall July 2013
  • Slide 2
  • What is JPA? Java Persistence API Framework for managing relational data from Java applications Standardized approach developed through the Java Community Process (JCP) Three main areas: API for storage/retrieval of entities JPQL (query language) Object/Relational Metadata
  • Slide 3
  • JPA Versions JPA has had three major version releases 1.0, 2.0, 2.1 We are targeting JPA version 2.1 Fairly recent, finalized April 2013
  • Slide 4
  • JPA 2.1 Features Converters Bulk Operations Stored Procedure support Database Schema Generation Entity Graphs JPQL/Criteria enhancements Unsynchronized Persistence Contexts
  • Slide 5
  • Vendor Support for JPA Versions
  • Slide 6
  • Vendor Neutrality Ideally we would like to stay vendor-neutral and use only JPA features But unfortunately we cant! Two gaps: Lack of programmatic access to mapping metadata Lack of support for custom ID generation strategies Fortunately, this list is fairly small.
  • Slide 7
  • Vendor Selection Team working on JPA support in KRAD are recommending the use of EclipseLink as the default JPA implementation Lazy loading semantics are the same as OJB, therefore eases the transition Is the reference implementation of JPA Provides us an easy method for programmatic read/write access to metadata Support for custom identifier generation
  • Slide 8
  • So why use JPA then? Why not just use EclipseLink-specific annotations and functionality instead of JPA?
  • Slide 9
  • Design Time! Design Time!
  • Slide 10
  • Database Plugging JPA into KRAD Data Layer KRAD Data API JPA Persistence Provider JPA Metadata Provider JPA Metadata Provider EclipseLink Client Application Code
  • Slide 11
  • EntityManager Configuration Spring provides LocalContainerEntityManagerFactoryBean But weve created a simpler version to handle setting up KRAD for JPA with EclipseLink
  • Slide 12
  • JpaPersistenceProvider save verify the data object is valid and writable perform "reference linking" (see KRAD Data Layer Design document for information on linking) execute an EntityManager.merge(...) return the merged object find execute an EntityManager.find(...) return the result findMatching translate from the Rice QueryByCriteria to a JPA Query and execute it translate the result of the query into Rice QueryResults and return it delete verify the data object is valid and writable execute an EntityManager.delete(...)
  • Slide 13
  • SharedEntityManager Provided by Spring Allows us to inject an EntityManager that is shared across multiple classes Example usage with JpaPersistenceProvider
  • Slide 14
  • JPA Metadata Provider Provides metadata about Entities managed by the persistence unit Relationships, collections, keys, etc. Pulls what it can from the pure JPA Metamodel Gets the rest from EclipseLink-specific APIs
  • Slide 15
  • Slide 16
  • Sequences and Generated IDs For Oracle we use native sequences For MySQL we use _S tables to simulate sequences Can implement similar behavior using an EclipseLink SessionCustomizer
  • Slide 17
  • Converters Supported natively as of JPA 2.1! Allows for conversion between database and java types For example, storing booleans as Y and N character data in the database Boolean, KualiDecimal, KualiPercent, KualiInteger, Encrypted values
  • Slide 18
  • Extension Framework In KNS, allowed for institutions to customize database by adding tables with additional columns and linking them to the delivered parent table Required manual copy and modification of OJB mapping files Using programattic metadata modification, can do this programatically now with JPA + EclipseLink
  • Slide 19
  • Slide 20
  • Custom DAOs and Data Access It is still very likely that applications will continue to need custom DAOs for certain cases In these cases, simply create the DAO and inject the shared EntityManager into it and use the JPA apis directly JPQL Crteria Query Etc.
  • Slide 21
  • Database JPA with krad-data, services, and DAOs KRAD Data API JPA Persistence Provider JPA Metadata Provider JPA Metadata Provider EclipseLink Client Application Code Service API Service Implementation Data Access Object
  • Slide 22
  • Backend Development 1.Create JPA entities, map with annotations 2.Wire EntityManagerFactory bean in Spring 3.Wire SharedEntityManager bean ins Spring 4.Inject into a JpaPersistenceProvider 5.Inject into a JpaMetadataProvider 6.Register both providers with ModuleConfiguration 7.Use the KRAD DataObjectService!