WWW.BOOK.DISLIB.INFO
FREE ELECTRONIC LIBRARY - Books, dissertations, abstract
 
<< HOME
CONTACTS



Pages:     | 1 |   ...   | 15 | 16 || 18 | 19 |   ...   | 27 |

«Introduction to Core Data Programming Guide 11 Who Should Read This Document 11 Organization of This Document 11 See Also 13 Technology Overview 14 ...»

-- [ Page 17 ] --

The corollary of this point is that whether an object is a fault is not the same as whether its data has been retrieved from the store. Whether or not an object is a fault simply means whether or not a given managed object has all its attributes populated and is ready to use. If you need to determine whether an object is a fault, you can send it an isFault message without firing the fault. If isFault returns NO, then the data must be in memory. However, if isFault returns YES, it does not imply that the data is not in memory. The data may be in memory, or it may not, depending on many factors influencing caching.

Turning Objects into Faults Turning a realized object into a fault can be useful in pruning the object graph (see “Reducing Memory Overhead” (page 145)), as well as ensuring property values are current (see “Ensuring Data Is Up-to-Date” (page 76)). Turning a managed object into a fault releases unnecessary memory, sets its in-memory property values to nil, and breaks strong references to related objects.

2012-09-19 | Copyright © 2004, 2012 Apple Inc. All Rights Reserved.

Faulting and Uniquing Uniquing Ensures a Single Managed Object per Record per Context You can turn a realized object into a fault with the refreshObject:mergeChanges: method. If you pass NO as the mergeChanges argument, you must be sure that there are no changes to that object’s relationships.

If there are, and you then save the context, you will introduce referential integrity problems to the persistent store.

When an object turns into a fault, it is sent a didTurnIntoFault message. You may implement a custom didTurnIntoFault method to perform various “housekeeping” functions (see, for example, “Ensuring Data Is Up-to-Date” (page 76)).

Note: Core Data avoids the term unfaulting because it is confusing. There’s no “unfaulting” a virtual memory page fault. Page faults are triggered, caused, fired, or encountered. Of course, you can release memory back to the kernel in a variety of ways (using the functions vm_deallocate, munmap, or sbrk). Core Data describes this as “turning an object into a fault”.

Faults and KVO Notifications When Core Data turns an object into a fault, key-value observing (KVO) change notifications (see Key-Value Observing Programming Guide ) are sent for the object’s properties. If you are observing properties of an object that is turned into a fault and the fault is subsequently realized, you receive change notifications for properties whose values have not in fact changed.

Although the values are not changing semantically from your perspective, the literal bytes in memory are changing as the object is materialized. The key-value observing mechanism requires Core Data to issue the notification whenever the values change as considered from the perspective of pointer comparison. KVO needs these notifications to track changes across key paths and dependent objects.

Uniquing Ensures a Single Managed Object per Record per Context Core Data ensures that—in a given managed object context—an entry in a persistent store is associated with only one managed object. The technique is known as uniquing. Without uniquing, you might end up with a context maintaining more than one object to represent a given record.

2012-09-19 | Copyright © 2004, 2012 Apple Inc. All Rights Reserved.

Faulting and Uniquing Uniquing Ensures a Single Managed Object per Record per Context For example, consider the situation illustrated in Figure 2; two employees have been fetched into a single managed object context. Each has a relationship to a department, but the department is currently represented by a fault.

Figure 2 Independent faults for a department object It would appear that each employee has a separate department, and if you asked each employee for their department in turn—turning the faults into regular objects—you would have two separate Department objects in memory. However, if both employees belong to the same department (for example, "Marketing"), then Core Data ensures that (in a given managed object context) only one object representing the Marketing department is ever created. If both employees belong to the same department, their department relationships would both therefore reference the same fault, as illustrated in Figure 3.

Figure 3 Uniqued fault for two employees working in the same department 2012-09-19 | Copyright © 2004, 2012 Apple Inc. All Rights Reserved.

