Chapter 9. Persistence Tutorial 95
System.out.println(email + ": " + membershipDate);
}
9.8.2.3. Updating Link Attributes
The DataAssociationCursor.getLink() method can be used to fetch the DataObject that rep-
resents a link. This DataObject can then be used to modify the link and persist the results.
// Put the current session in a variable for convenience.
Session ssn = SessionManager.getSession();
// Get a group.
DataObject group = ssn.retrieve(new OID("Group", ...));
// Get the members association.
DataAssociation members = (DataAssociation) group.get("members");
// Iterate over the members of the group and modify each link.
DataAssociationCursor cursor = members.getDataAssociationCursor();
while (cursor.next()) {
// Fetch the link object for the current row.
DataObject link = cursor.getLink();
// Get the membership date from the link data object.
java.util.Date oldDate = (java.util.Date) \
link.get("membershipDate");
// Incrememnt the membership date by 1 millisecond.
java.util.Date newDate = new \
java.util.Date(oldDate.getTime() + 1);
// Set the new date
link.set("membershipDate", newDate);
}
// Persist all the changed links.
group.save();
Note
Only group.save() is called to persist thechanges. Changes to the links areautomatically persisted
when the parent object is saved.
9.8.2.4. Filtering and Ordering based on Link Attributes
To access the values of a link attribute when filtering or setting the order of a data association, simply
put the special link prefix in front of the link attribute name.
// Put the current session in a variable for convenience.
Session ssn = SessionManager.getSession();
// Get a group.
DataObject group = ssn.retrieve(new OID("Group", ...));