Re: EOF digest, Vol 1 #595 - 5 msgs
Carl Lindberg <[email protected]>
| Newsgroups | gmane.comp.web.webobjects.eof |
|---|---|
| Message-ID | <[email protected]> |
>
> Jonathan Rochkind wrote:
>
>> At 09:22 AM 11/6/2002 +0000, John Pollard wrote:
>>
>>> One of the problems with the batchFetchRelationship approach is that
>>> it is built up with one OR per object in the NSArray passed to it. Am
>>> I right in thinking that most databases will limit the number of ORs
>>> in an SQL statement? In my case I happen to know the top level
>>> NSArray
>>> will not be too large, but the second level (Companies in your
>>> example
>>> above) could contain thousands of results.
>>
>>
>> True, that's a good point. In the case of my own database, MS SQL
>> Server, I believe the limit is around 3000. So it's pretty high, but
>> could sometimes be exceeded. You could write the code to batch the
>> second-level fetch into groups of X, where X is the limit. (Ie, call
>> the
>> second-level batchFetchRelationship multiple times, with no more than
>> X
>> objects each time). It's not ideal, and it's kind of a pain, but it's
>> better than nothing.
>
> Chuck Hill wrote:
> Another of my vauge recollections... :-)
>
> A few weeks back Max Muller added some sort of batch fetching display
> group to
> Wonder. I recall very little about it, but one thing sticks in my
> head. He
> said he found a limit of about 300 OR conditions. I don't recall why
> or if this
> was database specific - I think he was puzzled about the reason for
> this limitation.
>
> Anyway, this might be worth looking into and you might find some code
> to assist.
>
> Chuck
With Oracle I remember hitting the maximum size of a SQL statement
before I hit any limit of OR conditions... I did something like
Jonathan Rochkind suggests, doing multiple calls to
batchFetchRelationship(). I think I passed 999 in as the batchCount to
be safe. This was WO 4.5 code, but hopefully it still works with WO5...
public static void batchFetchRelationship(EOEditingContext context,
NSArray objects, String relationshipKey, int batchCount) {
if ( context == null || objects == null || objects.count() == 0
|| relationshipKey == null) )
return;
String entityName =
((EOEnterpriseObject)objects.objectAtIndex(0)).entityName();
EOEntity entity =
EOModelGroup.defaultGroup().entityNamed(entityName);
if ( entity == null )
throw new RuntimeException("Invalid entity name: " +
entityName);
EORelationship relationship =
entity.relationshipNamed(relationshipKey);
if ( relationship == null )
throw new RuntimeException("Invalid relationship name: " +
relationshipKey);
EODatabaseContext dbContext =
EOUtilities.databaseContextForModelNamed(context,
entity.model().name());
for (int i = 0, count = objects.count(); i < count; i +=
batchCount) {
int maxIndex = i + batchCount;
if ( maxIndex > count )
maxIndex = count;
NSArray subarray = objects.subarrayWithRange(new NSRange(i,
maxIndex-i));
dbContext.batchFetchRelationship(relationship, objects,
context);
}
}
-Carl Lindberg