* EOControl/EOFetchSpecification.m

(-[EOFetchSpecification fetchSpecificationNamed:entityNamed:]}:
	Implemented upon bug report by Philip Moetteli.
	* EOAccess/EOAttributePriv.h (-[EOAttribute _valueClass]):
	Declare new private method.
	* EOAccess/EOAttribute.m: Remove declaration of unsused static
	variable.  Format documentation.
	(-[EOAttribute serverTimeZone]): Remove duplicate
	implementation which is always overriden by the category
	and correct the category implementation.
	(-[EOAttribute valueClassName]): Minor optimisation.
	(-[EOAttribute externalType]): Ditto.
	(-[EOAttribute valueType]): Ditto.
	(-[EOAttribute newValueForBytes:length:]): Use -_valueClass
	method to insure correct valueClass usage.  Bug reported
	by Philip Moetteli.
	(-[EOAttribute newValueForBytes:length:encoding:]): Ditto.
	(-[EOAttribute adaptorValueType]): Ditto.
	(-[EOAttribute validateValue:]): Ditto.  Use -width method to
	insure correct usage of width with respect to prototypes.
	(-[EOAttribute _valueClass]): New private method.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gdl2/trunk@17960 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
David Ayers 2003-10-23 15:06:51 +00:00
parent 6b282e94ae
commit 6b82f558c1
3 changed files with 108 additions and 65 deletions

View file

@ -3,6 +3,24 @@
* EOControl/EOFetchSpecification.m * EOControl/EOFetchSpecification.m
(-[EOFetchSpecification fetchSpecificationNamed:entityNamed:]}: (-[EOFetchSpecification fetchSpecificationNamed:entityNamed:]}:
Implemented upon bug report by Philip Moetteli. Implemented upon bug report by Philip Moetteli.
* EOAccess/EOAttributePriv.h (-[EOAttribute _valueClass]): Declare
new private method.
* EOAccess/EOAttribute.m: Remove declaration of unsused static
variable. Format documentation.
(-[EOAttribute serverTimeZone]): Remove duplicate implementation
which is always overriden by the category and correct the category
implementation.
(-[EOAttribute valueClassName]): Minor optimisation.
(-[EOAttribute externalType]): Ditto.
(-[EOAttribute valueType]): Ditto.
(-[EOAttribute newValueForBytes:length:]): Use -_valueClass method
to insure correct valueClass usage. Bug reported by Philip
Moetteli.
(-[EOAttribute newValueForBytes:length:encoding:]): Ditto.
(-[EOAttribute adaptorValueType]): Ditto.
(-[EOAttribute validateValue:]): Ditto. Use -width method to
insure correct usage of width with respect to prototypes.
(-[EOAttribute _valueClass]): New private method.
2003-09-29 Philip Moetteli <Philip.Moetteli@tele2.ch> 2003-09-29 Philip Moetteli <Philip.Moetteli@tele2.ch>

View file

