SlideShare ist ein Scribd-Unternehmen logo
1 von 56
Scale Your JPA Applications with Distributed Database Partitions Dr. Pinaki Poddar [email_address] Session Number: D05
Overview ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],JPA uses POJO for Domain Model ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Persistence Unit ,[object Object],[object Object],[object Object],*.class META-INF/persistence.xml orm.xml Persistence Unit
How to obtain a Persistence Unit? Instantiate via bootstrap  EntityManagerFactory construction is costly WARNING EntityManagerFactory  emf = Persistence .createEntityManagerFactory( “test” ) ; InitialiContext ctx = new InitialContext(); EntityManagerFactory  emf = ctx .lookup( “myEMF” ) ); Look up in JNDI  @PersistenceUnit (unitName= “test” ) private   EntityManagerFactory  emf; Inject as a resource
Persistence Context Persistence Context ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
How to obtain a Persistence Context? EntityManager  em = emf.createEntityManager() Construct from Persistence Unit  @PersistenceContext private   EntityManager  em; Inject as a resource
Persistence Context manages instances in a group em1 = emf.createEntityManager(); em2 = emf.createEntityManager(); Account ID NAME AMOUNT SELECT  ID,NAME  FROM  ACCOUNT t WHERE  t.ID=1245 Persistence Unit Persistence Context Account pc1 =  em1.find(Account.class,1245); Persistence Context Account pc2 =  em2.find(Account.class,1245); 2347 John $ 12000.57 1245 Mary $ 34568.89
A Question about Identity ,[object Object],[object Object],Java supports two identities ,[object Object],JPA adds another identity ,[object Object],[object Object],pc1 == pc2 ? pc1.equals(pc2) ? Important questions
Life of Persistence Context em = emf.createEntityManager(); begin(); commit(); flush(); clear(); close(); begin(); commit(); Extended Persistence Context Transactional Persistence Context Time
Query executes in a Persistence Context  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Transaction Scaling in JPA em = emf.createEntityManager() begin() commit() flush() clear() close() begin() commit() Extended Persistence Context Transaction-scoped Persistence Context L2 Data Cache Database Transaction Time
Optimistic Versioning scales transaction begin(); commit(); pc1 = find(Item.class, 1234); qty:5 version: 56 Item:1234 qty:30 version: 56 Item:1234 begin(); commit(); pc2 = find(Item.class, 1234); qty:5 version: 56 Item:1234 qty:87 version: 56 Item:1234 UPDATE  ITEM  SET  QTY=30, VERSION=57  WHERE  ID=1234  AND  VERSION=56 ID 1234 QTY 5 VERSION 56 ID 1234 QTY 30 VERSION 57 pc2.setQty(87); pc1.setQty(30); 1 3 4 2 5 6 7 9 8 UPDATE  ITEM  SET  QTY=87, VERSION=57  WHERE  ID=1234  AND  VERSION=56 10 Optimistic Exception
Multi-level caches favor read-mostly sessions em1 = emf.createEntityManager(); em1.begin() em1.commit() em2.begin() em2.commit() L2 Data Cache Database Access & Transaction Time em1.query() em2 = emf.createEntityManager(); em2.find() em2.find() em2.remove()
Scaling against Data Volume ,[object Object],[object Object],[object Object],[object Object],[object Object]
Distributed Horizonal Partition ,[object Object],[object Object],[object Object],[object Object]
divide et impera   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Overview ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
What is Slice? ,[object Object],[object Object],[object Object],[object Object],Slice is  not  the best thing since sliced bread
What is OpenJPA? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Architectural Tiers of JPA-based service JPA-based User Application OpenJPA Standard JPA API JDBC API
Architectural Tiers of Slice-based service Slice-based User Application OpenJPA Standard JPA API JDBC API Slice OpenJPA is a plugabble platform
Features of Slice Slice-based User Application OpenJPA Standard JPA API JDBC API Slice No change to Application code or Domain Model User-defined Distribution & Replication Policy Flexible per-Slice Configuration Parallel Query Execution Heterogeneous Databases Master-based Sequence Targeted  Query
Overview ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Using Slice ,[object Object],[object Object],[object Object]
Persistence Unit Configuration  <? xml  version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> < persistence  xmlns=&quot; http://java.sun.com/xml/ns/persistence &quot;  xmlns:xsi=&quot; http://www.w3.org/2001/XMLSchema-instance &quot; version=&quot;1.0&quot;  xsi:schemaLocation=&quot; http://java.sun.com/xml/ns/persistence   http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd &quot;> < persistence-unit  name=&quot; test “ transaction=“ RESOURCE_LOCAL ”> < provider > org.apache.openjpa.persistence.PersistenceProviderImpl </provider> < class > domain.EntityA </class> < class > domain.EntityB </class> < properties > < property  name=&quot; openjpa.ConnectionDriverName &quot;  value=&quot; com.mysql.jdbc.Driver &quot;/> < property  name=&quot; openjpa.ConnectionURL &quot;  value=&quot; jdbc:mysql://localhost/test &quot;/> < property  name=&quot; openjpa.jdbc.SynchronizeMappings &quot; value=&quot; buildSchema &quot;/> < property  name=&quot; openjpa.Log &quot;  value=&quot; SQL=TRACE &quot;/> </ properties > </ persistence-unit > List of known Persistent types Vendor-specific  configuration Governed by  XML Schema JPA Provider is pluggable META-INF/persistence.xml Identified by Unit Name
Per-Slice Configuration  < properties > < property   name=&quot; openjpa.BrokerFactory&quot;  value =“ slice &quot;/> < property   name =“openjpa.slice.Names”  value =“ One,Two,Three ”/> < property   name =“openjpa.slice.Master”  value =“ One ”/> < property  name=&quot; openjpa.slice.DistributionPolicy &quot;  value=“ acme.org.MyDistroPolicy &quot;/> < property  name=&quot; openjpa.ConnectionDriverName &quot;  value=&quot; com.mysql.jdbc.Driver &quot;/> < property  name=&quot; openjpa.slice.One.ConnectionURL &quot;  value=&quot; jdbc:mysql://localhost/slice1 &quot;/> < property  name=“ openjpa.slice.Two.ConnectionURL ”  value=“ jdbc:mysql://localhost/slice2 ”/> < property  name=“ openjpa.slice.Three.ConnectionDriverName ” value=“ com.ibm.db2.jcc.DB2Driver ”/> < property  name=“ openjpa.slice.Three.ConnectionURL ” value=“ jdbc:db2 :// mac3:50000/slice3 ”/> < property  name=&quot; openjpa.jdbc.SynchronizeMappings &quot; value=&quot; buildSchema &quot;/> </ properties > </ persistence-unit > META-INF/persistence.xml Activate Slice Declare slices Configure each slice Configure common behavior Define Data Distribution Policy
Rules of Configuring slices  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
How to distribute data across slices? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],@Entity public class   Person  { private   String  name; private   int  age; @OneToOne  ( cascade = ALL ) private   Address  address; } @Entity public class   Address  { private   String  city; } User   Application Domain Classes Data Distribution Policy
Distribution Policy public   interface   DistributionPolicy  {  /**  * Gets the name of the slice where the given newly persistent  * instance will be stored.  *  * @param pc The newly persistent or to-be-merged object.  * @param slices name of the configured slices.  * @param context persistence context managing the given instance.  *  * @return identifier of the slice. This name must match one of the  * configured slice names.  * @see DistributedConfiguration#getSliceNames()  */  String   distribute ( Object  pc,  List<String>  slices,  Object  context);  }  Slice will call this method while persisting or merging a  root  instance. The instance and its  closure  will be stored in the returned slice.
Collocation Constraint ,[object Object],[object Object],[object Object],[object Object],[object Object],0+ 1+ 1 1 Customer Order LineItem
What if schema is not a Constrained Tree Schema? ,[object Object],[object Object],[object Object],Company Department Employee Address Country
Replicate  Master Data  across slices ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Replication Policy public   interface   ReplicationPolicy  {  /**  * Gets the name of the slices where the given newly persistent  * instance will be replicated.  *  * @param pc The newly persistent or to-be-merged object.  * @param slices name of the configured slices.  * @param context persistence context managing the given instance.  *  * @return identifier(s) of the slice. Each name must match one of the  * configured slice names.  * @see DistributedConfiguration#getSliceNames()  */  String[]   replicate ( Object  pc,  List<String>  slices,  Object  context);  }  Slice will call this method while persisting any @Replicated instance.
Distributed Query ,[object Object],[object Object]
Distributed Query ,[object Object],slice1 slice3 slice2 List result = em.createQuery(“ SELECT   e   FROM   Employee e   WHERE  e.age  <  30”) .getResultList(); 2001 29 BILL 2005 37 LEUNG 2008 22 ROB JOIN_YEAR AGE NAME 1987 41 JOSE 1999 35 SHIVA 2002 31 HARI JOIN_YEAR AGE NAME 1975 43 SANDRA 2007 24 MARY 2001 35 JOHN JOIN_YEAR AGE NAME 2007 24 MARY 2008 22 ROB 2001 29 BILL 2008 22 ROB 2001 29 BILL 2007 24 MARY
Distributed Query (Sorting) ,[object Object],slice1 slice3 slice2 List result = em.createQuery(“ SELECT   e   FROM   Employee e   WHERE  e.age  <  30 ORDER BY  e.name ”).getResultList(); 2001 29 BILL 2005 37 LEUNG 2008 22 ROB JOIN_YEAR AGE NAME 1987 41 JOSE 1999 35 SHIVA 2002 31 HARI JOIN_YEAR AGE NAME 1975 43 SANDRA 2007 24 MARY 2001 35 JOHN JOIN_YEAR AGE NAME 2007 24 MARY 2008 22 ROB 2001 29 BILL 2007 22 ROB 2007 24 MARY 2001 29 BILL
Distributed Top-N Query ,[object Object],slice1 slice3 slice2 List result = em.createQuery(“ SELECT   e   FROM   Employee e   ORDER BY   e.age ”) .setMaxResult( 2 ).getResultList(); 2001 29 BILL 2005 37 LEUNG 2008 22 ROB JOIN_YEAR AGE NAME 1987 41 JOSE 1999 35 SHIVA 2002 31 HARI JOIN_YEAR AGE NAME 1975 43 SANDRA 2007 24 MARY 2001 35 JOHN JOIN_YEAR AGE NAME 2001 29 BILL 2008 22 ROB 2001 35 JOHN 2007 24 MARY 1999 35 SHIVA 2002 31 HARI 2007 24 MARY 2008 22 ROB
Distributed Top-N Query ,[object Object],slice1 slice3 slice2 List result = em.createQuery(“ SELECT   e   FROM   Employee e ”) .setMaxResult( 2 ).getResultList(); 2001 29 BILL 2005 37 LEUNG 2008 22 ROB JOIN_YEAR AGE NAME 1987 41 JOSE 1999 35 SHIVA 2002 31 HARI JOIN_YEAR AGE NAME 1975 43 SANDRA 2007 24 MARY 2001 35 JOHN JOIN_YEAR AGE NAME 2001 29 BILL 2008 22 ROB 2001 35 JOHN 2007 24 MARY 1999 35 SHIVA 2002 31 HARI 2007 24 MARY 2008 22 ROB
Targeted Query ,[object Object],slice1 slice3 slice2 List result = em.createQuery(“ SELECT   e   FROM   Employee e   WHERE   e.age   >   34 ”) .setHint(“ openjpa.slice.Targets ”, “ slice1,slice3 ”) .getResultList(); 2001 29 BILL 2005 37 LEUNG 2008 22 ROB JOIN_YEAR AGE NAME 1987 41 JOSE 1999 35 SHIVA 2002 31 HARI JOIN_YEAR AGE NAME 1975 43 SANDRA 2007 24 MARY 2001 35 JOHN JOIN_YEAR AGE NAME 2001 35 JOHN 1975 43 SANDRA 1999 35 SHIVA 1987 41 JOSE 1999 35 SHIVA 1987 41 JOSE 2001 35 JOHN 1975 43 SANDRA
Aggregate Query ,[object Object],slice1 slice3 slice2 Number  sum = ( Number )em.createQuery(“ SELECT   SUM( e.age )   FROM   Employee e   WHERE   e.age   >   30 ”).getSingleResult(); 2001 29 BILL 2005 37 LEUNG 2008 22 ROB JOIN_YEAR AGE NAME 1987 41 JOSE 1999 35 SHIVA 2002 31 HARI JOIN_YEAR AGE NAME 1975 43 SANDRA 2007 24 MARY 2001 35 JOHN JOIN_YEAR AGE NAME 78 37 107 222 78 37 107
Aggregate Query ,[object Object],slice1 slice3 slice2 3 WRONG! Number  sum = ( Number )em.createQuery(“ SELECT   AVG( e.age )   FROM   Employee e   WHERE   e.age   >   30 ”).getSingleResult(); 2001 29 BILL 2005 37 LEUNG 2008 22 ROB JOIN_YEAR AGE NAME 1987 41 JOSE 1999 35 SHIVA 2002 31 HARI JOIN_YEAR AGE NAME 1975 43 SANDRA 2007 24 MARY 2001 35 JOHN JOIN_YEAR AGE NAME 37.0 37.0 35.6 36.5 37.0 37.0 35.6
Distributed Aggregate Query Limitations ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Query for Replicated Entities ,[object Object],Number  sum = ( Number )em.createQuery(“ SELECT   COUNT( c )   FROM   Coutry c ”)  .getSingleResult(); slice1 slice3 slice2 3 3 @Entity @Replicated public   class  Country {..} 1200M INDIA 82M GERMANY 300M US POPULATION CODE 1200M INDIA 82M GERMANY 300M US POPULATION CODE 1200M INDIA 82M GERMANY 300M US POPULATION CODE
Updates ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Database and Transaction ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Overview ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Core Architectural constructs of OpenJPA EntityManager Factory BrokerFactory EntityManager Broker StoreManager JDBCStore Manager JDBC API OpenJPA Configuration creates creates delegates delegates configured by
Distributed Template Design Pattern public class   DistributedTemplate < T >  implements   T ,  Iterable < T > { protected   List < T >  _delegates  =  new   ArrayList < T >(); public   boolean  execute(String arg0) { boolean  ret =  true ; for  ( T  t :this )   ret = t.execute(arg0)  &  ret; return  ret; } public   Iterator < T > iterator() { return   _delegates .iterator(); } } ,[object Object],[object Object],[object Object]
Slice extends OpenJPA by Distributed Template EntityManager Factory BrokerFactory EntityManager Broker DistributedStoreManager JDBCStore Manager JDBC API JDBCStore Manager JDBCStore Manager Distributed Configuration delegates delegates creates creates configures applies Distributed Template Pattern Not aware of partitioned Databases
Overview ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Future Work: Evolving data distribution ,[object Object],[object Object],[object Object],[object Object]
Future Work: Courage under Fire ,[object Object],[object Object],[object Object],[object Object]
Future Work: Heterogeneity ,[object Object],[object Object],[object Object],[object Object],[object Object]
Overview ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Thank You!

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction to Drools
Introduction to DroolsIntroduction to Drools
Introduction to Droolsgiurca
 
Unit testing: unitils & dbmaintain
Unit testing: unitils & dbmaintainUnit testing: unitils & dbmaintain
Unit testing: unitils & dbmaintainnevenfi
 
Kotlin @ Coupang Backed - JetBrains Day seoul 2018
Kotlin @ Coupang Backed - JetBrains Day seoul 2018Kotlin @ Coupang Backed - JetBrains Day seoul 2018
Kotlin @ Coupang Backed - JetBrains Day seoul 2018Sunghyouk Bae
 
JSR 354 Hackday - What you can do...
JSR 354 Hackday - What you can do...JSR 354 Hackday - What you can do...
JSR 354 Hackday - What you can do...Anatole Tresch
 
Spring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentationSpring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentationsourabh aggarwal
 
Rule Engine & Drools
Rule Engine & DroolsRule Engine & Drools
Rule Engine & DroolsSandip Jadhav
 
Advance java session 5
Advance java session 5Advance java session 5
Advance java session 5Smita B Kumar
 
WebSphere Message Broker v6.x Overview - 2008-01-09
WebSphere Message Broker v6.x Overview - 2008-01-09WebSphere Message Broker v6.x Overview - 2008-01-09
WebSphere Message Broker v6.x Overview - 2008-01-09Mårten Gustafson
 
Testing persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitTesting persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitPeter Wilcsinszky
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenchesLukas Smith
 
