mirror of
https://github.com/gnustep/libs-gdl2.git
synced 2025-02-21 02:20:55 +00:00
* EOAccess/EODatabaseContext.m: o added assert in _primaryKeyForObject: o in -recordChangesInEditingContext test nil/eonull on relationshipCommitedSnapshotValue and relationshipSnapshotValue instead of only nil testing o in -recordChangesInEditingContext fix for value changing testing when commitedSnapshotValue is nil/EONull * EOAccess/EOEntity.m: o logs o fix in inverseRelationshipClassPropertyNames to test on destination entity property names * EOControl/EOClassDescription.m: o logs * EOControl/GNUmakefile: o added EONSAddOns.h * EOCOntrol/EOKeyValueCoding.m: o fixes in NSArray -computeXXForKey: * EOAccess/EOSQLExpression.m: o assert in -sqlStringForKeyValueQualifier: o -sqlStringForArrayOfQualifiers:operation: hanlde different qualifier cases using isKindOfClass: may probably be improved o logs * EOControl/EOEditingContext.m: o fix in unprocessedInfo (invert/change swap). * EOControl/EOQualifier.m o -qualifierWithQualifierFormat:varargList: raise exception if operator is unknwon * EOControl/EOMutableKnownKeyDictionary.m: o add precision in exception message * EOAccess/EORelationship.m: o more info in some logs o fix in -_sourceRowToForeignKeyMapping for foreign keys which are not in primaryKey. * EOControl/EODatabaseOperation.m: o in -setDatabaseOperator: Don't Delete a not inserted object * EOControl/EOAccessFault.m: o logs o EOAccessFaultHandler: -dealloc fix: call super dealloc o implement faultWillFire: This fix a hard memory problem * EOControl/EOFault.m: o -dealloc: fix possible infinite loop o logs * EOCheapCopyArray.m: o ucomment retain/release/... o fix shallowCopy for memory management. This was causing hard memory trouble git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@16217 72102866-910b-0410-8b05-ffd578937521
532 lines
14 KiB
Objective-C
532 lines
14 KiB
Objective-C
/**
|
|
EOFetchSpecification.m <title>EOFetchSpecification</title>
|
|
|
|
Copyright (C) 2000 Free Software Foundation, Inc.
|
|
|
|
Author: Mirko Viviani <mirko.viviani@rccr.cremona.it>
|
|
Date: February 2000
|
|
|
|
$Revision$
|
|
$Date$
|
|
|
|
<abstract></abstract>
|
|
|
|
This file is part of the GNUstep Database Library.
|
|
|
|
<license>
|
|
This library is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU Library General Public
|
|
License as published by the Free Software Foundation; either
|
|
version 2 of the License, or (at your option) any later version.
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Library General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
License along with this library; see the file COPYING.LIB.
|
|
If not, write to the Free Software Foundation,
|
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
</license>
|
|
**/
|
|
|
|
#include "config.h"
|
|
|
|
RCS_ID("$Id$")
|
|
|
|
#import <Foundation/NSCoder.h>
|
|
#import <Foundation/NSDictionary.h>
|
|
#import <Foundation/NSValue.h>
|
|
#import <Foundation/NSDebug.h>
|
|
|
|
#import <EOControl/EOFetchSpecification.h>
|
|
#import <EOControl/EOKeyValueArchiver.h>
|
|
#import <EOControl/EOObserver.h>
|
|
#import <EOControl/EODebug.h>
|
|
#import <EOControl/EONSAddOns.h>
|
|
#import <EOControl/EOQualifier.h>
|
|
|
|
|
|
@implementation EOFetchSpecification
|
|
|
|
+ (void)initialize
|
|
{
|
|
if (self == [EOFetchSpecification class])
|
|
{
|
|
Class cls = NSClassFromString(@"EODatabaseContext");
|
|
|
|
if (cls != Nil)
|
|
[cls class]; // Insure correct initialization.
|
|
}
|
|
}
|
|
|
|
|
|
+ (EOFetchSpecification *)fetchSpecification
|
|
{
|
|
return [[[self alloc] init] autorelease];
|
|
}
|
|
|
|
- (id) init
|
|
{
|
|
if ((self = [super init]))
|
|
{
|
|
_flags.isDeep = YES;
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- (void)dealloc
|
|
{
|
|
#ifdef DEBUG
|
|
NSDebugFLog(@"Dealloc EOFetchSpecification %p. ThreadID=%p",
|
|
(void*)self,(void*)objc_thread_id());
|
|
#endif
|
|
|
|
DESTROY(_qualifier);
|
|
DESTROY(_sortOrderings);
|
|
DESTROY(_entityName);
|
|
DESTROY(_hints);
|
|
DESTROY(_prefetchingRelationshipKeys);
|
|
DESTROY(_rawAttributeKeys);
|
|
|
|
[super dealloc];
|
|
|
|
#ifdef DEBUG
|
|
NSDebugFLog(@"Stop Dealloc EOFetchSpecification %p. ThreadID=%p",
|
|
(void*)self,(void*)objc_thread_id());
|
|
#endif
|
|
}
|
|
|
|
- (id) initWithEntityName: (NSString *)entityName
|
|
qualifier: (EOQualifier *)qualifier
|
|
sortOrderings: (NSArray *)sortOrderings
|
|
usesDistinct: (BOOL)usesDistinct
|
|
isDeep: (BOOL)isDeep
|
|
hints: (NSDictionary *)hints
|
|
{
|
|
if ((self = [self init]))
|
|
{
|
|
ASSIGN(_entityName, entityName);
|
|
ASSIGN(_qualifier, qualifier);
|
|
ASSIGN(_sortOrderings, sortOrderings);
|
|
|
|
[self setUsesDistinct: usesDistinct];
|
|
[self setIsDeep: isDeep];
|
|
[self setHints: hints];
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- (EOFetchSpecification *)fetchSpecificationByApplyingBindings: (id)bindings
|
|
{
|
|
[self notImplemented:_cmd];
|
|
return nil;
|
|
}
|
|
|
|
- (EOFetchSpecification *)fetchSpecificationWithQualifierBindings: (NSDictionary *)bindings
|
|
{
|
|
[self notImplemented: _cmd];
|
|
return nil;
|
|
}
|
|
|
|
+ (EOFetchSpecification *)fetchSpecificationNamed: (NSString *)name
|
|
entityNamed: (NSString *)entityName
|
|
{
|
|
return nil;
|
|
}
|
|
|
|
+ (EOFetchSpecification *)fetchSpecificationWithEntityName: (NSString *)name
|
|
qualifier: (EOQualifier *)qualifier
|
|
sortOrderings: (NSArray *)sortOrderings
|
|
{
|
|
return [[[EOFetchSpecification alloc]
|
|
initWithEntityName: name
|
|
qualifier: qualifier
|
|
sortOrderings: sortOrderings
|
|
usesDistinct: NO
|
|
isDeep: YES
|
|
hints: nil] autorelease];
|
|
}
|
|
|
|
+ (EOFetchSpecification *)fetchSpecificationWithEntityName: (NSString *)name
|
|
qualifier: (EOQualifier *)qualifier
|
|
sortOrderings: (NSArray *)sortOrderings
|
|
usesDistinct: (BOOL)usesDistinct
|
|
isDeep: (BOOL)isDeep
|
|
hints: (NSDictionary *)hints
|
|
{
|
|
return [[[EOFetchSpecification alloc]
|
|
initWithEntityName: name
|
|
qualifier: qualifier
|
|
sortOrderings: sortOrderings
|
|
usesDistinct: usesDistinct
|
|
isDeep: isDeep
|
|
hints: hints] autorelease];
|
|
}
|
|
|
|
|
|
+ (EOFetchSpecification *)fetchSpecificationWithEntityName: (NSString *)name
|
|
qualifier: (EOQualifier *)qualifier
|
|
sortOrderings: (NSArray *)sortOrderings
|
|
usesDistinct: (BOOL)usesDistinct
|
|
{
|
|
return [[[EOFetchSpecification alloc]
|
|
initWithEntityName: name
|
|
qualifier: qualifier
|
|
sortOrderings: sortOrderings
|
|
usesDistinct: usesDistinct
|
|
isDeep: YES
|
|
hints: nil] autorelease];
|
|
}
|
|
|
|
- (id) copyWithZone: (NSZone *)zone
|
|
{
|
|
EOFetchSpecification *ret = [EOFetchSpecification allocWithZone:zone];
|
|
//order: hints, isdeep, usesDistinct,sortOrderings, qualifier,entityName
|
|
//and call nitWithEntityName:qualifier:sortOrderings:usesDistinct:isDeep:hints:
|
|
//after:
|
|
/* [fetch setLocksObjects:[_fetchSpecification locksObjects]];
|
|
[fetch setRefreshesRefetchedObjects:[_fetchSpecification refreshesRefetchedObjects]];
|
|
[fetch setPrefetchingRelationshipKeyPaths:[_fetchSpecification prefetchingRelationshipKeyPaths
|
|
[fetch setRawRowKeyPaths:[_fetchSpecification rawRowKeyPaths
|
|
setFetchLimit:fetchLimit
|
|
setPromptsAfterFetchLimit: promptsAfterFetchLimit
|
|
setRequiresAllQualifierBindingVariables:requiresAllQualifierBindingVariables
|
|
*/
|
|
//call setXX fn instead to have "willChange" ??
|
|
ret->_qualifier = [(id <NSCopying>)_qualifier copyWithZone: zone];
|
|
ret->_sortOrderings = [_sortOrderings copyWithZone: zone]; //mirko: ASSIGN(ret->_sortOrderings, _sortOrderings);
|
|
ret->_entityName = [_entityName copyWithZone: zone];
|
|
ret->_hints = [_hints copyWithZone: zone];
|
|
ret->_prefetchingRelationshipKeys = [_prefetchingRelationshipKeys copyWithZone: zone];
|
|
ret->_rawAttributeKeys = [_rawAttributeKeys copyWithZone: zone];
|
|
ret->_fetchLimit = _fetchLimit;
|
|
ret->_flags = _flags;
|
|
|
|
return ret;
|
|
}
|
|
|
|
- (void)encodeWithCoder: (NSCoder *)coder
|
|
{
|
|
[coder encodeObject: _qualifier];
|
|
[coder encodeObject: _sortOrderings];
|
|
[coder encodeObject: _entityName];
|
|
[coder encodeObject: _hints];
|
|
[coder encodeValueOfObjCType: @encode(unsigned int) at: &_fetchLimit];
|
|
[coder encodeObject: _prefetchingRelationshipKeys];
|
|
[coder encodeObject: _rawAttributeKeys];
|
|
[coder encodeValueOfObjCType: @encode(unsigned int) at: &_flags];
|
|
}
|
|
|
|
- (id)initWithCoder: (NSCoder *)coder
|
|
{
|
|
_qualifier = [[coder decodeObject] retain];
|
|
_sortOrderings = [[coder decodeObject] retain];
|
|
_entityName = [[coder decodeObject] retain];
|
|
_hints = [[coder decodeObject] retain];
|
|
[coder decodeValueOfObjCType: @encode(unsigned int) at: &_fetchLimit];
|
|
_prefetchingRelationshipKeys = [[coder decodeObject] retain];
|
|
_rawAttributeKeys = [[coder decodeObject] retain];
|
|
[coder decodeValueOfObjCType: @encode(unsigned int) at: &_flags];
|
|
|
|
return self;
|
|
}
|
|
|
|
- (id) initWithKeyValueUnarchiver: (EOKeyValueUnarchiver*)unarchiver
|
|
{
|
|
if ((self = [self init]))
|
|
{
|
|
ASSIGN(_hints, [unarchiver decodeObjectForKey: @"hints"]);
|
|
ASSIGN(_qualifier, [unarchiver decodeObjectForKey: @"qualifier"]);
|
|
ASSIGN(_sortOrderings, [unarchiver decodeObjectForKey: @"sortOrderings"]);
|
|
ASSIGN(_entityName, [unarchiver decodeObjectForKey: @"entityName"]);
|
|
ASSIGN(_prefetchingRelationshipKeys,
|
|
[unarchiver decodeObjectForKey: @"prefetchingRelationshipKeyPaths"]);
|
|
ASSIGN(_rawAttributeKeys, [unarchiver decodeObjectForKey: @"rawRowKeyPaths"]);
|
|
|
|
_fetchLimit = [unarchiver decodeIntForKey: @"fetchLimit"];
|
|
_flags.usesDistinct = [unarchiver decodeBoolForKey: @"usesDistinct"];
|
|
_flags.isDeep = [unarchiver decodeBoolForKey: @"isDeep"];
|
|
_flags.locksObjects = [unarchiver decodeBoolForKey: @"locksObjects"];
|
|
_flags.refreshesRefetchedObjects =
|
|
[unarchiver decodeBoolForKey: @"refreshesRefetchedObjects"];
|
|
_flags.promptsAfterFetchLimit =
|
|
[unarchiver decodeBoolForKey: @"promptsAfterFetchLimit"];
|
|
_flags.allVariablesRequiredFromBindings =
|
|
[unarchiver decodeBoolForKey: @"requiresAllQualifierBindingVariables"];
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
- (void) encodeWithKeyValueArchiver: (EOKeyValueUnarchiver*)archiver
|
|
{
|
|
[self notImplemented: _cmd];
|
|
}
|
|
|
|
- (NSString*)description
|
|
{
|
|
NSMutableString *desc = [NSMutableString string];
|
|
|
|
[desc appendString: @"{\n"];
|
|
[desc appendString: [NSString stringWithFormat: @"hints = %@;\n",
|
|
[_hints description]]];
|
|
[desc appendString: [NSString stringWithFormat: @"qualifier = %@;\n",
|
|
_qualifier]];
|
|
[desc appendString: [NSString stringWithFormat: @"sortOrderings = %@;\n",
|
|
[_sortOrderings description]]];
|
|
[desc appendString: [NSString stringWithFormat: @"entityName = %@;\n",
|
|
_entityName]];
|
|
[desc appendString: [NSString stringWithFormat: @"prefetchingRelationshipKeyPaths = %@;\n",
|
|
[_prefetchingRelationshipKeys description]]];
|
|
[desc appendString: [NSString stringWithFormat: @"rawRowKeyPaths = %@;\n",
|
|
[_rawAttributeKeys description]]];
|
|
[desc appendString: [NSString stringWithFormat: @"fetchLimit = %d;\n",
|
|
_fetchLimit]];
|
|
[desc appendString: [NSString stringWithFormat: @"usesDistinct = %s;\n",
|
|
_flags.usesDistinct ? "YES" : "NO"]];
|
|
[desc appendString: [NSString stringWithFormat: @"isDeep = %s;\n",
|
|
_flags.isDeep ? "YES" : "NO"]];
|
|
[desc appendString: [NSString stringWithFormat: @"locksObjects = %s;\n",
|
|
_flags.locksObjects ? "YES" : "NO"]];
|
|
[desc appendString: [NSString stringWithFormat: @"refreshesRefetchedObjects = %s;\n",
|
|
_flags.refreshesRefetchedObjects ? "YES" : "NO"]];
|
|
[desc appendString: [NSString stringWithFormat: @"promptsAfterFetchLimit = %s;\n",
|
|
_flags.promptsAfterFetchLimit ? "YES" : "NO"]];
|
|
[desc appendString: [NSString stringWithFormat: @"requiresAllQualifierBindingVariables = %s;\n",
|
|
_flags.allVariablesRequiredFromBindings ? "YES" : "NO"]];
|
|
[desc appendString: @"}"];
|
|
|
|
return desc;
|
|
}
|
|
|
|
- (void)setEntityName: (NSString *)entityName
|
|
{
|
|
[self willChange];
|
|
ASSIGN(_entityName, entityName);
|
|
}
|
|
|
|
- (NSString *)entityName
|
|
{
|
|
return _entityName;
|
|
}
|
|
|
|
- (void)setSortOrderings: (NSArray *)sortOrderings
|
|
{
|
|
ASSIGN(_sortOrderings, sortOrderings);
|
|
}
|
|
|
|
- (NSArray *)sortOrderings
|
|
{
|
|
return _sortOrderings;
|
|
}
|
|
|
|
- (void)setQualifier: (EOQualifier *)qualifier
|
|
{
|
|
[self willChange];
|
|
ASSIGN(_qualifier, qualifier);
|
|
}
|
|
|
|
- (EOQualifier *)qualifier
|
|
{
|
|
return _qualifier;
|
|
}
|
|
|
|
- (void)setUsesDistinct: (BOOL)usesDistinct
|
|
{
|
|
[self willChange];
|
|
_flags.usesDistinct = usesDistinct;
|
|
}
|
|
|
|
- (BOOL)usesDistinct
|
|
{
|
|
return _flags.usesDistinct;
|
|
}
|
|
|
|
- (void)setIsDeep: (BOOL)isDeep
|
|
{
|
|
[self willChange];
|
|
_flags.isDeep = isDeep;
|
|
}
|
|
|
|
- (BOOL)isDeep
|
|
{
|
|
return _flags.isDeep;
|
|
}
|
|
|
|
- (void)setLocksObjects: (BOOL)locksObjects
|
|
{
|
|
[self willChange];
|
|
_flags.locksObjects = locksObjects;
|
|
}
|
|
|
|
- (BOOL)locksObjects
|
|
{
|
|
return _flags.locksObjects;
|
|
}
|
|
|
|
- (void)setRefreshesRefetchedObjects: (BOOL)refreshesRefetchedObjects
|
|
{
|
|
[self willChange];
|
|
_flags.refreshesRefetchedObjects = refreshesRefetchedObjects;
|
|
}
|
|
|
|
- (BOOL)refreshesRefetchedObjects
|
|
{
|
|
return _flags.refreshesRefetchedObjects;
|
|
}
|
|
|
|
- (void)setFetchLimit: (unsigned)fetchLimit
|
|
{
|
|
[self willChange];
|
|
_fetchLimit = fetchLimit;
|
|
}
|
|
|
|
- (unsigned)fetchLimit
|
|
{
|
|
return _fetchLimit;
|
|
}
|
|
|
|
- (void)setPromptsAfterFetchLimit: (BOOL)promptsAfterFetchLimit
|
|
{
|
|
[self willChange];
|
|
_flags.promptsAfterFetchLimit = promptsAfterFetchLimit;
|
|
}
|
|
|
|
- (BOOL)promptsAfterFetchLimit
|
|
{
|
|
return _flags.promptsAfterFetchLimit;
|
|
}
|
|
|
|
- (void)setAllVariablesRequiredFromBindings: (BOOL)allVariablesRequired
|
|
{
|
|
_flags.allVariablesRequiredFromBindings = allVariablesRequired;
|
|
}
|
|
|
|
- (BOOL)allVariablesRequiredFromBindings
|
|
{
|
|
return _flags.allVariablesRequiredFromBindings;
|
|
}
|
|
|
|
- (void)setPrefetchingRelationshipKeyPaths: (NSArray *)prefetchingRelationshipKeys
|
|
{
|
|
[self willChange];
|
|
ASSIGN(_prefetchingRelationshipKeys, prefetchingRelationshipKeys);
|
|
}
|
|
|
|
- (NSArray *)prefetchingRelationshipKeyPaths
|
|
{
|
|
return _prefetchingRelationshipKeys;
|
|
}
|
|
|
|
- (void)setRawAttributeKeys: (NSArray *)rawAttributeKeys
|
|
{
|
|
ASSIGN(_rawAttributeKeys, rawAttributeKeys);
|
|
}
|
|
|
|
- (NSArray *)rawAttributeKeys
|
|
{
|
|
return _rawAttributeKeys;
|
|
}
|
|
|
|
- (void)setFetchesRawRows: (BOOL)fetchRawRows
|
|
{
|
|
if (fetchRawRows)
|
|
[self setRawRowKeyPaths: [NSArray array]];
|
|
else
|
|
[self setRawRowKeyPaths: nil];
|
|
}
|
|
|
|
- (BOOL)fetchesRawRows
|
|
{
|
|
if ([self rawRowKeyPaths])
|
|
return YES;
|
|
else
|
|
return NO;
|
|
}
|
|
|
|
- (void)setHints: (NSDictionary *)hints
|
|
{
|
|
//TODO: set fetchLimit,... from hints ???
|
|
[self willChange];
|
|
//even if nil: initWithDictionary:copyItems:
|
|
//thedict objectForKey:EOPrefetchingRelationshipHintKey
|
|
//EOFetchLimitHintKey
|
|
//EOPromptAfterFetchLimitHintKey
|
|
ASSIGN(_hints, hints);
|
|
}
|
|
|
|
- (NSDictionary *)_hints
|
|
{
|
|
return _hints;
|
|
}
|
|
|
|
- (NSDictionary *)hints
|
|
{
|
|
NSMutableDictionary *hints = (NSMutableDictionary *)_hints;
|
|
BOOL promptsAfterFetchLimit;
|
|
NSArray *prefetchingRelationshipKeyPaths;
|
|
unsigned fetchLimit;
|
|
|
|
fetchLimit = [self fetchLimit];
|
|
promptsAfterFetchLimit = [self promptsAfterFetchLimit];
|
|
prefetchingRelationshipKeyPaths = [self prefetchingRelationshipKeyPaths];
|
|
|
|
if (fetchLimit != 0 || promptsAfterFetchLimit
|
|
|| [prefetchingRelationshipKeyPaths count] > 0)
|
|
{
|
|
NSMutableDictionary *mutableHints = [NSMutableDictionary
|
|
dictionaryWithDictionary: hints];
|
|
|
|
hints = mutableHints;
|
|
|
|
if (fetchLimit != 0)
|
|
{
|
|
[mutableHints setObject: [NSNumber numberWithInt: fetchLimit]
|
|
forKey: @"EOFetchLimitHintKey"];
|
|
}
|
|
|
|
if (promptsAfterFetchLimit)
|
|
{
|
|
[mutableHints setObject: [NSNumber numberWithBool:
|
|
promptsAfterFetchLimit]
|
|
forKey: @"EOPromptAfterFetchLimitHintKey"];
|
|
}
|
|
|
|
if ([prefetchingRelationshipKeyPaths count] > 0)
|
|
{
|
|
[mutableHints setObject: prefetchingRelationshipKeyPaths
|
|
forKey: @"EOPrefetchingRelationshipHintKey"];
|
|
}
|
|
}
|
|
|
|
return hints;
|
|
}
|
|
|
|
- (NSArray *)rawRowKeyPaths
|
|
{
|
|
return _rawAttributeKeys;
|
|
}
|
|
|
|
- (void)setRawRowKeyPaths: (NSArray *)rawRowKeyPaths
|
|
{
|
|
[self willChange];
|
|
ASSIGN(_rawAttributeKeys, rawRowKeyPaths);
|
|
}
|
|
|
|
- (BOOL)requiresAllQualifierBindingVariables
|
|
{
|
|
NSDebugMLLog(@"gsdb", @"self=%p", self);
|
|
return _flags.allVariablesRequiredFromBindings;
|
|
}
|
|
|
|
- (void)setRequiresAllQualifierBindingVariables: (BOOL)flag
|
|
{
|
|
[self willChange];
|
|
[self notImplemented: _cmd];
|
|
}
|
|
|
|
@end
|