User's Manual

96 Chapter 9. Persistence Tutorial
// Get the members association.
DataAssociation members = (DataAssociation) group.get("members");
// Iterate over new members of the group.
DataAssociationCursor cursor = members.getDataAssociationCursor();
// Get yesterday’s date.
java.util.Date yesterday =
new java.util.Date(System.currentTimeMilis() - \
1000 * 60 * 60 * 24);
// Restrict to recent members
Filter f = cursor.addFilter("link.membershipDate
:date");
f.set("date", yesterday);
// Order by membership date, descending
cursor.setOrder("link.membershipDate desc");
while (cursor.next()) {
...
}
9.9. Dynamic Object Types
Thus far, the documentation has assumed that developers know the types of objects that they will
be dealing with at compile time. More concretely, it has assumed that all SQL table definitions and
PDL files have already been defined by the developer. In some situations, however, this assumption is
invalid.
Sometimes developers want to provide site administrators with an interface to create their own types
of objects and store custom information within the database. Since it is not possible to anticipate all
information anyone will ever want to store in the system and it is not feasible to require developers
to manually create all types, the system contains the notion of a DynamicObjectType that provides
developers with the ability to create data schemas (and persist data to that schema) at run time. This
is one of the main motivations of the Metadata-Driven SQL.
The implementation of dynamically storing information has been broken into two parts. The first
part, dynamically creating new object types, uses the DynamicObjectType class. The second part,
dynamically associating objects to each other, is handled by DynamicAssociation.
9.9.1. Using Dynamic Object Types
In order to provide developers with the ability to declare objects at run time instead of at compile
time, the persistence system has the notion of a DynamicObjectType. A Dynamic Object Type allows
users to dynamically create and modify Object Types. It can be used to create a subtype of an existing
object type, add and remove Attributes and RoleReferences, and perform many other tasks related to
the new object type.
The way that this is done is relatively simple. The developer uses methods within the class to set the
Model and object type name and create attributes. When the code saves the current object type, it does
the following:
1. Creates the DDL that needs to be executed to store information about the specific object type.
2. Generates the PDL that needs to be stored so that the object type will be instantiated when the
server restarts.