Faulting and Uniquing Uniquing Ensures a Single Managed Object per Record per Context If Core Data did not use uniquing, then if you fetched all the employees and asked each in turn for their department—thereby firing the corresponding faults—a new Department object would be created every time.

This would result in a number of objects, each representing the same department, that could contain different and conflicting data. When the context was saved, it would be impossible to determine which is the correct data to commit to the store.

More generally, all the managed objects in a given context that refer to the Marketing Department object refer to the same instance—they have a single view of Marketing’s data—even if it is a fault.

Note: This discussion has focused on a single managed object context. Each managed object context represents a different view of the data. If the same employees are fetched into a second context, then they—and the corresponding Department object—are all represented by different objects in memory. The objects in different contexts may have different and conflicting data. It is precisely the role of the Core Data architecture to detect and resolve these conflicts at save time.





2012-09-19 | Copyright © 2004, 2012 Apple Inc. All Rights Reserved.

Using Persistent Stores This article describes how you create a persistent store, and how you can migrate a store from one type to another, and manage store metadata. For more about persistent store types, the differences between them, and how you can configure aspects of their behavior, see “Persistent Store Features” (page 130).

Creating and Accessing a Store Access to stores is mediated by an instance of NSPersistentStoreCoordinator. You should not need to directly access a file containing a store. From a persistent store coordinator, you can retrieve an object that represents a particular store on disk. Core Data provides an NSPersistentStore class to represent persistent stores.

To create a store, you use a persistent store coordinator. You must specify the type of the store to be created, optionally a configuration of managed object model associated with the coordinator, and its location if it is

not an in-memory store. The following code fragment illustrates how you can create a read-only XML store:

NSManagedObjectContext *moc = #Get a context#;

NSPersistentStoreCoordinator *psc = [moc persistentStoreCoordinator];

NSError *error = nil;

NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:1]

–  –  –

To retrieve a store object from a coordinator, you use the method persistentStoreForURL:. You can use

a store to restrict a fetch request to a specific store, as shown in the following code fragment:

NSPersistentStoreCoordinator *psc = #Get a coordinator#;

2012-09-19 | Copyright © 2004, 2012 Apple Inc. All Rights Reserved.

Using Persistent Stores Changing a Store’s Type and Location NSURL *myURL = #A URL identifying a store#;

NSPersistentStore *myStore = [psc persistentStoreForURL:myURL];

NSFetchRequest *request = [[NSFetchRequest alloc] init];

[request setAffectedStores:[NSArray arrayWithObject:myStore]];

Changing a Store’s Type and Location You can migrate a store from one type or location to another (for example, for a Save As operation) using the NSPersistentStoreCoordinator method migratePersistentStore:toURL:options:withType:error:. After invocation of this method, the original store is removed from the coordinator, thus store is therefore no longer a useful reference. The method is illustrated in the following code fragment, which shows how you can migrate a store from one location to another. If the old store type is XML, then the example also converts the store to SQLite NSPersistentStoreCoordinator *psc = [aManagedObjectContext persistentStoreCoordinator];

NSURL *oldURL = #URL identifying the location of the current store#;

NSURL *newURL = #URL identifying the location of the new store#;

–  –  –

withType:NSSQLiteStoreType error:&error];

Core Data follows the procedure below to migrate a store:

1. Create a temporary persistence stack

2. Mount the old and new stores

3. Load all objects from the old store

4. Migrate the objects to the new store The objects are given temporary IDs, then assigned to the new store. The new store then saves the newly assigned objects (committing them to the external repository).

2012-09-19 | Copyright © 2004, 2012 Apple Inc. All Rights Reserved.

Using Persistent Stores Associate Metadata With a Store to Provide Additional Information and Support Spotlight Indexing Core Data then informs other stacks that the object IDs have changed (from the old to the new stores), which is how things "keep running" after a migration.

5. Unmount old store

6. Return the new store

An error can occur if:

You provide invalid parameters to the method ● Core Data cannot add the new store ● Core Data cannot remove the old store ● In the latter two cases, you get the same errors you would if you called addPersistentStore: or removePersistentStore: directly. if an error occurs when adding or removing the store, you should treat this as an exception since the persistence stack is likely to be in an inconsistent state.

If something fails during the migration itself, instead of an error you get an exception. In these cases, Core Data unwinds cleanly and there should be no repair work necessary. You can examine the exception description to determine what went wrong—there is a wide variety of possible errors, ranging from "disk is full" and "permissions problems" to "The SQLite store became corrupted" and "Core Data does not support cross store relationships".

Associate Metadata With a Store to Provide Additional Information and Support Spotlight Indexing A store’s metadata provides additional information about the store that is not directly associated with any of the entities in the store.

The metadata is represented by a dictionary. Core Data automatically sets key-value pairs to indicate the store type and its UUID. You can add additional keys that may be either custom for your application, or one of the standard set of keys to support Spotlight indexing (if you also write a suitable importer) such as kMDItemKeywords.

You should be careful about what information you put into metadata. First, Spotlight imposes a limit to the size of metadata. Second, replicating an entire document in metadata is probably not useful. Note, though, that it is possible to create a URL to identify a particular object in a store (using URIRepresentation)—the URL may be useful to include as metadata.

2012-09-19 | Copyright © 2004, 2012 Apple Inc. All Rights Reserved.

Using Persistent Stores Associate Metadata With a Store to Provide Additional Information and Support Spotlight Indexing Getting the Metadata

There are two ways to get the metadata for a store:

1. Given an instance of a persistent store, you can get its metadata using the

NSPersistentStoreCoordinator instance method metadataForPersistentStore:.

2. You can retrieve metadata from a store without the overhead of creating a persistence stack using the NSPersistentStoreCoordinator class method,

metadataForPersistentStoreOfType:URL:error:.

There is an important difference between these approaches. The instance method, metadataForPersistentStore:, returns the metadata as it currently is in your program, including any changes that may have been made since the store was last saved. The class method, metadataForPersistentStoreOfType:URL:error:, returns the metadata as it is currently represented in the store itself. If there are pending changes to the store, the returned value may therefore be out of sync.

Setting the Metadata

There are two ways you can set the metadata for a store:



Pages:     | 1 |   ...   | 15 | 16 || 18 | 19 |   ...   | 27 |


Similar works:

«Discussion Paper Deutsche Bundesbank No 23/2015 Many a little makes a mickle: macro portfolio stress test for small and medium-sized German banks Ramona Busch Philipp Koziol Marc Mitrovic Discussion Papers represent the authors‘ personal opinions and do not necessarily reflect the views of the Deutsche Bundesbank or its staff. Editorial Board: Daniel Foos Thomas Kick Jochen Mankart Christoph Memmel Panagiota Tzamourani Deutsche Bundesbank, Wilhelm-Epstein-Straße 14, 60431 Frankfurt am Main,...»

«1 Chapter 6: 19th Century Avant-Garde The Avant-Garde in the 19th Century 6.1 Thomas Couture, The Romans of the Decadence, 1847. In 1847, Thomas Couture’s immense painting The Romans of the Decadence became one of the most popular Salon paintings of the entire nineteenth century (6.1). Measuring over 15’ by 25’, the canvas stretches past the viewer’s peripheral vision and achieves an almost widescreen scale. Couture filled its carefully researched Roman architectural setting with...»

