RE: EOFetchSpecification subclass hints

"Schoenenberger Dominique" <[email protected]> Wed, 4 Aug 2004 20:13:48 +0200
Newsgroups gmane.comp.web.webobjects.eof
Message-ID <[email protected]>
WebObjects will not take care of the subclasses of an entity if you add a "EOCustomQueryExpressionHintKey" hint to a fetchspecification.

However, if you want to avoid this, you may fake it. I explain how but first, I give you some explanations about what's going on during the fetch: 

1) The EODatabaseContext perform a selectObjectsWithFetchSpecification on the EODatabaseChannel. 
During this step, no EO is created, only dictionaries.
During this step the _isFetchingSingleTableEntity variable of the database channel is set to false in case you use the "EOCustomQueryExpressionHintKey" hint even if you have subclasses !! (for good reasons probably ?)

2) Then the EODatabaseContext perform a series of "fetchObject". During this step, the entity is calculated but it take care of the sub-entities only if the _isFetchingSingleTableEntity flag of the database channel is set to true.

So, to fake it, what you have to do is to force the _isFetchingSingleTableEntity flag to be true. This should be done between step 1 and 2 and a good place to do it is in the database context delegate method "databaseContextDidSelectObjects" called at the end of database channel selectObjectsWithFetchSpecification method (see step 1).

So, I add the below method to my database context delegate (be careful that the delegate class if of the package com.webobjects.eoaccess to have access to the _isFetchingSingleTableEntity flag of the database channel): 

	public void databaseContextDidSelectObjects(EODatabaseContext dc,
												EOFetchSpecification fs,
												EODatabaseChannel channel) {
		if (fs.entityName().equals("....")) // or whatever condition you may need
			channel._isFetchingSingleTableEntity = true;
	}

Dominique

> -----Original Message-----
> From: [email protected] [mailto:[email protected]]On
> Behalf Of Dominique Schoenenberger
> Sent: Wednesday, August 04, 2004 12:18 AM
> To: [email protected]
> Subject: EOFetchSpecification subclass hints
> 
> 
> My problem is to use fetch specification with hint like in 
> this example:
> 
>          EOSQLExpression sql = 
> ERXEOAccessUtilities.sqlExpressionForFetchSpecification(ec, spec, 
> start, end);
>          NSDictionary hints = new NSDictionary(sql, 
> "EOCustomQueryExpressionHintKey");
>          spec.setHints(hints);
> 
>          return ec.objectsWithFetchSpecification(spec);
> 
> This is working fine expect the fact it won't create the 
> objects of the 
> right subclass as soon as you are using an 
> "EOCustomQueryExpressionHintKey" hint like in the above example.
> 
> How can I have my own sql code to fetch a table and get the right 
> subclass instanciated ?
> 
> 
> Dominique
> 
> _______________________________________________
> EOF mailing list
> [email protected]
> http://www.omnigroup.com/mailman/listinfo/eof
>