2 Copyright (C) 2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "EOFetchSpecification+CoreData.h"
23 #include "EOSortOrdering+CoreData.h"
24 #include "EOQualifier+CoreData.h"
28 @implementation EOFetchSpecification(CoreData)
30 - (id)initWithFetchRequest:(NSFetchRequest *)_fr {
41 /* convert sort descriptors */
43 sd = [_fr sortDescriptors];
45 if ((count = [sd count]) > 0) {
48 so = [[NSMutableArray alloc] initWithCapacity:count];
49 for (i = 0; i < count; i++) {
52 soo = [[EOSortOrdering alloc] initWithSortDescriptor:
53 [sd objectAtIndex:i]];
55 soo = [sd objectAtIndex:i]; /* oh well, this is sneaky */
56 NSLog(@"WARNING(%s): could not convert NSSortDescriptor to "
57 @"EOSortOrdering: %@", __PRETTY_FUNCTION__, soo);
64 /* convert predicate */
66 q = [EOQualifier qualifierForPredicate:[_fr predicate]];
70 // TODO: maybe add 'affectedStores' as a hint?
71 self = [self initWithEntityName:[[_fr entity] name]
72 qualifier:q sortOrderings:so
73 usesDistinct:YES isDeep:NO
75 [so release]; so = nil;
77 [self setFetchLimit:[_fr fetchLimit]];
81 - (NSArray *)sortOrderingsAsSortDescriptors {
86 if ((a = [self sortOrderings]) == nil)
88 if ((count = [a count]) == 0)
91 if (count == 1) /* common, optimization */
92 return [NSArray arrayWithObject:[[a objectAtIndex:0] asSortDescriptor]];
94 ma = [NSMutableArray arrayWithCapacity:count];
95 for (i = 0; i < count; i++)
96 [ma addObject:[[a objectAtIndex:i] asSortDescriptor]];
100 - (NSFetchRequest *)fetchRequestWithEntity:(NSEntityDescription *)_entity {
103 fr = [[[NSFetchRequest alloc] init] autorelease];
104 [fr setEntity:_entity];
105 [fr setFetchLimit:[self fetchLimit]];
106 [fr setPredicate:[[self qualifier] asPredicate]];
107 [fr setSortDescriptors:[self sortOrderingsAsSortDescriptors]];
111 - (NSFetchRequest *)fetchRequestWithModel:(NSManagedObjectModel *)_model {
112 NSEntityDescription *entity;
115 entity = ((s = [self entityName]) != nil)
116 ? [[_model entitiesByName] objectForKey:s]
119 return [self fetchRequestWithEntity:entity];
122 @end /* EOFetchSpecification(CoreData) */
125 @implementation NSFetchRequest(EOCoreData)
127 - (NSFetchRequest *)fetchRequestWithEntity:(NSEntityDescription *)_entity {
130 - (NSFetchRequest *)fetchRequestWithModel:(NSManagedObjectModel *)_model {
134 @end /* NSFetchRequest(EOCoreData) */