SlideShare a Scribd company logo
Easy ORM-ness with Objectify-AppengineMeetu MaltiarInphina Technologies
Overall Presentation GoalGoogle Datastore BasicsOptions available for managing persistenceObjectify-AppengineDemo of an application using Objectify
Enough About MeSenior Software Engineer at InphinaTechnologies that interest me:     Cloud Computing     Scala     Hadoop
Datastore BasicsEntitiesOperationsKeysTransactions
EntitiesAn Entity is an object’s worth of data in the datastoreIn 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
OperationsGet() an entity as a whole from datastorePut() an entity as whole in datastoreDelete() an entity from datastoreQuery() for entities matching criteria you define
KeysIn 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)
Keys ContinuedThere is actually a third parameter required to identify an entity and it is called parentParent places the child in the same entity group as the parentParent (which can be null for the un-parented, root entity) is also required to uniquely identify an Entity.
Keys ContinuedSo, 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.
TransactionsData gets stored in gigantic form of thousands of machinesIn order to perform an atomic transaction datastore requires that entities lie on same servers.To give us more control over where our data is stored, the datastore has a concept of an entity groupTo give us more control over where our data is stored, the datastore has a concept of an entity group
Transactions ContinuedWithin a Transaction we can access data from a single entity groupChoose entity groups carefullyWhy not have everything in a single entity group?Google restricts number of requests per second per entity group
Executing TransactionsWhen we execute get(), put(), delete() or query() in transactionWe must operate it on single entity groupAll operations will either fail or succeed completelyIf another process modifies the data before commit datastore operation will fail
Tools
Persistence OptionsJPA/JDOGoogle DatastorePersistence Frameworks on GAE  Objectify-Appengine  Twig  Simple Datastore  Slim3
Google Datastore ChallengesSupports just four operationsIt persists GAE-Specific entity classes rather than POJO’sDatastore Keys are untyped
JPA/JDO ChallengesExtra CruftFetch Groups   Detaching   Owned/UnownedrelationshipsLeaky AbstractionKeys   Entity Groups   Indexes
Developers Dilemma
ObjectifyIt lets you persist, retrieve, delete and query typed objectsAll native datastore features are supportedIt provides type safe key and query classes
Objectify Design ConsiderationsMinimally impacts cold start time. It is light weightNo external dependencies apart from GAE SDK
Working With DatastoreEntity ent = new Entity(“car”);ent.setProperty(“color”, “red”);ent.setProperty(“doors”, 2);service.put(ent);
Objectify ORMNess Objects!Employee emp = new Employee();emp.setFirstName(“John”);emp.setLastName(“Smith”);service.put(emp);
An Objectify Entitypublic class Employee {  @Id Long id;   private String firstName;   private String lastName;}
get() OperationObjectify ofy = Objectifyservice.begin();Employee emp = ofy.get(Employee.class, 123);Map<Long, Employee> employees = ofy.get(Employee.class, 123, 124, 125);
put() OperationObjectify 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);
delete() OperationObjectify ofy = Objectifyservice.begin();ofy.delete(Employee.class, 123);Employee emp = // get Employee from some whereofy.delete(emp);
query() OperationObjectify ofy = Objectifyservice.begin();List<Employee> employees =       ofy.query(Employee.class).filter(“firstName =”, “John”)
Demo    get()    put()    delete()    query()
Objectify Best PracticesUse a DAO to register entitiesAutomatic Scanningnot advised adds to initialization time    will require dependency jars apart from GAE    will require changes in web.xmlGAE 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.
Objectify Best Practices …Use Batch Gets Instead of QueriesUse Indexes sparinglyBy 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 queryAvoid @ParentIn JPA “owned” entity relationship provides referential integrity checking and cascading deletes and saves. Not so here.
Happy Developer
ConclusionJDO/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.EntityObjectify 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.
mmaltiar@inphina.comwww.inphina.comhttp://thoughts.inphina.com
ReferencesObjectify-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-platformTwitter mining with Objectify-Appengine http://www.ibm.com/developerworks/java/library/j-javadev2-14/?ca=drs-

More Related Content

PDF
Easy ORM-ness with Objectify-Appengine - Indicthreads cloud computing confere...
PDF
Data access
PDF
Hibernate An Introduction
PPTX
Hibernate in Nutshell
PDF
Introduction to Datastore
PDF
.Net Classes and Objects | UiPath Community
PPTX
Certification preparation - Net classses and functions.pptx
Easy ORM-ness with Objectify-Appengine - Indicthreads cloud computing confere...
Data access
Hibernate An Introduction
Hibernate in Nutshell
Introduction to Datastore
.Net Classes and Objects | UiPath Community
Certification preparation - Net classses and functions.pptx

What's hot (19)

