User's Manual

66 Chapter 9. Persistence Tutorial
This object type definition almost models the SQL that we have defined above but it is missing any
mention of the unique constraint. To allow for this and to allow the DDL generator to correctly gen-
erate unique constraints the persistence layer allows you to specify either a single property or a set of
properties as being unique. The syntax for this is as follows:
SINGLE UNIQUE PROPERTY:
object type User {
BigDecimal id = users.id INTEGER;
unique String[0..1] screenName = users.screen_name VARCHAR(100);
...
}
SET OF UNIQUE PROPERTIES:
object type Node {
BigDecimal id = nodes.id INTEGER;
Node[0..1] parent = join nodes.parent_id to nodes.id;
String[1..1] name = nodes.name VARCHAR(100);
object key (id);
unique (parent, name);
}
Therefore, in order to correctly model the publications, we need to add the constraint. The correct,
full publications object type defintion is below:
model tutorial;
object type Publication {
BigDecimal id = publications.publication_id INTEGER;
String name = publications.name VARCHAR(400);
String type = publications.name VARCHAR(400);
object key (id);
unique (name, type);
}
Note
Attributes cannot have the same name as a pdl reserved word without special quoting. For a list of
reserved words and escaping techniques, see Section D.2 PDL Reserved Words.
9.2.4. Getting Started with the API
Now that we know how to specify an Object Type using PDL, you can learn how to access the in-
formation from Java. The first step is to examine the public API that is provided by the persistence
system.
The persistence layer in the Web Application Framework is implemented in the Java package
(http://rhea.redhat.com/doc/waf/6.0/api/com/arsdigita/persistence/package-summary.html). This
package contains a set of classes and interfaces for working with persistent objects that store
themselves in a relational database. Some of the URLs listed contain a visual break with the "\"
character for printing formatting.