SlideShare a Scribd company logo
1 of 33
Download to read offline
Easy ORM-ness with Objectify-Appengine



                           Meetu Maltiar
                        Inphina Technologies




                                               1
Overall Presentation Goal


Google Datastore Basics
Options available for managing persistence
Objectify-Appengine
Demo of an application using Objectify



                                         2
Enough About Me
Senior Software Engineer at Inphina
Technologies that interest me:
  Cloud Computing
  Scala
  Hadoop




                                      3
Datastore Basics
Entities
Operations
Keys
Transactions




                   4
Entities
An Entity is an object’s worth of data in the
 datastore
In datastore an Entity is like HashMap-like object
  of type Entity
Datastore is conceptually a HashMap of keys to
 entities, and an Entity is conceptually a
 HashMap of name/value pairs



                                                5
Operations
Get() an entity as a whole from datastore
Put() an entity as whole in datastore
Delete() an entity from datastore
Query() for entities matching criteria you define




                                                    6
Keys
In the datastore, entities are identified by the id
  (or name) and a kind, which corresponds to the
  type of Object you are storing.


So, to get Employee #111 from datastore, we
  need to call something like get_from_datastore
  (“Employee”, 111)



                                                 7
Keys Continued
There is actually a third parameter required to
 identify an entity and it is called parent
Parent places the child in the same entity group
 as the parent
Parent (which can be null for the un-parented,
 root entity) is also required to uniquely
 identify an Entity.



                                                   8
Keys Continued
So, to get Employee #111 from datastore we
  need to call something equivalent to:
get_from_datastore (“Employee”, 111, null)

or,
get_from_datastore (“Employee”, 111, the_parent).

Instead of passing three parameters datastore
  wraps it in a single Object called Key.


                                                    9
Transactions
Data gets stored in gigantic form of thousands of
 machines
In order to perform an atomic transaction
  datastoreTo give us more that over where our data is same
             requires control entities lie on
  servers. stored, the datastore has a concept of an entity
            group

To give us more control over where our data is
 stored, the datastore has a concept of an entity
 group


                                                              10
Transactions Continued
Within a Transaction we can access data from a
 single entity group
Choose entity groups carefully
Why not have everything in a single entity
 group?
Google restricts number of requests per second
 per entity group



                                                 11
Executing Transactions
When we execute get(), put(), delete() or query()
 in transaction
We must operate it on single entity group
All operations will either fail or succeed
 completely
If another process modifies the data before
   commit datastore operation will fail



                                                12
Tools




        13
Persistence Options
JPA/JDO
Google Datastore
Persistence Frameworks on GAE
 Objectify-Appengine
 Twig
 Simple Datastore
 Slim3
                                14
Google Datastore Challenges
Supports just four operations
It persists GAE-Specific entity classes rather
  than POJO’s
Datastore Keys are untyped




                                            15
JPA/JDO Challenges
Extra Cruft
 Fetch Groups

 Detaching
 Owned/Unowned relationships

Leaky Abstraction
 Keys

 Entity Groups
 Indexes

                               16
Developers Dilemma




                     17
Objectify
It lets you persist, retrieve, delete and
  query typed objects
All native datastore features are supported
It provides type safe key and query classes




                                              18
Objectify Design Considerations
Minimally impacts cold start time. It is light
 weight
No external dependencies apart from GAE
 SDK




                                            19
Working With Datastore

Entity ent = new Entity(“car”);
ent.setProperty(“color”, “red”);
ent.setProperty(“doors”, 2);
service.put(ent);




                                   20
Objectify ORMNess Objects!

Employee emp = new Employee();
emp.setFirstName(“John”);
emp.setLastName(“Smith”);
service.put(emp);




                                 21
An Objectify Entity

public class Employee {
    @Id Long id;
    private String firstName;
    private String lastName;
}




                                22
get() Operation

Objectify ofy = Objectifyservice.begin();
Employee emp = ofy.get(Employee.class, 123);
Map<Long, Employee> employees =
          ofy.get(Employee.class, 123, 124, 125);




                                                    23
put() Operation

Objectify ofy = Objectifyservice.begin();
Employee emp = new Employee(“John”, “adams”);
ofy.put(emp);
System.out.println(“Id Generated is ” + emp.getId());
List<Employee> employees = createEmployees();
ofy.put(employees);




                                                        24
delete() Operation

Objectify ofy = Objectifyservice.begin();
ofy.delete(Employee.class, 123);


