RESTful and JSON remoting

Step by step creation

Create project

Create a new project that uses JPA persistence using EclipseLink and H2. Notice that the H2 database is in memory, so you will loose all data after exiting the application.

From the roo console, run:

project --topLevelPackage com.springsource.pizzashop

jpa setup --provider ECLIPSELINK --database H2_IN_MEMORY

Create domain entities

Generate all classes needed to build the PizzaShop domain model:

entity jpa --class ~.domain.Base --activeRecord false --testAutomatically
field string --fieldName name --sizeMin 2 --notNull

entity jpa --class ~.domain.Topping --activeRecord false --testAutomatically
field string --fieldName name --sizeMin 2 --notNull

entity jpa --class ~.domain.Pizza --activeRecord false --testAutomatically
field string --fieldName name --notNull --sizeMin 2
field number --fieldName price --type java.math.BigDecimal
field set --fieldName toppings --type ~.domain.Topping
field reference --fieldName base --type ~.domain.Base

entity jpa --class ~.domain.PizzaOrder --testAutomatically --activeRecord false --identifierType ~.domain.PizzaOrderPk
field string --fieldName name --notNull --sizeMin 2
field string --fieldName address --sizeMax 30
field number --fieldName total --type java.math.BigDecimal
field date --fieldName deliveryDate --type java.util.Date
field set --fieldName pizzas --type ~.domain.Pizza

field string --fieldName shopCountry --class ~.domain.PizzaOrderPk
field string --fieldName shopCity
field string --fieldName shopName

Define a repository layer for persistence

Generate a repository layer that manages the persistence. It is a DataAccessObject (DAO) alternative to the default ActiveRecord pattern to deal with persistence.

repository jpa --interface ~.repository.ToppingRepository --entity ~.domain.Topping
repository jpa --interface ~.repository.BaseRepository --entity ~.domain.Base
repository jpa --interface ~.repository.PizzaRepository --entity ~.domain.Pizza
repository jpa --interface ~.repository.PizzaOrderRepository --entity ~.domain.PizzaOrder