5050 dev nation
5050 dev nation5050 dev nation
5050 dev nationArun Gupta
 
Metrics for example Java project
Metrics for example Java projectMetrics for example Java project
Metrics for example Java projectZarko Acimovic
 
Java Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicJava Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicIMC Institute
 
Doctrine 2
Doctrine 2Doctrine 2
Doctrine 2zfconfua
 
BASTA 2013: Custom OData Provider
BASTA 2013: Custom OData ProviderBASTA 2013: Custom OData Provider
BASTA 2013: Custom OData ProviderRainer Stropek
 

Was ist angesagt? (20)

Hibernate in Nutshell
Hibernate in NutshellHibernate in Nutshell
Hibernate in Nutshell
 
Introduction to Drools
Introduction to DroolsIntroduction to Drools
Introduction to Drools
 
Unit testing: unitils & dbmaintain
Unit testing: unitils & dbmaintainUnit testing: unitils & dbmaintain
Unit testing: unitils & dbmaintain
 
Kotlin @ Coupang Backed - JetBrains Day seoul 2018
Kotlin @ Coupang Backed - JetBrains Day seoul 2018Kotlin @ Coupang Backed - JetBrains Day seoul 2018
Kotlin @ Coupang Backed - JetBrains Day seoul 2018
 
JSR 354 LJC-Hackday
JSR 354 LJC-HackdayJSR 354 LJC-Hackday
JSR 354 LJC-Hackday
 
