IDfCollections, Part V
December 19, 2011 Leave a Comment
In this final post of the IDfCollection series, I offer an alternative to the IDfCollection object, the dmRecordSet. The dmRecordSet is an object I created to extend the capabilities of the IDfCollection and overcome many of the limitations I have been discussing here. For example, the dmRecordSet allows you to:
- move forward, backward or randomly through the record set;
- reset the record set to the beginning or the end to be re-processed;
- add rows to the set;
- determine the number of rows in the set;
- determine if a record set is empty or not; and
- retrieve column definitions.
The following code provides some examples of how easy it is to use the dmRecordSet object.
Instantiate a dmRecordSet:
IDfCollection col = null;
String dql = "select r_object_id, object_name, "
+ "r_creation_date, a_content_type, r_full_content_size, a_is_template "
+ "from dm_document where folder('/Temp',descend)";
IDfQuery q = new DfQuery();
IDfTypedObject tObj = null;
q.setDQL(dql);
col = q.execute(session, DfQuery.DF_READ_QUERY);
// get record set
dmRecordSet dmRS = new dmRecordSet(col);
Test for empty set and count rows:
System.out.println("Record count = " + dmRS.getRowCount());
if (dmRS.isEmpty()) {
System.out.println("dmRecordSet is empty");
} else {
System.out.println("dmRecordSet is NOT empty");
}
Process record set:
while (dmRS.hasNext()) {
tObj = dmRS.next();
System.out.print(tObj.getString("r_object_id") + "\t");
System.out.println(tObj.getString("object_name");
}
Move to end and process set backwards:
tObj = dmRS.last();
while (dmRS.hasPrevious()) {
tObj = dmRS.previous();
System.out.print(tObj.getString("r_object_id") + "\t");
System.out.println(tObj.getString("object_name");
}
The class, source code and Javadoc for the dmRecordSet can be downloaded here.
I hope you have enjoyed this series on the IDfCollection object, one of the most commonly used but least functional objects in the DFC. As always, I appreciate your comments and feedback.

