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.