Employee emp = // get Employee from some where
ofy.delete(emp);




                                                 25
query() Operation


Objectify ofy = Objectifyservice.begin();


List<Employee> employees =
   ofy.query(Employee.class).filter(“firstName =”, “John”)




                                                             26
Demo
 get()
 put()
 delete()
 query()




            27
Objectify Best Practices
Use a DAO to register entities
Automatic Scanning
  not advised adds to initialization time
  will require dependency jars apart from GAE
  will require changes in web.xml
GAE spins down the instance when not in use. When it
 comes up the request is slow because of added
 initialization time. This is called cold start.

                                                   28
Objectify Best Practices …
Use Batch Gets Instead of Queries
Use Indexes sparingly
By default every field of object will be indexed. It comes with
  heavy computational price.
Use @Unindexed on entity level and @Indexed at fields required
  for query

Avoid @Parent
In JPA “owned” entity relationship provides referential integrity
   checking and cascading deletes and saves. Not so here.


                                                                  29
Happy Developer




                  30
Conclusion
JDO/JPA learning curve is steep due to App Engine’s non-
  relational nature and unique concepts such as entity groups,
  owned and un-owned relationships.
Google Datastore is low level. It makes no pretense of being
  relational but also does not allow working with objects. It just
  stores the objects of type
  com.google.appengine.api.datastore.Entity
Objectify is light weight and it preserves the simplicity and
  transparency of low level API and does all work converting to
  and from POJOS to Entity Objects.




                                                                     31
mmaltiar@inphina.com

      www.inphina.com
http://thoughts.inphina.com




                              32
References
Objectify-Appengine
  http://code.google.com/p/objectify-appengine/


Google IO 2011 Session on highly productive gwt
  rapid development with app-engine objectify-requestfactory
  and gwt-platform


Twitter mining with Objectify-Appengine
  http://www.ibm.com/developerworks/java/library/j-javadev2-14
  -


                                                               33

More Related Content

What's hot

Cloud computing BI publication 1
Cloud computing BI   publication 1Cloud computing BI   publication 1
Cloud computing BI publication 1
Jobe Bacwadi
 
Easy data-with-spring-data-jpa
Easy data-with-spring-data-jpaEasy data-with-spring-data-jpa
Easy data-with-spring-data-jpa
Staples
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
hr1383
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
Syed Shahul
 
Advanced Hibernate Notes
Advanced Hibernate NotesAdvanced Hibernate Notes
Advanced Hibernate Notes
Kaniska Mandal
 
12 global fetching strategies
12 global fetching strategies12 global fetching strategies
12 global fetching strategies
thirumuru2012
 

What's hot (19)

Cloud computing BI publication 1
Cloud computing BI   publication 1Cloud computing BI   publication 1
Cloud computing BI publication 1
 
Introduction to JPA (JPA version 2.0)
Introduction to JPA (JPA version 2.0)Introduction to JPA (JPA version 2.0)
Introduction to JPA (JPA version 2.0)
 
TY.BSc.IT Java QB U2
TY.BSc.IT Java QB U2TY.BSc.IT Java QB U2
TY.BSc.IT Java QB U2
 
Easy data-with-spring-data-jpa
Easy data-with-spring-data-jpaEasy data-with-spring-data-jpa
Easy data-with-spring-data-jpa
 
Backendless apps
Backendless appsBackendless apps
Backendless apps
 
An introduction into Spring Data
An introduction into Spring DataAn introduction into Spring Data
An introduction into Spring Data
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentation
 
Introduction to hibernate
Introduction to hibernateIntroduction to hibernate
Introduction to hibernate
 
JDBC - JPA - Spring Data
JDBC - JPA - Spring DataJDBC - JPA - Spring Data
JDBC - JPA - Spring Data
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
 
Spring framework part 2
Spring framework part 2Spring framework part 2
Spring framework part 2
 
Mastering Oracle ADF Bindings
Mastering Oracle ADF BindingsMastering Oracle ADF Bindings
Mastering Oracle ADF Bindings
 
Advanced Hibernate Notes
Advanced Hibernate NotesAdvanced Hibernate Notes
Advanced Hibernate Notes
 
Scala and Spring
Scala and SpringScala and Spring
Scala and Spring
 
Data herding
Data herdingData herding
Data herding
 
Hibernate Interview Questions | Edureka
Hibernate Interview Questions | EdurekaHibernate Interview Questions | Edureka
Hibernate Interview Questions | Edureka
 
