Squeak SmalltalkJoker Squeak Smalltalk : Persistency : prevnext Class Change Image Segment Smart Ref Stream

> While on the subject so to speak - I am currently migrating an app from
> 3.6 to 3.7 that uses ImageSegments for domain model storage. It then
> appeared to me that ImageSegments saved from 3.6 and loaded into 3.7 get
> broken Date instances. This is of course not surprising, given the
> change in representation of Dates.
>
> Now... the questions:
>
> 1. Should we care to make this work? Is it meant to work? I assume
> Squeaklanders might want it to work, though they don't use Dates much
> perhaps in their projects.

Yes, it should work. The conversion code for SmartRefStream is also called for 
objects in ImageSegments, because the outPointers array is serialized.

> 2. How can I fix it? Is there some place to hook in conversion code? I
> can of course sniff around but perhaps someone can give me a quick hint.

It is (or should be, anyway) the responsibility of people making changes to 
classes in the base image which might be in an ImageSegment (which would 
certainly include Dates) to make conversion methods.

You may need to provide one or more methods to fix this:

- convertToCurrentVersion: varDict refStream: smartRefStrm

is passed varDict, which is a Dictionary of the instVars by name. This is the 
probable method that you'll want to provide. This is called if the number of 
instance variables (and/or name? not sure) has changed since the object was 
stored.

- classVersion (a class side method), whose comment says: "Default.  Any class 
  may return a later version to inform readers that use ReferenceStream.  
  8/17/96 tk" "This method allows you to distinguish between class versions 
  when the shape of the class hasn't changed (when there's no change in the 
  instVar names). In the conversion methods you usually can tell by the inst 
  var names what old version you have. In a few cases, though, the same inst 
  var names were kept but their interpretation changed (like in the 
  layoutFrame). By changing the class version when you keep the same instVars 
  you can warn older and newer images that they have to convert." ^ 0

- comeFullyUpOnReload: smartRefStream

called after loading an object from a DataStream. Can return a different object 
(this is used, for instance, by DiskProxy instances). Can also do special 
things like hooking up the loaded object to other things that may not have been 
serialized.

And, for the other direction (for providing backwards compatibility, if that's 
important), there's

- objectForDataStream: aStream

but don't try returning anything but self or a DiskProxy, because I don't think 
that works. Still, if you'd like to (for instance) nil out caches, or store 
some instVars differently this can be a place to do it.

and also:

- prepareToBeSaved (Morph only)

which is called on Morphs being saved, and is a handy place to clean stuff up.

-- Ned Konz