Tuukka Norri avatar Tuukka Norri committed c7f9723

Bug fix, manual tuning
- Changed ObjectIDsByEntity to ObjectsByEntity because it can handle both object ids and objects or anything that responds to -entity and returns an object, for that matter.
- Changed the method added yesterday so that it sends NSNotifications properly.
- Changed an ordered list into an unordered one in the manual.

Comments (0)

Files changed (2)

Sources/BXDatabaseContext.m

 }
 
 static NSMutableDictionary*
-ObjectIDsByEntity (NSArray *ids)
+ObjectsByEntity (NSArray *objects)
 {
     NSMutableDictionary* dict = [NSMutableDictionary dictionary];
-    BXEnumerate (objectID, e, [ids objectEnumerator])
+    BXEnumerate (currentObject, e, [objects objectEnumerator])
     {
-        BXEntityDescription* entity = [(BXDatabaseObjectID *) objectID entity];
+        id entity = [currentObject entity];
         NSMutableArray* array = [dict objectForKey: entity];
         if (nil == array)
         {
             array = [NSMutableArray array];
             [dict setObject: array forKey: entity];
         }
-        [array addObject: objectID];
+        [array addObject: currentObject];
     }
     return dict;
 }
 {
     if (0 < [objectIDs count])
     {
-		NSMutableDictionary* idsByEntity = ObjectIDsByEntity (objectIDs);
+		NSMutableDictionary* idsByEntity = ObjectsByEntity (objectIDs);
 		AddObjectIDsForInheritance (idsByEntity);
 		NSNotificationCenter* nc = [self notificationCenter];
 
 {
     if (0 < [objectIDs count])
     {
-        NSMutableDictionary* idsByEntity = ObjectIDsByEntity (objectIDs);
+        NSMutableDictionary* idsByEntity = ObjectsByEntity (objectIDs);
         AddObjectIDsForInheritance (idsByEntity);
         NSNotificationCenter* nc = [self notificationCenter];
         		
 {
 	if (0 < [objectIDs count])
     {
-        NSMutableDictionary* idsByEntity = ObjectIDsByEntity (objectIDs);
+        NSMutableDictionary* idsByEntity = ObjectsByEntity (objectIDs);
         AddObjectIDsForInheritance (idsByEntity);
         NSNotificationCenter* nc = [self notificationCenter];
 		
 															 entity: anEntity predicate: predicate error: &localError];
 		
 		[self handleDidChangeForUpdate: &updateCtx newValues: aDict 
-					 sendNotifications: !(localError || [mDatabaseInterface autocommits])
+					 sendNotifications: !localError && [mDatabaseInterface autocommits]
 						  targetEntity: anEntity];
 		
 		if (nil == localError)
 	NSMutableDictionary* oldTargetsByObject = [NSMutableDictionary dictionary];
 	NSMutableDictionary* newTargetsByObject = [NSMutableDictionary dictionary];
 	NSArray* objectIDs = (id) [[givenObjects PGTSCollect] objectID];
-	NSMutableDictionary* idsByEntity = ObjectIDsByEntity (objectIDs);
+	NSMutableDictionary* idsByEntity = ObjectsByEntity (objectIDs);
 	AddObjectIDsForInheritance (idsByEntity);
 	
 	BXEnumerate (entity, e, [idsByEntity keyEnumerator])
 	NSDictionary* newTargetsByObject = ctx->ukc_new_targets_by_object;
 	
 	BXEnumerate (currentObject, e, [changedObjects objectEnumerator])
-	[currentObject setCachedValuesForKeysWithDictionary: newValues];
+	{
+		[currentObject setCachedValuesForKeysWithDictionary: newValues];
+	}
 	
-	NSArray* objectIDs = nil;
-	NSDictionary* userInfo = nil;
+	NSDictionary* objectsByEntity = nil;
 	if (shouldSend)
 	{
-		objectIDs = (id) [[changedObjects PGTSCollect] objectID];
-		userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
-					objectIDs, kBXObjectIDsKey,
-					changedObjects, kBXObjectsKey,
-					self, kBXDatabaseContextKey,
-					nil];
+		NSDictionary* objectsByEntity = ObjectsByEntity (changedObjects);
+		BXEnumerate (currentEntity, e, [objectsByEntity keyEnumerator])
+		{
+			NSArray* objects = [objectsByEntity objectForKey: currentEntity];
+			NSArray* objectIDs = (id) [[objects PGTSCollect] objectID];
+			NSDictionary* userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
+									  objectIDs, kBXObjectIDsKey,
+									  objects, kBXObjectsKey,
+									  self, kBXDatabaseContextKey,
+									  nil];
+			[nc postNotificationName: kBXUpdateEarlyNotification object: entity userInfo: userInfo];
+		}
 	}
 	
 	BXEnumerate (currentObject, e, [changedObjects objectEnumerator])
 	}
 	
 	if (shouldSend)
-		[nc postNotificationName: kBXUpdateEarlyNotification object: entity userInfo: userInfo];
+	{
+		ExpectV (objectsByEntity);
+		BXEnumerate (currentEntity, e, [objectsByEntity keyEnumerator])
+		{
+			NSArray* objects = [objectsByEntity objectForKey: currentEntity];
+			NSArray* objectIDs = (id) [[objects PGTSCollect] objectID];
+			NSDictionary* userInfo = [NSDictionary dictionaryWithObjectsAndKeys:
+									  objectIDs, kBXObjectIDsKey,
+									  objects, kBXObjectsKey,
+									  self, kBXDatabaseContextKey,
+									  nil];
+			[nc postNotificationName: kBXUpdateNotification object: entity userInfo: userInfo];
+		}
+	}
 }
 @end
 

Sources/BaseTen.h

  * controller subclasses.
  *
  * Compared to NSArrayController, BXSynchronizedArrayController can do the following things:
- * <ol>
+ * <ul>
  *     <li>It can present errors to the user when creating a new object fails.</li>
  *     <li>It can get a BXEntityDescription from its database context and fetch objects using it. NSEntityDescriptions cannot be used because they are CoreData-specific.</li>
  *     <li>It can lock the edited row in the database when an editing session begins.</li>
  *     <li>It can provide the selected objects' ids.</li>
- * </ol>
+ * </ul>
  *
  *
  * BXSynchronizedArrayController shouldn't be set to entity mode; the user interface for this isn't even available
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.