12 global fetching strategies
12 global fetching strategies12 global fetching strategies
12 global fetching strategies
 
Implementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDBImplementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDB
 
SOLID Principles
SOLID PrinciplesSOLID Principles
SOLID Principles
 

Similar to Easy ORM-ness with Objectify-Appengine - Indicthreads cloud computing conference 2011

Similar to Easy ORM-ness with Objectify-Appengine - Indicthreads cloud computing conference 2011 (20)

Easy ORMness with Objectify-Appengine
Easy ORMness with Objectify-AppengineEasy ORMness with Objectify-Appengine
Easy ORMness with Objectify-Appengine
 
S03 hybrid app_and_gae_datastore_v1.0
S03 hybrid app_and_gae_datastore_v1.0S03 hybrid app_and_gae_datastore_v1.0
S03 hybrid app_and_gae_datastore_v1.0
 
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
 
The 90-Day Startup with Google AppEngine for Java
The 90-Day Startup with Google AppEngine for JavaThe 90-Day Startup with Google AppEngine for Java
The 90-Day Startup with Google AppEngine for Java
 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0
 
Data herding
Data herdingData herding
Data herding
 
SPCA2013 - SharePoint Nightmares - Coding Patterns and Practices
SPCA2013 - SharePoint Nightmares - Coding Patterns and PracticesSPCA2013 - SharePoint Nightmares - Coding Patterns and Practices
SPCA2013 - SharePoint Nightmares - Coding Patterns and Practices
 
Green dao
Green daoGreen dao
Green dao
 
Agile Data Science 2.0
Agile Data Science 2.0Agile Data Science 2.0
Agile Data Science 2.0
 
Data Seeding via Parameterized API Requests
Data Seeding via Parameterized API RequestsData Seeding via Parameterized API Requests
Data Seeding via Parameterized API Requests
 
Agile Data Science 2.0 - Big Data Science Meetup
Agile Data Science 2.0 - Big Data Science MeetupAgile Data Science 2.0 - Big Data Science Meetup
Agile Data Science 2.0 - Big Data Science Meetup
 
Batch Applications for the Java Platform
Batch Applications for the Java PlatformBatch Applications for the Java Platform
Batch Applications for the Java Platform
 
JavaOne 2007 - TS4721
JavaOne 2007 - TS4721 JavaOne 2007 - TS4721
JavaOne 2007 - TS4721
 
03. oop concepts
03. oop concepts03. oop concepts
03. oop concepts
 
Ef Poco And Unit Testing
Ef Poco And Unit TestingEf Poco And Unit Testing
Ef Poco And Unit Testing
 
Building React Applications with Redux
Building React Applications with ReduxBuilding React Applications with Redux
Building React Applications with Redux
 
Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4Building Large Scale PHP Web Applications with Laravel 4
Building Large Scale PHP Web Applications with Laravel 4
 
Agile Data Science
Agile Data ScienceAgile Data Science
Agile Data Science
 
Dao pattern
Dao patternDao pattern
Dao pattern
 
Zend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching loggingZend framework 03 - singleton factory data mapper caching logging
Zend framework 03 - singleton factory data mapper caching logging
 

More from IndicThreads

Scrap Your MapReduce - Apache Spark
 Scrap Your MapReduce - Apache Spark Scrap Your MapReduce - Apache Spark
Scrap Your MapReduce - Apache Spark
IndicThreads
 
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
 Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
IndicThreads
 
Unraveling OpenStack Clouds
 Unraveling OpenStack Clouds Unraveling OpenStack Clouds
Unraveling OpenStack Clouds
IndicThreads
 

More from IndicThreads (20)

Http2 is here! And why the web needs it
Http2 is here! And why the web needs itHttp2 is here! And why the web needs it
Http2 is here! And why the web needs it
 
Understanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
Understanding Bitcoin (Blockchain) and its Potential for Disruptive ApplicationsUnderstanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
Understanding Bitcoin (Blockchain) and its Potential for Disruptive Applications
 
Go Programming Language - Learning The Go Lang way
Go Programming Language - Learning The Go Lang wayGo Programming Language - Learning The Go Lang way
Go Programming Language - Learning The Go Lang way
 
Building Resilient Microservices
Building Resilient Microservices Building Resilient Microservices
Building Resilient Microservices
 
App using golang indicthreads
App using golang  indicthreadsApp using golang  indicthreads
App using golang indicthreads
 
Building on quicksand microservices indicthreads
Building on quicksand microservices  indicthreadsBuilding on quicksand microservices  indicthreads
Building on quicksand microservices indicthreads
 