JSR 354 Hackday - What you can do...
JSR 354 Hackday - What you can do...JSR 354 Hackday - What you can do...
JSR 354 Hackday - What you can do...
 
Spring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentationSpring 4 advanced final_xtr_presentation
Spring 4 advanced final_xtr_presentation
 
Rule Engine & Drools
Rule Engine & DroolsRule Engine & Drools
Rule Engine & Drools
 
Advance java session 5
Advance java session 5Advance java session 5
Advance java session 5
 
WebSphere Message Broker v6.x Overview - 2008-01-09
WebSphere Message Broker v6.x Overview - 2008-01-09WebSphere Message Broker v6.x Overview - 2008-01-09
WebSphere Message Broker v6.x Overview - 2008-01-09
 
Testing persistence in PHP with DbUnit
Testing persistence in PHP with DbUnitTesting persistence in PHP with DbUnit
Testing persistence in PHP with DbUnit
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
Clojure: a LISP for the JVM
Clojure: a LISP for the JVMClojure: a LISP for the JVM
Clojure: a LISP for the JVM
 
Java 7: Quo vadis?
Java 7: Quo vadis?Java 7: Quo vadis?
Java 7: Quo vadis?
 
5050 dev nation
5050 dev nation5050 dev nation
5050 dev nation
 
