1 / 10

Introduction to Models using the Play Framework

Introduction to Models using the Play Framework. Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu HI 96822. Model-View-Controller in Play. H2. MySQL. Postgres. Twitter Bootstrap. Model - models.* package

vonda
Télécharger la présentation

Introduction to Models using the Play Framework

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Modelsusing the Play Framework Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu HI 96822

  2. Model-View-Controller in Play H2 MySQL Postgres Twitter Bootstrap Model - models.* package - EBean ORM Controller - routes file - controllers.* package Browser View - views/*.scala.html

  3. What is the Model? • A representation of "domain knowledge" • In Play, implemented as a set of Java class instances. • Think objects and relationships • The model should represent the domain well enough to answer any queries the user might ask of the application. • Two basic problems: • Designing the right model (domain abstraction) • Making it persistent

  4. Persistency approaches • Relational databases • Examples: MySQL, Postgres, Oracle • Well understood, very popular • Object-relational impedance mismatch • Object-oriented databases • Examples: Gemstone, db4o • Solves impedance mismatch problem • Failed to gain traction. • NoSQL persistent stores • Examples: Hadoop, MongoDB, Neo4J • Higher scalability; looser consistency

  5. Addressing the O/R Impedance Mismatch: Object-Relational Mappers (ORMs) • Provides a language allowing the developer to: • Map classes to tables • Map fields to columns • Specify arity (1-1, 1-Many, Many-1, Many-Many) • Provides API calls to: • Take class instances, save as rows in tables • Retrieve row, convert to class instance • Query the db "conveniently" (w/o SQL)

  6. Our ORM: EBean • Open source (LGPL) Java ORM. • Uses JPA annotations (@entity, @OneToOne, etc.) • Support for Postgres, MySQL, and H2 (default) • Supports "autofetch"—automatic query tuning • Can reduce data retrieved from DB based upon recognition that caller does not refer to it. • Default ORM provided by Play

  7. Example

  8. Model Design Process • 1. Create a simple data model diagram • Use the free LucidChart plugin to Google Docs • Determine the entities • Determine relationships between entities (1-1, 1-Many, Many-1, Many-Many) • 2. In the models package: • define Java classes for all of your entities • create fields corresponding to relationships • 3. In the tests package: • create a JUnit test class that verifies that your model can be created, persisted, modified, and queried appropriately.

  9. Heuristics for model development • http://ics613s13.wordpress.com/modules/web-application-development/model-development-hints/

  10. Next step • Watch the demo Model development screencast

More Related