PPTX
Certification preparation - Error Handling and Troubleshooting recap.pptx
PPTX
Testing database content with DBUnit. My experience.
PPT
hibernate with JPA
PPT
Intro To Hibernate
PPT
Entity Persistence with JPA
PPTX
Object identification and its management
PDF
ERRest in Depth
PDF
Introduction to JPA and Hibernate including examples
PDF
ERRest
PPT
Introduction to hibernate
PPTX
Jpa 2.1 Application Development
ODP
Hibernate complete Training
ODP
JPA Best Practices
PDF
ERRest - Designing a good REST service
PPTX
Introduction to Hibernate Framework
PPTX
Spring data jpa
PPT
Hibernate training mumbai_hql
PDF
JPA 2.1 performance tuning tips
Certification preparation - Error Handling and Troubleshooting recap.pptx
Testing database content with DBUnit. My experience.
hibernate with JPA
Intro To Hibernate
Entity Persistence with JPA
Object identification and its management
ERRest in Depth
Introduction to JPA and Hibernate including examples
ERRest
Introduction to hibernate
Jpa 2.1 Application Development
Hibernate complete Training
JPA Best Practices
ERRest - Designing a good REST service
Introduction to Hibernate Framework
Spring data jpa
Hibernate training mumbai_hql
JPA 2.1 performance tuning tips
Ad

Viewers also liked (16)

PPTX
The doll
PPTX
22nd june Run Against Tobacco project report
PDF
Testing your application on Google App Engine
PDF
Inphina cloud
PDF
Google appenginemigrationcasestudy
PPTX
God Bless America Presentation
PDF
Inphina at a glance
PPTX
Urbanising India and health issues
PDF
Preparing yourdataforcloud
PPTX
Urban Planning to address Non-Communicable diseases
PDF
Facilitair en Gebouwbeheer Werken in optimale vrijheid
PPTX
Healthy Cities India
PPTX
Ironman 15th March
PDF
PDF
Cloud Foundry Impressions
PPTX
Dynamic and Static Modeling
The doll
22nd june Run Against Tobacco project report
Testing your application on Google App Engine
Inphina cloud
Google appenginemigrationcasestudy
God Bless America Presentation
Inphina at a glance
Urbanising India and health issues
Preparing yourdataforcloud
Urban Planning to address Non-Communicable diseases
Facilitair en Gebouwbeheer Werken in optimale vrijheid
Healthy Cities India
Ironman 15th March
Cloud Foundry Impressions
Dynamic and Static Modeling
Ad

Similar to Easy ORMness with Objectify-Appengine (20)

PDF
Java Web Programming on Google Cloud Platform [2/3] : Datastore
PPTX
S03 hybrid app_and_gae_datastore_v1.0
PPT
JavaOne 2007 - TS4721
PPTX
Java Enterprise Performance - Unburdended Applications
PPT
The 90-Day Startup with Google AppEngine for Java
PDF
Spring data requery
PPTX
Spring Data JPA in detail with spring boot
PPT
ODP
PHP Barcelona 2010 - Architecture and testability
PPT
PyCon India 2010 Building Scalable apps using appengine
PDF
SPCA2013 - SharePoint Nightmares - Coding Patterns and Practices
PDF
Django design-patterns
PDF
Performance Tuning of .NET Application
PPT
PPT
Wcf data services
PDF
Data Seeding via Parameterized API Requests
PPTX
Spring Data JPA USE FOR CREATING DATA JPA
ODP
Deferred Processing in Ruby - Philly rb - August 2011
PPTX
Dapper performance
PPT
Introducing Struts 2
Java Web Programming on Google Cloud Platform [2/3] : Datastore
S03 hybrid app_and_gae_datastore_v1.0
JavaOne 2007 - TS4721
Java Enterprise Performance - Unburdended Applications
The 90-Day Startup with Google AppEngine for Java
Spring data requery
Spring Data JPA in detail with spring boot
PHP Barcelona 2010 - Architecture and testability
PyCon India 2010 Building Scalable apps using appengine
SPCA2013 - SharePoint Nightmares - Coding Patterns and Practices
Django design-patterns
Performance Tuning of .NET Application
Wcf data services
Data Seeding via Parameterized API Requests
Spring Data JPA USE FOR CREATING DATA JPA
Deferred Processing in Ruby - Philly rb - August 2011
Dapper performance
Introducing Struts 2

More from Inphina Technologies (6)

