ObjectExtender User's Guide and Reference
A composer is used to map a single class attribute to
multiple database columns. For example, in the Bank sample, the
name for VapCustomer is mapped to three fields in the
CUSTOMER table: FIRSTNAME, MIDINIT, and LASTNAME. If a
composer does not exist that matches your data, you can create one by creating
a new subclass of VapCustomer.
Note that composed attributes used as keys are not supported.
In this example, the VapNameComposer was created.
Do the following:
- Create a new class, VapNameComposer, that is a subclass of
VapComposer VapAttributeComposer. Next, implement
the following methods:
- sourceDatatype
- targetClass
- attributeNames
- objectFrom:
- dataFrom:
- Implement an instance method called targetClass (The target
class in this example will be VapName). This should return
the name of the class for the instance created as a result of the
objectFrom: message sent to the converter. Note that
in some cases it may be desirable to create your own target class such as was
done in this example.
- Implement an instance method called attributeNames . It
should return an array of the attribute name strings from the target
class. For example:
^#('firstName' 'middle' 'lastName')
- Implement an instance method called objectFrom: .
The argument will be an array containing the values for the attribute string
name from the method attributeNames in the same order. This
method will set the target class attributes based on these values and return
an instance of the target class. For example:
^VapName first: (array at: 1) middle: (array at: 2) last: (array at: 3))
- Implement an instance method called sourceDatatype .
This method should return an array of the data elements' class names
passed as a parameter to the objectFrom: message which is
sent to the converter.
For example,
^#(String String String)
- Implement an instance method called dataFrom: .
The argument will be an instance of the target class. This method is
responsible for returning a collection of objects that are to go to data store
fields. For example:
^(Array
with: anObject firstName
with anObject middle
with: anObject last)
The VapName class is used in the Bank sample to map one
attribute to several columns. It was used as follows:
- Launch the Model Browser.
- Select Bank from the Models.
- Select VapCustomer from the Model Classes.
- Select Edit Class from the Classes menu.
This opens the Class Editor.
- Click New to add a new attribute.
This opens the Attribute Editor.

- Type name in the Name field.
- Select VapName from the Type list.
VapName appears in the Type list because the new subclass of
VapComposer, VapNameComposer, was recognized with
VapName as its target type. The target type of any
VapComposer subclasses you create will also appear here.
- Select OK.
This concludes the example.
Changing part of a composed attribute like name does not cause the Customer
object to be marked "dirty" and updated in the database. To make the
Customer object dirty because of a name change, you must alter the name
attribute through the Customer's setName accessor.
Also note that if you have a complex attribute type and you want to change
the composer type, you must delete the complex attribute map from the Map
Browser and recreate it in the Property Map Editor.
[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]