Metrics for example Java project
Metrics for example Java projectMetrics for example Java project
Metrics for example Java project
 
Rest in flask
Rest in flaskRest in flask
Rest in flask
 
Java Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet BasicJava Web Programming [2/9] : Servlet Basic
Java Web Programming [2/9] : Servlet Basic
 
Doctrine 2
Doctrine 2Doctrine 2
Doctrine 2
 
BASTA 2013: Custom OData Provider
BASTA 2013: Custom OData ProviderBASTA 2013: Custom OData Provider
BASTA 2013: Custom OData Provider
 

Ähnlich wie Slice: OpenJPA for Distributed Persistence

Entity Persistence with JPA
Entity Persistence with JPAEntity Persistence with JPA
Entity Persistence with JPASubin Sugunan
 
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
 
Sqladria 2009 SRC
Sqladria 2009 SRCSqladria 2009 SRC
Sqladria 2009 SRCtepsum
 
Declarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi StyleDeclarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi StyleFelix Meschberger
 
Declarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi StyleDeclarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi StyleFelix Meschberger
 
OSGi ecosystems compared on Apache Karaf - Christian Schneider
OSGi ecosystems compared on Apache Karaf - Christian SchneiderOSGi ecosystems compared on Apache Karaf - Christian Schneider
OSGi ecosystems compared on Apache Karaf - Christian Schneidermfrancis
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2wiradikusuma
 
