Skip to content

Instantly share code, notes, and snippets.

@berngp
Created April 19, 2011 19:27
Show Gist options
  • Save berngp/929364 to your computer and use it in GitHub Desktop.
Save berngp/929364 to your computer and use it in GitHub Desktop.
Trying to simplify access to a legacy Lookup Table
//Usage sample
SomeLegacyStatus active = SomeLegacyStatus.ACTIVE
package org.some.package
class SomeLegacyStatus {
enum Status {
NONE,
ACTIVE,
PENDING,
SUSPENDED,
BANNED,
INACTIVE,
DEACTIVATED
}
static {
addEnumGettersToMetaClass()
}
/** */
String name
/** */
String desc
static constraints = {
name(blank: false, size: 1..64)
desc(nullable: true, size: 0..255)
}
static mapping = {
table 'status_lookup'
version false
id generator: 'assigned', column: 'status_lookup_id'
name column: 'status_lookup_name'
desc column: 'status_lookup_desc'
cache usage: 'read-only'
}
private static addEnumGettersToMetaClass() {
for (Status status: SomeLegacyStatus.Status.enumConstants) {
SomeLegacyStatus.metaClass.static."get${status.name()}" = {
SomeLegacyStatus.read(status.ordinal())
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment