Red Hat Web Application Framework 6.1 Manual de usuario Pagina 109

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 230
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 108
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 the changes. Changes to the links are automatically 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", ...));
Vista de pagina 108
1 2 ... 104 105 106 107 108 109 110 111 112 113 114 ... 229 230

Comentarios a estos manuales

Sin comentarios