EMC Developer Network

Caching Attribute Information
 

 

Fetching of attribute information is expensive in versions of DFC prior to 5.0. For this reason it is a good idea to cache attribute information in your application if you plan to use it a lot.

Here are two code samples; one that is bad and one that is good. They both assume you've already opened a collection using DfQuery().

Bad example:

int attributeCount = collection.getAttrCount();
while ( collection.next() )
{   
    for ( int i = 0; i < attributeCount; i++ )   
    {      
        IDfAttr attribute = collection.getAttr( i );      
        switch( attribute.getDataType() )      
        {      
        case IDfAttr.DM_BOOLEAN:         
            boolean v1 = collection.getBoolean( attribute.getName() );         
            break;
        default:         
            throw new Exception( "Unknown data type " );      
        }   
    }
}

Good example:

// Learn about attributes in the collection.
int attributeCount = collection.getAttrCount();
IDfAttr[] attributes = new IDfAttr[ attributeCount ];

for ( int i = 0; i < attributeCount; i++ )   
    attributes[ i ] = collection.getAttr( i ); 
    
// Iterate through the collection. 
while ( collection.next() )
{   
    for ( int i = 0; i < attributeCount; i++ )   
    {      
        switch( attribute[ i ].getDataType() )      
        {      
            case IDfAttr.DM_BOOLEAN:         
                boolean v1 = collection.getBoolean( attributes[ i ].getName() );         
                break;      
            default:         
                throw new Exception( "Unknown data type " );      
        }   
    }
}

In DFC 5.0 either code example will work reasonably well because attribute fetching has been made much cheaper.