|
|
1.1 ! root 1: ! 2: #import "AppController.h" ! 3: ! 4: @implementation AppController ! 5: ! 6: - appDidInit:sender ! 7: { ! 8: EODatabaseChannel *channel = [(id)[controller dataSource] databaseChannel]; ! 9: [channel setDelegate:self]; ! 10: ! 11: // Set a controller in memory sort by department and then lastName ! 12: [controller setSortOrdering:[NSArray arrayWithObjects: ! 13: [EOKeySortOrdering keyOrderingWithKey:@"departmentName" ordering:NSOrderedAscending], ! 14: [EOKeySortOrdering keyOrderingWithKey:@"lastName" ordering:NSOrderedAscending], nil]]; ! 15: ! 16: [controller fetch]; ! 17: return self; ! 18: } ! 19: ! 20: - validatesOnChange:sender ! 21: { ! 22: [self setValidatesImmediately:[sender intValue]]; ! 23: return self; ! 24: } ! 25: ! 26: - saveChanges:sender ! 27: { ! 28: // we can't call saveToDataSource directly since it doesn't automatically ! 29: // call saveToObjects first (bummer!) ! 30: if ([controller saveToObjects] && [controller saveToDataSource]) ! 31: return self; ! 32: return nil; ! 33: } ! 34: ! 35: ! 36: - (NSDictionary *)databaseChannel:channel ! 37: willRefetchObject:object ! 38: fromSnapshot:(NSDictionary *)snapshot ! 39: { ! 40: // Our object is being refetched, and will be refreshed with the given ! 41: // snapshot. Snapshot is really the set of class properties that would be ! 42: // passed to us in takeValuesFromDictionary (not the one we'd get from ! 43: // snapshotForObject). ! 44: // PROBLEM: if we have uncommitted edits to this object, they could get ! 45: // reset by refetching. ! 46: // OPTIONS: ! 47: // 1) Diff our object against it current (old) snapshot and see if we've ! 48: // made any changes. Only allow the update it we have. Might be slow. ! 49: // 2) If our EO keeps an explicit lock flag, we could check if it's locked ! 50: // for update. Sadly, we have no such lock. ! 51: // 3) Always ignore the refetch. Disadvantage: we'll never be able to ! 52: // refresh to see new changes made by others in the server. ! 53: // Since efficiency is not a major issue in this example, we'll choose #1. ! 54: NSDictionary *originalSnapshot = [[channel databaseContext] snapshotForObject:object]; ! 55: NSDictionary *currentSnapshot = [object valuesForKeys:[originalSnapshot allKeys]]; ! 56: if (![originalSnapshot isEqual:currentSnapshot]) { ! 57: // Conflicting update ! 58: // NSLog(@"Attempt to refetch a modified object with current snapshot: %@", currentSnapshot); ! 59: return nil; ! 60: } ! 61: // Okay, no conflict, so allow the update ! 62: return snapshot; ! 63: } ! 64: ! 65: @end
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.