EMC Developer Network

DFC best practice for IDfCollection.getTypedObject()
 

 

Avoid using "getTypedObject()" on a collection unless you specifically need the functionality it provides.

IDfCollection.getTypedObject() returns a memory cached version of the current row. This memory cached row can then be used after the collection has navigated beyond the row. If you don't need that functionality, you can just issue getxxx() methods directly on the collection to obtain values for the current row. This is faster because it does not require the object creation and caching of getTypedObject().

Here are two code samples for simple navigation through a collection. They assume that you do NOT need to access a given row after you have iterated to the next. They both assume you've already opened a collection using DfQuery().

Slow example:

while ( collection.next() )
{
    IDfPersistentObject row = collection.getTypedObject();
				
    String name = row.getString( "r_object_name" );
    IDfTime modifyDate = row.getDate( "r_modify_date" );
				
    // Do something with the values from the current row.
}			

Faster example:

while ( collection.next() )
{
    String name = collection.getString( "r_object_name" );
    IDfTime modifyDate = collection.getDate( "r_modify_date" );
			    
    // Do something with the values from the current row.
}

One reason why you may specifically want to use IDfCollection.getTypedObject() is if you need a memory-cached copy of an entire collection that can then be sorted and resorted based upon different criteria. For example:

// Suck all the rows into memory.
Vector[] rows = new Vector();
while ( collection.next() )
{
   rows.addElement( collection.getTypedObject() );
			   
   // Sort the rows by r_modify_date and then display.
   ...
			   
   // Sort the rows by r_object_name and then display.
   ...