GNUstep Core Data  0.1
Instance Methods | List of all members
GSPersistentStore Class Reference

Nn abstract superclass from which concrete implementations of various persistent store types are subclassed. More...

Inherits NSObject.

Inherited by GSSQLitePersistentStore.

Instance Methods

(id) - initWithURL:managedObjectModel:configuration:options:
 The designated initializer. More...
 
(NSURL *) - URL
 Getting the store's URL. More...
 
(NSString *) - configuration
 Getting the store's configuration. More...
 
(void) - setUUID:
 Sets the UUID of the receiver. More...
 
(void) - setMetadata:
 Sets the store's metadata dictionary. More...
 
(NSDictionary *) - metadata
 Returns the store's metadata. More...
 
(NSString *) - storeType
 Subclasses must override this to return the store's type as a string. More...
 
(NSDictionary *) - fetchObjectsWithEntity:predicate:error:
 Does a lookup in the store for an object that has ‘entity’ set and matches the provided predicate. More...
 
(BOOL) - writeSavingObjects:deletingObjects:error:
 Subclass must override this method. More...
 

Detailed Description

Nn abstract superclass from which concrete implementations of various persistent store types are subclassed.

Implementation Notes On Merging

Efficient merging works with the help of so-called object version numbers. A version number is an abstract sequential number kept separately for every object in it's managed object context and in the persistent store. Every time an object is saved, it's storage number is incremented in both the managed object context and then in the persistent store.

The trick is that the managed object context first checks that it's storage numbers are equal to those of the persistent store - that meaning that no other change to the objects has happened in the mean time. If, however, they are lower, there have been changes to objects by some other context working with the same persistent store. In that case the context's merge policy is consulted on how to deal with the conflicting objects:

(NB. There is no difference between a rollback and merge-by-property-store-trump (and overwrite and merge-by-property-object-trump) policy, or at least none that I have been able to make out: both policies cause the in-memory object to adjust to the state in the store (or vice versa), and no perfomance difference occurs, since their evaluation is based on a property-by-property basis. Could somebody please clarify this issue?)

Definition at line 43 of file GSPersistentStore.h.

Method Documentation

◆ configuration

- (NSString *) configuration

Getting the store's configuration.

Returns
The receiver's configuration.

Definition at line 60 of file GSPersistentStore.m.

◆ fetchObjectsWithEntity:predicate:error:

- (NSDictionary *) fetchObjectsWithEntity: (NSEntityDescription *)  entity
predicate: (NSPredicate *)  predicate
error: (NSError **)  error 

Does a lookup in the store for an object that has ‘entity’ set and matches the provided predicate.

Subclasses must override this method in order to implement their type-specific store interaction.

Returns
A dictionary where keys are managed object IDs and values are dictionaries containing key-value pairs for the corresponding properties of the managed object (the key being the key of the corresponding managed object's persistent property name and the value being the property's value). Relationships store the target object's managedObjectID - this is to allow serialization of object graphs. The context then uses this information and reconstructs the object graph to represent the data in the store (and handles faulting as adequate).

The following example demonstrates the format:

{ <ManagedObjectID-1> = { "AttributeName" = <attribute-value>; "ToOneRelationshipName" = <ManagedObjectID-2>; }; <ManagedObjectID-2> = { "ToManyRelationshipName" = ({ <ManagedObjectID-1>, <ManagedObjectID-2>, ... <ManagedObjectID-n> }); }; ... <ManagedObjectID-n> = { ... }; }

Here "{}" delimit an NSDictionary and "({})" delimit an NSSet, as in the usual property-list syntax.

If no object matches the provided search criteria, an empty array should be returned. Passing entity=nil and predicate=nil should return all the objects in the store. On error, this method should return ‘nil’ and set ‘error’ accordingly.

Definition at line 60 of file GSPersistentStore.m.

◆ initWithURL:managedObjectModel:configuration:options:

- (id) initWithURL: (NSURL *)  URL
managedObjectModel: (NSManagedObjectModel *)  model
configuration: (NSString *)  configuration
options: (NSDictionary *)  options 

The designated initializer.

Subclasses should override this method to implement their own necessary initialization (such as open a connection to the provided URL), but only after having invoked the superclass' implementation in order to assure that this abstract superclass is properly initialized.

Definition at line 60 of file GSPersistentStore.m.

◆ metadata

- (NSDictionary *) metadata

Returns the store's metadata.

For further information please see -[GSPersistentStore setMetadata:].

Returns
The receiver's metadata.

Definition at line 60 of file GSPersistentStore.m.

◆ setMetadata:

- (void) setMetadata: (NSDictionary *)  metadata

Sets the store's metadata dictionary.

The NSStoreUUIDKey and NSStoreTypeKey are automatically added. If they are already defined in the passed argument they will be overwritten in order to avoid interferrence from external code with the type and store UUID machinery, internal to Core Data.

Definition at line 60 of file GSPersistentStore.m.

◆ setUUID:

- (void) setUUID: (NSString *)  UUID

Sets the UUID of the receiver.

Subclasses should invoke this method when the UUID is read from the store. External code should NOT invoke it - this could mess up the store UUID machinery.

Definition at line 60 of file GSPersistentStore.m.

◆ storeType

- (NSString *) storeType

Subclasses must override this to return the store's type as a string.

This information is automatically added by GSPersistentStore to the store's meta-data dictionary as necessary.

Returns
The store type as a string.

Definition at line 60 of file GSPersistentStore.m.

◆ URL

- (NSURL *) URL

Getting the store's URL.

Returns
The receiver's URL.

Definition at line 60 of file GSPersistentStore.m.

◆ writeSavingObjects:deletingObjects:error:

- (BOOL) writeSavingObjects: (NSSet *)  objectsToWrite
deletingObjects: (NSSet *)  objectIDsToDelete
error: (NSError **)  error 

Subclass must override this method.

It should write the persistent store to it's URL location. In detail, this method must perform this:

  • Write it's metadata dictionary contents (the UUID is the only mandatory field). The UUID may need to be written only when the store is created - it is left to the store implementation whether it wants to overwrite it every time it is saved. The fate of the rest of the metadata is left entirely up to the store's decision.
  • Write the highest ID value.
  • Write the objects in ‘objectsToWrite’, adding them to the store, or overwriting the versions already in the store. Only persistent properties of the objects should be stored. Attributes should store the direct value of the attribute, whereas relationships should store the object ID of the target object(s).

    It is good practice to somehow 'key' the stored objects in the store against their object IDs (‘object’ here refers not to an instance of NSManagedObject, but instead to the stored aggregation of persistent properties) - this makes later access to objects easier.

  • Remove from the persistent store objects who's object IDs are in objectIDsToDelete.

If the write is successful this method should return YES, or, in case an error occured, return NO and indicate the reason for it in ‘error’.

Definition at line 60 of file GSPersistentStore.m.


The documentation for this class was generated from the following files: