User's Manual

Chapter 9. Persistence Tutorial 65
9.2.3.2. Model and Object Type
When creating a PDL file, the first line of the file must be the name of the model that defines the
namespace for the block definitions in the PDL file. This is similar to the name of the package in
a Java class and is necessary to avoid name collisions of object types that have the same name and
which exist in different PDL files. This example will use the tutorial model.
The second block of lines within a PDL file can either be a list of namespaces to import (similar to
Java’s import statement) or the declaration of the object type itself. See Section 9.2.6 Object Type
Inheritance for more information about importing.
The object type definition follows the import statement. The definition of an object type may include
attributes and event definitions. The Publication object type defined below has two attributes defined.
One of these attributes, id, is also part of the object key, which means that a Publication is uniquely
identified by the id attribute value.
The first block of code within the object type definition is a list of persistence attributes and mappings
of those attributes to database columns for the given object. Note that the attribute names do not need
to be the same as the column names. The attributes are a list of Java variables that a given Data Object
class can access. Finally, notices that in addition to the java data type at the beginning of the attribute
mapping the SQL data type is also present. This SQL data type allows for DDL generator to generate
the correct SQL. For a complete list of supported Java types, see Section D.2.2 PDL Attribute Types
// declare the namespace as "tutorial" using the "model" keyword
model tutorial;
// there are not any import statements because Publication does not
// extend anything.
// next comes the "object type" keyword followed by the name of
// the object type
object type Publication {
// the first block of code within the object type is a set of
// mappings from the Attribute Java type and Attribute name to
// the database column to which they correspond.
BigDecimal id = publications.publication_id INTEGER;
String name = publications.name VARCHAR(400);
}
9.2.3.3. Object Key
For each object type, you must define an object identifier for the purposes of uniquely identifying
object instances at run time. If the object type does not have a super type, the object key syntax is
used. If the object has a super type, a reference key must be declared to indicate how this object
joins with the supertype. (See Section 9.2.6 Object Type Inheritance for more details.) The following
example indicates how to designate that the Publication’s id attribute is the object identifier or key:
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);
}