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

Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links... | Read more »
Price of Glory unleashes its 1.4 Alpha u...
As much as we all probably dislike Maths as a subject, we do have to hand it to geometry for giving us the good old Hexgrid, home of some of the best strategy games. One such example, Price of Glory, has dropped its 1.4 Alpha update, stocked full... | Read more »
The SLC 2025 kicks off this month to cro...
Ever since the Solo Leveling: Arise Championship 2025 was announced, I have been looking forward to it. The promotional clip they released a month or two back showed crowds going absolutely nuts for the previous competitions, so imagine the... | Read more »
Dive into some early Magicpunk fun as Cr...
Excellent news for fans of steampunk and magic; the Precursor Test for Magicpunk MMORPG Crystal of Atlan opens today. This rather fancy way of saying beta test will remain open until March 5th and is available for PC - boo - and Android devices -... | Read more »
Prepare to get your mind melted as Evang...
If you are a fan of sci-fi shooters and incredibly weird, mind-bending anime series, then you are in for a treat, as Goddess of Victory: Nikke is gearing up for its second collaboration with Evangelion. We were also treated to an upcoming... | Read more »
Square Enix gives with one hand and slap...
We have something of a mixed bag coming over from Square Enix HQ today. Two of their mobile games are revelling in life with new events keeping them alive, whilst another has been thrown onto the ever-growing discard pile Square is building. I... | Read more »
Let the world burn as you have some fest...
It is time to leave the world burning once again as you take a much-needed break from that whole “hero” lark and enjoy some celebrations in Genshin Impact. Version 5.4, Moonlight Amidst Dreams, will see you in Inazuma to attend the Mikawa Flower... | Read more »
Full Moon Over the Abyssal Sea lands on...
Aether Gazer has announced its latest major update, and it is one of the loveliest event names I have ever heard. Full Moon Over the Abyssal Sea is an amazing name, and it comes loaded with two side stories, a new S-grade Modifier, and some fancy... | Read more »
Open your own eatery for all the forest...
Very important question; when you read the title Zoo Restaurant, do you also immediately think of running a restaurant in which you cook Zoo animals as the course? I will just assume yes. Anyway, come June 23rd we will all be able to start up our... | Read more »
Crystal of Atlan opens registration for...
Nuverse was prominently featured in the last month for all the wrong reasons with the USA TikTok debacle, but now it is putting all that behind it and preparing for the Crystal of Atlan beta test. Taking place between February 18th and March 5th,... | Read more »

Price Scanner via MacPrices.net

AT&T is offering a 65% discount on the ne...
AT&T is offering the new iPhone 16e for up to 65% off their monthly finance fee with 36-months of service. No trade-in is required. Discount is applied via monthly bill credits over the 36 month... Read more
Use this code to get a free iPhone 13 at Visi...
For a limited time, use code SWEETDEAL to get a free 128GB iPhone 13 Visible, Verizon’s low-cost wireless cell service, Visible. Deal is valid when you purchase the Visible+ annual plan. Free... Read more
M4 Mac minis on sale for $50-$80 off MSRP at...
B&H Photo has M4 Mac minis in stock and on sale right now for $50 to $80 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses: – M4 Mac mini (16GB/256GB): $549, $50 off... Read more
Buy an iPhone 16 at Boost Mobile and get one...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering one year of free Unlimited service with the purchase of any iPhone 16. Purchase the iPhone at standard MSRP, and then choose... Read more
Get an iPhone 15 for only $299 at Boost Mobil...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering the 128GB iPhone 15 for $299.99 including service with their Unlimited Premium plan (50GB of premium data, $60/month), or $20... Read more
Unreal Mobile is offering $100 off any new iP...
Unreal Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering a $100 discount on any new iPhone with service. This includes new iPhone 16 models as well as iPhone 15, 14, 13, and SE... Read more
Apple drops prices on clearance iPhone 14 mod...
With today’s introduction of the new iPhone 16e, Apple has discontinued the iPhone 14, 14 Pro, and SE. In response, Apple has dropped prices on unlocked, Certified Refurbished, iPhone 14 models to a... Read more
B&H has 16-inch M4 Max MacBook Pros on sa...
B&H Photo is offering a $360-$410 discount on new 16-inch MacBook Pros with M4 Max CPUs right now. B&H offers free 1-2 day shipping to most US addresses: – 16″ M4 Max MacBook Pro (36GB/1TB/... Read more
Amazon is offering a $100 discount on the M4...
Amazon has the M4 Pro Mac mini discounted $100 off MSRP right now. Shipping is free. Their price is the lowest currently available for this popular mini: – Mac mini M4 Pro (24GB/512GB): $1299, $100... Read more
B&H continues to offer $150-$220 discount...
B&H Photo has 14-inch M4 MacBook Pros on sale for $150-$220 off MSRP. B&H offers free 1-2 day shipping to most US addresses: – 14″ M4 MacBook Pro (16GB/512GB): $1449, $150 off MSRP – 14″ M4... Read more

Jobs Board

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.