Files
RestKit/Code/ObjectMapping/RKMappingOperationQueue.h
Blake Watters 70c73f2981 Fixed issue with order dependence in Core Data connections. fixes #173
Since OM 2.0 connection of relationships happened during the object mapping operation
instead of aggregately at the end of the process. In this commit, we have introduced a lightweight
queue for deferring portions of the mapping operation until a larger aggregate mapping has completed.

The changes are as follows:
* Introduced RKMappingOperationQueue for queueing portions of mapping. This is a synchronous queue modeled off
of NSOperationQueue that does NOT use threading (for Core Data friendliness).
* RKObjectMappingOperation now has a RKMappingOperationQueue queue property that defaults to nil
* RKObjectMappingOperation instances built via RKObjectMapper will has a mapping operation queue
assigned to the property.
* If a queue is present, RKManagedObjectMappingOperation will use it to defer the connection of relationships.
* At the end of an RKObjectMapper process, the mapping operation queue used by all mapping operations created
during the process will be executed. This allows all relationships to be connected after all object creation
has completed.

The queue is general purpose, though currently only used for the connection of relationships.
2011-09-20 12:02:50 -04:00

65 lines
1.9 KiB
Objective-C

//
// RKMappingOperationQueue.h
// RestKit
//
// Created by Blake Watters on 9/20/11.
// Copyright (c) 2011 RestKit. All rights reserved.
//
#import <Foundation/Foundation.h>
/**
Provides a simple interface for deferring portion of an larger object mapping
operation until the entire aggregate operation has completed. This is used by Core
Data to connect all object relationships once the entire object graph has been mapped,
rather than as each object is encountered.
Designed as a lightweight workalike for NSOperationQueue, which was not usable do to
its reliance on threading for concurrent operations. The threading was causing problems
with managed objects due to MOC being thread specific.
This class is not intended to be thread-safe and is used for queueing non-concurrent
operations that will be executed within the object mapper only. It is not a general purpose
work queue.
*/
@interface RKMappingOperationQueue : NSObject {
@protected
NSMutableArray *_operations;
}
/**
Adds an NSOperation to the queue for later execution
@param op The operation to enqueue
*/
- (void)addOperation:(NSOperation *)op;
/**
Adds an NSBlockOperation to the queue configured to executed the block passed
@param block A block to wrap into an operation for later execution
*/
- (void)addOperationWithBlock:(void (^)(void))block;
/**
Returns the collection of operations in the queue
@return A new aray containing the NSOperation objects in the order in which they were added to the queue
*/
- (NSArray *)operations;
/**
Returns the number of operations in the queue
@return The number of operations in the queue.
*/
- (NSUInteger)operationCount;
/**
Starts the execution of all operations in the queue in the order in which they were added to the queue. The
current threads execution will be blocked until all enqueued operations have returned.
*/
- (void)waitUntilAllOperationsAreFinished;
@end