Programatically creating a WODisplayGroup (take 2)

I wrote about programatically creating WODisplayGroups here. In that example I use a find() method to explicitly do a fetch, and those objects were assigned to the the WODisplayGroup.objectArray().

That is just my preferred way of handling the object fetch, but of course it is not the only way. If you wanted to emulate what happens if you create a WODisplayGroup by dragging an Entity from EOModeler into WebObjects Builder, you might do something like this:

protected WODisplayGroup _displayGroup;
protected EOEditingContext ec;   //Assume exists
protected String dateSourceName; //Name of the Entity
 
public WODisplayGroup displayGroup()
{
    if (_displayGroup == null) {
        _displayGroup = new WODisplayGroup();
        _displayGroup.setNumberOfObjectsPerBatch(batchSize);
        EODatabaseDataSource ds = new EODatabaseDataSource(
					ec, 
					dataSourceName);
        _displayGroup.setDataSource(ds);
        _displayGroup.fetch();
    }
    return _displayGroup;
}

You could also create a WODisplayGroup based on a master detail relationship like this:

protected WODisplayGroup _displayGroup;
protected EOEnterpriseObject masterObject; //The Master object
protected String detailKey; //The name of the relationship 
                            //in the masterObject that will
                            //provide the _displayGroup's objects
 
public WODisplayGroup displayGroup()
{
    if (_displayGroup == null) {
        _displayGroup = new WODisplayGroup();
        _displayGroup.setNumberOfObjectsPerBatch(batchSize);
        EODetailDataSource dds = new EODetailDataSource(
			masterObject.classDescription(),
			detailKey);
        _displayGroup.setDataSource(dds);
        _displayGroup.setMasterObject(masterObject);
        _displayGroup.setDetailKey(detailKey);
        _displayGroup.fetch();
    }
    return _displayGroup;
}

As before the WODisplayGroup API is here