You will need to create a new project for this tutorial. In Eclipse, open the File menu, select New and select Wonder REST Application (or ERRest Application, according to your WOLips version). Name your project as BlogRest.
. When the database will be created, it will be stored in your home directory (/Users/youruser/ on OS X).
You can also specify an absolute path where to store in you h2 database files. For example on Windows OS URL field can be like this:
jdbc:h2:C:/Users/ ... /BlogTutorial
Notice, in the path, *nix like file separator "/" instead of Windows like "\" (as you can read here).
Now, right-click on BlogModel and select New Entity.
Final list of attributes should look like this:
Now, it's time to link the two entities together. An Author can have multiple blog entries, and a BlogEntry can only have one author. To create the relationship (the join), right-click on Author and select New Relationship. On your right, select BlogEntry in the list. On your left, select to many BlogEntries, and on your right, select to one Author. Now, in BlogEntry, we need to store the primary key of the author so that we can make the join. The relationship builder allow us to add that attribute, so make sure and a new foreign key named is checked (it is checked by default). The Create Relationship pane should look like this:
If you check in the Outline tab, you should see that Author now have a blogEntries relationship, and BlogEntry have a author relationship.
You are now ready to save the model. Save it (File -> Save) and close the Entity Modeler window. If you open the Sources in the main Eclipse window, you will notice that the Sources folder contains a package named your.app.model. (If this folder doesn't appear, you may need to set your preferences to automatically generate these source files; see the second suggestion on http://wiki.wocommunity.org/display/documentation/Useful+Eclipse+or+WOLips+Preferences.)
That package have four Java classes: _Author, Author, _BlogEntry and BlogEntry. Those classes were generated by Veogen, a templating engine build on Velocity. The two classes that starts with a underscore are recreated every time you change the EOModel, so if you want to change something in those classes, you need to change the template (no need for that right now). But you can change freely the two classes that don't have the underscore, and this is what we will be doing.
What we are going to do is to write a simple method that returns the full name of an author, e.g. a method that simply concatenate the first name, a space and the last name of the author. To do so, double-click on Author.java and add the following methods: