Created
April 19, 2011 19:27
-
-
Save berngp/929364 to your computer and use it in GitHub Desktop.
Trying to simplify access to a legacy Lookup Table
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Usage sample | |
SomeLegacyStatus active = SomeLegacyStatus.ACTIVE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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