JUG Berlin Brandenburg: What's new in Java EE 7?
JUG Berlin Brandenburg: What's new in Java EE 7?JUG Berlin Brandenburg: What's new in Java EE 7?
JUG Berlin Brandenburg: What's new in Java EE 7?gedoplan
 
Accelerated data access
Accelerated data accessAccelerated data access
Accelerated data accessgordonyorke
 
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreJava Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreIMC Institute
 
Slice for Distributed Persistence (JavaOne 2010)
Slice for Distributed Persistence (JavaOne 2010)Slice for Distributed Persistence (JavaOne 2010)
Slice for Distributed Persistence (JavaOne 2010)Pinaki Poddar
 
Core Php Component Presentation
Core Php Component PresentationCore Php Component Presentation
Core Php Component PresentationJohn Coonen
 
Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8PrinceGuru MS
 
JEST: REST on OpenJPA
JEST: REST on OpenJPAJEST: REST on OpenJPA
JEST: REST on OpenJPAPinaki Poddar
 
Java one 2010
Java one 2010Java one 2010
Java one 2010scdn
 

Ähnlich wie Slice: OpenJPA for Distributed Persistence (20)

Entity Persistence with JPA
Entity Persistence with JPAEntity Persistence with JPA
Entity Persistence with JPA
 
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...
 
Sqladria 2009 SRC
Sqladria 2009 SRCSqladria 2009 SRC
Sqladria 2009 SRC
 
Declarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi StyleDeclarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi Style
 
Declarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi StyleDeclarative Services - Dependency Injection OSGi Style
Declarative Services - Dependency Injection OSGi Style
 
OSGi ecosystems compared on Apache Karaf - Christian Schneider
OSGi ecosystems compared on Apache Karaf - Christian SchneiderOSGi ecosystems compared on Apache Karaf - Christian Schneider
OSGi ecosystems compared on Apache Karaf - Christian Schneider
 
Introducing Struts 2
Introducing Struts 2Introducing Struts 2
Introducing Struts 2
 
JUG Berlin Brandenburg: What's new in Java EE 7?
JUG Berlin Brandenburg: What's new in Java EE 7?JUG Berlin Brandenburg: What's new in Java EE 7?
JUG Berlin Brandenburg: What's new in Java EE 7?
 
Accelerated data access
Accelerated data accessAccelerated data access
Accelerated data access
 
Java Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : DatastoreJava Web Programming on Google Cloud Platform [2/3] : Datastore
Java Web Programming on Google Cloud Platform [2/3] : Datastore
 
Introduction to Datastore
Introduction to DatastoreIntroduction to Datastore
Introduction to Datastore
 
JavaEE Spring Seam
JavaEE Spring SeamJavaEE Spring Seam
JavaEE Spring Seam
 
ORM JPA
ORM JPAORM JPA
ORM JPA
 
Os Leonard
Os LeonardOs Leonard
Os Leonard
 
Java EE 6 & Spring: A Lover's Quarrel
Java EE 6 & Spring: A Lover's QuarrelJava EE 6 & Spring: A Lover's Quarrel
Java EE 6 & Spring: A Lover's Quarrel
 
Slice for Distributed Persistence (JavaOne 2010)
Slice for Distributed Persistence (JavaOne 2010)Slice for Distributed Persistence (JavaOne 2010)
Slice for Distributed Persistence (JavaOne 2010)
 
Core Php Component Presentation
Core Php Component PresentationCore Php Component Presentation
Core Php Component Presentation
 
Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8Corephpcomponentpresentation 1211425966721657-8
Corephpcomponentpresentation 1211425966721657-8
 
