From fa3e5de72829b2458c6966b1cad3c99d62401a49 Mon Sep 17 00:00:00 2001 From: mltownsend Date: Fri, 28 May 2010 21:18:13 +0000 Subject: Changed the refresh method so that it creates a new persistentstore as well and clearing out the outlineview. --- Source/SPUserManager.h | 4 ++-- Source/SPUserManager.m | 29 +++++++++++++++++------------ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Source/SPUserManager.h b/Source/SPUserManager.h index aa6cce76..97ed03a4 100644 --- a/Source/SPUserManager.h +++ b/Source/SPUserManager.h @@ -66,9 +66,9 @@ } @property (nonatomic, retain) MCPConnection *mySqlConnection; -@property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator; +@property (nonatomic, retain) NSPersistentStoreCoordinator *persistentStoreCoordinator; @property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel; -@property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext; +@property (nonatomic, retain) NSManagedObjectContext *managedObjectContext; @property (nonatomic, retain) NSMutableDictionary *privsSupportedByServer; @property (nonatomic, retain) NSArray *treeSortDescriptors; diff --git a/Source/SPUserManager.m b/Source/SPUserManager.m index 48446d22..e6809921 100644 --- a/Source/SPUserManager.m +++ b/Source/SPUserManager.m @@ -756,18 +756,28 @@ return; } } - NSSet *registeredObjects = [managedObjectContext registeredObjects]; - for (NSManagedObject *registeredObject in registeredObjects) - { - [self.managedObjectContext refreshObject:registeredObject mergeChanges:NO]; - } [self.managedObjectContext reset]; [grantedSchemaPrivs removeAllObjects]; - //[grantedController fetch:nil]; [grantedTableView reloadData]; [self _initializeAvailablePrivs]; - [treeController fetch:nil]; + [outlineView reloadData]; + [treeController rearrangeObjects]; + + // Get all the stores on the current MOC and remove them. + NSArray *stores = [[self.managedObjectContext persistentStoreCoordinator] persistentStores]; + for(NSPersistentStore* store in stores) + { + NSError *error = nil; + [[self.managedObjectContext persistentStoreCoordinator] removePersistentStore:store error:error]; + } + // Add a new store + NSError *error = nil; + [[self.managedObjectContext persistentStoreCoordinator] + addPersistentStoreWithType:NSInMemoryStoreType configuration:nil URL:nil options:nil error:&error]; + + // Reinitialize the tree with values from the database. + [self _initializeUsers]; // After the reset, ensure all original password and user values are up-to-date. NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"SPUser" @@ -928,11 +938,6 @@ if (!isInitializing) [outlineView reloadData]; } -- (void)userManagerSheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void*)context -{ - [self refresh:nil]; -} - - (BOOL)updateUsers:(NSArray *)updatedUsers { for (NSManagedObject *user in updatedUsers) -- cgit v1.2.3