8-16-2001 by Christopher J. Demers

Class Definition Generator Tool for ReStore (DB Package).

This tool is a free add-on for the ReStore Object to RDB tool.  ReStore can be purchased from Solutions Software .

Disclaimer:

This is Alpha code.  I have been using it myself for the past few days, but it is defiantly not well tested. If I waited until I was done to post this code it might never get posted. ;)  Make sure you have working backups and use this code carefully.  Neither I nor any entity with which I may be associated will be responsible for the use or misuse of this code.  I am not affiliated with Solutions Software.  Use it at your own risk.

Background:

I have been using ReStore with Dolphin since it was released.  It is a great tool for persisting objects into relation databases.  It is different from many Object to RDB tools as the object structure defines the database structure.  This means it is best suited for situations were you control the DB structure.  This also saves the programmer from having to design and map a data structure.  However ReStore does require some additional class definition data due to the dynamically typed nature of Smalltalk.  This is accomplished through the use of a class side method, addClassDefinitionTo: .  This method defines the fields that will be saved into a classes table, and the data type of those fields.  The normal approach is to manually code this method based on your understanding of the class.  I like to program more than I like to type, hence this tool was born.

Description:

My tool will try to generate the class definition method based on a prototype instance of the class.  This makes it easy to adapt your existing objects to ReStore by running the generator on existing fully populated instances.  The generator will determine the fields already defined (either in the class or a super class), and will add new undefined fields to the existing method.  This means that you can rerun the generator on a class if you have added more instance variables.  If the method does not exist it will be created.  The generator uses the classes of the instance variables to decide upon the class descriptions.  The more completely populated the instance the better the ReStore definition will be.  I strongly suggest that the resulting method be reviewed.  This tool will save quite bit of typing but it can not read your mind. ;)  

Notes:

Collections will be handled.  If they are empty you will need to specify the class they contain.  If they are not empty they will use the first item to determine the contained class type.

If an instance variable is nil it will be mapped to UndefinedObject, which is not very useful, it it should either be deleted or mapped to a better class. 

There is no attempt to guess a maximum String size.  For efficiency sake this should be manually adjusted.

When there is a reference to an instance of a user defined class that does not inherit directly from Object a ChoicePrompter will be used to choose the class to map to.  This can be cached and reused for all instances of the class, or each field can prompt (the default).

The generator will not walk and process the referenced classes.  It currently works on one class at a time.  It is possible that this could be added in a future version depending upon user feedback, and my own experience with it.

If it is not easy to programmatically create a populated instance one can be retrieved from a UI by sending allInstances to the class. Inspect the results and pick a good instance that is as broadly representative of you class as possible.

Example:

CJDReStoreDefGen generate: myObject. "Class selection prompted for all fields."
CJDReStoreDefGen generateWithMap: myObject. "Class selection prompted only for unique classes."

The Package:

The ReStore Generator can be downloaded from the links bellow.  The package contains two classes.

Please give me feedback ( Christopher J. Demers ) about this code.  If I see that it is useful to people I will try to improve the documentation and add new features.  It is a lot of work to maintain public code, so I don't want to spend the time unless it is of value to others.

License:

This code is freeware, not public domain, I retain the copyright.  The code may be freely used and freely modified, but please don't redistributed modified versions (without asking me).

Download:

By downloading the code bellow you are signifying your acceptance of my license (above) and disclaimer (at top).

CJDReStoreTools.pac