Enums and Blackboard's ORM Framework

A while back I wrote about using Blackboard's ORM framework with your own beans. This is going to be a really quick post about how you can map database values to Java Enums.

This is done using the @EnumValueMapping annotation, which is only mentioned breifly in Blackboard's documention but is pretty simple to use. Let's start with an example:

@EnumValueMapping(values={"TOP", "BOTTOM", "LEFT", "RIGHT"})
enum Position {
    TOP, BOTTOM, LEFT, RIGHT
}

By annotating your enum with the @EnumValueMapping annotation, you can give each of the values a string representation or an integer representation like this:

@EnumValueMapping(values={"1", "2", "3", "4", "5"}, integer = true)
enum StarRating {
    ONE, TWO, THREE, FOUR, FIVE
}

The values in the annotation are assigned to the enum values in order.

Once you've annotated your enum like this, you can use it as the type of a field just like in the ORM post.

Previous
Previous

Useful aliases in the Blackboard Dev VM

Next
Next

Disabling Blackboard's SQL Query Cache for Development