Before starting these WODs, you should have successfully finished the play-example-mysql experience. Finishing this assignment means that you will have successfully set up MySQL on your computer, and installed and run a Play application that reads and writes data from that database. You will have also successfully deployed that application to CloudBees and set up its MySQL back-end.
The goal of this WOD is to start learning how to implement back-end persistence for your web applications using MySQL and EBean.
Before starting this WOD, you should set up your environment for running a recent version of your Digits application. This version should be committed to the master branch and should support multiple users.
You should also have a local copy of play-example-mysql in Eclipse for reference.
Instructions
Start your timer.
Create branch mysql-1. Create a branch off your master called “mysql-1″ to hold all of the work associated with this WOD. If this is not the first time you’re doing the WOD, increment the number as necessary.
Create ERD. Create a Lucid Chart showing the entities, relationships, and fields to be implemented in your Digits application.
Enhance project files for MySQL. Compare build.sbt, application.conf in play-example-mysql to the digits project versions, and update as necessary for MySQL.
Fix the Digits system to use -1 as the new Contact sentinel value, not 0. In MySQL, ids can start with 0, so using 0 as the value to indicate a new Contact will lead to bugs. Update the system to use -1 as the sentinel value. Check Application.java, ContactDB.java, ContactFormData.java, and routes.
Annotate entity classes. Remember to extend Model, add @Entity, add SerialVersionUID, add @Id, and add bidirectional relationship annotations. Add a find() method to simplify access to the EBean query language. Add getters and setters as needed.
Update ContactDB and UserInfoDB to use MySQL. Now edit the database classes to store and retrieve entities from MySQL, not from the in-memory structures.
Update Global.java to implement admin. Note that we now have to check to see if the Admin contacts have been already created on startup to prevent them from being created multiple times.
Setup new digits database. Create a new database called “digits” in your local MySQL server. Edit your environment variable to refer to it.
Run system, and debug any errors that occur. It is very helpful to monitor the contents of your MySQL database tables to better understand what your Play code is doing (or not doing).
Commit your changes. When you have it working, commit your changes. Use “Finished WOD.” as the commit message.
When finished, stop your timer, and record how many minutes it took you to complete the WOD.
Rx: < 60 minAv: 60-75 minSd: 75-90 minDNF: 90+ min
Demonstration
Once you’ve finished doing the WOD a single time, watch me do it:
Standard WOD Caveats
You’ll learn significantly less from watching me solve the
WOD if you haven’t attempted the WOD yourself first.
While it’s an achievement to finish the WOD no matter how long it takes, you
might experience “diminishing returns” if you work longer than the DNF
time. Thus, it might be strategic to stop working at the DNF time and watch
my solution.
After watching my solution, I recommend that you repeat the WOD if you
have not achieved at least Av performance. If so, be sure to:
Delete your old project so you cannot refer to it;
Don’t look at my screencast while you WOD; and
Reset your timer.
Feel free to keep trying until you make Rx if that’s of interest to you.