How to Think in RxJava Before Reacting
How to Think in RxJava Before ReactingHow to Think in RxJava Before Reacting
How to Think in RxJava Before Reacting
 
Iot secure connected devices indicthreads
Iot secure connected devices indicthreadsIot secure connected devices indicthreads
Iot secure connected devices indicthreads
 
Real world IoT for enterprises
Real world IoT for enterprisesReal world IoT for enterprises
Real world IoT for enterprises
 
IoT testing and quality assurance indicthreads
IoT testing and quality assurance indicthreadsIoT testing and quality assurance indicthreads
IoT testing and quality assurance indicthreads
 
Functional Programming Past Present Future
Functional Programming Past Present FutureFunctional Programming Past Present Future
Functional Programming Past Present Future
 
Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams Harnessing the Power of Java 8 Streams
Harnessing the Power of Java 8 Streams
 
Building & scaling a live streaming mobile platform - Gr8 road to fame
Building & scaling a live streaming mobile platform - Gr8 road to fameBuilding & scaling a live streaming mobile platform - Gr8 road to fame
Building & scaling a live streaming mobile platform - Gr8 road to fame
 
Internet of things architecture perspective - IndicThreads Conference
Internet of things architecture perspective - IndicThreads ConferenceInternet of things architecture perspective - IndicThreads Conference
Internet of things architecture perspective - IndicThreads Conference
 
Cars and Computers: Building a Java Carputer
 Cars and Computers: Building a Java Carputer Cars and Computers: Building a Java Carputer
Cars and Computers: Building a Java Carputer
 
Scrap Your MapReduce - Apache Spark
 Scrap Your MapReduce - Apache Spark Scrap Your MapReduce - Apache Spark
Scrap Your MapReduce - Apache Spark
 
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
 Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
Continuous Integration (CI) and Continuous Delivery (CD) using Jenkins & Docker
 
Speed up your build pipeline for faster feedback
Speed up your build pipeline for faster feedbackSpeed up your build pipeline for faster feedback
Speed up your build pipeline for faster feedback
 
Unraveling OpenStack Clouds
 Unraveling OpenStack Clouds Unraveling OpenStack Clouds
Unraveling OpenStack Clouds
 
Digital Transformation of the Enterprise. What IT leaders need to know!
Digital Transformation of the Enterprise. What IT  leaders need to know!Digital Transformation of the Enterprise. What IT  leaders need to know!
Digital Transformation of the Enterprise. What IT leaders need to know!
 

Recently uploaded

TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...Stronger Together: Developing an Organizational Strategy for Accessible Desig...
Stronger Together: Developing an Organizational Strategy for Accessible Desig...
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Choreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software EngineeringChoreo: Empowering the Future of Enterprise Software Engineering
Choreo: Empowering the Future of Enterprise Software Engineering
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
WSO2 Micro Integrator for Enterprise Integration in a Decentralized, Microser...
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
JavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate GuideJavaScript Usage Statistics 2024 - The Ultimate Guide
JavaScript Usage Statistics 2024 - The Ultimate Guide
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

