Presentation is loading. Please wait.

Presentation is loading. Please wait.

(1) Introduction to Models using the Play Framework Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University.

Similar presentations


Presentation on theme: "(1) Introduction to Models using the Play Framework Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University."— Presentation transcript:

1 (1) Introduction to Models using the Play Framework Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu HI 96822

2 (2) Model-View-Controller in Play Browser Controller - routes file - controllers.* package Model - models.* package - EBean ORM View - views/*.scala.html Twitter Bootstrap H2MySQLPostgres

3 (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 (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 (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 (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 (7) Example

8 (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 (9) Heuristics for model development http://ics613s13.wordpress.com/modules/web- application-development/model-development- hints/

10 (10) Next step Watch the demo Model development screencast


Download ppt "(1) Introduction to Models using the Play Framework Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University."

Similar presentations


Ads by Google