Menu

0.9.7 introduces DBEnum: for all your enumeration needs.

After much too-ing and fro-ing DBEnums have been finalised and added to the available datatypes.

Previously I talked about using sub-subclasses of DBRow and the example used a field called to automatically limit the results. Enumerations would help turn the database's inscrutable values into nice Java objects.

So toaomalkster, with a little distraction from me, has added DBIntegerEnum and DBStringEnum.

These are intended to be used instead of DBInteger and DBString when the database values have a special meaning. For instance in my earlier blog entry a 1 meant manager ad 2 meant Team Leader. For obvious reasons DBV can't generate DBEnums automatically so you'll have to add them yourselves.

Fortunately this is easy: change DBInteger to DBIntegerEnum<YourEnumClass> then define YourEnumClass as

    public static enum RecordType implements DBEnumValue<Integer> {
        YOUR_FIRST_ENUM_RECORD(1, "First Record"),
        YOUR_SECOND_ENUM_RECORD(2, "Second Record")...
        ;

        public Integer getCode(){
            // return the integer value stored in the database here
        }
        // Other methods as required
    }

After that DBV will automatically turn the literal value into a enumeration value for you to use. The enumeration can be used to set the field, limit the permitted and excluded values, and do everything else a String, Number, or Date can do.

I'm looking forward to adding enumerations to the 400+ tables at work, sort of ...

Posted by Gregory Graham 2014-02-06

Anonymous
Anonymous

Add attachments
Cancel