PDF
Scala collections
PDF
Cloud slam2011 multi-tenancy
PDF
Multi-Tenancy in the Cloud
PDF
Multi-tenancy in the cloud
PDF
Preparing your data for the cloud
PDF
Getting started with jClouds
Scala collections
Cloud slam2011 multi-tenancy
Multi-Tenancy in the Cloud
Multi-tenancy in the cloud
Preparing your data for the cloud
Getting started with jClouds

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Machine learning based COVID-19 study performance prediction
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Empathic Computing: Creating Shared Understanding
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Spectroscopy.pptx food analysis technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Cloud computing and distributed systems.
Building Integrated photovoltaic BIPV_UPV.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Programs and apps: productivity, graphics, security and other tools
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Machine learning based COVID-19 study performance prediction
Unlocking AI with Model Context Protocol (MCP)
Advanced methodologies resolving dimensionality complications for autism neur...
Review of recent advances in non-invasive hemoglobin estimation
Empathic Computing: Creating Shared Understanding
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
20250228 LYD VKU AI Blended-Learning.pptx
The AUB Centre for AI in Media Proposal.docx
Spectroscopy.pptx food analysis technology
MIND Revenue Release Quarter 2 2025 Press Release
NewMind AI Weekly Chronicles - August'25 Week I
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Cloud computing and distributed systems.

Easy ORMness with Objectify-Appengine

  • 1. Easy ORM-ness with Objectify-AppengineMeetu MaltiarInphina Technologies
  • 2. Overall Presentation GoalGoogle Datastore BasicsOptions available for managing persistenceObjectify-AppengineDemo of an application using Objectify
  • 3. Enough About MeSenior Software Engineer at InphinaTechnologies that interest me: Cloud Computing Scala Hadoop
  • 5. EntitiesAn Entity is an object’s worth of data in the datastoreIn 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
  • 6. OperationsGet() an entity as a whole from datastorePut() an entity as whole in datastoreDelete() an entity from datastoreQuery() for entities matching criteria you define
  • 7. KeysIn 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)
  • 8. Keys ContinuedThere is actually a third parameter required to identify an entity and it is called parentParent places the child in the same entity group as the parentParent (which can be null for the un-parented, root entity) is also required to uniquely identify an Entity.
  • 9. Keys ContinuedSo, 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.
  • 10. TransactionsData gets stored in gigantic form of thousands of machinesIn order to perform an atomic transaction datastore requires that entities lie on same servers.To give us more control over where our data is stored, the datastore has a concept of an entity groupTo give us more control over where our data is stored, the datastore has a concept of an entity group
  • 11. Transactions ContinuedWithin a Transaction we can access data from a single entity groupChoose entity groups carefullyWhy not have everything in a single entity group?Google restricts number of requests per second per entity group
  • 12. Executing TransactionsWhen we execute get(), put(), delete() or query() in transactionWe must operate it on single entity groupAll operations will either fail or succeed completelyIf another process modifies the data before commit datastore operation will fail
  • 13. Tools
  • 14. Persistence OptionsJPA/JDOGoogle DatastorePersistence Frameworks on GAE Objectify-Appengine Twig Simple Datastore Slim3
  • 15. Google Datastore ChallengesSupports just four operationsIt persists GAE-Specific entity classes rather than POJO’sDatastore Keys are untyped
  • 16. JPA/JDO ChallengesExtra CruftFetch Groups Detaching Owned/UnownedrelationshipsLeaky AbstractionKeys Entity Groups Indexes
  • 18. ObjectifyIt lets you persist, retrieve, delete and query typed objectsAll native datastore features are supportedIt provides type safe key and query classes
  • 19. Objectify Design ConsiderationsMinimally impacts cold start time. It is light weightNo external dependencies apart from GAE SDK
  • 20. Working With DatastoreEntity ent = new Entity(“car”);ent.setProperty(“color”, “red”);ent.setProperty(“doors”, 2);service.put(ent);
  • 21. Objectify ORMNess Objects!Employee emp = new Employee();emp.setFirstName(“John”);emp.setLastName(“Smith”);service.put(emp);
  • 22. An Objectify Entitypublic class Employee { @Id Long id; private String firstName; private String lastName;}
  • 23. get() OperationObjectify ofy = Objectifyservice.begin();Employee emp = ofy.get(Employee.class, 123);Map<Long, Employee> employees = ofy.get(Employee.class, 123, 124, 125);
  • 24. put() OperationObjectify 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);
  • 25. delete() OperationObjectify ofy = Objectifyservice.begin();ofy.delete(Employee.class, 123);Employee emp = // get Employee from some whereofy.delete(emp);
  • 26. query() OperationObjectify ofy = Objectifyservice.begin();List<Employee> employees = ofy.query(Employee.class).filter(“firstName =”, “John”)
  • 27. Demo get() put() delete() query()
  • 28. Objectify Best PracticesUse a DAO to register entitiesAutomatic Scanningnot advised adds to initialization time will require dependency jars apart from GAE will require changes in web.xmlGAE 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.
  • 29. Objectify Best Practices …Use Batch Gets Instead of QueriesUse Indexes sparinglyBy 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 queryAvoid @ParentIn JPA “owned” entity relationship provides referential integrity checking and cascading deletes and saves. Not so here.
  • 31. ConclusionJDO/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.EntityObjectify 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.
  • 33. ReferencesObjectify-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-platformTwitter mining with Objectify-Appengine http://www.ibm.com/developerworks/java/library/j-javadev2-14/?ca=drs-