GNUstep Core Data  0.1
NSFetchRequest.m
1 /* Implementation of the NSFetchRequest class for the GNUstep
2  Core Data framework.
3  Copyright (C) 2005 Free Software Foundation, Inc.
4 
5  Written by: Saso Kiselkov <diablos@manga.sk>
6  Date: August 2005
7 
8  This file is part of the GNUstep Core Data framework.
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 2.1 of the License, or (at your option) any later version.
14 
15  This library is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public
21  License along with this library; if not, write to the Free
22  Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
23  */
24 
25 #import "CoreDataHeaders.h"
26 
38 @implementation NSFetchRequest
39 
40 - (void) dealloc
41 {
42  TEST_RELEASE(_affectedStores);
43  TEST_RELEASE(_entity);
44  TEST_RELEASE(_predicate);
45 
46  [super dealloc];
47 }
48 
52 - (id) _initWithAffectedStores: (NSArray *) affectedStores
53  entity: (NSEntityDescription *) entity
54  fetchLimit: (unsigned int) fetchLimit
55  predicate: (NSPredicate *) predicate
56  sortDescriptors: (NSArray *) sortDescriptors
57 {
58  if ((self = [self init]))
59  {
60  ASSIGN(_affectedStores, affectedStores);
61  ASSIGN(_entity, entity);
62  _fetchLimit = fetchLimit;
63  ASSIGN(_predicate, predicate);
64  ASSIGN(_sortDescriptors, sortDescriptors);
65 
66  }
67  return self;
68 }
69 
73 - (NSArray *) affectedStores
74 {
75  return _affectedStores;
76 }
77 
81 - (void) setAffectedStores: (NSArray *) stores
82 {
83  ASSIGN(_affectedStores, stores);
84 }
85 
90 - (NSEntityDescription *) entity
91 {
92  return _entity;
93 }
94 
99 - (void) setEntity: (NSEntityDescription *) entity
100 {
101  ASSIGN(_entity, entity);
102 }
103 
108 - (unsigned int) fetchLimit
109 {
110  return _fetchLimit;
111 }
112 
116 - (void) setFetchLimit: (unsigned int) aLimit
117 {
118  _fetchLimit = aLimit;
119 }
120 
125 - (NSPredicate *) predicate
126 {
127  return _predicate;
128 }
129 
134 - (void) setPredicate: (NSPredicate *) predicate
135 {
136  ASSIGN(_predicate, predicate);
137 }
138 
143 - (NSArray *) sortDescriptors
144 {
145  return _sortDescriptors;
146 }
147 
153 - (void) setSortDescriptors: (NSArray *) sortDescriptors
154 {
155  ASSIGN(_sortDescriptors, sortDescriptors);
156 }
157 
158 // NSCopying
159 
160 - (id) copyWithZone: (NSZone *) zone
161 {
162  return [[NSFetchRequest allocWithZone: zone]
163  _initWithAffectedStores: _affectedStores
164  entity: _entity
165  fetchLimit: _fetchLimit
166  predicate: _predicate
167  sortDescriptors: _sortDescriptors];
168 }
169 
170 // NSCoding
171 
172 - (void) encodeWithCoder: (NSCoder *) coder
173 {
174  if ([coder allowsKeyedCoding])
175  {
176  [coder encodeObject: _affectedStores forKey: @"AffectedStores"];
177  [coder encodeObject: _entity forKey: @"Entity"];
178  [coder encodeInt: _fetchLimit forKey: @"FetchLimit"];
179  [coder encodeObject: _predicate forKey: @"Predicate"];
180  [coder encodeObject: _sortDescriptors forKey: @"SortDescriptors"];
181  }
182  else
183  {
184  [coder encodeObject: _affectedStores];
185  [coder encodeObject: _entity];
186  [coder encodeValueOfObjCType: @encode(unsigned int) at: &_fetchLimit];
187  [coder encodeObject: _predicate];
188  [coder encodeObject: _sortDescriptors];
189  }
190 }
191 
192 - (id) initWithCoder: (NSCoder *) coder
193 {
194  if ((self = [self init]))
195  {
196  if ([coder allowsKeyedCoding])
197  {
198  ASSIGN(_affectedStores, [coder
199  decodeObjectForKey: @"AffectedStores"]);
200  ASSIGN(_entity, [coder decodeObjectForKey: @"Entity"]);
201  _fetchLimit = [coder decodeIntForKey: @"FetchLimit"];
202  ASSIGN(_predicate, [coder decodeObjectForKey: @"Predicate"]);
203  ASSIGN(_sortDescriptors, [coder
204  decodeObjectForKey: @"SortDescriptors"]);
205  }
206  else
207  {
208  ASSIGN(_affectedStores, [coder decodeObject]);
209  ASSIGN(_entity, [coder decodeObject]);
210  [coder decodeValueOfObjCType: @encode(unsigned int)
211  at: &_fetchLimit];
212  ASSIGN(_predicate, [coder decodeObject]);
213  ASSIGN(_sortDescriptors, [coder decodeObject]);
214  }
215 
216  }
217  return self;
218 }
219 
220 @end
An object for storing details about managed object fetches.
unsigned int fetchLimit()
Returns the fetch limit of the receiver.
NSEntityDescription * entity()
Returns the entity of the fetch request.
NSArray * affectedStores()
Returns an array of stores on which this fetch will executed.
NSArray * sortDescriptors()
Returns the receiver's sort descriptors.
NSPredicate * predicate()
Returns the predicate of the receiver.