other register

Thursday, April 29, 2010

Convert GroovyRowResult into Domain Class

There are chances that you might want to convert a GroovyRowResult into a domain class. For example, in the clustered environment, certain class needs to "implments Serializable" but if there is GroovyRowResult is in the class, then it will throw as GroovyRowResult can not be serialized.

The workaround is simply create a dummy domain class with properties match the result set fields. It is case sensitive.

If it is oracle database, then it is case sensitive.

GroovyRowResult row = connection.firstRow("select user.firstname as \"firstname\"......")
def person = new Peson (row)

Monday, April 19, 2010

Number format

When comes to custom number formatting, you might have a user case like room number 001, 075. How to format this:

NumberFormat formatter = new DecimalFormat("000")
def s
s = formatter.format(1) // the result will be 001
s = formatter.format(75) // the result will be 075