]> err.no Git - sope/blob - sope-core/EOCoreData/EOFetchSpecification+CoreData.m
started EOCoreData library
[sope] / sope-core / EOCoreData / EOFetchSpecification+CoreData.m
1 /*
2   Copyright (C) 2005 SKYRIX Software AG
3   
4   This file is part of SOPE.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include "EOFetchSpecification+CoreData.h"
23 #include "EOSortOrdering+CoreData.h"
24 #include "EOQualifier+CoreData.h"
25 #include "common.h"
26
27
28 @implementation EOFetchSpecification(CoreData)
29
30 - (id)initWithFetchRequest:(NSFetchRequest *)_fr {
31 #warning IMPLEMENT ME
32   return nil;
33 }
34
35 - (NSArray *)sortOrderingsAsSortDescriptors {
36   NSMutableArray *ma;
37   NSArray  *a;
38   unsigned i, count;
39   
40   if ((a = [self sortOrderings]) == nil)
41     return nil;
42   if ((count = [a count]) == 0)
43     return nil;
44   
45   if (count == 1) /* common, optimization */
46     return [NSArray arrayWithObject:[[a objectAtIndex:0] asSortDescriptor]];
47   
48   ma = [NSMutableArray arrayWithCapacity:count];
49   for (i = 0; i < count; i++)
50     [ma addObject:[[a objectAtIndex:i] asSortDescriptor]];
51   return ma;
52 }
53
54 - (NSFetchRequest *)fetchRequestWithEntity:(NSEntityDescription *)_entity {
55   NSFetchRequest *fr;
56   
57   fr = [[[NSFetchRequest alloc] init] autorelease];
58   [fr setEntity:_entity];
59   [fr setFetchLimit:[self fetchLimit]];
60   [fr setPredicate:[[self qualifier] asPredicate]];
61   [fr setSortDescriptors:[self sortOrderingsAsSortDescriptors]];
62   return fr;
63 }
64
65 - (NSFetchRequest *)fetchRequestWithModel:(NSManagedObjectModel *)_model {
66   NSEntityDescription *entity;
67   NSString *s;
68   
69   entity = ((s = [self entityName]) != nil)
70     ? [[_model entitiesByName] objectForKey:s]
71     : nil;
72   
73   return [self fetchRequestWithEntity:entity];
74 }
75
76 @end /* EOFetchSpecification(CoreData) */