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 'typeNumber' 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 and a 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 enum RecordType implements DBEnumValue<Integer> {
        YOUR_FIRST_ENUM_RECORD(1),
        YOUR_SECOND_ENUM_RECORD(2)...
        ;

        private int code;

        private RecordType(int code) {
           this.code = code;
        }

        /** Gets the integer value stored in the database */
        @Override
        public Integer getCode(){
            return code;
        }
        // Other methods as required
    }

After that DBV will automatically turn the literal database value into an 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-09

Anonymous
Anonymous

Add attachments
Cancel





Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.