«ISSN 1814-2206 International Hop Growers` Convention I.H.G.C. Proceedings of the Scientific Commission INTERNATIONAL HOP GROWERS`CONVENTION Tettnang, Germany 24 28 June 2007 Impressum: Scientific Commission International Hop Growers` Convention (I.H.G.C.) Hop Research Center Hüll, Hüll 5 1/3, 85283 Wolnzach, Germany Internet:: http://www.lfl.bayern.de/ipz/hopfen/10585/index.php Dr. Elisabeth Seigner June 2007 © Scientific Commission, I.H.G.C. With Special Thanks to our Sponsors (logos...»

«1. Modellierung von UML State Machines für GeneSEZ Diese Anleitung konzentriert sich auf Unterschiede zwischen dem UMLund dem GeneSEZ-Metamodell sowie für die Modellierung mit der GeneSEZ Generator Framework wichtige Punkte und versteht sich nicht als allgemeines Tutorial zum Thema GeneSEZ oder State Machines. Alle Angaben beziehen sich auf Behavioral State Machines, da Protocol State Machines aktuell nicht unterstützt werden. Da für viele Notationselemente der UML State Machines entweder...»

«MAX-PL ANCK-INSTITUT F Ü R E U RO PÄ I S C H E R E C H T S G E S C H I C H T E TÄ T I G K E I T S B E R I C H T www.rg.mpg.de MAX-PL ANCK-INSTITUT F Ü R E U R O PÄ I S C H E R E C H T S G E S C H I C H T E Max-Planck-Institut Postanschrift für europäische Rechtsgeschichte Max-Planck-Institut für europäische Hausener Weg 120 Rechtsgeschichte 60489 Frankfurt am Main Postfach 930227 T +49 (69) 78978-0 60457 Frankfurt am Main F +49 (69) 78978-169 info@rg.mpg.de VORWORT  Der Neubau des...»

«Composition as Explanation Gertrude Stein First delivered by the author as a lecture at Cambridge and Oxford, this essay was first published by the Hogarth Press in London in 1926 and revived in the volume called What Are Masterpieces. There is singularly nothing that makes a difference a difference in beginning and in the middle and in ending except that each generation has something different at which they are all looking. By this I mean so simply that anybody knows it that composition is...»

«DISPOSITIF MAINS-LIBRES BLUETOOTH® SBTF 10 C2 BLUETOOTH®DISPOSITIF MAINSLIBRES BLUETOOTH® FREISPRECHMode d’emploi EINRICHTUNG Bedienungsanleitung BLUETOOTH® HANDS-FREE KIT Operating instructions IAN 91621 2 Avant de lire le mode d‘emploi, ouvrez la page contenant les illustrations et familiarisez-vous ensuite avec toutes les fonctions de l‘appareil. Klappen Sie vor dem Lesen die Seite mit den Abbildungen aus und machen Sie sich anschließend mit allen Funktionen des Gerätes vertraut....»

«THE POWER OF PRAISE – PART 2. JOSHUA 6:1-20. “Now Jericho was straitly shut up because of the children of Israel: none went out, and none came in. And the LORD said unto Joshua, See, I have given into thine hand Jericho, and the king thereof, and the mighty men of valour. And ye shall compass the city, all ye men of war, and go round about the city once. Thus shalt thou do six days. And seven priests shall bear before the ark seven trumpets of rams' horns: and the seventh day ye shall...»

«USING FEDERAL DATA TO MEASURE AND IMPROVE THE PERFORMANCE OF U.S. INSTITUTIONS OF HIGHER EDUCATION September 2015 Contents Introduction I. Defining and Measuring Quality in Higher Education Defining Quality II. Information and Decision Making in Postsecondary Education Information to Guide Student and Family Choices Potential Students Have Varied Goals and Information Needs How Might More and Better Information Help? Information about Affordability Information about Earnings, and Other Student...»

«Research Publication Date: 12 July 2011 ID Number: G00213333 Magic Quadrant for Data Center Outsourcing and Infrastructure Utility Services, Europe Claudio Da Rold, Gianluca Tramacere, Frank Ridder This Magic Quadrant examines 13 providers' abilities to deliver DCO and infrastructure utility services, as well as their vision for these services, in Europe. It will help you choose a data center service provider. © 2011 Gartner, Inc. and/or its affiliates. All rights reserved. Gartner is a...»





 
<<  HOME   |    CONTACTS
2016 www.book.dislib.info - Free e-library - Books, dissertations, abstract

Materials of this site are available for review, all rights belong to their respective owners.
If you do not agree with the fact that your material is placed on this site, please, email us, we will within 1-2 business days delete him.