TweetFollow Us on Twitter

Changing Frameworks

Volume Number: 14 (1998)
Issue Number: 3
Column Tag: Rhapsody

Handling a Changing Framework

by Kris Jensen

What to do when the latest update to your framework no longer provides an object essential to your project

Data storage and retrieval is an important part of most computer applications. In some cases, writing a document to a file is sufficient; in others, the information to be stored and retrieved is more complex, and your program may rely on a package of objects that implement data storage and retrieval for you. What do you do if that set of objects is no longer available?

This article shows how the modularity of object-oriented programming allows one to quickly modify programs without modifying code by plugging in a different set of objects and how the high-level Foundation Kit objects can be used to quickly code interim solutions.

An OS update broke our application

Stone Design's database management application, DataPhile, suffered from an updated OS removing objects essential to the application. DataPhile was originally built using the Indexing Kit package of data storage and indexing objects, a package that was included with the original NeXTSTEP programming tools. The Indexing Kit was never problem-free at its higher levels, and, at its lower levels, was difficult to port to other platforms. As NeXTSTEP became OPENSTEP and migrated to other hardware, the Indexing Kit disappeared.

DataPhile needed a new back-end. While we were researching the possibilities for replacing or porting the Indexing Kit, we also wanted to show that we could get the front-end up and running under OpenStep and Rhapsody. The solution was a quick and dirty back-end built using OpenStep Foundation Kit objects. We did not, at this point, want to change DataPhile's data storage paradigm, nor did we want to build a functional and efficient b-tree package; we just wanted to "plug in" some quickly built objects that would provide the surface functionality that we had been using in the Indexing Kit. Efficiency, either in space or time, was not an issue; speed in implementing something that would allow us to demo our front-end under Rhapsody was our goal.

An advantage of working in an object-oriented environment is that you can use a speedily-written, temporary set of objects that provides the functionality of the objects that are no longer available or provides a general storage model that works for your application. Later, you can re-implement the objects more efficiently. Or you can use your objects as glue to implement your storage model using another set of objects. As long as you don't change your objects' interface, you don't need to touch the rest of your code.

Our solution may interest you if:

  • You're porting an application and your data storage package is not available for your new platform.
  • You're developing an application and you haven't yet decided on what you're going to use for your data storage needs.
  • You're developing a small-scale project and you need a simple, free persistent data store.

Implementing a fix with Foundation Kit

Our solution followed these steps:

  1. Identify which classes and methods in the obsolete package are being used. We used five classes: IXStore, IXStoreFile, IXStoreDirectory, IXBTree and IXBTreeCursor and we used most of the public API of those classes. Our data storage model was based on being able to store key-value pairs (with the keys and values being of any size) and to retrieve the values either directly (via the key) or sequentially.
  2. Implement those classes and methods. Don't worry about how they "really" work; our goal is to provide functionality without modifying our client code. For example, IXStore was based on the idea of "blocks" of storage; I kept the idea of blocks, but they just became id's used for access into a dictionary.
  3. To do the implementation, figure out what you need to do and look for Foundation Kit classes that will provide that functionality. We needed three things: to store key-value pairs to disk and to access those pairs directly (by key value) and sequentially. The Foundation Kit includes NSPPLs (persistent property lists). The NSPPL class description in the Rhapsody Foundation Kit documentation, states:

"Like serialization, a persistent property list stores data in a binary format, provides fast access, and is lazy. It also allows you to make incremental changes to an NSPPL (even one that contains tens of megabytes of data), while still ensuring that your data is never corrupted. In this sense, an NSPPL is analogous to a database. Because of their ability to incrementally store and retrieve data, NSPPLs are particularly well-suited for working with large amounts of data (that is, data that has several elements, that occupies a large number of bytes, or both)."

NSPPLs can store NSDictionaries and NSArrays. NSDictionaries provide fast key-value lookup, but don't allow sequential access in any kind of sorted order. NSArrays can provide sequential access. I decided to use an NSPPL to implement an IXStoreFile, an NSDictionary to implement an IXStoreDirectory, and both an NSDictionary and an NSArray to implement an IXBTree.

IXStore is "a transaction based, compacting storage allocator designed for data-intensive applications." and IXStoreFile puts the storage on disk. For a temporary back-end, I decided to forego transactions and compacting and concurrency control and just implement the calls my client code used: the transaction calls from IXStore and the initialization methods from IXStoreFile. Even though I didn't plan to implement transactions, I didn't want to remove the transaction-oriented code from DataPhile, so the methods had to be there.

IXStoreDirectory and IXBTree conform to the IXBlockAndStore protocols, which use the notion of a handle to a block of storage. Because of this, I kept the idea of block numbers allocated by IXStore, but eliminated the idea of blocks as constant-sized storage units (meaning that something stored in an IXStore might extend over multiple blocks). Instead, each IXStore client would be assigned a block number which would provide access to that client's storage. So in IXStore and IXStoreFile, I needed to map block numbers to data. Since an NSPPL incorporates an NSDictionary to provide access to its storage, I decided to use that dictionary to store block number / data pairs.

