public <FT,FID>BaseForeignCollection<FT,FID> buildForeignCollection(Object parent,FID id) throws SQLException {
  if (foreignFieldType == null) {
    return null;
  }
  @SuppressWarnings("unchecked") Dao<FT,FID> castDao=(Dao<FT,FID>)foreignDao;
  if (!fieldConfig.isForeignCollectionEager()) {
    return new LazyForeignCollection<FT,FID>(castDao,parent,id,foreignFieldType,fieldConfig.getForeignCollectionOrderColumnName(),fieldConfig.isForeignCollectionOrderAscending());
  }
  LevelCounters levelCounters=threadLevelCounters.get();
  if (levelCounters.foreignCollectionLevel == 0) {
    levelCounters.foreignCollectionLevelMax=fieldConfig.getForeignCollectionMaxEagerLevel();
  }
  if (levelCounters.foreignCollectionLevel >= levelCounters.foreignCollectionLevelMax) {
    return new LazyForeignCollection<FT,FID>(castDao,parent,id,foreignFieldType,fieldConfig.getForeignCollectionOrderColumnName(),fieldConfig.isForeignCollectionOrderAscending());
  }
  levelCounters.foreignCollectionLevel++;
  try {
    return new EagerForeignCollection<FT,FID>(castDao,parent,id,foreignFieldType,fieldConfig.getForeignCollectionOrderColumnName(),fieldConfig.isForeignCollectionOrderAscending());
  }
  finally {
    levelCounters.foreignCollectionLevel--;
  }
}

public < FT , FID > BaseForeignCollection < FT , FID > buildForeignCollection ( Object parent , FID id ) throws SQLException { if ( foreignFieldType == null ) { return null ; } @ SuppressWarnings ( "unchecked" ) Dao < FT , FID > castDao = ( Dao < FT , FID > ) foreignDao ; if ( ! fieldConfig . isForeignCollectionEager ( ) ) { return new LazyForeignCollection < FT , FID > ( castDao , parent , id , foreignFieldType , fieldConfig . getForeignCollectionOrderColumnName ( ) , fieldConfig . isForeignCollectionOrderAscending ( ) ) ; } LevelCounters levelCounters = threadLevelCounters . get ( ) ; if ( levelCounters . foreignCollectionLevel == 0 ) { levelCounters . foreignCollectionLevelMax = fieldConfig . getForeignCollectionMaxEagerLevel ( ) ; } if ( levelCounters . foreignCollectionLevel >= levelCounters . foreignCollectionLevelMax ) { return new LazyForeignCollection < FT , FID > ( castDao , parent , id , foreignFieldType , fieldConfig . getForeignCollectionOrderColumnName ( ) , fieldConfig . isForeignCollectionOrderAscending ( ) ) ; } levelCounters . foreignCollectionLevel ++ ; try { return new EagerForeignCollection < FT , FID > ( castDao , parent , id , foreignFieldType , fieldConfig . getForeignCollectionOrderColumnName ( ) , fieldConfig . isForeignCollectionOrderAscending ( ) ) ; } finally { levelCounters . foreignCollectionLevel -- ; } }
build and return a foreign collection based on the field settings that matches the id argument . this can return null in certain circumstances .
