Changeset 224

Show
Ignore:
Timestamp:
03/15/07 01:14:15 (2 years ago)
Author:
rentzsch
Message:

[CHANGE] CoreData?+JRExtensions/mogenerator: moving position_ support back out of mogenerator machine template code generation and into a NSEntityDescription poser (NSEntityDescription_PositionSupport). Another chapter in the epic saga of "where can I put code that populates an attribute based on a fetch request without crashing Core Data?!?"

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/cocoa/CoreData+JRExtensions/CoreData+JRExtensions.m

    r216 r224  
    88 
    99- (id)initAndInsertIntoManagedObjectContext:(NSManagedObjectContext*)moc_ { 
    10         return [self initWithEntity:[[self class] entityDescriptionInManagedObjectContext:moc_] insertIntoManagedObjectContext:moc_]; 
     10        return [NSEntityDescription insertNewObjectForEntityForName:[[[self class] entityDescriptionInManagedObjectContext:moc_] name] 
     11                                                                                 inManagedObjectContext:moc_]; 
    1112} 
    1213 
  • trunk/cocoa/mogenerator/machine.m.motemplate

    r210 r224  
    1212        <$Attribute.attributeValueClassName$> *result = [self primitiveValueForKey:@"<$Attribute.name$>"]; 
    1313        [self didAccessValueForKey:@"<$Attribute.name$>"]; 
    14 <$if Attribute.name == position_$> 
    15         //      position_ is a calculated value: @max(position_)+1. Calculate it the first time it's used. 
    16         static BOOL fetching = NO; 
    17         if (!result || [result longLongValue] == -1) { 
    18                 fetching = YES; 
    19                 NSFetchRequest *fetchObjectWithMaximumPosition = [[[NSFetchRequest alloc] init] autorelease]; 
    20                 [fetchObjectWithMaximumPosition setEntity:[self entity]]; 
    21                 [fetchObjectWithMaximumPosition setSortDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"position_" ascending:NO] autorelease]]]; 
    22                 [fetchObjectWithMaximumPosition setFetchLimit:1]; 
    23                 NSArray *objectWithMaximumPosition = [[self managedObjectContext] executeFetchRequest:fetchObjectWithMaximumPosition error:nil]; 
    24                 assert(objectWithMaximumPosition && [objectWithMaximumPosition count] < 2); 
    25                 result = [NSNumber numberWithLongLong:[objectWithMaximumPosition count] ? [[[objectWithMaximumPosition lastObject] valueForKey:@"position_"] longLongValue]+1 : 0]; 
    26                 [self setPosition_:result]; 
    27                 fetching = NO; 
    28         } 
    29 <$endif$> 
    3014        return result; 
    3115}