I initially planned for the stored data to be the actual structures needed by the store clients: for example, to store the IXBTree's structure (an NSDictionary of key/data pairs) directly in the root dictionary. However, all NSDictionaries stored directly in an NSPPL must use NSStrings as keys: this didn't match the IXBTree's paradigm of arbitrary data for both keys and data. So I used the rootDictionary of the NSPPL to map block numbers to NSData objects; the NSData contained an archived version of the object to be stored.

IXStoreDirectory "provides access to store clients by name instead of by block handle." This obviously called for an NSDictionary mapping names to a structure that would keep track of an object, its class, and its block number.

An IXBTree "provides ordered associative storage and retrieval of untyped data. It identifies and orders data items, called values, by key using a comparator function". The information in an IXBTree can be accessed directly by key or sequentially, by using an IXBTreeCursor to traverse the b-tree. It's a fairly standard undergraduate computer science project to write a b-tree program, but this is for a quick back-end, so I decided to use prefab parts. Direct access could be provided by an NSDictionary mapping NSData keys to NSData values. Sequential access could be provided by a sorted NSArray of keys. The sorted array could be built easily by using the sortedArrayUsingFunction NSArray method. A cursor can be represented as an integer index into the sorted key array. It can be positioned (for a key that's in the b-tree) using the method indexOfObject. If the key is not already present, positioning becomes a little more complicated; I implemented a quick and dirty binary search on the array contents. If contents are added to or deleted from the key array, any cursors pointing into the array become invalid; I use an NSNotification to notify the IXBTreeCursors that are accessing the b-tree.

Conclusions

Putting all this together, I have a cover for the parts of the Indexing Kit that we needed (b-trees, cursors, and storage) that will allow us to continue to develop the DataPhile front end while we look for a replacement back end. It's not particularly robust or efficient, but it was built very quickly using Foundation objects. When we decide on another storage package, we can rewrite the guts of the cover objects without rewriting the code that uses the cover objects. You can take a look at my b-tree solution in the example code provided at the MacTech ftp site ftp://ftp.mactech.com/.

I also found that a simple way to store and index record objects of some type is to create a b-tree that maps an id number to an NSData that holds the record (serialized in whatever way you wish). Then create index b-trees that map keys (have your records create their own keys) to the record id number. This is demonstrated in the sample code that uses the b-tree code.


Kris Jensen, at the time an attorney for the State of California, bought an Apple II in 1980. It changed her life. She taught herself BASIC, started taking computer science courses, moved to New Mexico, entered the Ph.D. program in Computer Science at the University of New Mexico, bought a Macintosh, passed her comprehensive exams, became president of the local Apple Users Group in Albuquerque, met Andrew Stone, got NeXT representatives to demonstrate the NeXT cube at a users group meeting, joined Andrew in becoming NeXT developers, and didn't finish her Ph.D. because she was designing and writing NeXTSTEP software. Kris is happy to be back in the Macintosh world with Rhapsody. In her spare time, Kris calls square dances around the country.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »

Price Scanner via MacPrices.net

New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more
The latest Apple iPhone deals from wireless c...
We’ve updated our iPhone Price Tracker with the latest carrier deals on Apple’s iPhone 15 family of smartphones as well as previous models including the iPhone 14, 13, 12, 11, and SE. Use our price... Read more
Boost Mobile will sell you an iPhone 11 for $...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering an iPhone 11 for $149.99 when purchased with their $40 Unlimited service plan (12GB of premium data). No trade-in is required... Read more
Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobile’s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, available for $759 for 8-Core CPU/7-Core GPU/256GB models and $929 for 8-Core CPU/8-Core GPU/512GB models. Apple’s one-year warranty is... Read more
Updated Apple MacBook Price Trackers
Our Apple award-winning MacBook Price Trackers are continually updated with the latest information on prices, bundles, and availability for 16″ and 14″ MacBook Pros along with 13″ and 15″ MacBook... Read more
Every model of Apple’s 13-inch M3 MacBook Air...
Best Buy has Apple 13″ MacBook Airs with M3 CPUs in stock and on sale today for $100 off MSRP. Prices start at $999. Their prices are the lowest currently available for new 13″ M3 MacBook Airs among... Read more
Sunday Sale: Apple iPad Magic Keyboards for 1...
Walmart has Apple Magic Keyboards for 12.9″ iPad Pros, in Black, on sale for $150 off MSRP on their online store. Sale price for online orders only, in-store price may vary. Order online and choose... Read more
Apple Watch Ultra 2 now available at Apple fo...
Apple has, for the first time, begun offering Certified Refurbished Apple Watch Ultra 2 models in their online store for $679, or $120 off MSRP. Each Watch includes Apple’s standard one-year warranty... Read more

Jobs Board

DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
IT Systems Engineer ( *Apple* Platforms) - S...
IT Systems Engineer ( Apple Platforms) at SpaceX Hawthorne, CA SpaceX was founded under the belief that a future where humanity is out exploring the stars is Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.