Jeff,

we have the same problem with Enum classes. In the database we are storing a single selection of an enumeration as a string but in Java we want the String to be retrieved from the database as an instance of our Enum class. e.g.

In database we store the string "RED", but we want to map that to the "RED" instance of the following enum class (i.e. map to ColoursEnum.RED):

public class ColoursEnum
{
    private String name;
    private Colours(String name) { this.name = name; }
    public String toString() { return name; }
    public static final ColoursEnum RED = new ColoursEnum("RED");
    public static final ColoursEnum GREEN = new ColoursEnum("GREEN");
    public static final ColoursEnum BLUE = new ColoursEnum("BLUE");
}

Castor can already perform mappings between simple database types to classes (where the database types indicate the identity of an object). It would be great to hook into this mechanism using the mapping file (e.g. identify a "converter" class that implements a particular interface to perform the conversion from/to database type to/from Java class). A mechanism like this could significantly improve Castor's mapping strengths (and reduce the impedance mismatch further). I'm sure converters of this sort could be put to all sorts of good uses. Maybe one of the Castor developers (Thomas?) could indicate whether this functionality is on their "to do" list or even in the next release ;-)?

Thanks,
    Max
 

Jeff Hoare wrote:

Hi,
Is there anyway to map user defined data types in Castor. We are using a guio
framwork that defines its own set of java types. In may cases these are just
wrappers for some base Java Class, for example TextString is a wrapper for a
String, and the "name" property returns one of these classes.
We don't want to have to store these seperatly in tables, but as column
attributes of the class itself.
I can add specific getters/setters on the actual classes that return standard
java representations, but it would be good not to have to have these xtra's.
So :-)
Is it possible to map such classes to standard castor representations
or
Does this require an extension of the castor framework?

Jeff

-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
        unsubscribe castor-dev

Reply via email to