From: Q <qd...@gm...> - 2009-04-18 23:23:40
|
On 19/04/2009, at 4:59 AM, Jon Nolan wrote: > I'm trying to use javaEnum with INTEGER columns. The table is already > full of values which correspond to the ordinal of the Enum > subclass. I > know there are arguments against persisting the ordinal but in this > case > it is very useful and very safe. > > I'm struggling to get it working with anything other than VARCHAR > columns. I've set the external type to INTEGER, the class to my Enum, > the value type to both "i" and blank, the factory method to a status > method on my class called valueFromInteger() and the conversion method > to ordinal(). The init argument confuses me. It doesn't provide an > option for Integer. I've tried Bytes and Data with no luck. I'm > really > striking out blindly as I don't get exactly what these settings > should be. > > (a) Is what I'm trying even possible? > > (b) If so, any help would be appreciated. > I am currently doing this using the following enum: public enum InvoiceType { Postal (0, "Postal Invoice"), EMail (1, "E-mail"), DoNotPrint(2, "Don't Print Invoice"); private int code; private String description; private InvoiceType(int c, String d) { code = c; description = d; } public static InvoiceType withCode(String s) { for(InvoiceType t : InvoiceType.values()) { if (t.code == Integer.valueOf(s).intValue()) { return t; } } return null; } public String getCode() { return Integer.valueOf(code).toString(); } @Override public String toString() { return description; } } Note: the withCode() method could do with some improvement. The attribute declaration looks like this: |