Easy ORM-ness with Objectify-Appengine - Indicthreads cloud computing conference 2011

  • 1. Easy ORM-ness with Objectify-Appengine Meetu Maltiar Inphina Technologies 1
  • 2. Overall Presentation Goal Google Datastore Basics Options available for managing persistence Objectify-Appengine Demo of an application using Objectify 2
  • 3. Enough About Me Senior Software Engineer at Inphina Technologies that interest me: Cloud Computing Scala Hadoop 3
  • 5. Entities An Entity is an object’s worth of data in the datastore In datastore an Entity is like HashMap-like object of type Entity Datastore is conceptually a HashMap of keys to entities, and an Entity is conceptually a HashMap of name/value pairs 5
  • 6. Operations Get() an entity as a whole from datastore Put() an entity as whole in datastore Delete() an entity from datastore Query() for entities matching criteria you define 6
  • 7. Keys In the datastore, entities are identified by the id (or name) and a kind, which corresponds to the type of Object you are storing. So, to get Employee #111 from datastore, we need to call something like get_from_datastore (“Employee”, 111) 7
  • 8. Keys Continued There is actually a third parameter required to identify an entity and it is called parent Parent places the child in the same entity group as the parent Parent (which can be null for the un-parented, root entity) is also required to uniquely identify an Entity. 8
  • 9. Keys Continued So, to get Employee #111 from datastore we need to call something equivalent to: get_from_datastore (“Employee”, 111, null) or, get_from_datastore (“Employee”, 111, the_parent). Instead of passing three parameters datastore wraps it in a single Object called Key. 9
  • 10. Transactions Data gets stored in gigantic form of thousands of machines In order to perform an atomic transaction datastoreTo give us more that over where our data is same requires control entities lie on servers. stored, the datastore has a concept of an entity group To give us more control over where our data is stored, the datastore has a concept of an entity group 10
  • 11. Transactions Continued Within a Transaction we can access data from a single entity group Choose entity groups carefully Why not have everything in a single entity group? Google restricts number of requests per second per entity group 11
  • 12. Executing Transactions When we execute get(), put(), delete() or query() in transaction We must operate it on single entity group All operations will either fail or succeed completely If another process modifies the data before commit datastore operation will fail 12
  • 13. Tools 13
  • 14. Persistence Options JPA/JDO Google Datastore Persistence Frameworks on GAE Objectify-Appengine Twig Simple Datastore Slim3 14
  • 15. Google Datastore Challenges Supports just four operations It persists GAE-Specific entity classes rather than POJO’s Datastore Keys are untyped 15
  • 16. JPA/JDO Challenges Extra Cruft Fetch Groups Detaching Owned/Unowned relationships Leaky Abstraction Keys Entity Groups Indexes 16
  • 18. Objectify It lets you persist, retrieve, delete and query typed objects All native datastore features are supported It provides type safe key and query classes 18
  • 19. Objectify Design Considerations Minimally impacts cold start time. It is light weight No external dependencies apart from GAE SDK 19
  • 20. Working With Datastore Entity ent = new Entity(“car”); ent.setProperty(“color”, “red”); ent.setProperty(“doors”, 2); service.put(ent); 20
  • 21. Objectify ORMNess Objects! Employee emp = new Employee(); emp.setFirstName(“John”); emp.setLastName(“Smith”); service.put(emp); 21
  • 22. An Objectify Entity public class Employee { @Id Long id; private String firstName; private String lastName; } 22
  • 23. get() Operation Objectify ofy = Objectifyservice.begin(); Employee emp = ofy.get(Employee.class, 123); Map<Long, Employee> employees = ofy.get(Employee.class, 123, 124, 125); 23
  • 24. put() Operation Objectify ofy = Objectifyservice.begin(); Employee emp = new Employee(“John”, “adams”); ofy.put(emp); System.out.println(“Id Generated is ” + emp.getId()); List<Employee> employees = createEmployees(); ofy.put(employees); 24
  • 25. delete() Operation Objectify ofy = Objectifyservice.begin(); ofy.delete(Employee.class, 123); Employee emp = // get Employee from some where ofy.delete(emp); 25
  • 26. query() Operation Objectify ofy = Objectifyservice.begin(); List<Employee> employees = ofy.query(Employee.class).filter(“firstName =”, “John”) 26
  • 27. Demo get() put() delete() query() 27
  • 28. Objectify Best Practices Use a DAO to register entities Automatic Scanning not advised adds to initialization time will require dependency jars apart from GAE will require changes in web.xml GAE spins down the instance when not in use. When it comes up the request is slow because of added initialization time. This is called cold start. 28
  • 29. Objectify Best Practices … Use Batch Gets Instead of Queries Use Indexes sparingly By default every field of object will be indexed. It comes with heavy computational price. Use @Unindexed on entity level and @Indexed at fields required for query Avoid @Parent In JPA “owned” entity relationship provides referential integrity checking and cascading deletes and saves. Not so here. 29
  • 31. Conclusion JDO/JPA learning curve is steep due to App Engine’s non- relational nature and unique concepts such as entity groups, owned and un-owned relationships. Google Datastore is low level. It makes no pretense of being relational but also does not allow working with objects. It just stores the objects of type com.google.appengine.api.datastore.Entity Objectify is light weight and it preserves the simplicity and transparency of low level API and does all work converting to and from POJOS to Entity Objects. 31
  • 32. mmaltiar@inphina.com www.inphina.com http://thoughts.inphina.com 32
  • 33. References Objectify-Appengine http://code.google.com/p/objectify-appengine/ Google IO 2011 Session on highly productive gwt rapid development with app-engine objectify-requestfactory and gwt-platform Twitter mining with Objectify-Appengine http://www.ibm.com/developerworks/java/library/j-javadev2-14 - 33