@ -79,8 +79,6 @@ RCS_ID("$Id$")
@implementation EOAttribute @implementation EOAttribute
static NSString *defaultCalendarFormat = @"%b %d %Y %H:%M";
+ (id) attributeWithPropertyList: (NSDictionary *)propertyList + (id) attributeWithPropertyList: (NSDictionary *)propertyList
owner: (id)owner owner: (id)owner
{ {
@ -452,14 +450,6 @@ static NSString *defaultCalendarFormat = @"%b %d %Y %H:%M";
return _name; return _name;
} }
- (NSTimeZone *)serverTimeZone
{
if (_serverTimeZone)
return _serverTimeZone;
return [_prototype serverTimeZone];
}
- (NSString *)columnName - (NSString *)columnName
{ {
if (_columnName) if (_columnName)
@ -598,10 +588,13 @@ static NSString *defaultCalendarFormat = @"%b %d %Y %H:%M";
return NO; return NO;
} }
/** Return NO when the attribute corresponds to one SQL column in its entity associated table return YES otherwise. /**
An attribute with a definition such as "anotherAttributeName * 2" is derived * Return NO when the attribute corresponds to one SQL column in its entity
A Flattened attribute is also a derived attributes. * associated table return YES otherwise.
**/ * An attribute with a definition such as
* "anotherAttributeName * 2" is derived.
* A Flattened attribute is also a derived attributes.
**/
- (BOOL)isDerived - (BOOL)isDerived
{ {
//Seems OK //Seems OK
@ -612,11 +605,12 @@ A Flattened attribute is also a derived attributes.
} }
/** Returns YES if the attribute is flattened, NO otherwise. /**
A flattened attribute is an attribute with a definition using a relationship to another entity * Returns YES if the attribute is flattened, NO otherwise.
A Flattened attribute is also a derived attributes. * A flattened attribute is an attribute with a definition
**/ * using a relationship to another entity.
* A Flattened attribute is also a derived attribute.
**/
- (BOOL)isFlattened - (BOOL)isFlattened
{ {
BOOL isFlattened = NO; BOOL isFlattened = NO;
@ -630,41 +624,43 @@ A Flattened attribute is also a derived attributes.
- (NSString *)valueClassName - (NSString *)valueClassName
{ {
if (!_valueClassName && [self isFlattened])
return [[_definitionArray realAttribute] valueClassName];
if (_valueClassName) if (_valueClassName)
return _valueClassName; return _valueClassName;
if ([self isFlattened])
return [[_definitionArray realAttribute] valueClassName];
return [_prototype valueClassName]; return [_prototype valueClassName];
} }
- (NSString *)externalType - (NSString *)externalType
{ {
if (!_externalType && [self isFlattened])
return [[_definitionArray realAttribute] externalType];
if (_externalType) if (_externalType)
return _externalType; return _externalType;
if ([self isFlattened])
return [[_definitionArray realAttribute] externalType];
return [_prototype externalType]; return [_prototype externalType];
} }
- (NSString *)valueType - (NSString *)valueType
{ {
if(!_valueType && [self isFlattened])
return [[_definitionArray realAttribute] valueType];
if (_valueType) if (_valueType)
return _valueType; return _valueType;
if([self isFlattened])
return [[_definitionArray realAttribute] valueType];
return [_prototype valueType]; return [_prototype valueType];
} }
@end @end
@implementation EOAttribute (EOAttributeSQLExpression) @implementation EOAttribute (EOAttributeSQLExpression)
/** Returns the value to use in an EOSQLExpression. **/ /**
* Returns the value to use in an EOSQLExpression.
**/
- (NSString *) valueForSQLExpression: (EOSQLExpression *)sqlExpression - (NSString *) valueForSQLExpression: (EOSQLExpression *)sqlExpression
{ {
NSString *value=nil; NSString *value=nil;
@ -999,7 +995,10 @@ return nexexp
- (NSTimeZone *)serverTimeZone - (NSTimeZone *)serverTimeZone
{ {
return _serverTimeZone; if (_serverTimeZone)
return _serverTimeZone;
return [_prototype serverTimeZone];
} }
@end @end
@ -1018,18 +1017,22 @@ return nexexp
@implementation EOAttribute (EOAttributeValueCreation) @implementation EOAttribute (EOAttributeValueCreation)
/** returns a NSString or a custom-class value object from the supplied set of bytes. /**
Adaptor call this method during value creation when fetching objects from the database. * Returns an NSString or a custom-class value object
For efficiency reasons, the returned value is NOT autoreleased ! * from the supplied set of bytes.
**/ * The Adaptor calls this method during value creation
* when fetching objects from the database.
* For efficiency, the returned value is NOT autoreleased.
**/
- (id)newValueForBytes: (const void *)bytes - (id)newValueForBytes: (const void *)bytes
length: (int)length length: (int)length
{ {
NSMethodSignature *aSignature; NSMethodSignature *aSignature;
NSInvocation *anInvocation; NSInvocation *anInvocation;
NSData *value = nil; NSData *value = nil;
Class valueClass = [self _valueClass];
if (_valueClass != Nil && _valueClass != [NSData class]) if (valueClass != Nil && valueClass != [NSData class])
{ {
switch (_argumentType) switch (_argumentType)
{ {
@ -1037,15 +1040,15 @@ For efficiency reasons, the returned value is NOT autoreleased !
value = [[NSData alloc] initWithBytes:bytes length: length]; //For efficiency reasons, the returned value is NOT autoreleased ! value = [[NSData alloc] initWithBytes:bytes length: length]; //For efficiency reasons, the returned value is NOT autoreleased !
if(_valueFactoryMethod != NULL) if(_valueFactoryMethod != NULL)
value = [_valueClass performSelector: _valueFactoryMethod value = [valueClass performSelector: _valueFactoryMethod
withObject: [value autorelease]]; withObject: [value autorelease]];
break; break;
case EOFactoryMethodArgumentIsBytes: case EOFactoryMethodArgumentIsBytes:
value = [_valueClass alloc];//For efficiency reasons, the returned value is NOT autoreleased ! value = [valueClass alloc];//For efficiency reasons, the returned value is NOT autoreleased !
aSignature = aSignature =
[_valueClass [valueClass
instanceMethodSignatureForSelector: _valueFactoryMethod]; instanceMethodSignatureForSelector: _valueFactoryMethod];
anInvocation = [NSInvocation anInvocation = [NSInvocation
@ -1069,10 +1072,13 @@ For efficiency reasons, the returned value is NOT autoreleased !
return value; return value;
} }
/** returns a NSString or a custom-class value object from the supplied set of bytes using encoding. /**
Adaptor call this method during value creation when fetching objects from the database. * Returns a NSString or a custom-class value object
For efficiency reasons, the returned value is NOT autoreleased ! * from the supplied set of bytes using encoding.
**/ * The Adaptor calls this method during value creation
* when fetching objects from the database.
* For efficiency, the returned value is NOT autoreleased.
**/
- (id)newValueForBytes: (const void *)bytes - (id)newValueForBytes: (const void *)bytes
length: (int)length length: (int)length
encoding: (NSStringEncoding)encoding encoding: (NSStringEncoding)encoding
@ -1080,8 +1086,9 @@ For efficiency reasons, the returned value is NOT autoreleased !
NSMethodSignature *aSignature; NSMethodSignature *aSignature;
NSInvocation *anInvocation; NSInvocation *anInvocation;
id value = nil; id value = nil;
Class valueClass = [self _valueClass];
if (_valueClass != Nil && _valueClass != [NSString class]) if (valueClass != Nil && valueClass != [NSString class])
{ {
switch (_argumentType) switch (_argumentType)
{ {
@ -1090,15 +1097,15 @@ For efficiency reasons, the returned value is NOT autoreleased !
length: length] length: length]
encoding: encoding];//For efficiency reasons, the returned value is NOT autoreleased ! encoding: encoding];//For efficiency reasons, the returned value is NOT autoreleased !
value = [_valueClass performSelector: _valueFactoryMethod value = [valueClass performSelector: _valueFactoryMethod
withObject: [value autorelease]]; withObject: [value autorelease]];
break; break;
case EOFactoryMethodArgumentIsBytes: case EOFactoryMethodArgumentIsBytes:
value = [_valueClass alloc];//For efficiency reasons, the returned value is NOT autoreleased ! value = [valueClass alloc];//For efficiency reasons, the returned value is NOT autoreleased !
aSignature = aSignature =
[_valueClass [valueClass
instanceMethodSignatureForSelector: _valueFactoryMethod]; instanceMethodSignatureForSelector: _valueFactoryMethod];
anInvocation = [NSInvocation anInvocation = [NSInvocation
@ -1126,8 +1133,12 @@ For efficiency reasons, the returned value is NOT autoreleased !
} }
/** /**
For efficiency reasons, the returned value is NOT autoreleased ! * Returns an NSCalanderDate object
**/ * from the supplied time information.
* The Adaptor calls this method during value creation
* when fetching objects from the database.
* For efficiency, the returned value is NOT autoreleased.
**/
- (NSCalendarDate *)newDateForYear: (int)year - (NSCalendarDate *)newDateForYear: (int)year
month: (unsigned)month month: (unsigned)month
day: (unsigned)day day: (unsigned)day
@ -1222,16 +1233,16 @@ For efficiency reasons, the returned value is NOT autoreleased !
EOAdaptorValueType values[] = { EOAdaptorNumberType, EOAdaptorValueType values[] = { EOAdaptorNumberType,
EOAdaptorCharactersType, EOAdaptorCharactersType,
EOAdaptorDateType }; EOAdaptorDateType };
Class class; Class valueClass;
int i; int i;
for ( i = 0; i < 3; i++) for ( i = 0; i < 3; i++)
{ {
class = _valueClass; for ( valueClass = [self _valueClass];
valueClass != Nil;
for ( ; class != Nil; class = class_get_super_class(class)) valueClass = GSObjCSuper(valueClass))
{ {
if (class == adaptorClasses[i]) if (valueClass == adaptorClasses[i])
return values[i]; return values[i];
} }
} }
@ -1289,35 +1300,37 @@ For efficiency reasons, the returned value is NOT autoreleased !
//TODO: revoir //TODO: revoir
{ {
EOEntity *entity = [self entity]; //EOEntity *entity = [self entity];
//NSArray *pkAttributes = [entity primaryKeyAttributes]; //NSArray *pkAttributes = [entity primaryKeyAttributes];
//TODO wowhat //TODO wowhat
if (*valueP) if (*valueP)
{ {
if ([*valueP isKindOfClass: _valueClass] == NO) Class valueClass = [self _valueClass];
if ([*valueP isKindOfClass: valueClass] == NO)
{ {
if ([*valueP isKindOfClass: [NSString class]]) if ([*valueP isKindOfClass: [NSString class]])
{ {
if (_valueClass == [NSNumber class]) if (valueClass == [NSNumber class])
{ {
if ([_valueType isEqualToString: @"i"] == YES) if ([[self valueType] isEqualToString: @"i"] == YES)
*valueP = [NSNumber numberWithInt: *valueP = [NSNumber numberWithInt:
[*valueP intValue]]; [*valueP intValue]];
else else
*valueP = [NSNumber numberWithDouble: *valueP = [NSNumber numberWithDouble:
[*valueP doubleValue]]; [*valueP doubleValue]];
} }
else if (_valueClass == [NSDecimalNumber class]) else if (valueClass == [NSDecimalNumber class])
*valueP = [NSDecimalNumber *valueP = [NSDecimalNumber
decimalNumberWithString: *valueP]; decimalNumberWithString: *valueP];
else if (_valueClass == [NSData class]) else if (valueClass == [NSData class])
*valueP = [*valueP *valueP = [*valueP
dataUsingEncoding: NSASCIIStringEncoding dataUsingEncoding: NSASCIIStringEncoding
allowLossyConversion: YES]; allowLossyConversion: YES];
else if (_valueClass == [NSCalendarDate class]) else if (valueClass == [NSCalendarDate class])
*valueP = [[[NSCalendarDate alloc] *valueP = [[[NSCalendarDate alloc]
initWithString: *valueP] initWithString: *valueP]
autorelease]; autorelease];
@ -1327,13 +1340,15 @@ For efficiency reasons, the returned value is NOT autoreleased !
{ {
if ([*valueP isKindOfClass: [NSString class]]) if ([*valueP isKindOfClass: [NSString class]])
{ {
if (_width && [*valueP length] > _width) unsigned width = [self width];
if (width && [*valueP length] > width)
{ {
const char *buf; const char *buf;
buf = [*valueP cString]; buf = [*valueP cString];
*valueP = [NSString stringWithCString: buf *valueP = [NSString stringWithCString: buf
length: _width]; length: width];
} }
} }
else if ([*valueP isKindOfClass: [NSNumber class]]) else if ([*valueP isKindOfClass: [NSNumber class]])
@ -1387,6 +1402,17 @@ For efficiency reasons, the returned value is NOT autoreleased !
return _definitionArray; return _definitionArray;
} }
- (Class)_valueClass
{
if (_valueClass)
return _valueClass;
if ([self isFlattened])
return [[_definitionArray realAttribute] _valueClass];
return [_prototype _valueClass];
}
@end @end
@implementation EOAttribute (EOAttributePrivate2) @implementation EOAttribute (EOAttributePrivate2)
@ -1425,3 +1451,4 @@ For efficiency reasons, the returned value is NOT autoreleased !
} }
@end @end

View file

@ -28,23 +28,21 @@
#define __EOAttributePriv_h__ #define __EOAttributePriv_h__
@interface EOAttribute (EOAttributePrivate) @interface EOAttribute (EOAttributePrivate)
- (GCMutableArray *)_definitionArray; - (GCMutableArray *)_definitionArray;
- (void)setParent: (id)parent; - (void)setParent: (id)parent;
- (EOAttribute *)realAttribute; - (EOAttribute *)realAttribute;
- (Class)_valueClass;
@end @end
@interface EOAttribute (EOAttributePrivate2) @interface EOAttribute (EOAttributePrivate2)
- (BOOL) _hasAnyOverrides; - (BOOL) _hasAnyOverrides;
- (void) _resetPrototype; - (void) _resetPrototype;
- (void) _updateFromPrototype; - (void) _updateFromPrototype;
- (void) _setOverrideForKeyEnum: (int)keyEnum; - (void) _setOverrideForKeyEnum: (int)keyEnum;
- (BOOL) _isKeyEnumOverriden: (int)param0; - (BOOL) _isKeyEnumOverriden: (int)param0;
- (BOOL) _isKeyEnumDefinedByPrototype: (int)param0; - (BOOL) _isKeyEnumDefinedByPrototype: (int)param0;
@end @end
#endif /* __EOAttributePriv_h__ */ #endif /* __EOAttributePriv_h__ */