4 Copyright (C) 1999 MDlink online service center GmbH, Helge Hess
6 Author: Helge Hess (hh@mdlink.de)
9 This file is part of the GNUstep Database Library.
11 This library is free software; you can redistribute it and/or
12 modify it under the terms of the GNU Library General Public
13 License as published by the Free Software Foundation; either
14 version 2 of the License, or (at your option) any later version.
16 This library is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 Library General Public License for more details.
21 You should have received a copy of the GNU Library General Public
22 License along with this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 // $Id: EOArrayProxy.m 1 2004-08-20 10:38:46Z znek $
29 #import "EOArrayProxy.h"
30 #import "EODatabaseChannel.h"
31 #import "EODatabaseContext.h"
33 #import "EOSQLQualifier.h"
34 #import "EOGenericRecord.h"
36 @implementation EOArrayProxy
38 - (id)initWithQualifier:(EOSQLQualifier *)_qualifier
39 fetchOrder:(NSArray *)_fetchOrder
40 channel:(EODatabaseChannel *)_channel
42 self->qualifier = RETAIN(_qualifier);
43 self->fetchOrder = RETAIN(_fetchOrder);
44 self->channel = RETAIN(_channel);
48 + (id)arrayProxyWithQualifier:(EOSQLQualifier *)_qualifier
49 fetchOrder:(NSArray *)_fetchOrder
50 channel:(EODatabaseChannel *)_channel
52 return AUTORELEASE([[self alloc] initWithQualifier:_qualifier
53 fetchOrder:_fetchOrder
58 AUTORELEASE(self->content);
59 RELEASE(self->qualifier);
60 RELEASE(self->fetchOrder);
61 RELEASE(self->channel);
68 return self->content ? YES : NO;
71 - (EODatabaseChannel *)databaseChannel {
74 - (EOEntity *)entity {
75 return [self->qualifier entity];
77 - (NSArray *)fetchOrder {
78 return self->fetchOrder;
80 - (EOSQLQualifier *)qualifier {
81 return self->qualifier;
87 RELEASE(self->content);
94 NSMutableArray *result;
97 result = [NSMutableArray arrayWithCapacity:16];
99 didOpenChannel = (![self->channel isOpen])
100 ? [self->channel openChannel]
103 if ([self->channel isFetchInProgress]) {
104 [NSException raise:NSInvalidArgumentException
105 format:@"attempt to fetch with busy channel: %@", self];
109 [[self->channel databaseContext] transactionNestingLevel] > 0;
110 if (!inTransaction) {
111 if (![[self->channel databaseContext] beginTransaction]) {
112 NSLog(@"WARNING: could not begin transaction to fetch array proxy !");
115 [self->channel closeChannel];
120 if (![self->channel selectObjectsDescribedByQualifier:self->qualifier
121 fetchOrder:self->fetchOrder]) {
123 [[self->channel databaseContext] rollbackTransaction];
125 [self->channel closeChannel];
127 NSLog(@"ERROR: select on array proxy failed ..");
132 NSZone *z = [self zone];
135 while ((object = [self->channel fetchWithZone:z]))
136 [result addObject:object];
139 [self->channel cancelFetch];
141 if (!inTransaction) {
142 if (![[self->channel databaseContext] commitTransaction]) {
143 NSLog(@"WARNING: could not commit array proxy's transaction !");
146 [self->channel closeChannel];
152 [self->channel closeChannel];
154 self->content = [result copyWithZone:[self zone]];
158 // turn fault to real array ..
160 void _checkFetch(EOArrayProxy *self) {
161 if (self->content) return;
165 // NSArray operations
167 - (id)objectAtIndex:(unsigned int)_index {
169 return [self->content objectAtIndex:_index];
171 - (unsigned int)count {
173 return [self->content count];
175 - (unsigned int)indexOfObjectIdenticalTo:(id)_object {
177 return [self->content indexOfObjectIdenticalTo:_object];
182 - (id)copyWithZone:(NSZone*)zone {
183 if (NSShouldRetainWithZone(self, zone))
187 return [[NSArray allocWithZone:zone] initWithArray:self->content copyItems:NO];
191 - (id)mutableCopyWithZone:(NSZone*)zone {
193 return [[NSMutableArray alloc] initWithArray:self->content];
201 - (void)forwardInvocation:(NSInvocation *)_invocation {
203 [_invocation invokeWithTarget:self->content];
206 - (retval_t)forward:(SEL)_selector:(arglist_t)_frame {
208 return objc_msg_sendv(self->content, _selector, _frame);