JEST: REST on OpenJPA
JEST: REST on OpenJPAJEST: REST on OpenJPA
JEST: REST on OpenJPA
 
Java one 2010
Java one 2010Java one 2010
Java one 2010
 

Kürzlich hochgeladen

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Kürzlich hochgeladen (20)

Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
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
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

Slice: OpenJPA for Distributed Persistence

  • 1. Scale Your JPA Applications with Distributed Database Partitions Dr. Pinaki Poddar [email_address] Session Number: D05
  • 2.
  • 3.
  • 4.
  • 5. How to obtain a Persistence Unit? Instantiate via bootstrap EntityManagerFactory construction is costly WARNING EntityManagerFactory emf = Persistence .createEntityManagerFactory( “test” ) ; InitialiContext ctx = new InitialContext(); EntityManagerFactory emf = ctx .lookup( “myEMF” ) ); Look up in JNDI @PersistenceUnit (unitName= “test” ) private EntityManagerFactory emf; Inject as a resource
  • 6.
  • 7. How to obtain a Persistence Context? EntityManager em = emf.createEntityManager() Construct from Persistence Unit @PersistenceContext private EntityManager em; Inject as a resource
  • 8. Persistence Context manages instances in a group em1 = emf.createEntityManager(); em2 = emf.createEntityManager(); Account ID NAME AMOUNT SELECT ID,NAME FROM ACCOUNT t WHERE t.ID=1245 Persistence Unit Persistence Context Account pc1 = em1.find(Account.class,1245); Persistence Context Account pc2 = em2.find(Account.class,1245); 2347 John $ 12000.57 1245 Mary $ 34568.89
  • 9.
  • 10. Life of Persistence Context em = emf.createEntityManager(); begin(); commit(); flush(); clear(); close(); begin(); commit(); Extended Persistence Context Transactional Persistence Context Time
  • 11.
  • 12. Transaction Scaling in JPA em = emf.createEntityManager() begin() commit() flush() clear() close() begin() commit() Extended Persistence Context Transaction-scoped Persistence Context L2 Data Cache Database Transaction Time
  • 13. Optimistic Versioning scales transaction begin(); commit(); pc1 = find(Item.class, 1234); qty:5 version: 56 Item:1234 qty:30 version: 56 Item:1234 begin(); commit(); pc2 = find(Item.class, 1234); qty:5 version: 56 Item:1234 qty:87 version: 56 Item:1234 UPDATE ITEM SET QTY=30, VERSION=57 WHERE ID=1234 AND VERSION=56 ID 1234 QTY 5 VERSION 56 ID 1234 QTY 30 VERSION 57 pc2.setQty(87); pc1.setQty(30); 1 3 4 2 5 6 7 9 8 UPDATE ITEM SET QTY=87, VERSION=57 WHERE ID=1234 AND VERSION=56 10 Optimistic Exception
  • 14. Multi-level caches favor read-mostly sessions em1 = emf.createEntityManager(); em1.begin() em1.commit() em2.begin() em2.commit() L2 Data Cache Database Access & Transaction Time em1.query() em2 = emf.createEntityManager(); em2.find() em2.find() em2.remove()
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21. Architectural Tiers of JPA-based service JPA-based User Application OpenJPA Standard JPA API JDBC API
  • 22. Architectural Tiers of Slice-based service Slice-based User Application OpenJPA Standard JPA API JDBC API Slice OpenJPA is a plugabble platform
  • 23. Features of Slice Slice-based User Application OpenJPA Standard JPA API JDBC API Slice No change to Application code or Domain Model User-defined Distribution & Replication Policy Flexible per-Slice Configuration Parallel Query Execution Heterogeneous Databases Master-based Sequence Targeted Query
  • 24.
  • 25.
  • 26. Persistence Unit Configuration <? xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> < persistence xmlns=&quot; http://java.sun.com/xml/ns/persistence &quot; xmlns:xsi=&quot; http://www.w3.org/2001/XMLSchema-instance &quot; version=&quot;1.0&quot; xsi:schemaLocation=&quot; http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd &quot;> < persistence-unit name=&quot; test “ transaction=“ RESOURCE_LOCAL ”> < provider > org.apache.openjpa.persistence.PersistenceProviderImpl </provider> < class > domain.EntityA </class> < class > domain.EntityB </class> < properties > < property name=&quot; openjpa.ConnectionDriverName &quot; value=&quot; com.mysql.jdbc.Driver &quot;/> < property name=&quot; openjpa.ConnectionURL &quot; value=&quot; jdbc:mysql://localhost/test &quot;/> < property name=&quot; openjpa.jdbc.SynchronizeMappings &quot; value=&quot; buildSchema &quot;/> < property name=&quot; openjpa.Log &quot; value=&quot; SQL=TRACE &quot;/> </ properties > </ persistence-unit > List of known Persistent types Vendor-specific configuration Governed by XML Schema JPA Provider is pluggable META-INF/persistence.xml Identified by Unit Name
  • 27. Per-Slice Configuration < properties > < property name=&quot; openjpa.BrokerFactory&quot; value =“ slice &quot;/> < property name =“openjpa.slice.Names” value =“ One,Two,Three ”/> < property name =“openjpa.slice.Master” value =“ One ”/> < property name=&quot; openjpa.slice.DistributionPolicy &quot; value=“ acme.org.MyDistroPolicy &quot;/> < property name=&quot; openjpa.ConnectionDriverName &quot; value=&quot; com.mysql.jdbc.Driver &quot;/> < property name=&quot; openjpa.slice.One.ConnectionURL &quot; value=&quot; jdbc:mysql://localhost/slice1 &quot;/> < property name=“ openjpa.slice.Two.ConnectionURL ” value=“ jdbc:mysql://localhost/slice2 ”/> < property name=“ openjpa.slice.Three.ConnectionDriverName ” value=“ com.ibm.db2.jcc.DB2Driver ”/> < property name=“ openjpa.slice.Three.ConnectionURL ” value=“ jdbc:db2 :// mac3:50000/slice3 ”/> < property name=&quot; openjpa.jdbc.SynchronizeMappings &quot; value=&quot; buildSchema &quot;/> </ properties > </ persistence-unit > META-INF/persistence.xml Activate Slice Declare slices Configure each slice Configure common behavior Define Data Distribution Policy
  • 28.
  • 29.
  • 30. Distribution Policy public interface DistributionPolicy { /** * Gets the name of the slice where the given newly persistent * instance will be stored. * * @param pc The newly persistent or to-be-merged object. * @param slices name of the configured slices. * @param context persistence context managing the given instance. * * @return identifier of the slice. This name must match one of the * configured slice names. * @see DistributedConfiguration#getSliceNames() */ String distribute ( Object pc, List<String> slices, Object context); } Slice will call this method while persisting or merging a root instance. The instance and its closure will be stored in the returned slice.
  • 31.
  • 32.
  • 33.
  • 34. Replication Policy public interface ReplicationPolicy { /** * Gets the name of the slices where the given newly persistent * instance will be replicated. * * @param pc The newly persistent or to-be-merged object. * @param slices name of the configured slices. * @param context persistence context managing the given instance. * * @return identifier(s) of the slice. Each name must match one of the * configured slice names. * @see DistributedConfiguration#getSliceNames() */ String[] replicate ( Object pc, List<String> slices, Object context); } Slice will call this method while persisting any @Replicated instance.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48. Core Architectural constructs of OpenJPA EntityManager Factory BrokerFactory EntityManager Broker StoreManager JDBCStore Manager JDBC API OpenJPA Configuration creates creates delegates delegates configured by
  • 49.
  • 50. Slice extends OpenJPA by Distributed Template EntityManager Factory BrokerFactory EntityManager Broker DistributedStoreManager JDBCStore Manager JDBC API JDBCStore Manager JDBCStore Manager Distributed Configuration delegates delegates creates creates configures applies Distributed Template Pattern Not aware of partitioned Databases
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.

Hinweis der Redaktion

  1. DataCache will be standardized in JPA 2.0