User's Manual

Chapter 8. WAF Application Development Tutorial 51
8.5. Modeling Your Application
A new application is represented by a persistent Application object. A typical application uses the
WAF persistence layer to store and query the state of an Application data object. An Applica-
tion is more than just storage, however. It is also a set of behaviors, principally having to do with
containment and dispatch. Refer to Section 6.1 Applications to learn more.
You will subclass Application in order to introduce your own persistent properties and your own
application-specific behaviors. The data aspect of an Application is described using PDL.
This tutorial will use a sample application called Binder to illustrate how an Application is defined.
8.6. Persistent Object Types
A persistent object type definition is metadata that maps a Java object to storage in a relational schema.
As with many things in WAF, Application is one of these object types. As is the pattern for any
new application, our example creates a subtype of the Application type and adds properties to it.
model com.example.binder;
import com.arsdigita.web.Application;
// A Binder is an application that has a collection of Notes.
//
// @author Justin Ross
object type Binder extends Application {
component Note[0..n] notes = join binders.binder_id to notes.binder_id;
reference key (binders.binder_id);
}
Example 8-1. binder/pdl/com/example/binder/Binder.pdl
This definition adds just one property to Application, notes. The notes property tracks the set of
Notes belonging to a Binder.
model com.example.binder;
// A Note has a title and and body and is a component of a Binder.
//
// @author Justin Ross
versioned object type Note {
BigInteger[1..1] id = notes.note_id INTEGER;
String[1..1] title = notes.title VARCHAR(200);
String[0..1] body = notes.body VARCHAR(4000);
object key (id);
}
Example 8-2. binder/pdl/com/example/binder/Note.pdl
Observe that the Note object type is marked versioned. This means that any changes to Note will
be recorded in a change log. The WAF versioning service allows you to resurrect a specific version and
to list the changes made between two versions. For more information, refer to Section 4.11 Versioning
Service.
Once you’ve defined your PDL, the build system will generate relational tables to back your object
types.